Top Banner
Convolutional Neural Networks (CNN) Industrial AI Lab. Prof. Seungchul Lee
103

Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Aug 31, 2019

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Convolutional Neural Networks(CNN)

Industrial AI Lab.

Prof. Seungchul Lee

Page 2: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Convolution on Image

• Convolution in 2D

• Filter (or Kernel)

– Modify or enhance an image by filtering

– Filter images to emphasize certain features or remove other features

– Filtering includes smoothing, sharpening and edge enhancement

– Discrete convolution can be viewed as element-wise multiplication by a matrix

2

Image Kernel Output

Page 3: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Convolution on Image

3

Image Kernel Output

1 0 1

1 0 1

1 0 1

Page 4: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Convolution on Image

4

Image Kernel Output

1 1 1

0 0 0

1 1 1

Page 5: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Convolution on Image

5

Page 6: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

How to Find the Right Kernels

• We learn many different kernels that make specific effect on images

• Let’s apply an opposite approach

• We are not designing the kernel, but are learning the kernel from data

• Can learn feature extractor from data using a deep learning framework

6

Page 7: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Learning Visual Features

7

Page 8: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Fully Connected Neural Network (= ANN)

8

Page 9: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Fully Connected Neural Network

• Input– 2D image

– Vector of pixel values

• Fully connected– Connect neuron in hidden layer to all neurons in input layer

– No spatial information

– Spatial organization of the input is destroyed by flatten

– And many, many parameters !

• How can we use spatial structure in the input to inform the architecture of the network?

9

Page 10: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Using Spatial Structure

• Input– 2D image

– Matrix of pixel values

• Idea– Connect patches of input to neurons in hidden layer

– Neuron connected to region of input. Only “sees” these values

10

Page 11: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Using Spatial Structure

• Connect patch in input layer to a single neuron in subsequent layer.

• Use a sliding window to define connections.

• How can we weight the patch to detect particular features?

11

Page 12: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Applying Filters to Extract Features

1) Apply a set of weights - a filter - to extract local features

2) Use multiple filters to extract different features

3) Spatially share parameters of each filter (features that matter in one part of the input should matter elsewhere)

• Filter of size 4x4 : 16 different weights

• Apply this same filter to 4x4 patches in input

• Shift by 2 pixels for next patch

• This “patchy” operation is convolution

12

Page 13: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Feature Extraction and Convolution

13

Page 14: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

X or X?

• Image is represented as matrix of pixel values…and computers are literal !

• We want to be able to classify an X as an X even if it’s shifted, shrunk, rotated, deformed.

14

Page 15: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Features of X

15

Page 16: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Filters to Detect X Features

16

Page 17: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

The Convolution Operation

17

Page 18: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Convolutional Neural Networks (CNN)

• Motivation– The bird occupies a local area and looks the same in different parts of an image. We should

construct neural networks which exploit these properties.

18

Page 19: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

ANN Structure for Object Detection in Image

• Does not seem the best

• Did not make use of the fact that we are dealing with images

19

bird

Page 20: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Convolution Mask + Neural Network

• Does not seem the best

• Did not make use of the fact that we are dealing with images

20

Page 21: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Locality

• Locality: objects tend to have a local spatial support

– fully-connected layer → locally-connected layer

21

Page 22: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Locality

• Locality: objects tend to have a local spatial support

– fully-connected layer → locally-connected layer

22

We are not designing the kernel, but are learning the kernel from data→ Learning feature extractor from data

𝜔1 𝜔2 𝜔3

𝜔4 𝜔5 𝜔6

𝜔7 𝜔8 𝜔9

Page 23: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Object Size?

23

Page 24: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Convolutional Neural Networks (CNN)

• Matrix multiplication– Every output unit interacts with every interacts unit

• Convolution– Typically have sparse interactions

– Local connectivity

24

Page 25: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Deep Artificial Neural Networks

• Universal function approximator– Simple nonlinear neurons

– Linear connected networks

• Hidden layers– Autonomous feature learning

25

Class 2Class 1

Page 26: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Convolutional Neural Networks

• Structure– Weight sharing

– Local connectivity

• Optimization– Smaller searching space

26

Class 2Class 1

Page 27: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Multiple Filters (or Kernels)

27

Page 28: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Channels

• Colored image = tensor of shape (height, width, channels)

• Convolutions are usually computed for each channel and summed:

• Kernel size aka receptive field (usually 1, 3, 5, 7, 11)

28

Page 29: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Multi-channel 2D Convolution

29

Page 30: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Multi-channel 2D Convolution

30

