Achille
Achille

Reputation: 21

How to convert FloatTensor to ByteTensor with Pytorch?

I'm new to Pytorch and neural network programming but I've an issue I encountered and I'm not able to solve it on my own. My data are numpy arrays of 1 and 0. But when I try to train my net, I get this error :

RuntimeError: Expected object of type torch.ByteTensor but found type torch.FloatTensor for argument #2 'mat2'

the line where the error comes from is in the forward method of my net

x = self.fc1(x)

I've tried these to convert my tensors but I still get the error :

x = x.type('torch.ByteTensor')

and

x.byte()

Upvotes: 2

Views: 8272

Answers (1)

Mnez
Mnez

Reputation: 101

x.byte() returns what you need, but it's not an "inplace" method. Try doing:

x = x.byte()

Upvotes: 5

Related Questions