TreB1eN / InsightFace_Pytorch

Pytorch0.4.1 codes for InsightFace
MIT License
1.72k stars 418 forks source link

Attempting to deserialize object on a CUDA #113

Open newmluser opened 4 years ago

newmluser commented 4 years ago

I am running on a CPU machine and having this Error:

python .\face_verify.py mtcnn loaded {'data_path': WindowsPath('data'), 'work_path': WindowsPath('work_space'), 'model_path': WindowsPath('work_space/models'), 'log_path': WindowsPath('work_space/log'), 'save_path': WindowsPath('work_space/save'), 'input_size': [112, 112], 'embedding_size': 512, 'use_mobilfacenet': False, 'net_depth': 50, 'drop_ratio': 0.6, 'net_mode': 'ir_se', 'device': device(type='cpu'), 'test_transform': Compose( ToTensor() Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]) ), 'data_mode': 'emore', 'vgg_folder': WindowsPath('data/faces_vgg_112x112'), 'ms1m_folder': WindowsPath('data/faces_ms1m_112x112'), 'emore_folder': WindowsPath('data/faces_emore'), 'batch_size': 100, 'facebank_path': WindowsPath('data/facebank'), 'threshold': 1.5, 'face_limit': 10, 'min_face_size': 30} ir_se_50 model generated Traceback (most recent call last): File ".\face_verify.py", line 29, in learner.load_state(conf, 'cpu_final.pth', True, True) File "C:\Users\Desktop\pytorch-arcface\InsightFace_Pytorch\Learner.py", line 82, in load_state self.model.load_state_dict(torch.load(savepath/'model{}'.format(fixed_str))) File "C:\Users\Anaconda3\lib\site-packages\torch\serialization.py", line 387, in load return _load(f, map_location, pickle_module, **pickle_load_args) File "C:\Users\Anaconda3\lib\site-packages\torch\serialization.py", line 574, in _load result = unpickler.load() File "C:\Users\Anaconda3\lib\site-packages\torch\serialization.py", line 537, in persistent_load deserialized_objects[root_key] = restore_location(obj, location) File "C:\Users\Anaconda3\lib\site-packages\torch\serialization.py", line 119, in default_restore_location result = fn(storage, location) File "C:\Users\Anaconda3\lib\site-packages\torch\serialization.py", line 95, in _cuda_deserialize device = validate_cuda_device(location) File "C:\Users\Anaconda3\lib\site-packages\torch\serialization.py", line 79, 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='cpu' to map your storages to the CPU.

Can you please let me know if I am missing anything.

I have the in the path: .....\pytorch-arcface\InsightFace_Pytorch\work_space\save with the .pth file copied from one drive

nidengke commented 4 years ago

you can change Learner.py in line83 from: self.model.load_state_dict(torch.load(savepath/'model{}'.format(fixed_str))) to: self.model.load_state_dict(torch.load(savepath/'model{}'.format(fixed_str),map_location='cpu'))