[Solved] About torch.nn.functional.interpolate


(YoungMin Park) #1

About

torch.nn.functional.interpolate(
    input, size=None, scale_factor=None, mode='nearest', align_corners=None)

Document says

size (int or Tuple[int] or Tuple[int, int] or Tuple[int, int, int]) 
    – output spatial size.

But it looks not clear

I tried to upsample this one

torch.Size([1, 224, 224])

to (1, 341, 512)

But followings didn’t work

o_p_ref=F.interpolate(o_p_ref, size=(ori_img_s[0],ori_img_s[1]))
o_p_ref=F.interpolate(o_p_ref, size=(1, ori_img_s[0],ori_img_s[1]))

Only this ones with one integer work

o_p_ref=F.interpolate(o_p_ref, size=(ori_img_s[0]))
# torch.Size([1, 224, 341])

o_p_ref=F.interpolate(o_p_ref, size=(ori_img_s[1]))
# torch.Size([1, 224, 512])

Looking for some advice.


(YoungMin Park) #2

It has been solved by adding dimension

o_p_ref=o_p_ref.unsqueeze(dim=0)
# print(o_p_ref.shape) # torch.Size([1, 1, 224, 224])

o_p_ref=F.interpolate(o_p_ref, size=(ori_img_s[0],ori_img_s[1]))
# torch.Size([1, 1, 341, 512])