Hi and welcome to the chapter where we finally put all the pieces together and build a CNN.
So you would have seen previously all of the building blocks that we use remember to convalesce the
max spool do redo fully connected layer in the soft Mac's layers.
We're now going to stack everything together and create a simple CNN.
And this is what it looks like.
No, I won't go into too much detail with this diagram because this diagram can confuse you a bit,
but it's an actual, real CNN here.
What is tells us here this is the input image, which is the 28 by 28 Grayscale because it only has
one in the color depth and you can see the tiny little filter here.
This is our filter colonel here, and it's applied to this image.
Here we use we're using 282 filters in this example here.
And so we have 32 of these feature map outputs here and the feature map output size 26 by 26.
And then we have another convolutional layer here.
So we apply the filters again to this layer and we get a 24 by 24.
And this time we use were using 64 filters to produce 64 feature maps.
And then we applied a max layer here, and then we flatten that max below connected to an interim fully
connected layer.
So we have this one by nine thousand two hundred and sixty layer connected to a one by 128 fully connected.
And then that connects to the final 10 output nodes.
And then out of a lot of that node, we'll have to solve Max Libya.
So let's take a look at this.
Now this is a full year CNN.
So a lot of times people may get confused counting Marilou as a layer or something to flatten operations
as a layer of accounting max pool as layer.
Technically those alleys, yes, but in our new modern terminology, those aren't really considered
layers.
They're considered parts of the convolutional layers.
So control is associated with our activation function.
So it comes as one.
So everything in this box here is a layer.
So we have one to three folios in the CNN.
So it's a fully a deep CNN that's used to classify handwritten digits.
So here's another representation, and this is a representation I prefer because it helps you visually
understand what's happening in the CNN.
So you can see this is the input image right here.
These are the filter, the tributary filters applied, and we apply 22 filters.
So we get a 26 by 26 by 22 feature map output.
And then the second conflict has a tree by tree filter again, and we apply it here.
And then you can see it as a two by two filter here.
That's the max blue filter size.
So that's how we get 12 by 12 or 64.
It's half that.
Remember this feature map size of 24 by 24 by 64 and by applying maximum, we get an output size of
12 by 12 by 664.
And then we flatten this multiple layer and then we have this interim filter connected at 128 new layer
here.
Then that's connected to the final 10 outputs.
So you can see in this table here, this is the depth, the width, the height and the filter size of
each layer.
Just in case you want to go through it in detail and understand.
So feel free to pause this slide and inspect each of one to make sure it makes sense to you.
So let's take a look at how we calculate the output size of the convolutional first convolutional layer.
So that's the one in pink right here.
So you can see we had a 28 by 28 image with a tree by tree filter.
So now we can use this formula here.
This one that gives us the max, the feature map output size.
So we know we use 32 filters.
We use a stride of one.
Putting is zero.
So it's not used.
And a max boost, right, is two.
That's for literally as we consider maximum.
For now, we just use this.
So N is 28.
You can see it here.
P, which is padding is zero, so it's two by zero, which is zero minus three.
Tree is a filter size, so that's how we get twenty six.
In the end, it's 28 minus three, which is 25 over one.
So 25 plus one, which is 26.
So that's how we get to 26 by 26 output size here in the olden days of of constructing see it ends and
neural networks.
We would have to calculate these things nowadays to libraries do help us quite a bit, but it's important
to understand the size of the ugliest as they go through.
This is something you may need to do a lot sometimes of building you on CNN.
So let's take a look at the second convolutional cones, too.
So there's again, just try this.
So the feature map size now was twenty six by twenty six.
So we use 26 year padding is again zero in this case, and the filter size is tree.
So you can see in the formula over here we have twenty six plus, which is zero first of all, minus
three, so that gives us twenty twenty three twenty three.
Divide by one is twenty three plus one twenty four.
So that's how we get 24 by 24 as the output size here.
And remember, we did two dimension, which is the depth of these filters, depends on how much filters
are being used, which we specify when designing or CNN's.
So we do hardcoded how many filters we want to use and then the CNN libraries take it from there and
start treating.
And we'll go into training extensively in the next few sections.
But for now, it's important you understand all the building blocks of a CNN that's a forward propagation
part of a CNN.
So let's take a look at the output size calculation for Max.
This one is simple, and the formula still holds up as well.
We have an which is 24 two p, which is p z zero again minus F, which is two divided by two.
So we have 24 minus two, which is 22 divided by two, which is 11 11 plus one 12.
And that's how we get to 12 by 12.
Oops, that slide a bit too fast.
So now let's take a look at how we calculated up the size of the flattened layer so you can see the
flatten layer is right.
It's nine thousand two hundred sixteen.
That's actually quite simple.
You just multiply all the dimensions of the max layer here, twelve by 12 by four, which is effectively
flattening that layer.
So that's how we got that there.
It's quite simple to work out.
So the rest of our CNN.
This is another article, so we hardcore 228 notes here.
This is something we can specify, and you can use any number.
I tend to use multiple powers of two for my sizes, but you can use anything you want.
You can use 100000.
I've seen a lot of people use a thousand decimal based numbers, so it's fine, and the output of the
classes here don't output.
The woods represent each one represents a class.
So remember, in handwritten digits, we have 10 digits, zero, two to nine.
So we have a node that represents a probability of the output of it, of the image being that class.
So that's it for the building blocks of the CNN.
I know it probably still isn't fit to get fit to get a fully for you yet, but it will shortly sort
of keep watching the slides go back to your election notes if you want.
I have provided them for you to go over.
And don't worry, it will all make sense.
So in the next section, we will take a look at parameter counts and CNN.
So stay tuned for that.
Thank you.