ageitgey / face_recognition

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

Error during face_encodings - code: 7, reason: A call to cuDNN failed #854

Open suprnrdy opened 5 years ago

suprnrdy commented 5 years ago

Description

Following the JetsonNano instructions and incorporating ZED Camera feed by replaced cv2.VideoCapture with cam.retrieve_image (https://www.stereolabs.com/docs/opencv-python/#capturing-video), I get a crash during face_encoding.

I've verified that the image is converted to RGB and scaled down to 1/4 original size, yet still get this crash every time. When I try the original example using the ZED camera as a Universal Video Camera (UVC) [https://www.stereolabs.com/docs/opencv-python/#uvc-capture] there are no issues.

Error:

Traceback (most recent call last): File "facedetect.py", line 251, in <module> main_loop() File "facedetect.py", line 163, in main_loop face_encodings = face_recognition.face_encodings(rgb_small_frame, face_locations) File "/usr/local/lib/python3.6/dist-packages/face_recognition/api.py", line 210, in face_encodings return [np.array(face_encoder.compute_face_descriptor(face_image, raw_landmark_set, num_jitters)) for raw_landmark_set in raw_landmarks] File "/usr/local/lib/python3.6/dist-packages/face_recognition/api.py", line 210, in <listcomp> return [np.array(face_encoder.compute_face_descriptor(face_image, raw_landmark_set, num_jitters)) for raw_landmark_set in raw_landmarks] RuntimeError: Error while calling cudnnConvolutionForward( context(), &alpha, descriptor(data), data.device(), (const cudnnFilterDescriptor_t)filter_handle, filters.device(), (const cudnnConvolutionDescriptor_t)conv_handle, (cudnnConvolutionFwdAlgo_t)forward_algo, forward_workspace, forward_workspace_size_in_bytes, &beta, descriptor(output), output.device()) in file /tmp/pip-build-do6wa1sv/dlib/dlib/cuda/cudnn_dlibapi.cpp:1007. code: 7, reason: A call to cuDNN failed

What I Did (main_loop)

`def main_loop():

#conifgure ZED camera
init = sl.InitParameters()
cam = sl.Camera()
if not cam.is_opened():
    print("Opening ZED Camera...")
status = cam.open(init)
if status != sl.ERROR_CODE.SUCCESS:
    print(repr(status))
    exit()

runtime = sl.RuntimeParameters()
mat = sl.Mat()
print_camera_information(cam)

# ZED
# Get image size
image_size = cam.get_resolution()
width = image_size.width
height = image_size.height
left_image_rgba = np.zeros((height, width, 4), dtype=np.uint8)
# Prepare single image containers
left_image = sl.Mat()

# Track how long since we last saved a copy of our known faces to disk as a backup.
number_of_faces_since_save = 0

while True:
    # Grab a single frame of video (ZED)
    err = cam.grab(runtime)
    if err == sl.ERROR_CODE.SUCCESS:
        cam.retrieve_image(left_image, sl.VIEW.VIEW_LEFT)

    ## TODO: Look at what type the images are here. *******
    # Copy the left image to the left side of SBS image
    left_image_rgba[0:height, 0:width, :] = left_image.get_data()
    # Convert SVO image from RGBA to RGB
    left_image_rgb = cv2.cvtColor(left_image_rgba, cv2.COLOR_RGBA2RGB)

    # Resize frame of video to 1/4 size for faster face recognition processing
    small_frame = cv2.resize(left_image_rgb, (0, 0), fx=0.175, fy=0.175) #(ZED)

    # Convert the image from BGR color (which OpenCV uses) to RGB color (which face_recognition uses)
    rgb_small_frame = small_frame

    # Find all the face locations and face encodings in the current frame of video
    face_locations = face_recognition.face_locations(rgb_small_frame)
    print("Number of faces detected: ", len(face_locations))
    print(face_locations)
    print(rgb_small_frame.shape)
    face_encodings = face_recognition.face_encodings(rgb_small_frame, face_locations)

    # Loop through each detected face and see if it is one we have seen before
    # If so, we'll give it a label that we'll draw on top of the video.
    face_labels = []
    for face_location, face_encoding in zip(face_locations, face_encodings):
        # See if this face is in our list of known faces.
        metadata = lookup_known_face(face_encoding)

        # If we found the face, label the face with some useful information.
        if metadata is not None:
            time_at_door = datetime.now() - metadata['first_seen_this_interaction']
            face_label = f"At door {int(time_at_door.total_seconds())}s"

        # If this is a brand new face, add it to our list of known faces
        else:
            face_label = "New visitor!"

            # Grab the image of the the face from the current frame of video
            top, right, bottom, left = face_location
            face_image = small_frame[top:bottom, left:right]
            face_image = cv2.resize(face_image, (150, 150))

            # Add the new face to our known face data
            register_new_face(face_encoding, face_image)

        face_labels.append(face_label)

    # Draw a box around each face and label each face
    for (top, right, bottom, left), face_label in zip(face_locations, face_labels):
        # Scale back up face locations since the frame we detected in was scaled to 1/4 size
        top *= 4
        right *= 4
        bottom *= 4
        left *= 4

        # Draw a box around the face
        cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)

        # Draw a label with a name below the face
        cv2.rectangle(frame, (left, bottom - 35), (right, bottom), (0, 0, 255), cv2.FILLED)
        cv2.putText(frame, face_label, (left + 6, bottom - 6), cv2.FONT_HERSHEY_DUPLEX, 0.8, (255, 255, 255), 1)

    # Display recent visitor images
    number_of_recent_visitors = 0
    for metadata in known_face_metadata:
        # If we have seen this person in the last minute, draw their image
        if datetime.now() - metadata["last_seen"] < timedelta(seconds=10) and metadata["seen_frames"] > 5:
            # Draw the known face image
            x_position = number_of_recent_visitors * 150
            frame[30:180, x_position:x_position + 150] = metadata["face_image"]
            number_of_recent_visitors += 1

            # Label the image with how many times they have visited
            visits = metadata['seen_count']
            visit_label = f"{visits} visits"
            if visits == 1:
                visit_label = "First visit"
            cv2.putText(frame, visit_label, (x_position + 10, 170), cv2.FONT_HERSHEY_DUPLEX, 0.6, (255, 255, 255), 1)

    if number_of_recent_visitors > 0:
        cv2.putText(frame, "Visitors at Door", (5, 18), cv2.FONT_HERSHEY_DUPLEX, 0.8, (255, 255, 255), 1)

    # Display the final frame of video with boxes drawn around each detected fames
    # cv2.imshow('Video', frame)
    cv2.imshow("ZED", rgb_small_frame)

    # Hit 'q' on the keyboard to quit!
    if cv2.waitKey(1) & 0xFF == ord('q'):
        save_known_faces()
        break

    # We need to save our known faces back to disk every so often in case something crashes.
    if len(face_locations) > 0 and number_of_faces_since_save > 100:
        save_known_faces()
        number_of_faces_since_save = 0
    else:
        number_of_faces_since_save += 1

# Release handle to the webcam
#video_capture.release()
cv2.destroyAllWindows()
# Close (ZED)
cam.close()

`

congphase commented 4 years ago

Did you solve the issue? I'm facing the same issue.

Professor-Paradox commented 4 years ago

can you provide the trace back of this program's output,

if cudnn failed that means the installation of cudnn failed,verify that with nvcc -V this should output the cuda version being used,then download the libcudnn files from nvidia developer site and install them,try the mnistcudnn test. If that throws any errors the installation is messed up.