CSE 163
Convolutions�
Suh Young Choi�
🎶 Listening to: Inception soundtrack
💬 Before Class: Buffalo buffalo buffalo buffalo Buffalo buffalo buffalo. Weird how that’s a grammatically correct sentence.
Announcements
Project Report, Code, and Presentation now available
Resubmission cycle is open, closes Tuesday (8/12)
HW5 due on Thursday (last one of the quarter!)
2
Remaining Due Dates
To assist with planning:
3
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
Aug 3 | 4 | 5 | 6 | 7 THA 5 due | 8 | 9 |
10 | 11 CP 3 / LR 6 due | 12 Resubs due (THA 3-5) | 13 | 14 Report/Code due | 15 | 16 |
17 Presentation due | 18 CP 4 / LR 7 due | 19 Resubs due (THA 4-5) | 20 | 21 | 22 Last day to submit CP/LR Peer feedback due | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
This Time
Last Time
4
Images as
Matrices
5
Grey-scale images can be represented as matrices.
Grey-scale: 255
Grey-scale: 0
data = imageio.imread(‘...’)�
data[rows, columns] = #
Color Images
When you overlap each color channel, it creates a picture we are used to seeing.
6
data[rows, columns, channels] = #
Convolution
When wanting to use “local” information, we commonly use a sliding window approach (i.e. a convolution)
Move the sliding window across the image, and compute the sum of the element wise product of the window (kernel) and image
7
3 | 3 | 2 | 1 | 0 |
0 | 0 | 1 | 3 | 1 |
3 | 1 | 2 | 2 | 3 |
2 | 0 | 0 | 2 | 2 |
2 | 0 | 0 | 0 | 1 |
Image
0 | 1 | 2 |
2 | 2 | 0 |
0 | 1 | 2 |
Kernel
Convolution Example
8
Convolutions!
an unconvoluted example
9 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Kernel
9 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Output
| |
| |
| |
Kernel
9 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Output
| |
| |
| |
2
1
Kernel
18 |
8 |
2
1
18 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Output
| |
| |
| |
Kernel
8 |
18 |
2
1
18 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Output
| |
| |
| |
26
Kernel
8 |
18 |
2
1
18 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Output
| |
| |
| |
26
Kernel
8 |
18 |
2
1
9 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Output
| |
| |
| |
26
2
1
Kernel
2
1
8 |
18 |
2
1
9 | 16 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Output
| |
| |
| |
16 |
7 |
26
Kernel
7 |
16 |
2
1
8 |
18 |
2
1
9 | 16 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Output
| |
| |
| |
26
23
Kernel
7 |
16 |
2
1
8 |
18 |
2
1
9 | 16 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Output
| |
| |
| |
26
23
Kernel
7 |
16 |
2
1
8 |
18 |
2
1
9 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Output
| |
| |
| |
26
23
2
1
17
Kernel
7 |
16 |
2
1
8 |
18 |
2
1
9 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Output
| |
| |
| |
26
23
2
1
17
Kernel
7 |
16 |
2
1
8 |
18 |
2
1
9 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Output
| |
| |
| |
26
23
2
1
17
14
Kernel
7 |
16 |
2
1
8 |
18 |
2
1
9 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Output
| |
| |
| |
26
23
2
1
17
14
Kernel
7 |
16 |
2
1
8 |
18 |
2
1
9 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Output
| |
| |
| |
26
23
2
1
17
14
8
Kernel
7 |
16 |
2
1
8 |
18 |
2
1
9 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Output
| |
| |
| |
26
23
2
1
17
14
8
Kernel
7 |
16 |
2
1
8 |
18 |
2
1
9 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Output
| |
| |
| |
26
23
2
1
17
14
8
5
Kernel
7 |
16 |
2
1
8 |
18 |
2
1
9 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Output
| |
| |
| |
26
23
2
1
17
14
8
5
Kernel
How many times can we fit the kernel into the image?
| | |
| | |
| | |
| |
“
How many times can we fit the kernel into the image?
| | |
| | |
| | |
| |
“
How many times can we fit the kernel into the image?
| | |
| | |
| | |
| |
2
“
How many times can we fit the kernel into the image?
| | |
| | |
| | |
| |
2
“
How many times can we fit the kernel into the image?
| | |
| | |
| | |
| |
2
3
“
How many times can we fit the kernel into the image?
| | |
| | |
| | |
| |
2
3 x
| |
| |
| |
“
General formula:
| | |
| | |
| | |
| |
| |
| |
| |
image
(3x3)
kernel
(1x2)
output
(3x2)
(image_height – k_height + 1, image_width – k_width + 1)
“
More Generic Formula for Result Size
35
Image
Kernel
width
height
k_height
k_width
(0, 0)
k[0]
k[1]
(1, 0)
…
(width - k_width, 0)
k[width - k_width]
Total of (width - k_width + 1) kernels because of zero based indexing!
So the shape of the result will be (height - k_height + 1, width - k_width + 1)
Common Kernels
What do the numbers in the kernel do?
36
Identity
Edge Detection
Sharpen
Box Blur
Image Classification
For a really long time, image classification was done by painstakingly crafting these features (like edge detectors), by hand.
This kind of worked, but we quickly hit our peak using this method.
Then came the buzz-word… deep learning
37
Image Classification
38
Before Next Time
Next Time
39