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

尝试只用CPU时报错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. #16

Closed
yunmengjiangnan opened this issue Sep 21, 2021 · 1 comment

Comments

@yunmengjiangnan
Copy link

我尝试运行
python fishing.py image -f yolox/exp/yolox_tiny_fish.py -c weights/best_tiny3.pth --conf 0.25 --nms 0.45 --tsize 640 --device cpu
时报错
Traceback (most recent call last):
File "fishing.py", line 189, in
main(exp, args)
File "fishing.py", line 143, in main
agent.load_state_dict(torch.load(args.model_dir))
File "C:\Users\34703.conda\envs\ysfish\lib\site-packages\torch\serialization.py", line 594, in load
return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
File "C:\Users\34703.conda\envs\ysfish\lib\site-packages\torch\serialization.py", line 853, in _load
result = unpickler.load()
File "C:\Users\34703.conda\envs\ysfish\lib\site-packages\torch\serialization.py", line 845, in persistent_load
load_tensor(data_type, size, key, _maybe_decode_ascii(location))
File "C:\Users\34703.conda\envs\ysfish\lib\site-packages\torch\serialization.py", line 834, in load_tensor
loaded_storages[key] = restore_location(storage, location)
File "C:\Users\34703.conda\envs\ysfish\lib\site-packages\torch\serialization.py", line 175, in default_restore_location
result = fn(storage, location)
File "C:\Users\34703.conda\envs\ysfish\lib\site-packages\torch\serialization.py", line 151, in _cuda_deserialize
device = validate_cuda_device(location)
File "C:\Users\34703.conda\envs\ysfish\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 CPU.
image

尝试根据报错将fishing.py的115行改为ckpt = torch.load(ckpt_file, map_location=torch.device('cpu'))
仍出现此报错

@IrisRainbowNeko
Copy link
Owner

agent.load_state_dict(torch.load(args.model_dir))这一行也需要修改,agent.load_state_dict(torch.load(args.model_dir, map_location=torch.device('cpu')))

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