如何解决使用pytorch使用保存在gpu上的pickle文件绘制图形
import pickle
import matplotlib.pyplot as plt
plt.figure()
plt.title('train loss')
plt.xlabel('')
plt.ylabel('')
plt.plot(torch.load('./t_accli2.pickle',map_location = 'cpu'))
plt.savefig('./train_acc')
plt.show()
我正在尝试绘制以上图表。并得到以下错误。 我的模型在GPU上训练,并且绘制也在GPU上完成。我仍然收到以下错误。我已经使用pickle.dump保存了文件。这是一个精确的腌制文件,而不是保存的模型。
plt.plot(torch.load('./t_accli2.pickle',map_location = 'cpu'))
File "/home/enterprise.internal.city.ac.uk/adbb083/.local/lib/python3.5/site-packages/torch/serialization.py",line 529,in load
return _legacy_load(opened_file,map_location,pickle_module,**pickle_load_args)
File "/home/enterprise.internal.city.ac.uk/adbb083/.local/lib/python3.5/site-packages/torch/serialization.py",line 692,in _legacy_load
magic_number = pickle_module.load(f,**pickle_load_args)
File "/home/enterprise.internal.city.ac.uk/adbb083/.local/lib/python3.5/site-packages/torch/storage.py",line 134,in _load_from_bytes
return torch.load(io.BytesIO(b))
File "/home/enterprise.internal.city.ac.uk/adbb083/.local/lib/python3.5/site-packages/torch/serialization.py",line 702,in _legacy_load
result = unpickler.load()
File "/home/enterprise.internal.city.ac.uk/adbb083/.local/lib/python3.5/site-packages/torch/serialization.py",line 665,in persistent_load
deserialized_objects[root_key] = restore_location(obj,location)
File "/home/enterprise.internal.city.ac.uk/adbb083/.local/lib/python3.5/site-packages/torch/serialization.py",line 156,in default_restore_location
result = fn(storage,line 132,in _cuda_deserialize
device = validate_cuda_device(location)
File "/home/enterprise.internal.city.ac.uk/adbb083/.local/lib/python3.5/site-packages/torch/serialization.py",line 116,in validate_cuda_device
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.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。