In the last video we use data augmentation techniques to increase our validation accuracy to a 2 to
3 percent in this video.
We will use DG sixteen model architecture to further increase our validation accuracy about 90 percent
vs 60 was the runner up of 2014 i.e. unless we are C competition.
The problem is statement of that competition was to categorize millions of pictures and two thousand
different categories the pictures but of animals humans etc. and the categories were of different animal
species and many other so the problem we are trying to solve.
You can consider it as a subset of or is null two thousand forty eight unless VRC completion data
as we discuss in order to be lectured we can use conventional part of this three grain model architectures
and other problems
these models consist of two parts convolution base and then a fully connected neural network base the
constitutional base is used to identify features from the images and then the fully connected neural
base is used to classify those features
so for any similar kind of problem we can easily use retrain on the delusional beast to extract features
from our images and then we can all three layers of fully connected neural network to classify the desert
of this can be says in this video.
The idea is same we will use the corn base of VDI 16 model and then we will add one fully connected
layer and one output layer to classify the features extracted from what we do this extreme on base
so let the sun.
For us we will be creating two object green gender data and validation units.
We have already use the same generators in our previous cases also.
So we are using the same setting we are using these scaling off one by 255 to convert our odyssey we
will lose from 0 to 255 2 0 2 1.
Then we have rotation rotation which chip a chair shearing zoom range and horizontal flip to create
dummy augmented data and our target size of images is 150 by 150.
And we are using a bed size of 20.
We have already discussed this in detail in our previous videos.
So we are not going to discuss this here just like in our previous guests.
We have our own cool images for training and posing images for validation.
Now the second step was to create architecture photo or mortal now our idea is to first use of con base
of which uses 16 and then use to dense layer
so to use on base of.
We do this 16 you can vertically import that from us.
There is no need to manually build all the cone layers in that base.
So the import we do the 60.
You can just write from 10 sort of flowed out get a third application import.
We do these 16 and then give these three different parameters
so we are creating our cone base object.
And we are using we do this 60 and this out of the three parameters that we are passing.
First we need to provide weights so in any new national neural network first we provide randomized weight
and then our constitutional network tries to optimize those words since we do these 16 was used in that
competition and we can use the final weights of that more than
so to use those weights.
We have to write weights equal to imagine it.
Imagine that is the competition.
Add as we see completion
so to use train weights we just separate very quickly made to net and then there were two parts of that
we do these 16 model first for one base and then the fully connected neural network base we only want
the cone base from that model since cone bases are reusable those are mainly used to extract features
and not to categorize the images so we will be only using the base and we only need to import based
that's why we are using include underscore top equal to False if we want to import the whole model along
with the fully connected dense layers then you have to change it to group but in our case since we are
only importing the constitutional base we are waiting for this here
then next parameter is to give the input shape the input chip of our images are 1 4 feet by 1 4 feet
by 3.
That's why we are providing this couple here.
Let's turn this so we have imported our corn base from.
We did this 16 model
now to look at this.
You can just say one based thought somebody
oh if you're done this you will get details of all the layers of this which is this extreme corn based
now as we discuss in our TV lecture we use these 16 have this convolution of blocks.
So here you can see first convolution of block.
Then second conventional block in each block.
There are my people corn layers.
So in a sense I can blocks.
There are two layers and then a max pooling layer in third fourth and fifth look there are three corn
layers and then a max pooling layer
so in a way by importing BDD 16th we avoided creating these many layers and we have already imported
the final weights of that model.
So there is no need to randomly provide weights and optimize those weights.
We already have the final more than weights with us in this part of now.
The next step is to add fully connected dense layer and output layer in front of this one base.
Now this is similar to creating any CNN model.
We just have to create our model for us.
We are using models that sequential and then just like you add any other layer you can add the corn
base that we have imported so we will write model not AG.
And here you can just write the variable in which we have is stored.
This we did 60.
So what variable name was on base.
So plus we can add this one base.
Next we have to use a flat and layer and then include a fully connected dense layer and then output
layer.
So plus we are shedding light on layer and our dense layer with 256 Newton and then an output layer
with a single neuron.
The application is that a low in the dense layer and that duration is sigmoid in the output layer
you can run this and then you can look at the more than somebody as well so if you see this as a lot
more than somebody our first layer is reduced to 60.
We have around 14 millions trainable parameter in this we did this extreme layer.
Then we have a flatten layer.
Then we have a dense layer with around 2 million animal parameters and then finally an output layer
with 257 trainable parameters the total cranial parameter in our model is around 16 million.
Now as I told you earlier we were using the weights of the final.
We did this scene model so the weights are already optimized in this we do this extremely it.
Now if you don't want to screen those weights you can just freeze that layer to freeze that.
You can use corn based not training but equally false.
In that case the training parameter here will down to zero and our model will not try to optimize the
weights of this layer in that way.
We can significantly reduce the number of criminal parameters in our model and significantly improve
our execution time.
So if you run this one based or training equal to False our number of clinical parameters will reduce
from 16 million to just two point one million but here we are not running this and we are creating all
the 16 million parameters but in case you want to say thank you you can run this corn based or cleaning
equity funds
now.
The next step is to come by a lower margin we will be using the last function of binary cross entropy
since we have two classes then we are using Artemus prop as our optimizer and a learning rate of 2 and
210 is what a minus 5.
We are using somewhat smaller learning rate to get just because we want to fine tune our already train
more than the weights of this constitutional limits are already optimized and we just want to optimize
it and little steps leading to our problem.
So since we are fine tuning it we are not draining it from randomly assigned weights we can use a smaller
learning rate.
That is why we are using to train then race minus five and the metrics we want to calculate is of accuracy.
So training these models really takes somewhere between eight to 10 hours.
So it is better to use callbacks to say what are more than offset each epoch we are creating our check
point.
And we are saving our model for itI Paul.
You can also use save best only parameter here.
If you don't want to save 30 different models and if you give saved best quality crew we will save the
more than with the best value addition in score.
Now the next step is to the training data.
The step is similar to the last thing we will use for DNA rigor and then green generator with steps
but epoch and we'll also give validation generator and validation in steps for our evaluation data.
And yet we are also providing callback just to say well and more than that after each epoch.
So I have already executed this and these are the results.
So if you see the validation accuracies are in the range of 92 97.
So at the end of the book we will getting our training accuracy of our own 98 percent and the validation
accuracy of 98 percent as well.
You can see each epoch is taking around 15 minutes to train.
So just remember this may take up to eight to 10 hours to train our modern.
Now let's look at how accuracies and losses are changing with e.g. Paul
the orange line.
Here is for training accuracy.
The red line here is for validation accuracy.
And similarly we have validation lost in green and greening loss in blue
you can see that validation accuracy is oscillating between 97 to 98 and there is no further improvement
in accuracy as we move from lower epoch value to higher value so we can see that we have achieved a
convergence in our model and it is not possible to further improve this validation accuracy with increasing
number of epochs.
So if you compare the validation accuracy with our last CNN model in the last CNN model we were getting
the maximum accuracy of 84 percent.
But in this by using BDD 16 retrain more than we are achieving up to 97 98 percent of validation accuracy
and it is very easy to train our model using this.
We train models
so there is no need to create our own corn business.
You can just use any one on this pre train corn basis.
If the problem is segment is somewhat similar to that image neck problem misstatements.
Now I am also saving this history variable and glossy it to fight.
There is no need to do this this year will not.
We were on legal polluting the accuracies on our validation sets but now it's time to use our tests
to see how this model performs on our test asset.
Now we have to follow the same steps to evaluate our model for performance.
Again we will be using best generated
so we are creating another generator.
We are calling the best generator
we are using the test and that's called data.
This is the same object we use for regulation as well so hidden in this object.
We are just reshaping our data from 0 to 255 to 0 to 1 and then we are using flow from better tree and
here we are providing past that tree instead of validation vertically.
So what is generated is really no normally.
If we have data in the form of a data frame we use evaluate it but since we have our data flowing from
our directory that's why we have to use a really weird underscore generator.
So there is a simple back and forth effect.
We are using for a generator.
Similarly for you earlier we are using it will your generator.
And here also we have to provide our best generator object and the number of steps we have a bed size
of 20.
We have total data size of our home potent images.
That's why we need 50 steps thousand divided by 20 equal to 50.
So we will be able to give our all our estimate is in 50 steps.
So if you run this just like evaluate method you will get two values.
First is the lost value.
And second is the accuracy value.
And here you can see that the accuracy we are getting is that all 97 percent
so just 50 ways.
We started with a simple constitutional model.
At that time we were getting accuracy of around 70 percent to 40 percent.
Then we used data augmentation techniques to create dummy data and avoid or what.
In that case we were getting accuracy of our own 83 84 percent and in this case we used up drain.
We do these 16 more than caught our problem and in this case we are getting an accuracy of around 97
percent.
So we have increased our validation accuracy from 73 percent to 98 percent during this project.
That's all for this project.
Thank you.