All the tensor is ByteTensor, why this error occur?
I get this error ‘RuntimeError: expected Byte tensor (got Float tensor)’, but I print the input x showing it is Byte tensor.
How to fix this?
Part of code.
def forward(self, x1, x2, y):
print(x1.data)
x1 = self.conv1(x1) <------- ERROR HERE
Traceback (most recent call last):
File “/Users/wzy/PycharmProjects/pytorch/resnet.py”, line 277, in
train(epoch)
File “/Users/wzy/PycharmProjects/pytorch/resnet.py”, line 241, in train
h_x1, h_x2, h_y = model(x1, x2, y)
File “/Users/wzy/anaconda/lib/python3.5/site-packages/torch/nn/modules/module.py”, line 206, in call
result = self.forward(*input, **kwargs)
File “/Users/wzy/PycharmProjects/pytorch/resnet.py”, line 166, in forward
x1 = self.conv1(x1)
File “/Users/wzy/anaconda/lib/python3.5/site-packages/torch/nn/modules/module.py”, line 206, in call
result = self.forward(*input, **kwargs)
File “/Users/wzy/anaconda/lib/python3.5/site-packages/torch/nn/modules/conv.py”, line 237, in forward
self.padding, self.dilation, self.groups)
File “/Users/wzy/anaconda/lib/python3.5/site-packages/torch/nn/functional.py”, line 40, in conv2d
return f(input, weight, bias)
RuntimeError: expected Byte tensor (got Float tensor)
(0 ,0 ,.,.) =
0 0 0 … 255 255 255
0 0 0 … 255 255 255
0 0 1 … 255 255 255
… ⋱ …
0 0 1 … 255 255 255
0 0 0 … 255 255 255
0 0 0 … 255 255 255
(0 ,1 ,.,.) =
0 0 0 … 255 255 255
0 0 0 … 255 255 255
0 0 1 … 255 255 255
… ⋱ …
0 0 1 … 255 255 255
0 0 0 … 255 255 255
0 0 0 … 255 255 255
(0 ,2 ,.,.) =
0 0 0 … 255 255 255
0 0 0 … 255 255 255
0 0 1 … 255 255 255
… ⋱ …
0 0 1 … 255 255 255
0 0 0 … 255 255 255
0 0 0 … 255 255 255
[torch.ByteTensor of size 1x3x28x28]