How to simpler downsample an image tensor with bicubic?

Trying to downsample a batch of normalized image tensor but failed to get it work with transforms.Scale or PIL’s resize. Finally get it worked by :

LRTrans = transforms.Compose([
transforms.Scale(opt.imageSize // 4, Image.BICUBIC),
transforms.ToTensor(),
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)),
])
torch.FloatTensor(LRTrans(Image.fromarray(
real_cpu.mul(0.5).add(0.5).mul(255).byte()[i].transpose(0, 2).transpose(0, 1).numpy())).numpy())

Is there a better way to do this?

1 Like

If you relax your constraint on BICUBIC, you can use nn.AvgPool2d to downsample.

If not, yes this seems appropriate.

1 Like

What about nn.AdaptiveAvgPool2d?

Hi,what about using adaptive_max_pool2d if I want to retain the real value from original scale?
Looking forward to your help. Thank you!