深度学习报错日志

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

解决办法:
修改代码过后忘记把模型加载GPU里面跑了,导致输入详细是GPU,但模型是CPU的情况
添加cuda即可

model=UNet_CCT(in_chns=1,class_num=num_classes).to("cuda")

你可能感兴趣的:(#,非模型优化,深度学习,python,人工智能)