Where is PyTorch source code for bilinear interpolation for image resizing? Interested to code it from scratch

I cannot seem to backtrack from their libraries import to find the source code for the actual code of bilinear interpolation for image resize.

Tracking from torchvision.transforms.resize, I end up at torch.nn.functional where the interpolate function is imported from: (pytorch/functional.py at master · pytorch/pytorch · GitHub).

From here, I am lost. For bilinear interpolation (line 3722), it calls torch._C._nn.upsample_bilinear2d(). I believe this is the function that is typically called when someone does image resizing (default mode) in PyTorch.

Searching the code for torch._C._nn.upsample_bilinear2d(), I reach a dead-end here: (pytorch/_nn.pyi.in at master · pytorch/pytorch · GitHub)

The main reason for my inquiry is that I want to follow PyTorch bilinear interpolation (resizing image) algorithm for my CUDA code, I am currently writing a CUDA code that does batch multi-crop and resizing simultaneously which is not possible with PyTorch GPU code as you can only crop images sequentially and resize the crop sequentially too (2 individual serial process). A lot of bilinear interpolation for images seems to differ in their implementation.

The CUDA code for upsample_bilinear2d should be located here.

@ptrblck, do you know where is the CPU version of the code?

I think the CPU implementation is defined here.

Hi @ptrblck , thank you for the help. I still cannot seem to get the gist of how the implementation for bilinear interpolation is done for PyTorch. Regardless, thank you for the help!