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

Don't Read torch.load( ) with CPU #22

Open
Lee-jaehyun opened this issue Jan 5, 2022 · 3 comments
Open

Don't Read torch.load( ) with CPU #22

Lee-jaehyun opened this issue Jan 5, 2022 · 3 comments

Comments

@Lee-jaehyun
Copy link

My environment is python3.8 with MacBookAir(M1) .

I download the source code and run on terminal ' python run.py --source=0 --frame-rate25 '

I got this error message.

init
Traceback (most recent call last):
File "run.py", line 65, in
runPOS(source)
File "run.py", line 39, in call
capture = CaptureFrames(self.batch_size, source, show_mask=True)
File "/Users/jaehyuni/Desktop/rPPG-master/rPPG/capture_frames.py", line 21, in init
self.model.load_state_dict(torch.load('linknet.pth'), map_location='cpu')
File "/opt/homebrew/Caskroom/miniforge/base/envs/yolo/lib/python3.8/site-packages/torch/serialization.py", line 608, in load
return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
File "/opt/homebrew/Caskroom/miniforge/base/envs/yolo/lib/python3.8/site-packages/torch/serialization.py", line 787, in _legacy_load
result = unpickler.load()
File "/opt/homebrew/Caskroom/miniforge/base/envs/yolo/lib/python3.8/site-packages/torch/serialization.py", line 743, in persistent_load
deserialized_objects[root_key] = restore_location(obj, location)
File "/opt/homebrew/Caskroom/miniforge/base/envs/yolo/lib/python3.8/site-packages/torch/serialization.py", line 175, in default_restore_location
result = fn(storage, location)
File "/opt/homebrew/Caskroom/miniforge/base/envs/yolo/lib/python3.8/site-packages/torch/serialization.py", line 151, in _cuda_deserialize
device = validate_cuda_device(location)
File "/opt/homebrew/Caskroom/miniforge/base/envs/yolo/lib/python3.8/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.

So, I entered capture_frames.py .

edit
self.model.load_state_dict(torch.load('linknet.pth'), map_location='cpu')

Still the same error occurs.

Help me plz!

@msreevani060
Copy link

I am also facing the same issue. Help me plz to run this code

@AfonsoBernardes
Copy link

Hi there. I was having the same issue.

https://stackoverflow.com/questions/56369030/runtimeerror-attempting-to-deserialize-object-on-a-cuda-device

The first answer by Bando worked for me, hope it does for you too.

@XoxRumbleLorexoX
Copy link

I had edit the serialization.py & also the run.py

to

self.model.load_state_dict(torch.load('linknet.pth', map_location='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

4 participants