RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same
File "/remote-home/CS_IMIPAD_public3/yangdaoyu22/.conda/envs/dyy/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
result = self.forward(*input, **kwargs)
File "/remote-home/CS_IMIPAD_public3/yangdaoyu22/project/segmentation/WeekSupervised/ACDC/code/networks/unet_modified.py", line 29, in forward
return self.conv_conv(x)
File "/remote-home/CS_IMIPAD_public3/yangdaoyu22/.conda/envs/dyy/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
result = self.forward(*input, **kwargs)
File "/remote-home/CS_IMIPAD_public3/yangdaoyu22/.conda/envs/dyy/lib/python3.8/site-packages/torch/nn/modules/container.py", line 119, in forward
input = module(input)
File "/remote-home/CS_IMIPAD_public3/yangdaoyu22/.conda/envs/dyy/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
result = self.forward(*input, **kwargs)
File "/remote-home/CS_IMIPAD_public3/yangdaoyu22/.conda/envs/dyy/lib/python3.8/site-packages/torch/nn/modules/conv.py", line 399, in forward
return self._conv_forward(input, self.weight, self.bias)
File "/remote-home/CS_IMIPAD_public3/yangdaoyu22/.conda/envs/dyy/lib/python3.8/site-packages/torch/nn/modules/conv.py", line 395, in _conv_forward
return F.conv2d(input, weight, bias, self.stride,
RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same
Solution:
After modifying the code, I forgot to load the model into the GPU and run it. As a result, the input details are GPU, but the model is CPU,
just add cuda
model=UNet_CCT(in_chns=1,class_num=num_classes).to("cuda")
RuntimeError: CUDA error: an illegal memory access was encountered
I ran for a while before this happened
There are many solutions mentioned on the Internet:
- GPU is broken (mine is not)
- Some tensors are in cpu, some are in gpu ()
try to add the following sentence to the beginning of all files: still not working
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
- I guess there is a problem with my code, which leads to abnormal use of video memory. If you encounter this problem, you can try to reduce the use of video memory, for example: reduce the batchsize size, reduce the image_size size, change the num_work number of dataloader to 0, etc.