rPPG
rPPG copied to clipboard
Don't Read torch.load( ) with CPU
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!
I am also facing the same issue. Help me plz to run this code
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.
I had edit the serialization.py & also the run.py
to
self.model.load_state_dict(torch.load('linknet.pth', map_location='cpu'))