运行pytorch的时候,出现报错:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
/usr/local/python3/lib/python3.6/site-packages/torch/serialization.py:454: SourceChangeWarning: source code of class 'model.SSD300' has changed. you can retrieve the original source code by accessing the object's source attribute or set `torch.nn.Module.dump_patches = True` and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) Traceback (most recent call last): File "train.py", line 234, in <module> main() File "train.py", line 57, in main checkpoint = torch.load(checkpoint) File "/usr/local/python3/lib/python3.6/site-packages/torch/serialization.py", line 387, in load return _load(f, map_location, pickle_module, **pickle_load_args) File "/usr/local/python3/lib/python3.6/site-packages/torch/serialization.py", line 574, in _load result = unpickler.load() File "/usr/local/python3/lib/python3.6/site-packages/torch/serialization.py", line 537, in persistent_load deserialized_objects[root_key] = restore_location(obj, location) File "/usr/local/python3/lib/python3.6/site-packages/torch/serialization.py", line 119, in default_restore_location result = fn(storage, location) File "/usr/local/python3/lib/python3.6/site-packages/torch/serialization.py", line 95, in _cuda_deserialize device = validate_cuda_device(location) File "/usr/local/python3/lib/python3.6/site-packages/torch/serialization.py", line 79, 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='cpu' to map your storages to the CPU. |
报错原因:
这种情况一般就是pytorch与cuda版本不一致,先查看pytorch支持的cuda的版本:
1 2 3 |
>>> import torch >>> torch.version.cuda '10.0.130' |
然后看一下目前cuda的版本:
1 2 3 4 |
nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2017 NVIDIA Corporation Built on Fri_Nov__3_21:07:56_CDT_2017 Cuda compilation tools, release 9.1, V9.1.85 |
很明显,不匹配,需要更换cuda版本才可以。
本文最后更新于2020年1月8日,已超过 1 年没有更新,如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢!