TreB1eN / InsightFace_Pytorch

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

RuntimeError: Cannot re-initialize CUDA in forked subprocess. To use CUDA with multiprocessing, you must use the 'spawn' start method #158

Open Sureshthommandru opened 3 years ago

Sureshthommandru commented 3 years ago

When I run the Face_verify code in linux I got the error as below

Process Process-1: Traceback (most recent call last): File "/home/super/anaconda3/envs/test/lib/python3.8/multiprocessing/process.py", line 315, in _bootstrap self.run() File "/home/super/anaconda3/envs/test/lib/python3.8/multiprocessing/process.py", line 108, in run self._target(*self._args, **self._kwargs) File "face_rec1.py", line 147, in func_detect bboxes, faces = mtcnn.align_multi(image, conf.face_limit, 16) File "/home/super/Documents/Mahesh/mtcnn.py", line 33, in align_multi boxes, landmarks = self.detect_faces(img, min_face_size) File "/home/super/Documents/Mahesh/mtcnn.py", line 112, in detect_faces boxes = run_first_stage(image, self.pnet, scale=s, threshold=thresholds[0]) File "/home/super/Documents/Mahesh/mtcnn_pytorch/src/first_stage.py", line 34, in run_first_stage img = torch.FloatTensor(_preprocess(img)).to(device) File "/home/super/anaconda3/envs/test/lib/python3.8/site-packages/torch/cuda/init.py", line 184, in _lazy_init raise RuntimeError( RuntimeError: Cannot re-initialize CUDA in forked subprocess. To use CUDA with multiprocessing, you must use the 'spawn' start method

we tried torch.multiprocesing.set_start_method('spawn', force=True) But giving another error. Please provide the solution for this.