Hello and welcome back to the course on deep learning today we're talking about Max pooling and we've
got some very exciting slides coming up ahead.
And even a special surprise at the very end of the tutorial.
So let's get started.
The first question is what is pooling and why do we need it.
Well to answer that question let's have a look at these images on these images.
We've got a cheetah.
In fact it is the same exact cheetah on the first image.
That image is positioned properly and that she is looking straight at you on the second image.
It's a bit rotated.
And the third image a bit squashed.
And the thing here is that we want the neural network to be able to recognize the cheetah in every single
one of these images.
In fact this is just one cheetah.
What if we have lots of different shooters.
Here's a cheetah.
He is a cheetah.
Here's another cheetah his Ashira his Ishida cheetah and he a cheetah and we want the neural network
to recognize all of these shooters as cheaters and how can it do that if they're all looking in different
directions they're all in different parts of the image they're like their faces are positioned in different
parts of the image somebody is on the right hand side somebody in the left corner or somebody in the
middle.
They're all a bit different and the texture is a little bit different.
The lighting is a bit different.
There's lots of little differences and so if the neural network looks for exactly a certain feature
for instance a distinctive feature of the cheetah is the tears that are on its face going from the eyes
or the sheer The Shadow shadows that look like tears the texture of the pattern that is going from its
eyes down it's on the sides of its nose and looks like tears that's a distinctive feature of the Cheetah.
But if it's looking for that feature which it learned from certain cheetahs in an exact location or
an exact shape or form or texture it will never find these other shooters.
So we have to make sure that our neural network has a property called spatial invariance meaning that
it doesn't care where the features are again not not so much as itch which part of the image because
we're we've kind of taken that into consideration with our map we are poor with our convolutional there
but it doesn't have to care if the features are a bit tilted if the features are a bit different in
texture if the features are a bit closer of features or a bit further apart relative to relative to
each other.
So if the feature itself is a bit distorted our neural network has to have some level of flexibility
to be able to still find that feature.
And that is what pooling is all about.
So let's have a look at how pooling works.
Here's our feature map so we've already done our convolution and we've completed that part and now we're
working with the convolutional there.
Now we're going to apply pooling.
So how does it work.
We're going to be applying back pooling.
There's several different types of play complies mean pooling Max pooling some pooling and will comment
on those towards the end of the story.
But for now we're just applying Max pooling so we take a box of two by two pixels like that and again
it doesn't have to be two by two you can choose any size of box and again will comment on that towards
and is Tauriel and you place it in the top left hand corner and you find the maximum value in that box
and then you record only that value and you disregard the other three.
So in your box you have four values you just disregard three you only keep one the maximum which is
one in this case.
Then you move your box to the right by stride you select the stride once again.
So here we slide to stride of two and that's what you normally psyched you can say like the stride of
one you can select.
So there are overlapping boxes you can select any kind of strike that you like even three if you want
but we're selecting a stride of two here and that's what is commonly used.
And then you repeat the repeat the process you record that maxim here if you cross over and doesn't
matter you just keep continue doing what you're doing.
So you still record the maximum here 0 here the maximum is four.
Here are the maximums to here the maximum is 1 0 1 or 2 and then 1.
So as you can see a few things happened.
First of all we still were able to preserve the features right.
The maximum numbers they represent because we know how the conclusion Lehre works.
We know that the maximal or the large numbers in your feature map they represent where you actually
found the closest similarity to a feature.
But by then pooling these features we are first of all getting rid of 75 percent of the information
that is not the feature which is which is not the important things that we're looking out for because
we're just really three pixels out of four.
So we're only getting 25 percent.
And and then also because we are taking the maximum of the pixels that we or the values that we have
we are therefore accounting for any distortion.
So for instance two images in which for example the cheater's tears on the eyes are in one image there
a bit to the left or a bit rotated to the left and another one there a bit.
And are how they're supposed to be or how we like if you take one as the bases and another one there
are bits rotate to the left.
The puled feature will be exactly the same.
So you can see here if we are talking about the cheater's tears then let's say this is the four and
this is where it was here then if it was a bit rotated.
So for instance the four ended up over here.
Then when we are doing the pooling we're still going to get the same pool feature map and that's kind
of the principle behind it.
It's a very rough explanation again intuitive explanation but that's the point of pooling that we're
still being able to preserve the features and moreover account for their possible spatial or textural
or other kind of distortions.
And in addition to all of that we are reducing the size so there's another benefit.
So we've got we're preserving the features we're introducing spatial invariants we're reducing the size
by 75 percent which is huge which is really going to help us in terms of processing.
And moreover another benefit of pooling is we are reducing the number of parameters so we're reducing
again by 75 percent or reducing number of parameters that are going to go into our final Lares of the
neural network and therefore we're preventing overfitting.
It is a very important benefit of pooling that we're removing information and that is a good thing.
That is a good thing because that way our model won't be able to over fit onto that information because
especially because that information is not well and remember like at the very start we're talking about
even for human as humans it's important to see exactly the features rather than all this other noise
that is coming into our eyes.
Well same thing for neural networks they by disregarding the unnecessary non-important formation we're
helping with preventing of overfitting.
So there we go that is what pooling is about.
And the question here is of course why WiMax pooling right there's lots of different types of pooling
and a wide wide stride of too wide a size of two by two pixels lots of all these things.
And on that note I'd like to introduce you to this lovely research paper called evaluation of pooling
operations in convolutional architectures for object recognition by Dominic Scherrer from University
of Bonn.
There is the link and the beauty about this paper is that it's very very simple very straightforward
So if you've never read a research paper before what you'd like to give it a go.
This is a great place to start it's very short.
Only 10 pages.
Very easy to read.
And plus the extra benefit is that now that we've discussed convolution and pooling you will be totally
comfortable with everything that they're talking about in this paper in you.
This is a great way to actually reinforce and also I highly recommend checking this paper out.
I'll take 20 minutes to read it and you can even skip part 2 which is called related work if it feels
a bit farfetched or alienating.
Just don't read that part.
Go straight to from part 1 to part 3.
And one thing that you do need to know about this paper they talk about a concept called subsampling
which is subsampling is basically average pooling.
So remember how Here we were taking.
We're taking the maximum.
So in our squarer taking the maximum value there's a concept called Mean pooling or some pulling some
pulling as you just some of these values up average pooling or mean pooling you take the average value
out of all of these and subsampling is kind of like a generalization of men pooling.
It's it's a more kind of generalized approach to taking the average of of these values.
And you can read a bit more about in the paper but otherwise just think of it as average pooling when
you're reading a paper.
And so that's where you can get some additional information on this topic and now kind of let's recap
where have we gotten to.
So there is our input image.
Then we applied the convolution operation and we got the conclusion.
And now to each of those feature maps that we get We've applied the Pullinger.
So we've got we've done these two steps evolution and pooling and now we're going to do something very
fun something exciting.
We're going to experiment with this so this is a screenshot I took from a tool created by Adam Harley
from way back when he was at Ryerson University of computer science and now he's at Carnegie Mellon
I think doing his page.
And a great tool so let's open up let's have a look.
So you can find it you can actually find it through Google.
You have to know your role.
It's as it's just hard to find it through Google because there's no text here as we were just this year.
I'll see start Reierson dossier and this stuff.
And basically this is exactly what we're doing but visualize So here you need to draw a number so say
I draw number four and this tool will put the number four here.
That's your image.
In our first step then this is the convolution step.
Right.
And this is the pooling step and also pooling by the way is also called downsampling.
So pulling and downsampling are the same things.
So you can see it's applied convolution then it's applied pooling and you can see how it exactly works.
You can see what kind of convolutions that it has applied or what kind of filters it is applied what
they look like.
What features is looking out for.
And then it's applied pooling so it's reducing the size and you can see here that this is important.
So you can see that this is the convolved image and this is the puled image and you can still see the
same features is just less information but same features right features are preserved.
That's the important part.
And moreover if you know if all four was a bit too kind of like rotated a bit to the side it would still
be able to pick up very similar pool Lares.
And then after that it's got more letters we haven't talked about that yet.
So then he's got another convolutional a convolutional lair here which we actually won't have.
And then he has another poor lair but he's basically just repeating that same process.
And then after that this is what we're going to be talking further down in the course.
He's got the fully connected Lares and so on.
But you can definitely play around with that.
So if I delete that you like if I draw a 7 you will see that it actually tells you that the guess is
a guess is that this is a 7.
And the second guess the second likelihood is three.
So you can draw some some challenging things and see if it can pick them up.
So let's say if I draw something that looks like a 0 but it's not a finished 0 will it pick it up this
time didn't pick it up.
Looks like a 9 to that to the image.
What if I kind of like finish it like that.
So now it thinks it's a 0 or a 9 and you can see over there what's lighting up the 0.
But we'll talk about that part for the doubt.
Do one more let's say like like 8.
I think it's pretty hard for this now picked up an 8.
So you can see that goes into an 8 and then like after that it stops being recognizable the stops be
making sense to us humans.
Right.
These features that it's working with.
But at the same time it is correctly recognizing that it's an 8.
So definitely play around with that you can draw a smiley face.
What happens then.
Looks like a three to this to this tool because the tool is obviously trained up only on digits from
0 to nine.
So it has to recognize something there are those and recognizes a three it's like in life when you when
you see something like a type of fruit that you've never seen before like a custard apple or something
and you think that's it's like it's it's a pear because you've never actually seen one before you don't
know what to classify it as same thing here so it hasn't actually trained on smiley faces and that's
why it's thinks it's a tree as a tree.
So there you go it's a very powerful powerful tool it'll be helpful for you to play around of it actually
when you put your mouse over a pixel pixel that will show.
It shows you where the feature detector was to pick up that pixel so you can see where those pixels
are coming from and also so you can see how the filter was kind of like going through the image exactly
how we talked about and of course and here you can see you can see the pooling you can see that the
pulling is done with the pulling is done with a little square size of two by two and you can see that
it's a stride of two as well just as we discussed in today's tutorial.
So there go play or have a play around with that and I hope you enjoyed today's session.
I look forward to seeing you next time.
And until then enjoy deep learning.