hi all,
I’m new to pytorch and got in trouble testing with my pre-trained model. I think I get the input with correct format while it returns error ‘RuntimeError: Input type (CUDALongTensor) and weight type (CUDAFloatTensor) should be the same’. Here is the partial code:
net = DSN_net()
net = torch.load(args.weight)
input_data = Variable(torch.from_numpy(input_cube).long())
if args.use_gpu:
input_data = input_data.cuda()
net = net.cuda()
output = net(input_data)
also, I debug the code in this way:
input_data = Variable(torch.from_numpy(input_cube).long())
(Pdb) input_data = input_data.cuda()
(Pdb) out = net(input_data)
*** RuntimeError: Input type (CUDALongTensor) and weight type (CUDAFloatTensor) should be the same
(Pdb) type(input_data)
<class ‘torch.autograd.variable.Variable’>
(Pdb) type(net)
<class ‘dsn_net.DSN_net’>
(Pdb) type(net.conv1a.weight.data)
<class ‘torch.cuda.FloatTensor’>
(Pdb) type(input_data.data)
<class ‘torch.cuda.LongTensor’>
(Pdb) out = net(input_data)
*** RuntimeError: Input type (CUDALongTensor) and weight type (CUDAFloatTensor) should be the same
the debug results show that both the input and model weight are the desired type. In addition, I save my pre-trained model in pkl format. I have no idea why it does not work. Anyone could please help me with it ? Thanks a lot!