ageitgey / face_recognition

The world's simplest facial recognition api for Python and the command line
MIT License
53.01k stars 13.45k forks source link

RuntimeError when running multiprocessing example #841

Open carratala17707 opened 5 years ago

carratala17707 commented 5 years ago

I'm trying to use the facerec_from_webcam_multiprocessing.py example with cuda support, but everytime I run it I get this error:

Width: 640, Height: 480, FPS: 30
Process Process-5:
Traceback (most recent call last):
  File "/usr/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
    self.run()
  File "/usr/lib/python3.7/multiprocessing/process.py", line 99, in run
    self._target(*self._args, **self._kwargs)
  File "facerec_from_webcam_multiprocessing.py", line 78, in process
    face_locations = face_recognition.face_locations(rgb_frame, model="cnn")
  File "/usr/local/lib/python3.7/dist-packages/face_recognition/api.py", line 116, in face_locations
    return [_trim_css_to_bounds(_rect_to_css(face.rect), img.shape) for face in _raw_face_locations(img, number_of_times_to_upsample, "cnn")]
  File "/usr/local/lib/python3.7/dist-packages/face_recognition/api.py", line 100, in _raw_face_locations
    return cnn_face_detector(img, number_of_times_to_upsample)
RuntimeError: Error while calling cudaGetDevice(&the_device_id) in file /home/han/dlib-19.17/dlib/cuda/gpu_data.cpp:201. code: 3, reason: initialization error
Process Process-6:
Traceback (most recent call last):
  File "/usr/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
    self.run()
  File "/usr/lib/python3.7/multiprocessing/process.py", line 99, in run
    self._target(*self._args, **self._kwargs)
  File "facerec_from_webcam_multiprocessing.py", line 78, in process
    face_locations = face_recognition.face_locations(rgb_frame, model="cnn")
  File "/usr/local/lib/python3.7/dist-packages/face_recognition/api.py", line 116, in face_locations
    return [_trim_css_to_bounds(_rect_to_css(face.rect), img.shape) for face in _raw_face_locations(img, number_of_times_to_upsample, "cnn")]
  File "/usr/local/lib/python3.7/dist-packages/face_recognition/api.py", line 100, in _raw_face_locations
    return cnn_face_detector(img, number_of_times_to_upsample)
RuntimeError: Error while calling cudaGetDevice(&the_device_id) in file /home/han/dlib-19.17/dlib/cuda/gpu_data.cpp:201. code: 3, reason: initialization error
Process Process-7:
Traceback (most recent call last):
  File "/usr/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
    self.run()
  File "/usr/lib/python3.7/multiprocessing/process.py", line 99, in run
    self._target(*self._args, **self._kwargs)
  File "facerec_from_webcam_multiprocessing.py", line 78, in process
    face_locations = face_recognition.face_locations(rgb_frame, model="cnn")
  File "/usr/local/lib/python3.7/dist-packages/face_recognition/api.py", line 116, in face_locations
    return [_trim_css_to_bounds(_rect_to_css(face.rect), img.shape) for face in _raw_face_locations(img, number_of_times_to_upsample, "cnn")]
  File "/usr/local/lib/python3.7/dist-packages/face_recognition/api.py", line 100, in _raw_face_locations
    return cnn_face_detector(img, number_of_times_to_upsample)
RuntimeError: Error while calling cudaGetDevice(&the_device_id) in file /home/han/dlib-19.17/dlib/cuda/gpu_data.cpp:201. code: 3, reason: initialization error
Process Process-8:
Traceback (most recent call last):
  File "/usr/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
    self.run()
  File "/usr/lib/python3.7/multiprocessing/process.py", line 99, in run
    self._target(*self._args, **self._kwargs)
  File "facerec_from_webcam_multiprocessing.py", line 78, in process
    face_locations = face_recognition.face_locations(rgb_frame, model="cnn")
  File "/usr/local/lib/python3.7/dist-packages/face_recognition/api.py", line 116, in face_locations
    return [_trim_css_to_bounds(_rect_to_css(face.rect), img.shape) for face in _raw_face_locations(img, number_of_times_to_upsample, "cnn")]
  File "/usr/local/lib/python3.7/dist-packages/face_recognition/api.py", line 100, in _raw_face_locations
    return cnn_face_detector(img, number_of_times_to_upsample)
RuntimeError: Error while calling cudaGetDevice(&the_device_id) in file /home/han/dlib-19.17/dlib/cuda/gpu_data.cpp:201. code: 3, reason: initialization error

I looked at the multiprocessing documentation and made a few changes in the script without success. Could you give me a hint on how could I make it work? Thanks in advance.

angiglesias commented 5 years ago

I had that same issue with python 3.6 and fixed doing the import of face_recognition module inside the process function

carratala17707 commented 5 years ago

I had that same issue with python 3.6 and fixed doing the import of face_recognition module inside the process function

Thank you for your answer! but that didn't work for me... Anyone else?

SaddamBInSyed commented 5 years ago

@carratala17707 @angiglesias

Hi all,

I am facing the same issue in jetson nano board.

did you solve your pbm? help appreciated.

xcaizewu commented 4 years ago

@carratala17707 @angiglesias

Hi all,

I am facing the same issue in jetson nano board.

did you solve your pbm? help appreciated.

i solved this pbm, use cpu when you install dilb. @SaddamBInSyed