1:TypeError: can’t convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
yy=y_pred.numpy()
解决方法:改成yy=y_pred.cuda().data.cpu().numpy()
2:tensor和numpy的转换 a是tensor
解决方法:b=a.numpy()
3:读取nii文件并显示的时候
用到import skimage.io as io
ImportError: cannot import name ‘_validate_lengths’
解决方法:出现上述错误的原因是由于在安装其他库的过程中,numpy库的版本变了,所以导致错误。因此,只需升级一下scikit-image库
pip install -U scikit-image
4:AttributeError: ‘torch.device’ object has no attribute ‘_apply’
解决方法:原因是模型没有实例化,net = model() 写成了 net = model;