1
00:00:00,750 --> 00:00:07,680
Hi and welcome to the chapter on parameter counts in CNN's We will explore in this section, how do

2
00:00:07,680 --> 00:00:13,290
you get the number, calculate the number of parameters that your CNN has, and we'll take a look at

3
00:00:13,290 --> 00:00:14,730
what learnable parameters are.

4
00:00:15,300 --> 00:00:16,290
So let's get started.

5
00:00:16,950 --> 00:00:18,840
So firstly, what are parameters?

6
00:00:19,260 --> 00:00:22,920
Well, parameters are the variables that need to be linked when creating a model.

7
00:00:23,310 --> 00:00:29,010
So initially, when we start creating a CNN, we initialize all the parameter variables with random

8
00:00:29,010 --> 00:00:34,410
values, or we can do different types of initialization, but for now, consider them random values.

9
00:00:35,130 --> 00:00:40,590
And these are often called learnable parameters, because that's exactly what the neural network learns,

10
00:00:41,100 --> 00:00:43,080
and it's often referred to as weights.

11
00:00:43,380 --> 00:00:45,840
That's actually that's how I refrigerant, to be honest.

12
00:00:46,830 --> 00:00:51,720
And our hidden layers, like the convolutional Leo and the fully connected layers all have these learnable

13
00:00:51,720 --> 00:00:52,890
parameters or weights.

14
00:00:53,610 --> 00:00:56,340
So let's take a look at how we calculate the number of parameters.

15
00:00:56,910 --> 00:01:02,080
Remember in this input image here and this was a tree by tree kill.

16
00:01:02,820 --> 00:01:04,140
And in this case, example.

17
00:01:04,140 --> 00:01:07,470
Here we have 16 filters and this is the output size.

18
00:01:07,830 --> 00:01:09,280
So how many remote?

19
00:01:09,350 --> 00:01:13,450
Remember, I said the parameters are in the filters.

20
00:01:13,470 --> 00:01:15,630
Essentially, that's what that's what we're learning.

21
00:01:15,900 --> 00:01:17,820
We're learning parameters for those filters.

22
00:01:18,150 --> 00:01:22,350
So let's see how we calculate how many parameters comprise of these filters.

23
00:01:22,740 --> 00:01:29,010
So we have 16 convolution filters, which tree by tree kernels does the input image size of matter in

24
00:01:29,010 --> 00:01:30,080
this case with the parameters?

25
00:01:30,090 --> 00:01:31,320
No, only the depth.

26
00:01:31,410 --> 00:01:34,290
So if it's color image, it will be multiplied by tree.

27
00:01:34,890 --> 00:01:40,590
So all that matters here is that we have 16 colored filters of tree battery kernel size, and this is

28
00:01:40,590 --> 00:01:48,900
how we calculate the parameters in one filter its tree by tree by one, which is adept, plus one which

29
00:01:48,900 --> 00:01:49,590
is the bias.

30
00:01:49,590 --> 00:01:51,390
And we'll talk about bias in the next slide.

31
00:01:51,900 --> 00:01:52,860
So that gives us 10.

32
00:01:53,400 --> 00:02:00,660
So if we have 16 of those filters, this will give us 160 parameters for the first filter layer.

33
00:02:02,070 --> 00:02:03,630
So let's talk about biases now.

34
00:02:04,260 --> 00:02:10,050
So bias is important because they allow us to shift our activation function left or right by adding

35
00:02:10,050 --> 00:02:10,950
a constant value.

36
00:02:11,430 --> 00:02:16,000
And this value is this bias is shared opinion or the filter.

37
00:02:16,050 --> 00:02:21,390
So in the case where we have an RGV image, it's shared among all those tree filters.

38
00:02:22,110 --> 00:02:28,590
So those had shed biases per neuron or filter allowed a filter to detect the same feature.

39
00:02:28,950 --> 00:02:34,200
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.

40
00:02:34,230 --> 00:02:37,920
Shade so that they can all detect the same picture in spite of the color.

41
00:02:38,550 --> 00:02:41,280
And again, biases are a minimal parameter.

42
00:02:41,580 --> 00:02:47,610
So either initialized with random values and in the training process, the neural network learns the

43
00:02:47,610 --> 00:02:49,770
best value for those biases.

