Welcome to the section on people counting with TensorFlow.
This task involves taking in an image like this one and then automatically counting a number of people
in this image feed or this image from a video feed, which in this case gives us a total of 54 people.
So this means that in this case, our dataset is made up of inputs, which are this kind of images and
then outputs which contain this point here.
So this like sample output where we have all the positions in this input image where we have the head
of a person found.
The dataset, which I'll be working with, is the Shanghai Tech dataset.
The Shanghai tech dataset is made up of two main parts that are the Part A and the part B and the part
A.
We have more of very densely packed people in an image, whereas the Part B contains images where the
people are not very close to each other.
So let's look at the part.
A Yeah, we have the training and the test data, the ground.
We have the images here.
So yeah, we have 182 images, Ground truth, 182.
We also have the training, the images.
300 and then the ground truth.
So so what happens here is we have this image, for example, this image one right here.
We see that these people are it's kind of like a very densely packed image.
And then this ground data right here contains all the points in the image where there is a human head.
If we enlarge those images we see we have this kind of very crowded images.
So we see that what this dataset will be able to train models which could, for example, in the case
where we are having a drone during an event, we could count our.
Predicts the number of people who are the events just by taking an aerial photo of the event.
So see the kind of images we have now for the Part B, we have less crowded images.
We can see that there just.
Footage from CCTV cameras of people moving across the streets and maybe going to buy or going to various
occupations.
All I would have had a well, we have very huge crowds showing that people people have actually come
together for an event.
You could get this dataset via this link right here.
Now, once we have this input as an image and then we have this output or it shows us exactly where
the different persons have found in the image, the first idea that comes to our mind will be maybe
to take that input and then train end to end with this output points.
But generally in people counting, we don't use this output like this.
We actually transform this output into a Gaussian map.
Now a Gaussian map looks like this.
This here is what we obtain when we have many points.
But now if we have just one point is just one person, the map we shall obtain will look like this now.
Instance for us to focus on just one pixel point where the person's head is found and give the value
of one.
What we do is we draw some sort of circle around that person's head, where the sum of all the points
are.
The different values we shall give will be equal as one.
So this means that that point with the value one has been scattered all around that circle, such that
all those different values will not give the value.
One unlike the previous situation where we have just one point, which is our value one and all the
surroundings of value zero.
In this case we have all the we have that one point which may take a value of say, 0.2 points around
it, 0.1 around 0.05, 0.005 and so on and so forth.
But what's important to note is that the sum of all those gives us a value of one such that when we
have many of them, like in this case, we see that wherever we have so many people, we have this this
yellow color.
You're telling us that these circles that we have here have somehow come together, because if we have
say, let's take these two people here, if we have these two people together, this person's own circle
with this other person's own circle will tend to form a region where the.
Values are higher than in the situation where we have these two people who are a bit separate from each
other.
But in the case where we were using these maps, we wouldn't have this.
And they'll be because this point will have a value.
One, all those around it will have value zero.
This point in value one, everything around it having value zero at this point one, this point one,
everything around it, having value zero.
But with the maps, as we could see now, regions surrounding.
Places where there are many people tend to have or tend to take higher values as compared to, say,
regions like this one around.
Around this two people here.
It happens that the way we distribute this points around a person's head follows a Gaussian distribution.
Now, although we're using a two dimensional Gaussian distribution here for the points surrounding the
person, we are going to explain this using this one Z go show distribution.
This x axis represents the position of a pixel, and then the Y axis represents the probability of that
pixel being a head.
So this means that the closer we are to a given herd, the higher the probability is called.
As you could see right here, this pixel positions which are around the head, which we could consider
the head to or the head position to be the mean.
Now this position right here is the mean.
And then we also have a standard deviation, which is like a value or a position from the mean above
which the probability of being a head is very, very low.
So if our standard deviation is say at this point here, so we have the mean here, right here, which
is considered to be mu.
As you could see right here, we have mu minus sigma.
Mu plus sigma.
I will notice that above this, like this mu minus sigma mu plus sigma.
If we cut this through the Gaussian bell shaped curve, we'll see that all values which fall in this
range have a reasonable probability of being a head.
But as soon as we move out of that range, this probability becomes very, very small.
And that's why we see right here that as we have at this actual point where the person's head is found,
we have this very yellow color as we're going out of this turns greenish and then bluish and then purple
and then finally get this popular color.
Now, note that the very yellow actually stands for one, and then this purple color stands for zero.
But nonetheless, this isn't actually one since those the the one value has been shared among all the
different points surrounding the person.
So, yeah, we could have a value of, say, 0.5 and then value surrounded and have a value of 0.1 and
then 0.05 and so on and so forth.
Now, to get the details of the Gaussian distribution, you can look at our course on probability.
Now we are going to be generating this kind of maps for each of the points.
Now let's look at the formula for this probability distribution right here.
This probability distribution is defined such that we have P of x where X is, the position is equal
to one divided by the square root of two pi sigma squared, where sigma is the standard deviation.
Now note that the standard deviation can be defined such that this region within which we have this
reasonable probability score of being a head, of being a person is restrained to only positions which
are very close to the person's head.
So in that sense, this mu minus sigma now falls around this and Mu plus sigma falls around this position
right here.
And from this we see clearly that this is going to be a hyper parameter for our model wherein we could
vary the values for this sigma to see whether when we choose points, when we decide to work with points
very close to the person's head.
Or we just had to work with points which are also very far from the person's head that's generating
maps such that this circle is very large.
We see how it affects our model's accuracy and predicting whether there is a person in that position
or not, or better still encountered the number of people who are located in that image.
So that set the standard deviation as where it goes is a deviation.
So it tells us how much or better still, how many points surrounding the head.
We decide to share that one score of the head width.
So here we have this.
Now this is what we get here.
Times e to the negative half of x minus mu mule is the mean divided by sigma.
All of that squared.
We are going to use the we are going to consider the mu to be equal to zero.
So this is going to be minus half of x divided by sigma, all of that squared.
And since the Gaussian distribution is a probability distribution, more specifically a continuous probability
distribution, the integral from negative infinity to positive infinity of P of x, the x equals one.
Now this comes back to the fact that we are having a point here at the center which we are sharing across
all the different points surrounding it.
And that's why when you find an integral here, we have a value of one.
Now recall this integral is just like finding the area under this curve right here.
So you see this --, that portion in orange here, this area should always be equals one.
And then coming back to the image, this comes to the fact that the sum of all this different pixel
values surrounding this head should be equals one.
And that said, when we have so many different positions like this, if we sum all the pixel values,
they should all give us values of one.