Face_recognition: performance difference between jetson nano and PC

Created on 5 Jun 2019  ·  3Comments  ·  Source: ageitgey/face_recognition

  • face_recognition version: 1.2.3(both)
  • Python version: 3.5.2
  • Operating System: windows10 and ubuntu

Description

When I ran my test code on Windows, the test images worked perfectly. After I ported the code to jetson nano(ubuntu), face_recognition could not recognize the picture at all.
当我在windows下测试人脸识别的时候,代码很完美的识别人脸,但是将代码移植到jetson nano(ubuntu)后,完全不能识别。

What I Did

My code:
`# Optional - the bounding boxes of each face if you already know them.
known_image1 = face_recognition.load_image_file("images/lv/微信图片_20190603103821.jpg")
known_image2 = face_recognition.load_image_file("images/lv/424.jpg")
known_image3 = face_recognition.load_image_file("images/lv/微信图片_20190603150416.jpg")
unknown_image = face_recognition.load_image_file("test_image/微信图片_20190603195500.jpg")

up_samples = 2
boxes1 = face_recognition.face_locations(known_image1)
boxes2 = face_recognition.face_locations(known_image2)
boxes3 = face_recognition.face_locations(known_image3)
un_boxes = face_recognition.face_locations(unknown_image)

print('start encoding')
known_image_en1 = face_recognition.face_encodings(known_image1, boxes1)[0]
known_image_en2 = face_recognition.face_encodings(known_image2, boxes2)[0]
known_image_en3 = face_recognition.face_encodings(known_image3, boxes3)[0]
unknown_image_en = face_recognition.face_encodings(unknown_image, un_boxes)[0]

know_faces = [
known_image_en1,
known_image_en2,
known_image_en3
]
face_distances = face_recognition.face_distance(know_faces, unknown_image_en)

result = face_recognition.compare_faces(know_faces, unknown_image_en)
print(result)`

The result is [True, True, True]. But in Jetson nano, I got [False, False, False]. I didn't change images

Most helpful comment

Hi @lfjd05,

Yes, this is a real bug. The issue is that the Jetson Nano CUDA libraries actually have a bug in them that causes the convolutions to be calculated incorrectly. The solution (until Nvidia fixes the CUDA implementation on Jetson) is to re-compile dlib on the Jetson Nano to force dlib to use a different method to calculate convolutions.

Luckily, the fix is simple to do. I cover it in my article here: https://medium.com/@ageitgey/build-a-hardware-based-face-recognition-system-for-150-with-the-nvidia-jetson-nano-and-python-a25cb8c891fd

Here's the relevant part cut and pasted from the article:

There is currently a bug in Nvidia’s own CUDA libraries for the Jetson Nano that keeps it from working correctly. To work around the bug, we’ll have to download dlib, edit a line of code, and re-compile it. But don’t worry, it’s no big deal.

In Terminal, run these commands:

wget http://dlib.net/files/dlib-19.17.tar.bz2 
tar jxvf dlib-19.17.tar.bz2
cd dlib-19.17

That will download and uncompress the source code for dlib. Before we compile it, we need to comment out a line. Run this command:

gedit dlib/cuda/cudnn_dlibapi.cpp

This will open up the file that we need to edit in a text editor. Search the file for the following line of code (which should be line 854):

forward_algo = forward_best_algo;

And comment it out by adding two slashes in front of it, so it looks like this:

//forward_algo = forward_best_algo;

Now save the file, close the editor, and go back to the Terminal window. Next, run these commands to compile and install dlib:

cd dlib
sudo python3 setup.py install

This will take around 30–60 minutes to finish and your Jetson Nano might get hot, but just let it run.

Finally, we need to install the face_recognition Python library. Do that with this command:

sudo pip3 install face_recognition

All 3 comments

After I print face_encodings. I found the encodings is different from windows when I use same jpg.

Hi @lfjd05,

Yes, this is a real bug. The issue is that the Jetson Nano CUDA libraries actually have a bug in them that causes the convolutions to be calculated incorrectly. The solution (until Nvidia fixes the CUDA implementation on Jetson) is to re-compile dlib on the Jetson Nano to force dlib to use a different method to calculate convolutions.

Luckily, the fix is simple to do. I cover it in my article here: https://medium.com/@ageitgey/build-a-hardware-based-face-recognition-system-for-150-with-the-nvidia-jetson-nano-and-python-a25cb8c891fd

Here's the relevant part cut and pasted from the article:

There is currently a bug in Nvidia’s own CUDA libraries for the Jetson Nano that keeps it from working correctly. To work around the bug, we’ll have to download dlib, edit a line of code, and re-compile it. But don’t worry, it’s no big deal.

In Terminal, run these commands:

wget http://dlib.net/files/dlib-19.17.tar.bz2 
tar jxvf dlib-19.17.tar.bz2
cd dlib-19.17

That will download and uncompress the source code for dlib. Before we compile it, we need to comment out a line. Run this command:

gedit dlib/cuda/cudnn_dlibapi.cpp

This will open up the file that we need to edit in a text editor. Search the file for the following line of code (which should be line 854):

forward_algo = forward_best_algo;

And comment it out by adding two slashes in front of it, so it looks like this:

//forward_algo = forward_best_algo;

Now save the file, close the editor, and go back to the Terminal window. Next, run these commands to compile and install dlib:

cd dlib
sudo python3 setup.py install

This will take around 30–60 minutes to finish and your Jetson Nano might get hot, but just let it run.

Finally, we need to install the face_recognition Python library. Do that with this command:

sudo pip3 install face_recognition

Thank you very much. I've got the right results in Jetson nano by your article.

Was this page helpful?
0 / 5 - 0 ratings