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

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. #140

Closed
nEdAy opened this issue Jan 5, 2021 · 2 comments

Comments

@nEdAy
Copy link

nEdAy commented Jan 5, 2021

python3 --version
Python 3.9.0

python u2net_portrait_test.py
Number of images:  8
...load U2NET---173.6 MB
Traceback (most recent call last):
  File "/Users/Kevin.SuTJ/Desktop/U^2 Net/u2net_portrait_test.py", line 117, in <module>
    main()
  File "/Users/Kevin.SuTJ/Desktop/U^2 Net/u2net_portrait_test.py", line 87, in main
    net.load_state_dict(torch.load(model_dir))
  File "/usr/local/lib/python3.9/site-packages/torch/serialization.py", line 595, in load
    return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
  File "/usr/local/lib/python3.9/site-packages/torch/serialization.py", line 774, in _legacy_load
    result = unpickler.load()
  File "/usr/local/lib/python3.9/site-packages/torch/serialization.py", line 730, in persistent_load
    deserialized_objects[root_key] = restore_location(obj, location)
  File "/usr/local/lib/python3.9/site-packages/torch/serialization.py", line 175, in default_restore_location
    result = fn(storage, location)
  File "/usr/local/lib/python3.9/site-packages/torch/serialization.py", line 151, in _cuda_deserialize
    device = validate_cuda_device(location)
  File "/usr/local/lib/python3.9/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 CPU.

In the u2net_portrait_test.py i added , map_location=torch.device("cpu")

net.load_state_dict(torch.load(model_dir))

to

net.load_state_dict(torch.load(model_dir, map_location=torch.device("cpu")))

And then I'm doing fine.

@a-stankevich
Copy link

This is fixed in #3 and #133. But it looks like this repo has been abandoned by the owner :(

@nEdAy
Copy link
Author

nEdAy commented Jan 11, 2021

@a-stankevich thanks.

@nEdAy nEdAy closed this as completed Jan 11, 2021
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