Bicubic interpolation in pytorch
I'm trying to do bicubic interpolation on a torch.Tensor.

I know about torch.nn.functional.interpolate, but that method doesn't support bicubic interpolation yet.

I know that PIL images support bicubic interpolation, so I created this snippet (part of torch.nn.Module).

def build_transform(self, shape):
    h, w = shape[2] * self.scale_factor, shape[3] * self.scale_factor
    return Compose([
        ToPILImage(),
        Resize((h, w), interpolation=PIL.Image.BICUBIC),
        ToTensor()
      ])

def forward(self, x: Tensor):
    if self.transform is None:
        self.transform = self.build_transform(x.shape)

    shape = x.shape[0], x.shape[1], x.shape[2] * self.scale_factor, x.shape[3] * self.scale_factor
    new = Tensor(size=shape, device=x.device)

    for i in range(x.shape[0]):
        new[i] = self.transform(x[i])
    new.requires_grad_()

    return new


My assumption is that this method is slower than interpolating the Tensor in one pass.

My Question: Is there no other way to compute this without the loop? I assume that the difference would be noticeable (correct me if I'm wrong).

torch.nn.functional.interpolate() with mode='bicubic' is supported since pytorch 1.2.0.
