In this lecture, we are going to look at a CoLab notebook that does image classification using PI talks
with the convolutional neural network on the 10 data dataset.
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.
All right, so there are a few major differences at the start of this code.
First, you can see that the imports are almost the same as before, except that we also import towards
that functional.
You'll see how that will be used very shortly.
I'd like to introduce these new things when there's not much else going on so that you can learn about
different ways of doing the same thing, which could be useful in the future.
Next, you'll notice that we're importing the C14 data set, which is a color image data set and is
even more difficult than fashion.
Most, however, since the data set is included in talk vision, loaning it in is just as easy as it
was for the previous two data sets.
Next, let's look at the raw data by calling the data attribute, as you can see, it's slightly different
from amnesty and fashion amnesty, which return to torture Tensas.
Instead, C14 is stored as a regular Nampara.
And the tape is using a.
Next, let's check the shape of the training data, we can see that we have 50000 training samples in
each training sample is a 32 by 32 color image.
Next, let's check the targets.
This is, again, different from amnesty.
Instead of being stored as a Tenzer, it's stored as a list.
Next, let's get the number of classes K by adding all the targets to a set and then taking the length
of that set of.
Next, let's create our data load of objects, which is the same as how we did it before.
As mentioned previously, here's a good opportunity to look at one of the quirks of PI talk.
If we look at the shape of the data yielded by our data loader, we see something interesting.
The batch that's yielded by the data loader has shaped one by three by 32 by 32.
This should seem strange to you because now the color channel comes before the spatial dimensions instead
of after Piter, which hides this detail from you by getting you to use data loaders and special data
set functions.
Next, let's look at our CNN custom model class.
You'll notice that this is built a little differently from our previous CNN.
What I'm trying to do is show you different ways of accomplishing the same thing.
One thing that's different is the number of input color channels, which is now three instead of one
since our data is in color.
Next, you'll notice that in the constructor, I've only defined layers that involve parameters, so
there are no real you activations.
So where did they go?
Well, remember that none of these layers are actually called until we get to the forward function.
So let's look at the forward function, we can see here that instead of treating the rellenos as module's
or layer's, we can treat them like functions which can be accessed from torture that functional.
That's the new thing we imported earlier, if you recall.
In fact, dropout can be applied this way as well.
You can also see here an alternative way of using the view function, which, as you recall, flattens
the data.
Instead of putting the minus one in the last dimension, we can put minus one in the first dimension
and then specify the second dimension explicitly.
This isn't any extra work for us because we had to calculate this value anyway inside the constructor.
So you can see 128 times, three times three, both in the constructor and in the forward function.
All right, so next is a bunch of stuff we've seen before, so I'm going to skip over it a lot faster.
So we instantiate our model, we move the model to the GPU, we create a loss in optimizer.
We do our boccherini at the send loop.
And we can see that our model trains quite fast at around six or seven seconds per epoch.
If we look at the per iteration, it seems to look OK.
Next, we check the model accuracy.
So we get about 75 percent on the train set and a 66 percent on the test set.
Of course, this is going to vary depending on several different factors, so when you run this, you
might get a slightly different answer.
But clearly, this is a much more difficult data set than most or fashion missed.
Next, we look at the confusion matrix.
In fact, there are so many things that we predict wrong that it's kind of difficult to look at, we
can see that we confuse one and nine a lot.
One corresponds to automobile and nine corresponds to truck.
This makes sense and fits our intuition.
We can see that three and five get confused a lot.
Three corresponds to CAT and five corresponds to a dog.
That makes sense, especially when you consider that these are very small pictures.
We can also see that zero and eight get confused, the lot zero corresponds to airplane and eight corresponds
to ship, that makes less sense and perhaps it could simply point to the fact that our model is just
not powerful enough.
So if we scroll down to the bottom and we look at some misclassified samples, maybe we can make sense
of these results.
So here's a horse predicted as an airplane that does not make sense at all.
Here's a bird predicted as a deer, that kind of makes sense.
Is a truck protected as an automobile, that kind of makes sense.
He was a cat protected as a bird, looks like a small blob, so that kind of makes sense.
Here's a frog predicted as a deer that doesn't really make sense.
Here's a dog predicted as a cat, that kind of makes sense.
All right, so it seems that a lot of these wrong predictions, the neural network should be able to
get right.
So in the coming lectures, we're going to see how we can improve this model.