GPU训练模型在CPU下使用
今天我想试试那个SkyAR,但是我没找到GPU的电脑我就想在CPU下使用GPU训练好的模型,使用的时遇到了下面这个问题
`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上训练,加载模型时需要映射到CPU上才能使用。
解决方式就是在代码中找到加载模型的那个位置
我的是下面这样
checkpoint = torch.load(os.path.join(self.ckptdir,'best_ckpt.pt'))
将它修改为
checkpoint = torch.load(os.path.join(self.ckptdir,'best_ckpt.pt'),map_location=torch.device(device))
就可以使用了
`