Hi and welcome back.
Now let's take a look at using PyTorch to train a model on the fashion this data set.
Firstly, without regularization, so let's close these previous notebooks and open up this notebook
file.
So there we go.
So what we're going to do?
We're going to do the same thing we did in the first part of its lesson, which was this one here where
we basically just train trino model.
So we just load or packages before.
And we were training on model on the fashion amnesty to set which we import using to watch vision data
sets, thought fashion gymnast.
And you can specify you want true for the training dataset.
Such training all forms for the test dataset.
And it's quickly downloaded here.
So we have that already next to we create our train and test data, Lueders.
We set the classes as well here.
We print the ships here just to check and make sure the dataset loaded correctly.
It's always good to visualize some data here.
I'm going quite fast because we would have done this in previous lessons before.
There's nothing new.
I'm teaching you right now, but if you just want to, if you want me to slow down, just request me
to do it and I can remake these videos.
So now let's move on to putting the images, visualizing the classes with torch vision.
So we'll quickly do that here, and you would notice that it's the foreground, the basically the binaries
that show has been inverted.
And that's because this is actually how the classes look.
They don't look like this.
We just cleaned it up for using degree on the score, which does the reverse mapping of the it's basically
a binaries invasion.
It does here.
And this one is the actual images here.
So you can see it's quite similar to the amnesty to set.
So now let's take a look at building and treating a simple CNN with no regularization, so this network
should be quite familiar to you.
It's what we trained our amnesty to set on in the previous lesson.
So let's created there, and now let's define our loss and optimization functions.
So we've done that there.
Now let's try this.
Let's try this for 10 epochs.
Actually, let's create 15 epochs while we're at it, and I won't go through this code because it's
the exact same code we went through in the first lesson of the deep learning section of this course.
So let's begin training this here.
This might take a little while so you can restart the video when it's finished.
Hi, so welcome back.
So our model has finished completed training right now, and you can see we've finished the eighteen
hundred when it's finished here.
That's a number of many batches and we get the accuracy out after each hundred mini batch iterations.
So you can take a look the accuracy here.
However, this isn't the final accuracy.
Let's just stop this loop, and let's take a look at what our final model accuracy is.
And the reason why this isn't the final model accuracy, because this is just the accuracy of the test
batch at that point in time, it's going to be very similar to this.
However, it's going to be more like an average of all of these together.
And you can see when you more or less average all of these.
Together, we get a final accuracy accuracy score to be ninety one point one four percent.
So that's pretty good.
That's actually remarkably good better than a Keros model as well.
Let's take a look at our training plots now, and you can see things are they went as expected, may
have had a slight dip at the end and the loss was continuously going down.
So in this case, you can't actually see this model is over overfitting at this point in time.
However, it does seem to be like slightly going down, so you may have wanted to introduce some early
stopping around that point here.
So anyway, let's see if our model weights and what I'm going to demo, which, you know, is some data
augmentation.
So what I'm going to demo to you now, which I didn't do in the Keros lesson, however, I just wanted
to show you guys what the actual data transformations do when you add these augmentation parameters.
And so what we can do.
Remember, we have already have this data or transform here that we've put into this list right here
with all these different transforms.
We're doing some random assigned color to I'm not going to do this because it's a little bit hard to
see anyway.
Visualization, but this is going to do some random horizontal flips, random rotation and then John,
some degree of skill.
So let's take a look at what that looks like.
So we create a small little function here.
This function is basically takes a parameter which we have a d for this six and creates six subplots
in a row so that we can actually see the six different random augmentations that will apply to one single
image know dataset.
So we access that image here.
Converting it to NumPy Remedies Transit, that's from our batch.
Yeah, and then we have the data that.
No, I let's pull it out here, and we use the power of Pill
Pillow is a next library that actually allows us to do image processing.
It's quite nice, actually, and we use it from time to time for some of the with some of the utility
functions, it makes things, makes the code more readable, often has good, some good tools.
We won't spend too much time using pill.
We're talking about pill, but every now and then you will see it mentioned in the code.
So all of this discussion with you there, what this does here, this just converts it into.
Instead of using the OpenCV GB conversion and all of those things, sometimes we can just use pill.
It loads it as a RGV of this case as a grayscale, so it doesn't matter, but it just converted into
a pill format image, which we can easily visualize here.
So let's view this now, and you can see this is exactly what happens in a training loop.
You can see this image here.
This is probably one of the original images, and although it's not, they're all going to be manipulated
somehow.
And then so you can see the different manipulations of the image as it passes through.
You can see this one has been shifted down.
This one looks like it's slightly rotated.
This one flipped and it rotated a bit.
So you can see that the images are never consistently the same.
This is good.
This helps generalization.
So but we didn't use it in this training loop here.
We didn't.
We didn't use any of these augmentations.
We'll talk about that in the next lesson where I actually talk more about these transformations, how
they're done.
Just remember that that's data augmentation is a regularization method that works very well with image
datasets.
So I'll stop now and I'll see you in the next lesson.
Thank you.