I want to use grid_sample(), and make a small example for test:
import torch.nn.functional as F
import torch.optim as optim
import torch
import torchvision
from PIL import Image
import numpy as np
img = Image.open('frame1.jpg')
img = np.array(img)
img = np.array([img])
b = torch.from_numpy(img)
b = b.permute(0, 3, 1, 2)
print(b.size())
# b has the size (1, 3, 360, 640)
flow = torch.rand(1, 360, 640 , 2)
b = Variable(b)
flow = Variable(flow)
ohno = F.grid_sample(b, flow)
but I got some error:
Traceback (most recent call last):
File “test.py”, line 25, in
ohno = F.grid_sample(b, flow)
File “/usr/local/lib/python3.5/dist-packages/torch/nn/functional.py”, line 995, in grid_sample
return GridSampler.apply(input, grid)
File “/usr/local/lib/python3.5/dist-packages/torch/nn/_functions/vision.py”, line 30, in forward
backend = type2backend[type(input)]
File “/usr/local/lib/python3.5/dist-packages/torch/_thnn/init.py”, line 15, in getitem
return self.backends[name].load()
KeyError: <class ‘torch.ByteTensor’>
Does any one know where I am wrong?