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

执行代码时,发生了如下错误:

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.

发现是在载入权重文件时出现了错误:

state_dict = torch.load(’./models/epoch_51-93.993.pth’)

我的电脑上没有GPU,而载入文件时默认使用GPU,应该改为:

state_dict = torch.load(’./models/epoch_51-93.993.pth’, map_location=‘cpu’)

你可能感兴趣的:(疑难杂症,python,网络实现,cuda,pytorch,神经网络)