使用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 (将#修改为@)