Open mafeng199325 opened 3 months ago
The above issue seems to be concerning to map_location argument, in order to resolve:
Replace the line, self.load_state_dict(torch.load(model_file)['model'])
, here
with :
self.load_state_dict(torch.load(model_file, map_location='cuda:0')['model'])
Do let me know if this helps :)
上述问题似乎与map_location 参数有关,为了解决:替换此处的 行
self.load_state_dict(torch.load(model_file)['model'])
和 :
self.load_state_dict(torch.load(model_file, map_location='cuda:0')['model'])
如果有帮助的话请告诉我:)
Solved thanks
(rord) robot@robot-System-Product-Name:/app/imgfeature/RoRD-main$ python extractMatch.py demo/rgb/rgb1_1.jpg demo/rgb/rgb1_2.jpg --model_file models/rord.pth Traceback (most recent call last): File "extractMatch.py", line 177, in
model = D2Net(
File "/app/imgfeature/RoRD-main/lib/model_test.py", line 62, in init
self.load_state_dict(torch.load(model_file)['model'])
File "/home/robot/miniconda3/lib/python3.8/site-packages/torch/serialization.py", line 592, in load
return _load(opened_zipfile, map_location, pickle_module, pickle_load_args)
File "/home/robot/miniconda3/lib/python3.8/site-packages/torch/serialization.py", line 851, in _load
result = unpickler.load()
File "/home/robot/miniconda3/lib/python3.8/site-packages/torch/serialization.py", line 843, in persistent_load
load_tensor(data_type, size, key, _maybe_decode_ascii(location))
File "/home/robot/miniconda3/lib/python3.8/site-packages/torch/serialization.py", line 832, in load_tensor
loaded_storages[key] = restore_location(storage, location)
File "/home/robot/miniconda3/lib/python3.8/site-packages/torch/serialization.py", line 175, in default_restore_location
result = fn(storage, location)
File "/home/robot/miniconda3/lib/python3.8/site-packages/torch/serialization.py", line 151, in _cuda_deserialize
device = validate_cuda_device(location)
File "/home/robot/miniconda3/lib/python3.8/site-packages/torch/serialization.py", line 142, in validate_cuda_device
raise RuntimeError('Attempting to deserialize object on CUDA device '
RuntimeError: Attempting to deserialize object on CUDA device 1 but torch.cuda.device_count() is 1. Please use torch.load with map_location to map your storages to an existing device.**