在CPU中运行GPU程序,出现以下问题
If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.
问题
RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.
出现以下错误
定位到19行
model_hyper.load_state_dict((torch.load('./koniq_pretrained.pkl')))
解决方案:
在模型加载时,指定 map_location='cpu'
即可,代码如下:
model_hyper.load_state_dict((torch.load('./koniq_pretrained.pkl',map_location='cpu')))