Hi and welcome to the chapter on parameter counts in CNN's We will explore in this section, how do
you get the number, calculate the number of parameters that your CNN has, and we'll take a look at
what learnable parameters are.
So let's get started.
So firstly, what are parameters?
Well, parameters are the variables that need to be linked when creating a model.
So initially, when we start creating a CNN, we initialize all the parameter variables with random
values, or we can do different types of initialization, but for now, consider them random values.
And these are often called learnable parameters, because that's exactly what the neural network learns,
and it's often referred to as weights.
That's actually that's how I refrigerant, to be honest.
And our hidden layers, like the convolutional Leo and the fully connected layers all have these learnable
parameters or weights.
So let's take a look at how we calculate the number of parameters.
Remember in this input image here and this was a tree by tree kill.
And in this case, example.
Here we have 16 filters and this is the output size.
So how many remote?
Remember, I said the parameters are in the filters.
Essentially, that's what that's what we're learning.
We're learning parameters for those filters.
So let's see how we calculate how many parameters comprise of these filters.
So we have 16 convolution filters, which tree by tree kernels does the input image size of matter in
this case with the parameters?
No, only the depth.
So if it's color image, it will be multiplied by tree.
So all that matters here is that we have 16 colored filters of tree battery kernel size, and this is
how we calculate the parameters in one filter its tree by tree by one, which is adept, plus one which
is the bias.
And we'll talk about bias in the next slide.
So that gives us 10.
So if we have 16 of those filters, this will give us 160 parameters for the first filter layer.
So let's talk about biases now.
So bias is important because they allow us to shift our activation function left or right by adding
a constant value.
And this value is this bias is shared opinion or the filter.
So in the case where we have an RGV image, it's shared among all those tree filters.
So those had shed biases per neuron or filter allowed a filter to detect the same feature.
So if it's the same feature in a color in a red, green or blue, that's how they that's how it works.
Shade so that they can all detect the same picture in spite of the color.
And again, biases are a minimal parameter.
So either initialized with random values and in the training process, the neural network learns the
best value for those biases.
So let's calculate the number of parameters in a, you know, a simple CNN here.
So let's take a look at this.
This is the final answer here, but we can calculate that for one which we have done here, we get 320
parameters.
Not that much.
However, look at kind of Zoom calls, too is No.
22.
The story tree by tree by 22 plus one.
That was the initial control filter and then multiplied by 64, because now we have 64 filters in this
layer here.
So we end up with eighteen thousand four hundred ninety four parameters.
However, that's not where the bulk of oak branches are.
Remember, conveyors basically does feature extractors that spike depending on whether you like something
simple, like a edge or a line or color blob was spotted in the image.
How do we actually combine all these different features that we learned is basically in the fully connected
layers here?
And that's why these tend to have a lot of parameters as well.
So here's how we can calculate the number of parameters in those layers here.
Remember this flattened?
We flattened this Max Boulia separation operation here, so we have nine thousand two hundred and sixteen
here, but it's a fully connected layer, so we have to go first.
We have plus bias plus one.
And then we multiplied by the fully connected layer because every note here is connected to every note
here.
So this blows up and we get about a million, 1.1, seven, nine million parameters in this FC layer
here and then is not actually able to output a here where we have 128 plus one multiplied by 10, and
that gives us one thousand two hundred and ninety.
So we solve these up here.
We get one point roughly one point two million parameters in this simple CNN.
Now, that might sound like a lot, but actually, this is a fairly lightweight.
You know, I would say it's small, moderately small CNN.
I have seen a lot smaller sedans that work quite well.
But generally, most of the complicated deep sea lanes that you encounter will have anywhere from 10
to 15, sometimes eighty six million.
YOLO v five, which has a lot of parameters.
So this is how we calculate the parameters to if you wanted to break it down and do this, you can do
it yourself.
However, luckily the libraries like PyTorch and TensorFlow and Keras, they can print and display these
parameters upwards for us after we construct the CNN in that language in a library, I should say.
So next, we'll stop there, and next we'll take a look at why CNN's works so well for images.
Thank you and stay tuned for that lesson.