Syllabus Lesson 123 of 246 · Module 10: Networks that see (CNNs)
Module 10: Networks that see (CNNs)

Going back up: upsampling and transposed convolution

Why it matters Generators (Modules 15 to 17, in Part 2 of the course) must turn a small feature map back into a full image. There are two ways to grow a map, and one of them leaves a famous checkerboard artefact.

  • Nearest upsampling: copy each pixel into a 2 by 2 block, then apply an ordinary convolution. Smooth and simple.
  • Transposed convolution with stride 2: each input pixel "stamps" the filter onto the output, 2 pixels apart. Where stamps overlap, contributions add up. With a 3-wide filter and stride 2, some output pixels get two stamps and their neighbours get one: an uneven pattern that shows up as a checkerboard.

Tiny numbers

Input [1, 1, 1], filter [1, 1, 1], stride 2: stamps start at 0, 2 and 4, giving [1, 1, 2, 1, 2, 1, 1]. A flat input came out bumpy.

Words and symbols in this lesson
convolution
sliding a small grid of weights (a filter) across an image, one dot product per position
filter, feature map
the small learned grid of weights; and the image of its responses
padding (p), stride (s)
zeros added around the edge; how many pixels the filter moves each step
transposed convolution
stamping a filter onto a bigger output; can leave a checkerboard
Your turn

Write upsample2(x) for a 1D array (each value twice) and tconv1d(x, w, stride) (stamp x[i] * w starting at i * stride; output length (len(x) - 1) * stride + len(w)). Then set checkerboard to tconv1d(np.ones(6), np.ones(3), 2).

Spotted a problem in this lesson? Report it · Ask about this lesson

This exercise opens soon

Finish the lesson before it and this one unlocks. The whole course is free, no account needed, and you can read this lesson right now.