Very poor Performance with with NVIDIA Jetson Nano 2GB in Face Recognition

So i just started my adventure further into the AI and Deep Learning World. With a little help of @paul.mcwhorter Video Series on Youtube, and some additional stuff I read alongside. Now i’m at the point where the Facial recognition starts and i cant get a proper Frame rate for the Project it seems to be around .2 fps.

First of all some Information from my System.
NVIDIA Jetson Nano (Developer Kit Version)
L4T 32.6.1 [ JetPack 4.6 ]
Ubuntu 18.04.6 LTS
Kernel Version: 4.9.253-tegra
CUDA 10.2.300
CUDA Architecture: 5.3
OpenCV version: 4.1.1
OpenCV Cuda: NO
CUDNN: 8.2.1.32
TensorRT: 8.0.1.6
Vision Works: 1.6.0.501
VPI: ii libnvvpi1 1.1.15 arm64 NVIDIA Vision Programming Interface library
Vulcan: 1.2.70
dlib 19.17
face_recognition 1.3.0
Here is the Programm i try to run but it dont run properly:

import cv2
import pickle
import face_recognition
import os
#Variables Data
names = []
encodings = []
font = cv2.FONT_HERSHEY_SIMPLEX

#Load the Trainingfile
with open('train.pkl','rb') as file:
    names = pickle.load(file)
    encodings = pickle.load(file)

#Setup Cam 
cam = cv2.VideoCapture(0)
#Showing Cam
while True:
    #Looking for Faces in the Frame
    ret,frame = cam.read()
    frameSmall = cv2.resize(frame,(0,0),fx = .3, fy = .3)
    frameRGB = cv2.cvtColor(frameSmall, cv2.COLOR_BGR2RGB)
    facePosition = face_recognition.face_locations(frameRGB)
    allEncodings = face_recognition.face_encodings(frameRGB,facePosition)
    for (top,right,bottom,left), face_encoding in zip(facePosition,allEncodings):
        name = 'unknown Person'
        match = face_recognition.compare_faces(encodings,face_encoding)
        if True in match:
            first_match_index = match.index(True)
            name = names[first_match_index]
        top = top*3
        right = right*3
        bottom = bottom*3
        left = left*3
        cv2.rectangle(frame,(left,top),(right,bottom),(0,255,0),2)
        cv2.putText(frame, name,(left,top-6),font,.75,(0,0,255))
    #Showing The Frame
    cv2.imshow('Cam', frame)
    cv2.moveWindow('Cam',0,0)
    if cv2.waitKey(100) == ord('q'):
        break

cam.release()
cv2.destroyAllWindows

I appreciate every help

Thankyou for including your system information.

your issue (need for speed) is related to: OpenCV Cuda: NO
your using your CPU to process in cv2.

first check out.

also this thread:

Thanks for your answer. Sorry I didnt replied but I had a full schedule. I just upgraded my OpenCV and got CUDA Support in OpenCV. Its now looking like this:
NVIDIA Jetson Nano (Developer Kit Version)
L4T 32.6.1 [ JetPack 4.6 ]
Ubuntu 18.04.6 LTS
Kernel Version: 4.9.253-tegra
CUDA 10.2.300
CUDA Architecture: 5.3
OpenCV version: 4.5.5
OpenCV Cuda: YES
CUDNN: 8.2.1.32
TensorRT: 8.0.1.6
Vision Works: 1.6.0.501
VPI: ii libnvvpi1 1.1.15 arm64 NVIDIA Vision Programming Interface library
Vulcan: 1.2.70

However I build a FPS Counter to track how much FPS I get and it barely made it to 2 FPS which is horrible. My programm uses OpenCV 4.5.5 (checked it with cv2.version). I also checked in with jtop to see GPU usage when im running the Programm and it seems like the Programm still doesnt use any of it.

Is it not the face_recognition which is the problematic part since OpenCV just grabs the Frame draws some Circle and thats it. Nothing heavy load there or am I missing something. face_recognition compares the Faces so I think this is my Problem isnt it ?

I don’t see you using your GPU to process this in your python script.

net.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA)
net.setPreferableTarget(cv2.dnn.DNN_TARGET_CUDA)

again please read this:

and this for more help:

Sorry im not a python guy or I’d be able to help you more. Want to do this inTensorFlow.js nodejs I’d be of more help 2 you.

1 Like

Yeah its okay I appreciate your help. But I dont understand I use the face_recognition library as my model if im right or ? So if i use the Lines you appended I will use another model am I right ? I read the other Forum post but i dont quiete get it.

Looks Like your right on the model needing to be different.

Check out this howto:

I took a look at his code provided for the example: https://techvidvan.s3.amazonaws.com/machine-learning-projects/face-detection-opencv-python.zip

It looks like you need to use the cnn model.
i found this in his example code.

# Find the face location and encodings for the current frame
    # 'cnn' runs on gpu and it is more accurate. change it to 'hog' is you want to run on cpu.
    face_locations = face_recognition.face_locations(Current_image, model='cnn')  
    face_encodes = face_recognition.face_encodings(Current_image,face_locations)

I hope this puts you on the right path.

Side Note:
If you start working on object detection using openCV and python let me know I’m working on that now.
I love nvidia and they have some great tutorials:

but they lock you into their eco system with their great tools. but having to import nvida-utils is not on my todo list

on day 12 of learning python and I’ve Just got openCV + cv2.cuda_GpuMat + python cropping the rtsp stream using the GPU.

code snippit:

while True:
            # read current frame
            _, img = camera.read()

            img_to_gpu = cv2.cuda_GpuMat()
            img_to_gpu.upload(img)

            #imgCrop = img[yStart:heigth_of_crop, xStart:width_of_crop] #CPU CROP
            #imgCrop = cv2.UMat(img, [yStart, heigth_of_crop], [xStart, width_of_crop]) #GPU UMAT CROP
            imgCrop = cv2.cuda_GpuMat(img_to_gpu, [yStart, heigth_of_crop], [xStart, width_of_crop]) #GPU cuda_UMAT CROP
            imgCrop = imgCrop.download()
            

            # encode as a jpeg image and return it
            yield cv2.imencode('.jpg', imgCrop)[1].tobytes()

if you head down the object detection route give me a PM (private msg] and I’ll see if I can help you out as that is what im working on now.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.