1 of 39

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.

2 of 39

Announcements

Project Report, Code, and Presentation now available

  • Full specs can be found on the course website
  • Report/Code submitted together in Gradescope
  • Presentation submitted as a video link in Google Form
  • Hard limits on length of reports/videos!!

Resubmission cycle is open, closes Tuesday (8/12)

  • Late submission for HW 5 accepted during this cycle
  • Note that late submissions will get late feedback!

HW5 due on Thursday (last one of the quarter!)

2

3 of 39

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

4 of 39

This Time

  • Convolutions

Last Time

  • Numpy arrays
  • Broadcasting
  • Images

4

5 of 39

Images as

Matrices

5

Grey-scale images can be represented as matrices.

Grey-scale: 255

Grey-scale: 0

data = imageio.imread(‘...’)�

data[rows, columns] = #

6 of 39

Color Images

When you overlap each color channel, it creates a picture we are used to seeing.

  • Pixels on your monitor let out specified R/G/B light

6

data[rows, columns, channels] = #

7 of 39

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

8 of 39

Convolution Example

8

9 of 39

Convolutions!

an unconvoluted example

10 of 39

9

8

7

6

5

4

3

2

1

Image

2

1

Kernel

11 of 39

9

8

7

6

5

4

3

2

1

Image

2

1

Output

Kernel

12 of 39

9

8

7

6

5

4

3

2

1

Image

2

1

Output

2

1

Kernel

13 of 39

18

8

2

1

18

8

7

6

5

4

3

2

1

Image

2

1

Output

Kernel

14 of 39

8

18

2

1

18

8

7

6

5

4

3

2

1

Image

2

1

Output

26

Kernel

15 of 39

8

18

2

1

18

8

7

6

5

4

3

2

1

Image

2

1

Output

26

Kernel

16 of 39

8

18

2

1

9

8

7

6

5

4

3

2

1

Image

2

1

Output

26

2

1

Kernel

17 of 39

2

1

8

18

2

1

9

16

7

6

5

4

3

2

1

Image

2

1

Output

16

7

26

Kernel

18 of 39

7

16

2

1

8

18

2

1

9

16

7

6

5

4

3

2

1

Image

2

1

Output

26

23

Kernel

19 of 39

7

16

2

1

8

18

2

1

9

16

7

6

5

4

3

2

1

Image

2

1

Output

26

23

Kernel

20 of 39

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

21 of 39

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

22 of 39

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

23 of 39

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

24 of 39

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

25 of 39

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

26 of 39

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

27 of 39

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

28 of 39

How many times can we fit the kernel into the image?

29 of 39

How many times can we fit the kernel into the image?

30 of 39

How many times can we fit the kernel into the image?

2

31 of 39

How many times can we fit the kernel into the image?

2

32 of 39

How many times can we fit the kernel into the image?

2

3

33 of 39

How many times can we fit the kernel into the image?

2

3 x

34 of 39

General formula:

image

(3x3)

kernel

(1x2)

output

(3x2)

(image_height – k_height + 1, image_width – k_width + 1)

35 of 39

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)

36 of 39

Common Kernels

What do the numbers in the kernel do?

36

Identity

Edge Detection

Sharpen

Box Blur

37 of 39

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

38 of 39

Image Classification

  • Is this a solved problem?
    • We get pretty decent error rates on challenges like ImageNet
  • What we can’t do
    • Sometimes can’t generalize to other real-world datasets
    • Adversarial attacks

38

39 of 39

Before Next Time

  • Complete Lesson 20
    • Remember not for points, but do go towards Checkpoint Tokens
  • HW5 due tomorrow
  • Go to section!

Next Time

  • Machine learning with images

39