CPU error
Rukhmini opened this issue · 1 comments
Whenever I am trying to run the code using CPU it is showing the error like this:
RuntimeError Traceback (most recent call last)
in
----> 1 detector = FaceDetector(name='mobilenet', weight_path='mobilenet.pth', device='cpu')
~\FRS\FaceLib-master\facelib\Retinaface\Retinaface.py in init(self, name, weight_path, device, confidence_threshold, top_k, nms_threshold, keep_top_k, face_size)
42
43 # setting for model
---> 44 model.load_state_dict(torch.load(weight_path))
45 model.to(device).eval()
46 self.model = model
~\Anaconda3\envs\cpu_env\lib\site-packages\torch\serialization.py in load(f, map_location, pickle_module, **pickle_load_args)
591 return torch.jit.load(f)
592 return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
--> 593 return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
594
595
~\Anaconda3\envs\cpu_env\lib\site-packages\torch\serialization.py in _legacy_load(f, map_location, pickle_module, **pickle_load_args)
771 unpickler = pickle_module.Unpickler(f, **pickle_load_args)
772 unpickler.persistent_load = persistent_load
--> 773 result = unpickler.load()
774
775 deserialized_storage_keys = pickle_module.load(f, **pickle_load_args)
~\Anaconda3\envs\cpu_env\lib\site-packages\torch\serialization.py in persistent_load(saved_id)
727 obj = data_type(size)
728 obj._torch_load_uninitialized = True
--> 729 deserialized_objects[root_key] = restore_location(obj, location)
730 storage = deserialized_objects[root_key]
731 if view_metadata is not None:
~\Anaconda3\envs\cpu_env\lib\site-packages\torch\serialization.py in default_restore_location(storage, location)
176 def default_restore_location(storage, location):
177 for _, _, fn in _package_registry:
--> 178 result = fn(storage, location)
179 if result is not None:
180 return result
~\Anaconda3\envs\cpu_env\lib\site-packages\torch\serialization.py in _cuda_deserialize(obj, location)
152 def _cuda_deserialize(obj, location):
153 if location.startswith('cuda'):
--> 154 device = validate_cuda_device(location)
155 if getattr(obj, "_torch_load_uninitialized", False):
156 storage_type = getattr(torch.cuda, type(obj).name)
~\Anaconda3\envs\cpu_env\lib\site-packages\torch\serialization.py in validate_cuda_device(location)
136
137 if not torch.cuda.is_available():
--> 138 raise RuntimeError('Attempting to deserialize object on a CUDA '
139 'device but torch.cuda.is_available() is False. '
140 'If you are running on a CPU-only machine, '
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.
you must change also the device in Face Recognizer,
go to the config file and set it to CPU
the config file is in facelib/InsightFace/models/data/config.py