RuntimeError: The stride of the 3rd dimension (the channel dimension) of the numpy array must be 1
- 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
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
Can you post a full code sample that reproduces this problem?
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?
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 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 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
@zhihuilics Thank you. It is now working. cv2.cvtColor(small_frame, cv2.COLOR_BGR2RGB) did the trick
@vinay-kumar This command cv2.cvtColor(small_frame, cv2.COLOR_BGR2RGB) where did you put in file?
@jamemyjamess Replace rgb_frame = frame[:, :, ::-1] with rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB).
@zhihuilics Now it work! thanks you so much.
@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