‫Our next step is to create architecture for our model, we will be using almost the same architecture.
‫We will be using sequential keras api.
‫And we will be adding four con layer.
‫We will start with 32 filters.
‫Then 64 filters.
‫Then 128 filters.
‫Then again, 128 filters.
‫And after each of this con layer, we will.
‫We are also applying pooling layer.
‫And as always, the activation function is the RELU for all these layers.
‫And after that, this time, we are also applying dropout layer.
‫So what this layer will do is it will deactivate 50 percent of neurons during each epoch.
‫It will randomly pick 50 percent of our neurons and it will deactivate them.
‫And we will be training model with the remaining 50 percent of neurons during each epoch.
‫So for each epoch, we are activating randomly 50 percent of our total neurons.
‫We are using dropout here because dropout is a very effective layer to avoid overfitting in our model
‫.
‫So this is our a model architecture.
‫Now, the next step is to compile
‫For lost function, we will be using binary cross entropy.
‫Since we have two different classes.
‫If you remember earlier in mnist, we had 10 different classes and there we were using sparce categorical
‫Cross entropy.
‫But here, since we have one the two classes, we are using binary Cross entropy for optimizer
‫.
‫We are using rms prop with learning rate of zero point zero zero one.
‫And since this is a classification problem, we are calculating accuracy metrics as well.
‫The next step is to train our model.
‫Since we are taking our data from train generator, we have to use fit generator to fit our model.
‫So we'll be using model dot fit generator, then train generator
‫This the data generator, which will continuously generate data in the batches of 32 images.
‫And then here we are using steps per Epoch as hundred.
‫Earlier in our last model, we were using a batch size of 20 steps.
‫Per Epoch as hundred because we only had 2000 images
‫For training purposes.
‫But this time, since we are randomly generating images from this transformation, we can use more than
‫2000 images as well.
‫This time we are using a batch size of 32 and steps per epoch as hundred.
‫So overall, in each epoch we are feeding around three thousand two hundred images.
‫The number of epochs this time is hundred.
‫And similarly, we will use validation generator to get the validation data.
‫Now, since we are running this four hundred epochs, if you are using a system with less than 16
‫Gb of RAM and without any graphics card, it may take up to one and half to two hours to create
‫this model.
‫That's why I have already train this model and I have the data of over hundred epochs here.
‫You can see that our validation accuracy is increasing with each epoch and at around ninety two hundred
‫Epoch
‫We are getting a validation accuracy between 82 to 84 percent and.
‫A training accuracy of around 84 to 85 percent
‫So if you compare in our last model, we were getting training accuracy of around 95 to 98 percent
‫and a significantly lower validation accuracy of our own 79 percent.
‫In this model, we are getting almost same validation and our training accuracy of around 84 percent.
‫So you can say that with our image pre processing and creating dummy images we have treated over fitting
‫in our model
‫After running this, you can save your model by model dot save method and lets just create this graph
‫to see how our validation accuracy and training accuracy are changing with each epoch.
‫So this orange and red lines are for accuracy.
‫This orange line is for training accuracy and red line is for validation accuracy.
‫You can see here that the validation accuracy is more than 80 percent as well as the training.
‫Accuracy is also more than 80 percent.
‫And both are moving together.
‫So there are no evidence of overfitting.
‫In our model
‫And this is still increasing.
‫So if you run it for, say, 40 or 50 more epochs, the validation accuracy may reach around 85, 86
‫percent as well.
‫So that's all for this video.
‫We see that by augmenting our initial dataset, by applying sheer rotation, width shift, height, shift
‫And flips
‫We can treat overfitting fitting in our data and we can get a higher valuation accuracy from our model.
‫Thank you.