Downsampling tensors

How can i downsample a tensor representing an image using Nearest/Bilinear interpolation?

I’ve tried using torch.nn.Upsample with a size smaller than the original one, my outputs seem fine and i don’t get any errors. Are there any problems i’m not seeing with this kind of usage of Upsample?

1 Like

Same question here…

Finally it has been implemented by
https://pytorch.org/docs/stable/nn.html?highlight=interpolate#torch.nn.functional.interpolate
:grinning:

6 Likes

Upsample uses F.interpolate as suggested.
We can check the source to see what’s actually doing: https://pytorch.org/docs/stable/_modules/torch/nn/functional.html#interpolate
The default mode ‘nearest’ doesn’t suit downscaling but ‘bilinear’ works fine (please correct me if I’m wrong!).
Otherwise, just use mode ‘area’ or adaptive_avg_pool2d directly. However, the latter seems a bit slower than ‘bilinear’.