44
00:02:50,610 --> 00:02:55,350
So let's calculate the number of parameters in a, you know, a simple CNN here.

45
00:02:56,040 --> 00:02:57,650
So let's take a look at this.

46
00:02:57,660 --> 00:03:04,230
This is the final answer here, but we can calculate that for one which we have done here, we get 320

47
00:03:04,230 --> 00:03:04,800
parameters.

48
00:03:04,920 --> 00:03:05,670
Not that much.

49
00:03:06,570 --> 00:03:10,130
However, look at kind of Zoom calls, too is No.

50
00:03:10,290 --> 00:03:11,010
22.

51
00:03:11,010 --> 00:03:13,560
The story tree by tree by 22 plus one.

52
00:03:13,980 --> 00:03:23,190
That was the initial control filter and then multiplied by 64, because now we have 64 filters in this

53
00:03:23,190 --> 00:03:23,700
layer here.

54
00:03:24,120 --> 00:03:27,270
So we end up with eighteen thousand four hundred ninety four parameters.

55
00:03:27,810 --> 00:03:30,270
However, that's not where the bulk of oak branches are.

56
00:03:30,710 --> 00:03:37,440
Remember, conveyors basically does feature extractors that spike depending on whether you like something

57
00:03:37,440 --> 00:03:42,060
simple, like a edge or a line or color blob was spotted in the image.

58
00:03:42,780 --> 00:03:49,050
How do we actually combine all these different features that we learned is basically in the fully connected

59
00:03:49,050 --> 00:03:49,590
layers here?

60
00:03:49,920 --> 00:03:52,530
And that's why these tend to have a lot of parameters as well.

61
00:03:52,980 --> 00:03:55,980
So here's how we can calculate the number of parameters in those layers here.

62
00:03:56,430 --> 00:03:57,480
Remember this flattened?

63
00:03:57,480 --> 00:04:03,260
We flattened this Max Boulia separation operation here, so we have nine thousand two hundred and sixteen

64
00:04:03,270 --> 00:04:06,510
here, but it's a fully connected layer, so we have to go first.

65
00:04:06,510 --> 00:04:07,950
We have plus bias plus one.

66
00:04:08,520 --> 00:04:12,630
And then we multiplied by the fully connected layer because every note here is connected to every note

67
00:04:12,630 --> 00:04:12,900
here.

68
00:04:13,380 --> 00:04:20,760
So this blows up and we get about a million, 1.1, seven, nine million parameters in this FC layer

69
00:04:20,760 --> 00:04:28,200
here and then is not actually able to output a here where we have 128 plus one multiplied by 10, and

70
00:04:28,200 --> 00:04:30,900
that gives us one thousand two hundred and ninety.

71
00:04:31,590 --> 00:04:33,480
So we solve these up here.

72
00:04:33,480 --> 00:04:38,580
We get one point roughly one point two million parameters in this simple CNN.

73
00:04:39,210 --> 00:04:43,400
Now, that might sound like a lot, but actually, this is a fairly lightweight.

74
00:04:43,460 --> 00:04:47,400
You know, I would say it's small, moderately small CNN.

75
00:04:47,880 --> 00:04:50,370
I have seen a lot smaller sedans that work quite well.

76
00:04:50,700 --> 00:04:57,420
But generally, most of the complicated deep sea lanes that you encounter will have anywhere from 10

77
00:04:57,420 --> 00:04:59,520
to 15, sometimes eighty six million.

78
00:05:00,100 --> 00:05:02,170
YOLO v five, which has a lot of parameters.

79
00:05:02,650 --> 00:05:07,930
So this is how we calculate the parameters to if you wanted to break it down and do this, you can do

80
00:05:07,930 --> 00:05:08,470
it yourself.

81
00:05:08,950 --> 00:05:14,170
However, luckily the libraries like PyTorch and TensorFlow and Keras, they can print and display these

82
00:05:14,170 --> 00:05:19,690
parameters upwards for us after we construct the CNN in that language in a library, I should say.

83
00:05:20,470 --> 00:05:26,470
So next, we'll stop there, and next we'll take a look at why CNN's works so well for images.

84
00:05:26,920 --> 00:05:28,720
Thank you and stay tuned for that lesson.
