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.