Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running environment error #14

Open
mafeng199325 opened this issue Jul 24, 2024 · 2 comments
Open

Running environment error #14

mafeng199325 opened this issue Jul 24, 2024 · 2 comments

Comments

@mafeng199325
Copy link

(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.
**

@UditSinghParihar
Copy link
Owner

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 :)

@mafeng199325
Copy link
Author

上述问题似乎与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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants