RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is Fal

RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False.

问题描述

没有GPU,torch安装的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.

数据加载的时候使用了GPU,

找到你报错时对应的地址
打开文件
将语句,

 torch.load(model_path)

改为:

 model = torch.load(model_path, map_location='cpu')

上面语句中的model_path、model根据你的实际对应的修改

举个例子:

 param_dict = torch.load(trained_path)

改为

 param_dict = torch.load(trained_path, map_location='cpu')

如果对你有用的话,请给我点赞、留言吧

参考:
https://blog.csdn.net/quantum7/article/details/89333293

感谢以上的分享!

写作时间:2020.5.3
如需转载,请注明出处,否则将追究法律责任。

你可能感兴趣的:(python,深度学习,linux,gpu,cuda)