我在训练模型的时候使用了nn.DataParallel
,并在在服务器gpu测试也同时将训练好的模型并行载入,这样没有问题,但是我将训练好的模型在本地cpu运行的时候出错。这里记录出错的地方,并记录大致流程。
1. 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.
根据提示看出CPU读取模型的时候应该带map_location=torch.device('cpu')
参数,所以加上参数:
load_model = torch.load