cuda问题

发布于 2022-01-03  144 次阅读


Traceback (most recent call last):
  File "test.py", line 50, in <module>
    MyEnsembleNet = fusion_refine(args.imagenet_model, args.rcan_model)
  File "D:\pycharm\image-drop-wu\model.py", line 403, in __init__
    self.feature_extract=Dehaze(imagenet_model)
  File "D:\pycharm\image-drop-wu\model.py", line 363, in __init__
    res2net101.load_state_dict(torch.load(os.path.join(imagenet_model,'res2net101_v1b_26w_4s-0812c246.pth')))
  File "D:\Anaconda3\envs\image-drop-wu\lib\site-packages\torch\serialization.py", line 608, in load
    return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
  File "D:\Anaconda3\envs\image-drop-wu\lib\site-packages\torch\serialization.py", line 787, in _legacy_load
    result = unpickler.load()
  File "D:\Anaconda3\envs\image-drop-wu\lib\site-packages\torch\serialization.py", line 743, in persistent_load
    deserialized_objects[root_key] = restore_location(obj, location)
  File "D:\Anaconda3\envs\image-drop-wu\lib\site-packages\torch\serialization.py", line 175, in default_restore_location
    result = fn(storage, location)
  File "D:\Anaconda3\envs\image-drop-wu\lib\site-packages\torch\serialization.py", line 151, in _cuda_deserialize
    device = validate_cuda_device(location)
  File "D:\Anaconda3\envs\image-drop-wu\lib\site-packages\torch\serialization.py", line 135, 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 C
PU.
只是给出一个较小的答案。要解决此问题,您可以更改文件中指定的函数的参数。这存储在:load()serialization.py./site-package/torch/serialization.py

写:

def load(f, map_location='cpu', pickle_module=pickle, **pickle_load_args):
而不是:

def load(f, map_location=None, pickle_module=pickle, **pickle_load_args):
希望它有帮助。

擦肩而过的概率