RuntimeError: Invalid device, must be cuda device
lrn1314 opened this issue · 2 comments
Hello, I encountered this error while running the code. I downloaded the code and ran it directly. I have installed python 1.6.0, cuda 10.2, cuDNN7.6 and python 3.7. What is the situation, please?
Train/Val with 4/4
Epoch: 1
/LBP/model.py:178: UserWarning: masked_fill_ received a mask with dtype torch.uint8, this behavior is now deprecated,please use a mask with dtype torch.bool instead. (Triggered internally at /pytorch/aten/src/ATen/native/TensorAdvancedIndexing.cpp:570.)
I_i.narrow(1, 0, 1).masked_fill_(self.mask_tmp, 0.)
/LBP/model.py:179: UserWarning: masked_fill_ received a mask with dtype torch.uint8, this behavior is now deprecated,please use a mask with dtype torch.bool instead. (Triggered internally at /pytorch/aten/src/ATen/native/TensorAdvancedIndexing.cpp:570.)
I_i.narrow(1, 1, 1).masked_fill_(self.mask_tmp, 0.)
/LBP/model.py:180: UserWarning: masked_fill_ received a mask with dtype torch.uint8, this behavior is now deprecated,please use a mask with dtype torch.bool instead. (Triggered internally at /pytorch/aten/src/ATen/native/TensorAdvancedIndexing.cpp:570.)
I_i.narrow(1, 2, 1).masked_fill_(self.mask_tmp, 0.)
/LBP/model.py:181: UserWarning: masked_fill_ received a mask with dtype torch.uint8, this behavior is now deprecated,please use a mask with dtype torch.bool instead. (Triggered internally at /pytorch/aten/src/ATen/native/TensorAdvancedIndexing.cpp:570.)
self.L_i.narrow(1, 0, 1).masked_fill_(self.mask_tmp, 0.)
main.py:132: FutureWarning:multichannel
is a deprecated argument name forstructural_similarity
. It will be removed in version 1.0. Please usechannel_axis
instead.
ssim.append(compare_ssim(a[i], b[i], win_size=11, data_range=255.0, multichannel=True))
Val (4/4) G:17.1737, S:0.8090, P:22.16, M:0.0603
Traceback (most recent call last):
File "main.py", line 221, in
train()
File "main.py", line 185, in train
model.save_networks('Model_weights')
File "/LBP/model.py", line 74, in save_networks
net.cuda(self.opt.device)
File "/root/miniconda3/envs/myconda/lib/python3.7/site-packages/torch/nn/modules/module.py", line 458, in cuda
return self._apply(lambda t: t.cuda(device))
File "/root/miniconda3/envs/myconda/lib/python3.7/site-packages/torch/nn/modules/module.py", line 354, in _apply
module._apply(fn)
File "/root/miniconda3/envs/myconda/lib/python3.7/site-packages/torch/nn/modules/module.py", line 354, in _apply
module._apply(fn)
File "/root/miniconda3/envs/myconda/lib/python3.7/site-packages/torch/nn/modules/module.py", line 376, in _apply
param_applied = fn(param)
File "/root/miniconda3/envs/myconda/lib/python3.7/site-packages/torch/nn/modules/module.py", line 458, in
return self._apply(lambda t: t.cuda(device))
RuntimeError: Invalid device, must be cuda device
Please first make sure the 'cuda:0' is available. If still not work, try replace '.cuda(self.opt.device)' by '.cuda()'.
After modification, it can run to Epoch2, but there are still new errors.
Epoch: 2
Traceback (most recent call last):
File "main.py", line 221, in
train()
File "main.py", line 160, in train
I_g, I_o, loss_G = model.optimize_parameters()
File "/LBP/model.py", line 274, in optimize_parameters
self.forward()
File "/LBP/model.py", line 187, in forward
self.L_o = self.netLBP(self.L_i, self.mask)
File "/root/miniconda3/envs/myconda/lib/python3.7/site-packages/torch/nn/modules/module.py", line 722, in _call_impl
result = self.forward(*input, **kwargs)
File "/LBP/networks.py", line 119, in forward
out = self.trans(input) + lbp
File "/root/miniconda3/envs/myconda/lib/python3.7/site-packages/torch/nn/modules/module.py", line 722, in _call_impl
result = self.forward(*input, **kwargs)
File "/LBP/trans.py", line 310, in forward
x = self.conv1(x)
File "/root/miniconda3/envs/myconda/lib/python3.7/site-packages/torch/nn/modules/module.py", line 722, in _call_impl
result = self.forward(*input, **kwargs)
File "/root/miniconda3/envs/myconda/lib/python3.7/site-packages/torch/nn/modules/conv.py", line 419, in forward
return self._conv_forward(input, self.weight)
File "/root/miniconda3/envs/myconda/lib/python3.7/site-packages/torch/nn/modules/conv.py", line 416, in _conv_forward
self.padding, self.dilation, self.groups)
RuntimeError: Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the same