Convolutional Neural Network
Lecture 16
Introduction to convolutional architecture for image analysis
EECS 189/289, Fall 2026 @ UC Berkeley
Joseph E. Gonzalez and Narges Norouzi
Roadmap
1854077
Network Design Considerations for Images
1854077
Story So Far
1854077
A Problem
1854077
A Problem
A network that recognizes "cat" feature regardless of the location and scale of the target object.
1854077
A Problem
Network must be shift and scale invariant.
1854077
Demo: An MLP on Moved Digits
A fully connected network (784, 256, 10) trained on centered MNIST digits.
Centered test digits: 96.0% correct.
The same digits moved 4 pixels right: 29.7%.
1854077
Scanning Is Referred to as Convolution
1854077
Scanning Is Referred to as Convolution
1854077
Scanning Is Referred to as Convolution
1854077
Scanning Is Referred to as Convolution
1854077
Scanning Is Referred to as Convolution
1854077
Scanning Is Referred to as Convolution
1854077
Scanning Is Referred to as Convolution
1854077
Scanning Is Referred to as Convolution
1854077
Scanning Is Referred to as Convolution
1854077
Scanning Is Referred to as Convolution
1854077
Scanning Is Referred to as Convolution
1854077
Scanning Is Referred to as Convolution
max
Maximum of all the outputs (Equivalent of Boolean OR)
The strength of having the feature anywhere in the image
Same shared weights
1854077
Scanning Is Referred to as Convolution
max
1854077
Regular Network vs. Scanning Network
max
1854077
Element of the Convolutional Neural Network
1854077
Back to Scanning Network
max
1854077
How to Identify a Feature in a Receptive Field?
1854077
How to Implement Scanning of Features with Weight-Sharing?
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
-1 | -1 | -1 |
2 | 2 | 2 |
-1 | -1 | -1 |
Feature extractor
Or kernel
Horizontal line detector
-1
At each position: multiply the window by the kernel entry by entry and add the 9 products.
The same 9 weights are used at every position.
1854077
How to Implement Scanning of Features with Weight-Sharing?
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
Stride = 1
-1 | -1 | -1 |
2 | 2 | 2 |
-1 | -1 | -1 |
Feature extractor
Or kernel
Horizontal line detector
-1
0
At each position: multiply the window by the kernel entry by entry and add the 9 products.
The same 9 weights are used at every position.
1854077
How to Implement Scanning of Features with Weight-Sharing?
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
Stride = 1
-1 | -1 | -1 |
2 | 2 | 2 |
-1 | -1 | -1 |
Feature extractor
Or kernel
Horizontal line detector
-1
0
1
At each position: multiply the window by the kernel entry by entry and add the 9 products.
The same 9 weights are used at every position.
1854077
How to Implement Scanning of Features with Weight-Sharing?
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
Stride = 1
-1 | -1 | -1 |
2 | 2 | 2 |
-1 | -1 | -1 |
Feature extractor
Or kernel
Horizontal line detector
-1
0
1
3
At each position: multiply the window by the kernel entry by entry and add the 9 products.
The same 9 weights are used at every position.
1854077
How to Implement Scanning of Features with Weight-Sharing?
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
Stride = 1
-1 | -1 | -1 |
2 | 2 | 2 |
-1 | -1 | -1 |
Feature extractor
Or kernel
Horizontal line detector
-1
0
1
3
2
At each position: multiply the window by the kernel entry by entry and add the 9 products.
The same 9 weights are used at every position.
1854077
How to Implement Scanning of Features with Weight-Sharing?
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
Stride = 1
-1 | -1 | -1 |
2 | 2 | 2 |
-1 | -1 | -1 |
Feature extractor
Or kernel
Horizontal line detector
-1
0
1
3
2
1
At each position: multiply the window by the kernel entry by entry and add the 9 products.
The same 9 weights are used at every position.
1854077
How to Implement Scanning of Features with Weight-Sharing?
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
Stride = 1
-1 | -1 | -1 |
2 | 2 | 2 |
-1 | -1 | -1 |
Feature extractor
Or kernel
Horizontal line detector
-1
0
1
3
2
1
1
At each position: multiply the window by the kernel entry by entry and add the 9 products.
The same 9 weights are used at every position.
1854077
How to Implement Scanning of Features with Weight-Sharing?
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
-1 | -1 | -1 |
2 | 2 | 2 |
-1 | -1 | -1 |
Feature extractor
Or kernel
Horizontal line detector
-1
0
Stride = 1
1
3
2
1
1
1
At each position: multiply the window by the kernel entry by entry and add the 9 products.
The same 9 weights are used at every position.
1854077
How to Implement Scanning of Features with Weight-Sharing?
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
-1 | -1 | -1 |
2 | 2 | 2 |
-1 | -1 | -1 |
Feature extractor
Or kernel
Horizontal line detector
-1
0
Stride = 1
1
3
2
1
1
1
1
0
0
0
1
1
1
0
0
0
-1
-1
-1
1
1
1
-1
-1
-1
-1
-1
-1
1
1
2
1
1
0
1854077
How to Implement Scanning of Features with Weight-Sharing?
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
-1 | -1 | -1 |
2 | 2 | 2 |
-1 | -1 | -1 |
Feature extractor
Or kernel
Horizontal line detector
-1
0
Stride = 1
1
3
2
1
1
1
1
0
0
0
1
1
1
0
0
0
-1
-1
-1
1
1
1
-1
-1
-1
-1
-1
-1
1
1
2
1
1
0
1854077
If we convolve a kernel of size 5x5 with an image of size 8x8 with the stride of 1, what are the output dimensions?
The Slido app must be installed on every computer you’re presenting from
Do not edit�How to change the design
1854077
How to Implement Scanning of Features with Weight-Sharing?
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
-1 | -1 | -1 |
2 | 2 | 2 |
-1 | -1 | -1 |
Horizontal line detector
-1
0
Stride = 1
1
3
2
1
1
1
1
0
0
0
1
1
1
0
0
0
-1
-1
-1
1
1
1
-1
-1
-1
-1
-1
-1
1
1
2
1
1
0
-1
-1 | 2 | -1 |
-1 | 2 | -1 |
-1 | 2 | -1 |
Vertical line detector
1854077
How to Implement Scanning of Features with Weight-Sharing?
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
-1 | -1 | -1 |
2 | 2 | 2 |
-1 | -1 | -1 |
Horizontal line detector
-1
0
Stride = 1
1
3
2
1
1
1
1
0
0
0
1
1
1
0
0
0
-1
-1
-1
1
1
1
-1
-1
-1
-1
-1
-1
1
1
2
1
1
0
-1
-1 | 2 | -1 |
-1 | 2 | -1 |
-1 | 2 | -1 |
Vertical line detector
0
1854077
How to Implement Scanning of Features with Weight-Sharing?
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
-1 | -1 | -1 |
2 | 2 | 2 |
-1 | -1 | -1 |
Horizontal line detector
-1
0
Stride = 1
1
3
2
1
1
1
1
0
0
0
1
1
1
0
0
0
-1
-1
-1
1
1
1
-1
-1
-1
-1
-1
-1
1
1
2
1
1
0
-1
-1 | 2 | -1 |
-1 | 2 | -1 |
-1 | 2 | -1 |
Vertical line detector
0
1
1854077
How to Implement Scanning of Features with Weight-Sharing?
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
-1 | -1 | -1 |
2 | 2 | 2 |
-1 | -1 | -1 |
Horizontal line detector
-1
0
Stride = 1
1
3
2
1
1
1
1
0
0
0
1
1
1
0
0
0
-1
-1
-1
1
1
1
-1
-1
-1
-1
-1
-1
1
1
2
1
1
0
-1
-1 | 2 | -1 |
-1 | 2 | -1 |
-1 | 2 | -1 |
Vertical line detector
0
1
0
1854077
How to Implement Scanning of Features with Weight-Sharing?
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
-1 | -1 | -1 |
2 | 2 | 2 |
-1 | -1 | -1 |
Horizontal line detector
-1
0
Stride = 1
1
3
2
1
1
1
1
0
0
0
1
1
1
0
0
0
-1
-1
-1
1
1
1
-1
-1
-1
-1
-1
-1
1
1
2
1
1
0
-1
-1 | 2 | -1 |
-1 | 2 | -1 |
-1 | 2 | -1 |
Vertical line detector
0
1
0
2
1854077
How to Implement Scanning of Features with Weight-Sharing?
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
-1 | -1 | -1 |
2 | 2 | 2 |
-1 | -1 | -1 |
Horizontal line detector
-1
0
Stride = 1
1
3
2
1
1
1
1
0
0
0
1
1
1
0
0
0
-1
-1
-1
1
1
1
-1
-1
-1
-1
-1
-1
1
1
2
1
1
0
-1
-1 | 2 | -1 |
-1 | 2 | -1 |
-1 | 2 | -1 |
Vertical line detector
0
1
0
2
-2
1854077
How to Implement Scanning of Features with Weight-Sharing?
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
-1 | -1 | -1 |
2 | 2 | 2 |
-1 | -1 | -1 |
Horizontal line detector
-1
0
Stride = 1
1
3
2
1
1
1
1
0
0
0
1
1
1
0
0
0
-1
-1
-1
1
1
1
-1
-1
-1
-1
-1
-1
1
1
2
1
1
0
-1
-1 | 2 | -1 |
-1 | 2 | -1 |
-1 | 2 | -1 |
Vertical line detector
0
1
0
2
-2
-2
1854077
How to Implement Scanning of Features with Weight-Sharing?
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
-1 | -1 | -1 |
2 | 2 | 2 |
-1 | -1 | -1 |
Horizontal line detector
-1
0
Stride = 1
1
3
2
1
1
1
1
0
0
0
1
1
1
0
0
0
-1
-1
-1
1
1
1
-1
-1
-1
-1
-1
-1
1
1
2
1
1
0
-1
0
1
0
2
-2
-2
1
1
0
3
-3
-2
1
1
0
3
-3
-1
-1
2
1
1
-2
-1
-1
2
2
-1
-1
-2
1
2
1
-2
0
-1 | 2 | -1 |
-1 | 2 | -1 |
-1 | 2 | -1 |
Vertical line detector
Feature Map
1854077
If we convolve 4 kernels of size 5x5 with an image of size 8x8 with the stride of 1, what are the output dimensions?
The Slido app must be installed on every computer you’re presenting from
Do not edit�How to change the design
1854077
Convolution Example
Each output is bright where the digit contains the kernel's pattern.
Top: horizontal strokes.
Middle: vertical strokes.
Bottom: diagonals.
1854077
1854077
The dimension of features decreases but the depth usually increases.
1854077
What If We Want to Keep the Same Image Dimensions?
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
-1 | -1 | -1 |
2 | 2 | 2 |
-1 | -1 | -1 |
Feature extractor
Or kernel
Horizontal line detector
0
1854077
What If We Want to Keep the Same Image Dimensions?
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
-1 | -1 | -1 |
2 | 2 | 2 |
-1 | -1 | -1 |
Feature extractor
Or kernel
Horizontal line detector
0
0
Feature Map
1854077
Avoiding Redundancy
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
-1 | -1 | -1 |
2 | 2 | 2 |
-1 | -1 | -1 |
Feature extractor
Or kernel
Horizontal line detector
0
Stride = 2
1854077
Avoiding Redundancy
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
-1 | -1 | -1 |
2 | 2 | 2 |
-1 | -1 | -1 |
Feature extractor
Or kernel
Horizontal line detector
0
-1
Stride = 2
……
1854077
Characteristics of Image Analysis
Patterns are usually smaller than high-resolution images.
Patterns can appear anywhere in the image.
Addressed with convolution
1854077
Characteristics of Image Analysis
Patterns are usually smaller than high-resolution images.
Patterns can appear anywhere in the image.
Patterns might appear at different scales.
1854077
How Can We Detect Features at Different Scale?
-1 | -1 | -1 |
2 | 2 | 2 |
-1 | -1 | -1 |
-1
0
1
3
2
1
1
1
1
0
0
0
1
1
1
0
0
0
-1
-1
-1
1
1
1
-1
-1
-1
-1
-1
-1
1
1
2
1
1
0
-1
0
1
0
2
-2
-2
1
1
0
-3
-2
1
1
3
-3
-1
1
1
-2
-1
-1
2
2
-1
-1
-2
1
2
1
-2
0
-1 | 2 | -1 |
-1 | 2 | -1 |
-1 | 2 | -1 |
3
0
2
-1
2
-1
Down-sampling features
This is called pooling.
1854077
How Can We Detect Features at Different Scale?
-1 | -1 | -1 |
2 | 2 | 2 |
-1 | -1 | -1 |
1
3
2
1
1
1
0
0
0
1
1
1
0
0
0
-1
-1
-1
1
1
1
-1
-1
-1
-1
-1
-1
1
1
2
1
1
0
-1
0
1
0
2
-2
-2
1
1
0
-3
-2
1
1
3
-3
-1
1
1
-2
-1
-1
2
2
-1
-1
-2
1
2
1
-2
0
-1 | 2 | -1 |
-1 | 2 | -1 |
-1 | 2 | -1 |
3
0
2
-1
2
-1
This is called pooling.
Down-sampling features
1854077
How Can We Detect Features at Different Scale?
-1 | -1 | -1 |
2 | 2 | 2 |
-1 | -1 | -1 |
1
3
2
1
1
1
0
0
0
1
1
1
0
0
0
-1
-1
-1
1
1
1
-1
-1
-1
-1
-1
-1
1
1
2
1
1
0
-1
0
1
0
2
-2
-2
1
1
0
-3
-2
1
1
3
-3
-1
1
1
-2
-1
-1
2
2
-1
-1
-2
1
2
1
-2
0
-1 | 2 | -1 |
-1 | 2 | -1 |
-1 | 2 | -1 |
3
0
2
-1
2
-1
Down-sampling features
1854077
How Can We Detect Features at Different Scale?
-1 | -1 | -1 |
2 | 2 | 2 |
-1 | -1 | -1 |
3
2
1
1
0
0
1
1
1
0
0
0
-1
-1
-1
1
1
1
-1
-1
-1
-1
-1
-1
1
1
2
1
1
0
-1
0
1
0
2
-2
-2
1
1
0
-3
-2
1
1
3
-3
-1
1
1
-2
-1
-1
2
2
-1
-1
-2
1
2
1
-2
0
-1 | 2 | -1 |
-1 | 2 | -1 |
-1 | 2 | -1 |
3
0
2
-1
2
-1
Down-sampling features
1854077
How Can We Detect Features at Different Scale?
-1 | -1 | -1 |
2 | 2 | 2 |
-1 | -1 | -1 |
3
2
1
1
0
0
1
1
1
0
0
0
-1
-1
-1
1
1
1
-1
-1
-1
-1
-1
-1
1
1
2
1
1
0
-1
0
1
0
2
-2
-2
1
1
0
-3
-2
1
1
3
-3
-1
1
1
-2
-1
-1
2
2
-1
-1
-2
1
2
1
-2
0
-1 | 2 | -1 |
-1 | 2 | -1 |
-1 | 2 | -1 |
3
0
2
-1
2
-1
Down-sampling features
1854077
How Can We Detect Features at Different Scale?
-1 | -1 | -1 |
2 | 2 | 2 |
-1 | -1 | -1 |
3
2
1
1
1
1
1
2
1
-1
0
1
0
2
-2
-2
1
1
0
-3
-2
1
1
3
-3
-1
1
1
-2
-1
-1
2
2
-1
-1
-2
1
2
1
-2
0
-1 | 2 | -1 |
-1 | 2 | -1 |
-1 | 2 | -1 |
3
0
2
-1
2
-1
Down-sampling features
1854077
How Can We Detect Features at Different Scale?
-1 | -1 | -1 |
2 | 2 | 2 |
-1 | -1 | -1 |
3
2
1
1
1
1
1
2
1
-1
0
1
0
2
-2
-2
1
1
0
-3
-2
1
1
3
-3
-1
1
1
-2
-1
-1
2
2
-1
-1
-2
1
2
1
-2
0
-1 | 2 | -1 |
-1 | 2 | -1 |
-1 | 2 | -1 |
3
0
2
-1
2
-1
Down-sampling features
1854077
How Can We Detect Features at Different Scale?
-1 | -1 | -1 |
2 | 2 | 2 |
-1 | -1 | -1 |
3
2
1
1
1
1
1
2
1
-2
1
1
3
-1
2
1
0
-1 | 2 | -1 |
-1 | 2 | -1 |
-1 | 2 | -1 |
3
2
2
Down-sampling features
1854077
How Can We Detect Features at Different Scale?
-1 | -1 | -1 |
2 | 2 | 2 |
-1 | -1 | -1 |
3
2
1
1
1
1
1
2
1
1
1
1
3
2
1
0
-1 | 2 | -1 |
-1 | 2 | -1 |
-1 | 2 | -1 |
3
2
Down-sampling features
1854077
How Can We Detect Features at Different Scale?
-1 | -1 | -1 |
2 | 2 | 2 |
-1 | -1 | -1 |
3
2
1
1
1
1
1
2
1
1
1
1
3
2
1
0
-1 | 2 | -1 |
-1 | 2 | -1 |
-1 | 2 | -1 |
3
2
Down-sampling features
Each 2×2 block keeps its largest value. The 6×6 map becomes 3×3.
1854077
CNN Design
1854077
Convolution
Pooling
Good features for image understanding tasks
Flatten
Cat?
This network can also be deep.
1854077
Convolution
Flatten
Pooling
Convolution
Pooling
Output
Each convolution and pooling block gives more feature maps, each one smaller.
Flatten the last maps into one vector and classify it with a fully connected network.
1854077
Convolution
Flatten
Pooling
Convolution
Pooling
Output
def __init__(self, num_classes=10):
super().__init__()
self.conv1 = nn.Conv2d(1, 8, kernel_size=3, padding=1)
nn.Conv2d(
in_channels, # # of input feature maps (e.g., 3 for RGB)
out_channels, # # of filters you learn → # of output feature maps
kernel_size, # filter size (int or (kh, kw))
stride=1, # step size of the filter (int or (sh, sw))
padding=0, # add zeros around the image (int, tuple, or 'same')
bias=True, # learn an additive bias per output channel
padding_mode='zeros' # 'zeros' (default), 'reflect', 'replicate'
)
1854077
How many parameters are trained in the first convolution layer?
The Slido app must be installed on every computer you’re presenting from
Do not edit�How to change the design
1854077
Convolution
Flatten
Pooling
Convolution
Pooling
Output
def __init__(self, num_classes=10):
super().__init__()
self.conv1 = nn.Conv2d(1, 8, kernel_size=3, padding=1)
self.pool = nn.MaxPool2d(2, 2)
1854077
Convolution
Flatten
Pooling
Convolution
Pooling
Output
def __init__(self, num_classes=10):
super().__init__()
self.conv1 = nn.Conv2d(1, 8, kernel_size=3, padding=1)
self.pool = nn.MaxPool2d(2, 2)
self.conv2 = nn.Conv2d(8, 64, kernel_size=3, padding=1)
1854077
How many parameters are trained in the second convolution layer?
The Slido app must be installed on every computer you’re presenting from
Do not edit�How to change the design
1854077
Convolution
Flatten
Pooling
Convolution
Pooling
Output
def __init__(self, num_classes=10):
super().__init__()
self.conv1 = nn.Conv2d(1, 8, kernel_size=3, padding=1)
self.pool = nn.MaxPool2d(2, 2)
self.conv2 = nn.Conv2d(8, 64, kernel_size=3, padding=1)
self.fc1 = nn.Linear(64 * 7 * 7, 256)
self.fc2 = nn.Linear(256, num_classes)
self.dropout = nn.Dropout(0.25)
1854077
Convolution
Flatten
Pooling
Convolution
Pooling
Output
def forward(self, x):
x = self.pool(F.relu(self.conv1(x))) # 8x14x14
x = self.pool(F.relu(self.conv2(x))) # 64x7x7
x = x.view(x.size(0), -1) # flatten: 64*7*7
x = self.dropout(F.relu(self.fc1(x)))
return self.fc2(x)
1854077
Convolution
Flatten
Pooling
Convolution
Pooling
Output
1854077
Convolution
Flatten
Pooling
Convolution
Pooling
Output
class SmallCNN(nn.Module):
def __init__(self):
super().__init__()
self.features = nn.Sequential(
nn.Conv2d(1, 8, 3, padding=1),
nn.ReLU(),
nn.MaxPool2d(2),
nn.Conv2d(8, 64, 3, padding=1),
nn.ReLU(),
nn.MaxPool2d(2), )
self.classifier = nn.Sequential(
nn.Flatten(),
nn.Linear(64*7*7, 256),
nn.ReLU(),
nn.Dropout(0.25),
nn.Linear(256, 10))
def forward(self, x):
x = self.features(x)
return self.classifier(x)
1854077
Demo: Moved Digits, Three Networks
Test accuracy on digits moved 4 pixels:
MLP: 30%
SmallCNN: 65%
CNN with global max pooling: 98%
1854077
Removing the Fully Connected Head
nn.Sequential(
conv, ReLU, pool, # as in SmallCNN
conv, ReLU, pool,
conv, ReLU,
nn.Conv2d(64, 10, 1), # 10 maps, 7x7
nn.AdaptiveMaxPool2d(1), # max per map
nn.Flatten()) # 10 class scores
24,170 parameters (SmallCNN: 810,394).
At 4 pixels moved: 98% correct (SmallCNN: 65%).
1854077
What Do CNNs Learn?
1854077
What Do the Filters Learn?
A deep network trained on faces and on cars (Lee et al., 2009).
Bottom: layer 1, edges.
Middle: layer 2, parts such as eyes, noses, and wheels.
Top: layer 3, whole faces and cars.
1854077
SmallCNN's First-Layer Kernels
1854077
Gabor Filters
1854077
The ImageNet Task (2009)
1854077
AlexNet (Link)
Credit: https://medium.com/data-science/advanced-topics-in-deep-convolutional-neural-networks-71ef1190522d
1854077
AlexNet's Tricks to Improve Generalization
Slides adapted from Geofrey Hinton, University of Toronto
1854077
AlexNet's First Convolution Layer
96 convolutional kernels of size 11×11×3 learned by the first convolutional layer on the 224×224×3 input images.
The top 48 kernels were learned on GPU 1 while the bottom 48 kernels were learned on GPU 2.
GPU 1 kernels: mostly gray oriented edges and stripes, like Gabor filters. GPU 2 kernels: mostly color blobs.
1854077
A Layer-2 Kernel Is Not a Picture
1854077
Which Patches Excite a Layer-2 Unit?
1854077
How About Higher Layers?
Ross Girshick, Jeff Donahue, Trevor Darrell, Jitendra Malik, “Rich feature hierarchies for accurate object detection and semantic segmentation”, CVPR, 2014
1854077
How About Higher Layers?
Ross Girshick, Jeff Donahue, Trevor Darrell, Jitendra Malik, “Rich feature hierarchies for accurate object detection and semantic segmentation”, CVPR, 2014
Top regions for six POOL5 units: Maximally activating images for some POOL5 (5th pool layer) neurons of an AlexNet. The activation values and the receptive field of the particular neuron are shown in white. Some neurons are responsive to upper bodies, text, or specular highlights.
1854077
Which Pixels Matter?
1854077
Saliency and Guided Backpropagation
1854077
Saliency and Guided Backpropagation
1854077
Demo: AlexNet on a Photo
AlexNet with its ImageNet weights, on one photo.
Top-5 predictions, random crops and flips, layer-1 kernels, feature maps, occlusion, saliency, and guided backprop.
1854077
Convolutional Neural Network
Lecture 16
Reading: Chapter 10 in Bishop Deep Learning Textbook