我用GPU訓練了一個模型,想在本機(只有CPU)加載測試時出錯:
raise RuntimeError('Attempting to deserialize object on a CUDA ' 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()添加 map_location=torch.device('cpu')
參數即可