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.
方法:
找到出错中你熟悉的py文件对应代码位置,本人这里是上图红色框的地方,红色框内容如下
报错代码:
target_model.load_state_dict(torch.load(load_path_target))
修改为:
target_model.load_state_dict(torch.load(load_path_target,map_location=torch.device('cpu')))