In this lecture, we you're going to improve our previous results using some of the techniques we just
learned about, including data augmentation and batch normalization.
This lecture is going to walk you through a prepared CoLab notebook, although a very good exercise,
which I always recommend is once you know how this is done, to try and recreate it yourself with as
few references as possible.
As usual, you can look at the title of the notebook to determine what notebook we are currently looking
at.
One important feature of this notebook is that it has many options for you to choose from.
We've added quite a few things since the last script.
So as an exercise, one thing you want to try is experiment with what happens if only some of these
options are used and not others.
For example, check the results when we don't have data augmentation, check the results when we don't
have BATCHELLER, check the results if we remove one layer of convolutions.
This is part of the process of improving your results and hyper parameter optimization.
OK, so at the top, you'll see that when we load in the data set, we specify a transforms that compose
instead of just transforms that to Tenzer.
This is a list of things I tried.
And you definitely want to play around with these to see if you can improve the results.
There are tons of things here and each of these things has its own parameters.
So test them out and see what happens.
So pretty much everything in this script is the same as the previous C14 script, so let's just scroll
down to where we build the model.
And so here we're just inspecting the data.
Here's the data loader.
All right, so here's what we define, the model.
The first thing you'll see is that I've taken away the striated convolutions in this scenario for these
small images.
Normal convolution followed by maximally actually seems to work better.
But also, we're taking inspiration from the VG network, where they do multiple convolution layers
before they do pooling.
Now Viji is designed for much larger images.
So it's also a much larger network.
They actually have five groups of convolutions and pullings, and each group has multiple convolutions,
too, in the first couple layers and three in the following layers.
So that's another thing we've done differently.
First convolution with no strides and now multiple convolutions before doing pooling.
Initially, you might want to try only this by itself to see how it works.
The next thing you can see that we've added is a backchannel and later after every convolution, not
much to say here since we just described how and why it works.
But as I mentioned before, because I added so many things to the script, you want to turn some off
and turn them on at different combinations so you can see for yourself the effect each of them has.
You'll notice that for these convolutions I've used, padding equals one.
This is because I wanted to show you how to achieve same padding such that the output image is always
equal in size to the input image.
Basically, we can take the formula from the PI torture documentation and plug in values for the kernel
size in stride.
Then we use the fact that we want each out to be equal to H in and then we can solve for P.
In this case I get P equals one.
So that means if we want the same mode convolution then we have to use padding equals one.
This makes convolutional arithmetic a little easier for us after each convolution, the size of the
image remains the same.
And after the Max P'Pool, the image is downsampled by two.
So basically, you can take 32 and divide it by two, three times.
We end up with four, so the size of the input of the first linear layer is 128 times four times four.
Finally, we have our final dense layers with the drop out, which is the same as before.
All right, so let's scroll down so we instantiate the model, move the model to the GPU, create the
loss and optimizer to batch gradient descent.
Observe our losses, so these epochs take a little longer, around 15 seconds, and also notice that
we did 80 epochs instead of just 15.
All right, so here's the latest iteration, something you may have noticed in the previous script is
that it had some overfitting and you can see here that the overfitting effect is less.
So let's look at the accuracy.
And you can see that we reach much higher accuracy than before, so now we get about 94 percent on the
transfer and 87 percent on the test said.
Next, let's look at the confusion matrix.
All right, so this is encouraging because a lot of these off diagonal numbers are a lot smaller than
before.
You'll notice that a few of them are still quite high, such as when we confuse threes and fives, which
are cats and dogs.
I think this is the most difficult to discriminate in this data set because in a 32 by 32 image, cats
and dogs are going to look extremely similar.
We also still see a lot of guns and knives being confused, which correspond to automobiles and trucks.
Again, that seems to make a lot of sense.
OK, so let's take a look at a few misclassified samples.
So here is a cat predicted as a truck that doesn't really make sense.
Here's a truck predicted as an automobile.
I think we can agree that that might be a truck.
Here's a cat predicted as a horse, we can kind of see how that might be a horse or a dog.
Here's a frog predicted as a cat.
So this frog is kind of in the same poses a cat might stand in.
Is a horse predicted as a deer?
So, again, we can kind of see why that might be.
Here's a truck predicted as a ship.
Personally, I don't think it looks like anything.
Here's an automobile predicted as an airplane.
So that seems kind of wrong.
It looks like a car.
Here's a horse predicted as a deer that seems to make sense.
Is a dog protected as a horse, that kind of makes sense.
So are these four legged animals are very hard to distinguish, at least for a neural network.
Here's a bird predicted as a horse.
If we look closely, it kind of looks like a bird.
We can definitely tell it looks more like a bird than a horse, but if you weren't told the label,
you might not even know what it is.
So I think it's clear that while we improve the performance of the neural network, it still doesn't
reach human level image recognition capability.
One conclusion you can draw from this lecture could be summarized as bigger is better.
We've seen that by virtually adding a lot more data to our data set and using a much larger neural network
than what we've seen so far in this course, we were able to significantly improve the performance of
our network on this data set.
This is a very common theme and deep learning, and it's often surprising because it seems so simple.
The fact that it's so simple actually makes it seem less profound than it really is.
Some people believe that instead of better algorithms, we just need to scale up our data and our models
and our compute.
And this by itself will lead to breakthroughs in AI.
As noted, our final known network in this lecture is much larger than what we've worked with so far
in general, CNN's can get pretty deep, even hundreds of layers.
This is a big jump from the last section when all we had was just two dense layers at this scale.
It helps to be able to see a summary of your model in some way.
And so the torture summary library allows you to do just that by calling the summary function and passing
in the model and input size, you get a table that shows every layer in your model, along with some
other useful information, such as the output shape and the number of parameters in each layer.
So first, we have our initial kofta delayer, which has 896 parameters, and it's Alpe shape is 32
by 32 by 32.
This is because we use the same mode convolution.
We can do a quick sanity check to make sure that the number of parameters makes sense.
Our filter is three by three by three by 32.
That's because it has three input channels.
Its size is three by three and it has 32 output channels.
And so three times, three times, three times 32 is 864.
Then we have the bias term, which is a vector of size 32.
So 864 plus 32 is 896, which checks out.
If we scroll down to the end, we can see the total number of parameters in the model for this neural
network, it's about two point four million.
So, again, a big jump from what we were working with previously.