Hi and welcome to our first regularisation lesson.
So in this lesson, what we're going to do, we're going to train a model on the fashion amnesty to
set.
Firstly, without any regularization.
So let's begin to open this up based on the book here.
I already have it opened.
And this opens the lesson file.
So this is where the fashionista the F.A. dataset looks like these are some of the some of the classes
inside of it.
It's 10 classes.
It basically incorporates 10 classes of clothing items.
I don't know them.
All right.
No, actually, I should have probably prepped that for the lesson, but as you can see, you can visualize
them here.
They are things like dresses, sweaters, shoes, slippers, T-shirts, shirts is another category,
I believe, so that's basically what we're going to do.
It's it's called fashion fashionista, mainly because it's in the same style and format as the original
amnesty to said which you've seen in the previous lessons.
There are grayscale images and there are 28 by 28 pixels, and they're also the exact same number of
classes is 50 tells sorry, 60000 training data, set data images and 10000 test data images.
So actually, I'm stupid enough.
I'm stupid.
Here are the classes here for the fashion this that I told you I didn't remember, and they're actually
right here in this code.
So let's begin loading our dataset.
So to load this dataset?
You've seen how we loaded the amnesty to set with cameras.
Yes, from TensorFlow Dot Keras Dot datasets, and you import the dataset you want.
Here we don't.
We're downloading the fashion amnesty, so we have fashion, amnesty or load data, and it puts the
training data, training labels, test data test labels into these variables right here.
And this is something that they don't provided for us.
We just we basically have to find this online and maybe the data set right up or read me file that describes
what the classes are and the ordering of this of these classes are quite important because whenever
you return probability, let's say the max probability of this image is class two.
It needs to correspond to the second element in this area.
So this would be class would be index zero index one index two.
So the order has to be important.
The order corresponds to what class it is.
So we have a T-shirt, trouser pullover, dress code issued sneaker bag and ankle boots.
Apparently, those are the ten classes of clothing.
Who knew?
Anyway, so let's check to see if we're using yoga for you.
But let me just run this block of code before it takes a little while because you see it has to connect
to a virtual machine in the cloud somewhere and then actually can see the specs of that machine right
here.
How much RAM and how this we're using.
And it tells us we're actually all using the GPU back end to his.
That's a quick way to check as opposed to checking it like this, which would have what I've shown you
guys before.
This is apparently new because I don't remember seeing this information when you hover over the RAM
and disk icons appear.
So now that we have downloadable data set, let's just we don't need to do this to be fair.
But let's just check to make sure TensorFlow is using a CPU GPU and it is, and it displays the name
of the CPU.
This is a Tesla P 100, which is a fairly decent GPU.
By the way, if you're using club free, you might get a different GPU.
You might get one of the key A-series chips, which are a bit slower.
I'm paying $10 a month for Color Pro, which I find to be a steal of a deal.
That's quite good value for money because because these GPUs are basically a roughly the speed of like
the Nvidia's like a 20 60 or 30 60 CPU plus to come with 16GB of RAM.
So that's quite quite good.
So we can just print out like we've done before.
Just some specs.
And if our data so we get samples, how many test samples, for example, the the size.
So it's always good to do this, always good to just inspect the leadership, to make sure it's what
you expected.
Because many times I've seen guys and myself included load data and we don't actually load to write
data or sometimes our test data set is blank because we specified a bad path somewhere.
So now let's visualize some of the sample data here, which I mean, basically, you've seen that before
appear, but in order to visualize it with the class cinema and to do that, all we do, we just loop
true from one to 51.
They focus because this subplot has and started the index of one.
We just load the images here.
So we describe going from one to fifty one to first five basically for this fifty one images technically.
But we.
We're not looking into this image because we're starting at one and just putting it into subplots with
my plot Libya.
So let's run this and we can see our categories and example images here.
So this is pretty cool.
This is also very useful because it's good to understand how your dataset was labeled because a lot
of times errors can be found in the labeling by just simply inspecting it beforehand.
It's always a good practice.
It's something that we should all be doing.
I don't always do it sometimes, and it comes back to haunt me.
So make sure you do this next, you know, the data preprocessing that we have to do for us.
So what do we do with this?
Get our rows and columns of this 28 by 28 and we stick it into the input shape because we use that as
a variable and we pass it to a Keros sequential model is when we're building it next.
Let's run that next.
We have to do all one hot encoding, which you've understood from before.
So when something is like Level four, label five, we just we have these 10 rows here and they're all
zeros except the Fool, except the five, except to accept the six.
So you can you can understand that it's quite simple, and we do that by using the two categorical function
that we've loaded here.
We've seen all this before, which is why I'm going a bit fast.
Apologies if you if you missed or forgot the other lesson you can always go back to.
Let's see this one here.
We explain it in quite a bit of detail.
So now let's move on to building our model.
So again, I'm not going to go through all the steps that we did previously where I showed you how to
set the kernel size and set rlu and all those things you've seen it before.
And here's some extra notes just in case you forgot.
So let's go ahead and build this model.
And you can see we just have to import the layers beforehand right up here.
We also import SD, which is the stochastic gradient descent optimizer that we'll be using.
So you may have noticed if you have a good memory that this is the same CNN that we tried amnesty on.
So in theory, it does seem CNN architecture should work well for the fashion this dataset because it's
28 by 28 and it's grayscale images as well.
However, that theory may not always hold, but let's find out.
And now we're ready to compile our model.
So we do that to print out the parameters you can see it's the same as we saw previously, and now we're
ready to train our model.
So let's train this model now.
It's going to take twenty one seconds for e-book and we're training it for 15 epochs here.
So this will take a little while.
But let's do it, and let's fast forward it to the end when it's complete.
OK, there we go.
So you can see it's finished training and accuracy is actually pretty decent.
However, I want you to note something here that's quite important.
You can see that volition accuracy peaked quite early on.
It picked up maybe at the 7th epoch and afterward.
What do we see?
You can see it's actually slightly decreasing, actually peaked here, but then slightly decreased here.
And look at the training accuracy as you can.
You can see the training actually got better and better every time, every for every epoch.
This is an example of overfitting.
You can see it's overfitting no to the training data.
It's getting quite good.
However, performance on the validation accuracy isn't that great.
So this would be a very good time to if we were training for longer epochs, but probably use early
stopping, at least stopping if we start really stopping at five.
Meaning that if the validation lost, doesn't evolution, accuracy or loss, whichever one we want to
monitor, doesn't decrease for five consecutive epochs, then we stop training.
So you can see here it didn't basically increase by much all this way here.
So most likely, an early stopping algorithm would probably stop around here or here somewhere.
So that brings us to the end of this lesson.
I hope you enjoyed it.
It should have served as a good recap on how to train CNN on a different dataset.
This time now we're using the fashionista as opposed to the eminence dataset.
And what we'll do next.
Note the performance here we get roughly 90 percent performance after 15 epochs.
What we're going to do?
We're going to introduce a few of the regularization techniques and we'll assess its performance and
compare it.
So I'll see you in the next lesson.
Thank you.