1 of 46

AIWS Practical 2:�Convolutional Neural Network (CNN)

2 of 46

5W 1H

  • Who
  • When
  • Where
  • What
  • Why
  • How

3 of 46

5W 1H

  • Who: You
  • When: 2023/1/11
  • Where: GUGC Building
  • What: CNN
  • Why
  • How

4 of 46

5W 1H

  • Who: You
  • When: 2023/1/11
  • Where: GUGC Building
  • What: CNN (Part 1)
  • Why ? (Part 2)
  • How ? (Part 3)

5 of 46

Part 1:�What is CNN?

6 of 46

What is CNN?

Which diagram better describes the architecture of CNN?

7 of 46

What is CNN?

Which diagram better describes the architecture of CNN?

8 of 46

What is C?

Which diagram better describes the architecture of CNN?

9 of 46

What is Convolution?

Which diagram better describes the architecture of CNN?

10 of 46

Convolution

1*1 + 1*0 + 1*1 +

0*0 + 1*1 + 1*0 +

0*1 + 0+0 + 1*1 = 4

11 of 46

Convolution

Sum over element-wise multiplication

12 of 46

Convolution

Values of weights of the filter?

13 of 46

Convolution

Values of weights of the filter?

1, 0, 1,

0, 1, 0,

1, 0, 1

14 of 46

Convolution

Size of the filter?

15 of 46

Convolution

Size of the filter?

3*3?

16 of 46

Convolution

Size of the filter?

3*3*1 (height, width, depth)

17 of 46

Filter depth is easily overlooked.

18 of 46

Filter depth is easily overlooked.

All Convolution Animations Are Wrong (Neural Networks)

https://www.youtube.com/watch?v=w4kNHKcBGzA

https://animatedai.github.io/

​

19 of 46

How standard convolution calculation works along depth

a) 2D convolution for each input channel with 2D filters & add up

= b) element-wise product between input & 3D filters & add up

20 of 46

How standard convolution calculation works along depth

a) 2D convolution for each input channel with 2D filters & add up

21 of 46

How standard convolution calculation works along depth

b) element-wise product between input & 3D filters & add up

22 of 46

Summary: Part 1

1. CNN gets inputs & outputs with certain depth

​

2. Thus, filter (or kernel) should also have depth for the convolution, apart from the number of filter

​

3. Filter depth is same with input’s depth

​

4. Convolution is just sum of element-wise multiplication between corresponding (i.e., same position) weights of filter & input

23 of 46

Part 2:�Why CNN?

24 of 46

Part 2:�Why CNN (used for image)?

25 of 46

Black box

26 of 46

CNN vs ANN

What is the difference?

27 of 46

Convolution operation

Did you see this before?

28 of 46

Convolution operation

Similar vectors (or values) 🡺 Higher values

29 of 46

Convolution operation

Similar vectors (or values) 🡺 Higher values

  • CNN updates weights to get desired (higher) values via convolution

30 of 46

Convolution operation

Similar vectors (or values) 🡺 Higher values

  • CNN updates weights to get desired (higher) values at the end of the network (i.e., neuron of correct class is most activated) via convolution

31 of 46

Convolution operation

Similar vectors (or values) 🡺 Higher values

  • CNN updates weights to get desired (higher) values at the end of the network (i.e., neuron of correct class is most activated) via convolution
  • CNN can learn weights which result in higher values after convolution
  • CNN can learn features

32 of 46

CNN learns features

Similar vectors (or values) 🡺 Higher values

  • CNN updates weights to get desired (higher) values at the end of the network (i.e., neuron of correct class is most activated) via convolution
  • CNN can learn weights which result in higher values after convolution
  • CNN can learn features

33 of 46

CNN learns features

CNN can learn features

🡺 So… What?

34 of 46

CNN learns features

CNN can learn features

🡺 In case of stationary data, like image, such features do not change by their position

​

35 of 46

Stationarity

CNN can learn features

🡺 In case of stationary data, like image, such features do not change by their position

🡺 We can use filter!!

36 of 46

Stationarity

We can use filter.

  • Okay. Then why using filter is good?...

37 of 46

CNN learns features

CNN can learn features (in case of stationary data, like image)

  • We can use filter.
  • Okay. Then why using filter is good?...
  • It dramatically reduces the number of parameters

38 of 46

Parameter sharing

Okay. Then why using filter is good?...

  • 1. A filter shares parameters

39 of 46

Parameter sharing

Okay. Then why using filter is good?...

  • 1. A filter shares parameters
  • 2. Improved statistical efficiency (in terms of data)

= one parameter can see (or learn) the data much more times

40 of 46

Locality of pixel dependencies

Parameter sharing is not only efficient, but it also gives locality on information

41 of 46

Locality of pixel dependencies

In case of the image data, pixels in red region is irrelevant to those in blue region

42 of 46

Locality of pixel dependencies

Parameter sharing is not only efficient, but it also gives locality on information

  • It makes connectivity between neurons in two adjacent layers sparse

43 of 46

Locality of pixel dependencies

Parameter sharing is not only efficient, but it also gives locality on information

  • It makes connectivity between neurons in two adjacent layers sparse
  • It results in locality between data (e.g., pixels)

44 of 46

Summary: Part 2

1. CNN can extract features, based on characteristic of convolution operation (cf. inner product)

​

2. A feature of image (or other stationary data) does not change along axis of time or location

​

3. Therefore, we can apply filter rather than using fully connected layer

​

4. Using filter results in 1) parameter sharing & 2) statistical efficiency

​

5. It also fits well in terms of locality of pixel dependencies, which is one of main characteristics of image data

45 of 46

Part 3:�How?

46 of 46

Build CNN model using Pytorch

​