pytorch出错: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False
错误一: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.devi
错误一: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.
解决方法:在torch.load(xxx)后面添加map_location=torch.device('cpu')
或者map_location='cpu'
示例:
state_dict = torch.load(self.model_path)
在torch.load括号后面添加map_location=torch.device('cpu')
或者map_location='cpu'
在这里修改如下:
state_dict = torch.load(self.model_path,map_location='cpu')
或
state_dict = torch.load(self.model_path,map_location='cpu')
修改之后,运行可能会出现以下错误:
错误二:AssertionError: Torch not compiled with CUDA enabled
解决方法:去掉所有的.cuda()
示例:
点击蓝色部分字体,进入代码,定位到出错位置,可以看到这边转换为cuda运行,将其注释掉即可
注释掉,并保存
继续运行程序,找出.cuda()
,并将其去掉
更多推荐
所有评论(0)