In the section on model training.
We'll just simply start by, um, calling our fit method while specifying the train data set, the validation
data set number of epochs, and the uh, set variables to be one.
So let's run this and then see what we obtain.
We get an error sequential um or input zero of layer sequential is incompatible with the layer expected
um known by 224 by 224 by three.
But the fine shape was 224 by two, 24 by three.
So, um, this tells us that we our inputs are what we've gotten here in our train data set is unmatched.
So let's get back and batch our data set.
So here already we had carry out the splitting.
And then we had our train data set.
Then we had this mapping.
So from here we could do batch uh and we specify the batch size.
Here we specify the batch size.
There we go.
So let's include batch size right here we have batch size.
And we say we want to have 32.
So that's it for the train data set.
Now let's repeat the same for the validation and then the testing.
So well let's, let's do let's carry out shuffling.
We have um before batching we'll shuffle.
So we shuffle and then we specify uh buffer size of eight.
Um reshuffle.
Which reshuffle.
Um each iteration set to true.
There we go.
We have the batch.
And then we also prefetch.
So here we have um prefetch prefetch.
And then we have TensorFlow data um auto tune.
So here we have auto tune okay.
So that's it for the train data set.
We could now repeat this for the validation.
So let's have that paste that.
Now we have Val take that off.
And here we have test.
So we have Val we have test.
And there we go.
So let's run that again and see what we obtain.
So here we have batch size not defined.
Let's run that again.
And that should be fine.
So we run this.
And then you see that we have um an output now which has been bashed.
So we should have the batch um dimension.
So that's it right there.
And you see we have 32 labels now.
So let's get back and continue with the training.
So let's run this again.
Now this should be fine.
We get in this other error logics and labels must have the same shape.
So we received um this output batch by two instead of batch by one.
And this makes sense because the way we created our outputs or if you look at our outputs we had here,
if you look at this output labels, we have just for each and every sample, we have just one output.
So um, it's not um shaped batch by two.
So let's get back here um in our model and modify this.
So instead of two we should have one.
So if we are parasitized parasitized is zero um uninfected uninfected is one.
So initially we were having two like this.
We're supposing that the first we're supposing that we would have um if it's parasitized then we would
have one and then zero.
And then if it's uninfected, then we would have um, zero and then one.
But we could simply just take all this off and just say if it's parasitized, we have zero.
And then if it's uninfected we have one.
So now we have an output of one unit instead of two.
So let's take all this off, um, recompile our model and that should be fine.
You could see now that our training has started, you could change the runtime, make sure you're using
a GPU, which is quite slow because we're using the CPU.
So if we take, um, the T4, that's it.
We're going to have to restart the runtime.
So let's go ahead and restart.
Let's run this again and uh go ahead and restart the training.
So let's have that.
We recompile and we start the training.
So we've restarted the training.
And as you could see we have this loss and validation loss values.
The training is quite slow with respect to how the loss values are dropping.
And so we could get back here and make some um adjustments.
Firstly we would use the ReLU activation instead of the sigmoid.
So we'll replace all this with relus.
Take this off and we have ReLU.
And then also uh here in this final layer we are going to leave this at sigmoid because we want our
outputs to, to lie between 0 and 1.
Then we'll modify this kernel sizes.
We'll go from 5 to 3.
And then we shall include batch normalization.
So just after the conv layer we have batch normalization.
And then just after this let's add a comma.
Just after this here we have batch normalization.
There we go.
We have batch normalization.
And we just we just copy this and paste out here.
So after the dense layer we would have batch norm take that off.
After this dense we also have batch norm.
So we including the batch normalization such that uh so that we could recenter and rescale the different
um features we generating from our layers.
So let's go ahead and stop the training and then recompile our model.
So we have that.
We recompile.
And let's just copy this here and paste out here and run that again.
Now just by looking at, um, the first two epochs, we see clearly that our model's loss now drops
much faster as compared to, uh, what we had previously.
So that's it.
You see that, um, the batch normalization plays a great role in stabilizing our training and hence
making it, uh, much faster.
So we have this we will now add the metric.
So metrics we will have binary accuracy.
Binary accuracy metric.
Uh make sure you import this.
So we have binary accuracy.
And the way accuracy works is quite simple.
So here we have or let's suppose that we have 100 samples.
So we have 100 samples.
Or let's say we have one that um samples in our test set.
Then if our model predicts correctly let's say 80 samples and doesn't correct or doesn't correctly predict
the remaining 20, then our accuracy is going to be 0.8 or 80%.
So it's just that simple and straightforward.
So that's what we're going to have when we um include this binary accuracy metric right here.
So you can see this is this is drop the vowel.
Uh loss starts increasing slightly.
Anyway let's just stop this and then we restart the training.
So let's take this off.
Um there we go.
Let's, let's, um, recompile, let's recompile, and then we restart the training with the training
are complete.
You could see here our model loss which drops.
And we also have this, uh, model accuracy which goes right up to, um, 0.95.
So, um, our model now performs much better with the batch normalization.
And we have this 95% accuracy, um, model.