Page 31: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Multi-channel 2D Convolution

31

Page 32: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Multi-channel 2D Convolution

32

Page 33: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Multi-channel 2D Convolution

33

Page 34: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Multi-channel 2D Convolution

34

Page 35: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Multi-channel 2D Convolution

35

Page 36: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Multi-channel 2D Convolution

36

Page 37: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Multi-channel 2D Convolution

37

Page 38: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Multi-channel 2D Convolution

38

Page 39: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Multi-channel 2D Convolution

39

Page 40: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Multi-channel 2D Convolution

40

Page 41: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Multi-channel and Multi-kernel 2D Convolution

41

Page 42: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Dealing with Shapes

• Activations or feature maps shape

– Input (𝑊𝑖 , 𝐻𝑖 , 𝐶)

– Output (𝑊𝑜, 𝐻𝑜, 𝐷)

• Kernel of Filter shape (𝑤, ℎ, 𝐶, 𝐷)– 𝑤 × ℎ Kernel size

– 𝐶 Input channels

– 𝐷 Output channels

• Numbers of parameters: (𝑤 × ℎ × 𝐶 + 1) × 𝐷– bias

42

Page 43: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Multi-channel 2D Convolution

• The kernel is not swiped across channels, just across rows and columns.

• Note that a convolution preserves the signal support structure.

• A 1D signal is converted into a 1D signal, a 2D signal into a 2D, and neighboring parts of the input signal influence neighboring parts of the output signal.

• A 3D convolution can be used if the channel index has some metric meaning, such as time for a series of grayscale video frames. Otherwise swiping across channels makes no sense.

• We usually refer to one of the channels generated by a convolution layer as an activation map.

• The sub-area of an input map that influences a component of the output as the receptive field of the latter.

• In the context of convolutional networks, a standard linear layer is called a fully connected layer since every input influences every output.

43

Page 44: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Padding and Stride

• Convolutions have two additional standard parameters:– The padding specifies the size of a zeroed frame added around the input

– the stride specifies a step size when moving the kernel across the signal.

44

Page 45: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Strides

• Strides: increment step size for the convolution operator

• Reduces the size of the output map

45

Example with kernel size 3×3 and a stride of 2 (image in blue)

Page 46: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Padding

• Padding: artificially fill borders of image

• Useful to keep spatial dimension constant across filters

• Useful with strides and large receptive fields

• Usually fill with 0s

46

Page 47: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Padding and Stride

• Here with 3 × 5 × 𝐶 as input

47

Page 48: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Padding and Stride

• Here with 3 × 5 × 𝐶 as input, a padding of (2,1)

48

Page 49: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Padding and Stride

• Here with 3 × 5 × 𝐶 as input, a padding of (2,1), a stride of (2,2)

49

Page 50: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Padding and Stride

• Here with 3 × 5 × 𝐶 as input, a padding of (2,1), a stride of (2,2), and a kernel of size 3 × 3 × 𝐶

50

Page 51: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Padding and Stride

• Here with 3 × 5 × 𝐶 as input, a padding of (2,1), a stride of (2,2), and a kernel of size 3 × 3 × 𝐶

51

Page 52: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Padding and Stride

• Here with 3 × 5 × 𝐶 as input, a padding of (2,1), a stride of (2,2), and a kernel of size 3 × 3 × 𝐶

52

Page 53: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Padding and Stride

• Here with 3 × 5 × 𝐶 as input, a padding of (2,1), a stride of (2,2), and a kernel of size 3 × 3 × 𝐶

53

Page 54: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Padding and Stride

• Here with 3 × 5 × 𝐶 as input, a padding of (2,1), a stride of (2,2), and a kernel of size 3 × 3 × 𝐶

54

Page 55: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Padding and Stride

• Here with 3 × 5 × 𝐶 as input, a padding of (2,1), a stride of (2,2), and a kernel of size 3 × 3 × 𝐶

55

Page 56: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Padding and Stride

• Here with 3 × 5 × 𝐶 as input, a padding of (2,1), a stride of (2,2), and a kernel of size 3 × 3 × 𝐶

56

Page 57: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Padding and Stride

• Here with 3 × 5 × 𝐶 as input, a padding of (2,1), a stride of (2,2), and a kernel of size 3 × 3 × 𝐶

57

Page 58: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Padding and Stride

• Here with 3 × 5 × 𝐶 as input, a padding of (2,1), a stride of (2,2), and a kernel of size 3 × 3 × 𝐶

58

Page 59: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Nonlinear Activation Function

59

Page 60: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Pooling

