<<

Convolutional Neural Networks

Computer vision deeplearning.ai Vision Problems

Image Classification Neural Style Transfer

Cat? (0/1)

64x64

Andrew Ng on large images

Cat? (0/1)

64x64

!" !# ⋮ ⋮ ⋮ %& !$

Andrew Ng Convolutional Neural Networks

Edge detection deeplearning.ai example Problem

vertical edges

horizontal edges Andrew Ng Vertical

1 10 -10 -10 -01 -1 3 0 1 2 7 4 1 10 -101 -101 -01 -1 1 5 8 9 3 1 1 10 -101 -101 -01 -1 2 7 2 5 1 3 1 10 -101 -101 -01 -1 ∗ = 0 1 3 1 7 8 0 -2 -4 -7 4 2 1 6 2 8 -3 -2 -3 -16 2 4 5 2 3 9

Andrew Ng Vertical edge detection 10 10 10 0 0 0 10 10 10 0 0 0 0 30 30 0 1 0 -1 10 10 10 0 0 0 0 30 30 0 ∗ 1 0 -1 = 10 10 10 0 0 0 0 30 30 0 1 0 -1 10 10 10 0 0 0 0 30 30 0 10 10 10 0 0 0

∗ Andrew Ng Convolutional Neural Networks

More edge deeplearning.ai detection Vertical edge detection examples

10 10 10 0 0 0 10 10 10 0 0 0 0 30 30 0 1 0 -1 10 10 10 0 0 0 0 30 30 0 ∗ 1 0 -1 = 10 10 10 0 0 0 0 30 30 0 1 0 -1 10 10 10 0 0 0 0 30 30 0 10 10 10 0 0 0

0 0 0 10 10 10 0 0 0 10 10 10 0 -30 -30 0 1 0 -1 0 0 0 10 10 10 0 -30 -30 0 ∗ 1 0 -1 = 0 0 0 10 10 10 0 -30 -30 0 1 0 -1 0 0 0 10 10 10 0 -30 -30 0 0 0 0 10 10 10

Andrew Ng Vertical and Horizontal Edge Detection 1 0 -1 1 1 1 1 0 -1 0 0 0 1 0 -1 -1 -1 -1 Vertical Horizontal 10 10 10 0 0 0 10 10 10 0 0 0 0 0 0 0 1 1 1 10 10 10 0 0 0 30 10 -10 -30 ∗ 0 0 0 = 0 0 0 10 10 10 30 10 -10 -30 -1 -1 -1 0 0 0 10 10 10 0 0 0 0 0 0 0 10 10 10 Andrew Ng Learning to detect edges 1 0 -1 1 0 -1 1 0 -1

3 0 1 2 7 4 1 5 8 9 3 1 #$ #% #& 2 7 2 5 1 3 #' #( #) 0 1 3 1 7 8 #* #+ #, 4 2 1 6 2 8 2 4 5 2 3 9 Andrew Ng Convolutional Neural Networks

Padding deeplearning.ai Padding

∗ =

Andrew Ng Valid and Same

“Valid”:

“Same”: Pad so that output size is the same as the input size.

Andrew Ng Convolutional Neural Networks

Strided deeplearning.ai convolutions Strided

2 3 3 4 7 43 4 4 6 34 2 4 9 4 6 1 6 0 9 21 8 0 7 12 4 0 3 2 3 -31 4 40 8 -431 3 40 8 -341 9 40 7 43 3 4 4 7 1 8 0 3 21 6 0 6 12 3 0 4 2 ∗ 1 0 2 = 4 -31 2 04 1 -341 8 40 3 -341 4 40 6 43 -1 0 3 3 1 2 0 4 12 1 0 9 12 8 0 3 2 0 -1 1 0 3 -31 9 0 2 -31 1 0 4 3

Andrew Ng Summary of convolutions

& × & image #× # filter padding p stride s

'()* +, '()* +, + 1 × + 1 - -

Andrew Ng Technical note on cross-correlation vs. convolution Convolution in math textbook:

2 3 7 4 6 2 6 6 9 8 7 4 3 4 5 3 4 8 3 8 9 ∗ 1 0 2 7 8 3 6 6 3 -1 9 7 4 2 1 8 3 4 3 2 4 1 9 8

Andrew Ng Convolutional Neural Networks

Convolutions over deeplearning.ai volumes Convolutions on RGB images

Andrew Ng Convolutions on RGB image

∗ =

4 x 4

Andrew Ng Multiple filters

∗ =

3 x 3 x 3 4 x 4

6 x 6 x 3 ∗ =

3 x 3 x 3 4 x 4

Andrew Ng Convolutional Neural Networks

One layer of a deeplearning.ai convolutional network Example of a layer

3 x 3 x 3

6 x 6 x 3 ∗

3 x 3 x 3

Andrew Ng Number of parameters in one layer

If you have 10 filters that are 3 x 3 x 3 in one layer of a neural network, how many parameters does that layer have?

Andrew Ng Summary of notation If layer l is a convolution layer: " # = filter size Input: $ # = padding Output: % # = stride # &' = number of filters Each filter is: Activations: Weights: bias:

Andrew Ng Convolutional Neural Networks

A simple convolution deeplearning.ai network example Example ConvNet

Andrew Ng Types of layer in a convolutional network:

- Convolution - Pooling - Fully connected

Andrew Ng Convolutional Neural Networks

Pooling layers deeplearning.ai Pooling layer: Max pooling

1 3 2 1 2 9 1 1 1 3 2 3 5 6 1 2

Andrew Ng Pooling layer: Max pooling

1 3 2 1 3 2 9 1 1 5 1 3 2 3 2 8 3 5 1 0 5 6 1 2 9

Andrew Ng Pooling layer: Average pooling

1 3 2 1 2 9 1 1 1 4 2 3 5 6 1 2

Andrew Ng Summary of pooling

Hyperparameters:

f : filter size s : stride Max or average pooling

Andrew Ng Convolutional Neural Networks

Convolutional neural deeplearning.ai network example Neural network example

Andrew Ng

Convolutional Neural Networks

Why convolutions? deeplearning.ai Why convolutions

Andrew Ng Why convolutions

10 10 10 0 0 0 10 10 10 0 0 0 0 30 30 0 1 0 -1 10 10 10 0 0 0 0 30 30 0 ∗ 1 0 -1 = 10 10 10 0 0 0 0 30 30 0 1 0 -1 10 10 10 0 0 0 0 30 30 0 10 10 10 0 0 0

Parameter sharing: A feature detector (such as a vertical edge detector) that’s useful in one part of the image is probably useful in another part of the image.

Sparsity of connections: In each layer, each output value depends only on a small number of inputs. Andrew Ng Putting it together

Training set (% & , ( & ) … (% + , ( + ).

(1

& + Cost , = - ℒ((1 . , ( . ) + ./& Use to optimize parameters to reduce ,

Andrew Ng