Upsampling: Nearest and Bilinear

medium
Unit 17 · Normalisation0/3 to milestone

Segmentation models, super-resolution and diffusion U-Nets all need to upsample feature maps.

Implement for a single-channel image (H, W):

  • upsample_nearest(img, factor): repeat each pixel factor × factor times → (H*factor, W*factor).
  • upsample_bilinear(img, out_h, out_w): use align-corners sampling, so output pixel (i, j) maps to the source coordinate (i * (H-1)/(out_h-1), j * (W-1)/(out_w-1)) (or 0 when the output size is 1). Interpolate linearly from the 4 surrounding pixels. The four corners of the output must equal the four corners of the input.
#vision#interpolation#numpy2 visible + 2 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Upsampling: Nearest and Bilinear · TechGradify