face_recognition icon indicating copy to clipboard operation
face_recognition copied to clipboard

RuntimeError: The stride of the 3rd dimension (the channel dimension) of the numpy array must be 1

Open vinay-kumar opened this issue 8 years ago • 11 comments

  • face_recognition version: 1.2.2
  • Python version: 2.7
  • Operating System: Ubuntu

Description

Describe what you were trying to get done. Installed latest dlib from source to enable CUDA

Tell us what happened, what went wrong, and what you expected to happen. Simply running face_recognition program yielded error

What I Did

File "face_recog.py", line 108, in <module>
    face_locations = face_recognition.face_locations(rgb_small_frame)
  File "/home/mobico/.local/lib/python2.7/site-packages/face_recognition/api.py", line 118, in face_locations
    return [_trim_css_to_bounds(_rect_to_css(face), img.shape) for face in _raw_face_locations(img, number_of_times_to_upsample, model)]
  File "/home/mobico/.local/lib/python2.7/site-packages/face_recognition/api.py", line 102, in _raw_face_locations
    return face_detector(img, number_of_times_to_upsample)
RuntimeError: The stride of the 3rd dimension (the channel dimension) of the numpy array must be 1

vinay-kumar avatar May 02 '18 11:05 vinay-kumar

Same problem.

face_recognition version: 1.2.2 face_recognition_model version: 0.3.0 Python version: 3.6.3 Operating System: Win10 numpy: 1.14.3

ghost avatar May 02 '18 13:05 ghost

Can you post a full code sample that reproduces this problem?

ageitgey avatar May 02 '18 20:05 ageitgey

When I use the example code to detect all the face locations in an image, the script works. But when I run the example code, facerec_from_video_file.py, which find face locations in the video, the script failed with the same error message. Could you please help us look into this issue?

zhihuilics avatar May 02 '18 20:05 zhihuilics

source is facerec_from_webcam_faster.py from examples folder. There is no modification from my side. I was using pip dlib and it was working fine but, as soon as, I installed dlib from source for CUDA support. I got this error.

vinay-kumar avatar May 03 '18 03:05 vinay-kumar

@vinay-kumar I changed the code and used the opencv function to convert from BGR to RGB. It works.

Did you successfully compile glib with CUDA support? I was stuck by the error that glib cannot find CUDA environment. I have checked every possible variable and nothing is missing.

zhihuilics avatar May 03 '18 03:05 zhihuilics

@zhihuilics Yes it was successful, I was also stuck once but then I carefully removed error, and I am using latest code. BGR to RGB is working fine. Here is the message from dlib install

-- Enabling CUDA support for dlib.  DLIB WILL USE CUDA

vinay-kumar avatar May 03 '18 03:05 vinay-kumar

@zhihuilics Thank you. It is now working. cv2.cvtColor(small_frame, cv2.COLOR_BGR2RGB) did the trick

vinay-kumar avatar May 03 '18 04:05 vinay-kumar

@vinay-kumar This command cv2.cvtColor(small_frame, cv2.COLOR_BGR2RGB) where did you put in file?

ghost avatar May 14 '18 18:05 ghost

@jamemyjamess Replace rgb_frame = frame[:, :, ::-1] with rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB).

zhihuilics avatar May 14 '18 18:05 zhihuilics

@zhihuilics Now it work! thanks you so much.

ghost avatar May 14 '18 18:05 ghost

@zhihuilics I changed that line with the one you provided and got this error: face_locations = face_recognition.face_locations(rgb_small_frame) NameError: name 'rgb_small_frame' is not defined

netrosec avatar May 16 '18 15:05 netrosec