Hello my friends.
Welcome back to this implementation and mostly welcome to part three
training, the CNN. In the previous tutorial,
we built the brain, which contained the eyes of the eye.
You know, thanks to the convolutional layers.
And now we're going to make the brain smart with that
training of the CNN on all our training set images.
And at the same time, as you see, we're going to evaluate
our same model on the test set over the epochs.
You know, we're going to train our CNN over 25 epochs.
And at each epoch
we'll actually see how our model is performing on our test set images.
So this is a different kind of training as what we before because we always
used to separate the training and the evaluation.
But here this will happen at the same time.
That's because we're doing some specific application which is computer vision.
All right.
Are you ready?
Let's do this.
Let's start with the first step compiling the CNN.
All right.
So in a new code cell we're going to compile the CNN.
Meaning we're going to connect it to an up to miser a loss function.
And some metrics.
And well you know here once again we're doing binary classification.
And so very simply we're going to compile our CNN
exactly the same way as how we build our A.
And then in the previous section,
because indeed we're going to choose once again an Adam optimizer
to, you know, perform stochastic gradient descent to update the weights
in order to reduce the loss error between the predictions and the target.
Then we're going to choose the same loss.
You know, the binary cross-entropy loss once again
because we're doing executives same task binary classification.
And then same for the metrics.
We're going to choose the accuracy metrics because that's, you know,
the most relevant way to measure the performance
of a classification model, which is exactly the case of our CNN.
And therefore, to compile the CNN.
Well, it's going to be a piece of cake,
because indeed we're going to do exactly the same as before.
So we're going to start by taking our CNN,
from which we're going to call the compile method,
which will take as inputs well first or up to miser,
which will choose to be the Adam optimizer.
Then the loss function, which will choose to be the binary
cross entropy.
All right.
And finally final argument the metrics.
We will choose only one.
But remember we have the choice to take several of them.
But just accuracy is fine.
And therefore in these pair of square brackets we're going to input in quotes.
Well that's accuracy.
And done.
This compiles successfully the CNN to the optimizer
the loss function and the metric.
So exactly the same as before.
However now to train the CNN on the training set
and evaluating it at the same time on the test set.
Well it will not be exactly the same as before, but
once again, very, very similar.
Let's check this out.
Let's create a new code cell.
And now you can actually guess the first two steps.
They're always the same.
The first step is to take of course our CNN from which.
And that's the second step.
What method do we need to call here.
Well once again this never changes.
This is of course to fit method, the fit method,
which as always will train the CNN on the training set.
Okay.
So this time what are going to be the inputs.
Well the first input is always the same.
It's going to be
of course the set, you know, the data set on which you're going to train
your model here, the CNN and that's of course the training set.
And the name of the parameter for that is simply x
and therefore will specify x to be, you know, our training set,
that exact same training set which we created in part one.
You know right here that training set, that training set to which we applied
this image, data generated to to indeed perform image augmentation.
All right.
That training set.
That's the first input of our parameter in this fit method
okay then next parameter.
All right.
So the next parameter is this time you know the difference.
The difference with what we did before.
So it has to do of course with the fact that we're not only training the CNN
on the training set, but also evaluating it at the same time on the test set.
And that second parameter corresponds exactly to this.
We have to specify here the validation data.
That's the name of the parameter.
But that's of course the set on which we want to evaluate our CNN.
And as of course the test set that will be the value of the parameter.
But the name of that parameter is, as I just said,
validation underscore data.
And this is equal, of course, to the test set.
Once again, that exact same test set which we created here in part
one when preprocessing it to set this one to which of course
no transformation was applied, only features killing.
Okay. So test set good.
And now we have one final argument, which is of course
you can totally guess what it is, right?
This is the inevitable argument when training a deep neural network.
I'm talking of course about the epochs parameter, which is the number of epochs,
and well, you know, to justify to you which number I chose.
Well, I actually start with ten epochs.
And I noticed that the accuracy was not converging.
So then I tried with 15 epochs,
because you're going to see that one epoch is actually pretty slow.
You know, it's actually a bit long.
I mean, much longer than the epochs in the training of our previous neural
network, you know?
And so I started with ten.
It was not enough then 15 still not enough, you know, still not converging.
And then 25 and 25 was perfect.
I had an accuracy that pretty much converged
not only on the training set, but also on the test set, you'll see.
So for the number of epochs here, we're going to choose 25.
Feel free to increase it if you have time.
You know, if you want to let your computer run for now.
More with 25 epochs here, it will be fine.
It will just take 10 to 15 minutes.
So that will be all good.
We'll get our results pretty fast.
All right. And well actually that's it.
That's only what we need to train our CNN
on the training set while evaluating it on the test set.
So perfect.
We smashed by three.
And we can now already move on to part four where
we're going to make our single prediction, which I remind will consist
of deploying our model on the two images of the single prediction
folder, this one for which, of course, our model will have to recognize
that there is a dog, and this one where our model will have to recognize
there is a cat.
So let's hope that it is right,
but we won't have the predictions in the next tutorial.
We will have them in the one after that.
Because remember, we're going to run our implementation
from Jupyter Notebook because we can do it in Google Colab.
The data set is to be all right.
So well, as soon as you're ready for part four, let's do this together.
And until then, enjoy machine learning.