Welcome to this new section.
We should start by looking at the error sanction loss function, which I'll use in training our model.
This function others loss function happens to be the Euclidean loss which is derived from the Euclidean
distance, and it goes as such.
For every pixel we have in our density map, we compare it with the true density map that was a target
density map.
So by doing that we have y true I this is for each I where I goes from one to M, where M represents
all the different pixels we could have in the density map.
Now, note that this m doesn't represent the by size.
It represents the total number of pixels nor density map.
So for each of those pixels we have y target minus y predicted squared, and then we simply add this
or sum this up.
Then at the end the answer we get, we find a square root.
Now, coming back to the code, all we need to do is to define this custom loss as such.
Once this custom loss is defined, we go ahead to set the learning rate.
We compile the model and we'll define the check point.
Now, yeah, instead of this, we should have CSR net.
So there we go.
We could start with this, run that, and now we're ready to train our model.
So we have this.
We train the we have our train generator, which we define already.
We shuffle a number of epochs on the callback.
So there we go.
Know that we shall train on just ten images from our dataset.
Then you could simply increase this to say 380 or 350.
Then the validation of, say, 50.
Now let's check on the arrow we have.
We told you that we haven't this Sigma.
Let's go up and check right here.
We okay.
We didn't do that, so we should have.
This was the Gaussian radius.
So we should have the Gaussian.
Reduce Gaussian radius.
Run it again.
That's fine.
Our models now train and quiet normally.
Now, note that the reason why we decide to work with a relatively low learning rate is because we are
using fine tuning in this VG model right here.
So we're trying not to avoid distorting the already trained weights of the VG model.
And also note that the reason why we don't selectively keep aside the batch normalization layers is
because the Vedge model, there are no batch normalization layers.
So with that, we look at our training.
Everything looks fine.
Also, note that the most common metric in this people counts and models is an accuracy.
We could actually use the mean average error or the mean square error.
So we just work with the mean squared, mean average error for now.
So that's it.
Now, while we were training our model, we could go ahead to put out a code for prediction.
So.
Right.
Yeah.
We have this input image just like what we had done previously.
Let's take this off.
We have the image, we load the image, we normalize it by fast dividing by 255 and then we subtract
the mean.
So it's just like having X minus the mean divided by the standard deviation.
So that's it.
So that's kind of like what we're doing.
So we have x equals x minus the mean minus divided by the standard deviation.
So for I, we do this for each of the channels.
That's why you have this right here, zero one and two because our image has three channels.
So for each channel we take each value minus the mean of the channel divided by the standard deviation
of that channel.
So that's we take off the non pass array since this is going to generate a ten.
So so we get back to our training.
Let's pause this from now.
So stop this canal for now.
And then we try to predict using this image from our dataset.
So there we go.
We see that this looks quite similar to the actual density map, which we had seen previously, which
was now this was no, this was 245.
So let's pick image one.
So that is it.
So it looks quite similar to this density map or we just generated right here the predicted density
map.
But then once this counting is done, that is once we have the sum of the outputs, we obtained 186
instead of 233.
So it means we need to continue training and then to come up with a model which doesn't over feed on
this few images.
We need to increase our data set to take in many more images.
We also continue trading again up to this loss of 0.77 and then running this, we obtain this result.
So we see that it's getting better.
Now to get better results.
Obviously just need to continue training, but this will always feed on the few images we've trained,
so we still have to include many more images and then use data augmentation techniques to increase our
data.