Hello, everyone, and welcome to this new and exciting session in which we are going to build our own
YOLO like model.
So from the paper we had already seen that we have this initial conv layers which are pre-trained on
the image net data set such that they could be used to extract very useful features from our input images.
And then this conv layers were followed by two fully connected layers which were designed in order to
adapt to our problem of object detection.
Now, given that we do not want to train this backbone year from scratch on the image net data set,
we'll use an already pre-trained backbone, which is the rest net 50.
Again, we have the output dimension defined as a number of classes plus five times B from the paper.
B is given to B two.
We've seen this already and then five because we have the probability of obtaining an object.
And then for the remaining four we have the bound and box.
So we have two of this bounding box predictions.
That's why here we have two times 510 plus the number of classes which in our case is equal 20.
Now we define this number of filters to be 512.
So that's it.
From year we have our full, complete model.
You could take this off.
You see that we have our pre trained race net, which is our backbone or our base model.
And then we followed this up with several conflicts similar to what we have here in the paper.
And then we have the global average pulling, which is what is given here in the paper.
Now, one thing we should note about the average pulling is the fact that when we have inputs, let's
say we have this seven by seven, then by let's say five, so we have one channel to three, four and
then five.
So let's suppose we have some of my seven, my five input.
Now after going into the global average pulling, what we will have here is the averaging of each and
every value or let's say pixel in each and every channel.
So for this channel, for example, we will have one representative value for this channel will have
one representative value, which is the average.
So for this we would have the average, this would have the average and this will have the average.
So we average all these values here.
And the problem with this is information about object position is lost.
And so instead of using this average pulling is preferable to use the flattening.
And so what we do is we'll take this off from here and then we'll have flatten.
Okay.
So once we have that, just as with the paper you see here, we have the fully connected layer, which
is this dense layer right here and then this other fully connected layer.
So we have that and then we reshape.
Now, this should be actually split.
Let's take all this year copy and paste.
So we're split by split by split or split by split by output dimension.
So it's seven by seven by 30.
So this is now our model.
You can see we have a total of 53 million parameters, 30 trainable and 23 non trainable.
That's from our rest net.
We are then going to define our model checkpoint where our file path is this year.
Then we're going to save only the weights, we're going to monitor the validation loss.
We're going to obviously save the model which produces the minimum or the smallest validation loss,
and that's it.
We save the base, we save the best weights only.
So we run that and then now we move to the scheduling here if the number of epochs is less than 40.
So the first 40 epochs, we use a learning rate of one times ten to a negative three between 40 and
80.
We use a learning rate of five times 10 to -4, and then after that we use a learning rate of one times
ten to the negative four.
So that's it.
We compile our model and then we start with the training.
Now, after training for a few epochs, you will notice that the model starts to over fit.
So in the next section, we are going to treat or use several techniques to help solve this or resolve
the problem of overfitting.
Now, we've been training for over 20 epochs and you could see clearly from the loss and the validation
of the train loss and the validation loss that our model starts performing well and at some point starts
overfitting.
As you could see here, we have the training loss, which keeps dropping right here, and then the validation
loss drops and then at some point starts increasing.
So clearly our model is overfitting.