Input type (torch.cuda.DoubleTensor) and weight type (torch.cuda.FloatTensor) should be the same

hello everyone.

i just keep getting this error whenever i try to train my model

RuntimeError: Input type (torch.cuda.DoubleTensor) and weight type (torch.cuda.FloatTensor) should be the same

you can find my code here

thank you

1 Like

Try moving the data to torch.float, i.e data.to(device=device, dtype=torch.float).

12 Likes

cast your input to float type by doing
input=input.float() before calling the forward pass
(I’m not sure if u should call this method after or before allocating tensor to cuda, before seems better.)

6 Likes

after i tried this i got another error

RuntimeError: 1only batches of spatial targets supported (non-empty 3D tensors) but got targets of size: : [64]

it seems you have to input 3d tensors, like x[i,j,k] but you are inputing a tensor of dim 64 ??

1 Like

yes that was a mistake I swapped (output, target) in the loss function.
thank you

i meet the same error ,if some somewhere not use cuda