• Compute a maximum value in a sliding window (max pooling)

• Reduce spatial resolution for faster computation

• Achieve invariance to local translation

• Max pooling introduces invariances

– Pooling size : 2×2

– No parameters: max or average of 2x2 units

60

Page 61: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Pooling

• The most standard type of pooling is the max-pooling, which computes max values over non-overlapping blocks

• For instance in 1d with a kernel of size 2

61

Page 62: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

62

Page 63: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

63

Page 64: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

64

Page 65: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

65

Page 66: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

66

Page 67: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

• Such an operation aims at grouping several activations into a single “more meaningful” one.

• The average pooling computes average values per block instead of max values

67

Page 68: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Pooling: Invariance

• Pooling provides invariance to any permutation inside one of the cell

• More practically, it provides a pseudo-invariance to deformations that result into local translations

68

Page 69: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Pooling: Invariance

• Pooling provides invariance to any permutation inside one of the cell

• More practically, it provides a pseudo-invariance to deformations that result into local translations

69

Page 70: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Multi-channel Pooling

70

Page 71: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Multi-channel Pooling

71

Page 72: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Multi-channel Pooling

72

Page 73: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Multi-channel Pooling

73

Page 74: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Multi-channel Pooling

74

Page 75: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Multi-channel Pooling

75

Page 76: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Multi-channel Pooling

76

Page 77: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Multi-channel Pooling

77

Page 78: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Multi-channel Pooling

78

Page 79: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Multi-channel Pooling

79

Page 80: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Multi-channel Pooling

80

Page 81: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Multi-channel Pooling

81

Page 82: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Multi-channel Pooling

82

Page 83: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Multi-channel Pooling

83

Page 84: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Multi-channel Pooling

84

Page 85: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Inside the Convolution Layer Block

85

Conv blocks

Page 86: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Classic ConvNet Architecture

• Input

• Conv blocks– Convolution + activation (relu)

– Convolution + activation (relu)

– ...

– Maxpooling

• Output– Fully connected layers

– Softmax

86

Page 87: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

CNNs for Classification: Feature Learning

• Learn features in input image through convolution

• Introduce non-linearity through activation function (real-world data is non-linear!)

• Reduce dimensionality and preserve spatial invariance with pooling

87

Page 88: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

CNNs for Classification: Class Probabilities

• CONV and POOL layers output high-level features of input

• Fully connected layer uses these features for classifying input image

• Express output as probability of image belonging to a particular class

88

Page 89: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

CNNs: Training with Backpropagation

• Learn weights for convolutional filters and fully connected layers

• Backpropagation: cross-entropy loss

89

Page 90: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Lab: CNN with TensorFlow

• MNIST example

• To classify handwritten digits

90

Page 91: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

CNN Structure

91

Page 92: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Weights, Biases and Placeholder

92

Page 93: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Build a Model

• Convolution layers

1) The layer performs several convolutions to produce a set of linear activations

2) Each linear activation is running through a nonlinear activation function

3) Use pooling to modify the output of the layer further

• Fully connected layers

– Simple multi-layer perceptrons (MLP)

93

Page 94: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Convolution

• First, the layer performs several convolutions to produce a set of linear activations

– Filter size : 3×3

– Stride : The stride of the sliding window for each dimension of input

– Padding : Allow us to control the kernel width and the size of the output independently

• 'SAME' : zero padding

• 'VALID' : No padding

94

Page 95: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Activation

• Second, each linear activation is running through a nonlinear activation function

95

Page 96: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Pooling

• Third, use a pooling to modify the output of the layer further

– Compute a maximum value in a sliding window (max pooling)

– Pooling size : 2×2

96

Page 97: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Second Convolution Layer

97

Page 98: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Fully Connected Layer

• Fully connected layer

– Input is typically in a form of flattened features

– Then, apply softmax to multiclass classification problems

– The output of the softmax function is equivalent to a categorical probability distribution, it tells you the probability that any of the classes are true.

98

Page 99: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Loss and Optimizer

• Loss

– Classification: Cross entropy

– Equivalent to apply logistic regression

• Optimizer

– GradientDescentOptimizer

– AdamOptimizer: the most popular optimizer

99

Page 100: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Optimization

100

Page 101: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Test or Evaluation

101

Page 102: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

Test or Evaluation

102

Page 103: Convolutional Neural Networks (CNN) - i-systems.github.ioi-systems.github.io/HSE545/iAI/DL/topics/06_CNN/02_CNN.pdf · Convolutional Neural Networks (CNN) ... •Did not make use

CNN Implemented in an Embedded System

103