issues with dlib library

Hello,

i uninstalled dlib via

pip3 uninstall dlib

and commented the following line

forward_algo = forward_best_algo;

within the file “cudnn_dlibapi.cpp”.

Then i did step three.

But face_detection is still not working.

Did i do anything wrong?

Best regards
Markus

Hi,

The original issue is that face_recognition.face_encodings will return NAN results, not in face_detection.
Do you meet another issue?

Thanks.

Hello AastaLLL,

yes and if i don’t misunderstood the post #16, this is a workaround for this problem.

Correct?

Thanks for your support.

Hi, can you please explain how to make these changes. Which file should I open after downloading wget http://dlib.net/files/dlib-19.16.tar.bz2 and extracting. Where is this file present? Should I just open it using text editor and make changes? Sorry for asking these questions, if it seems silly to all of you, Its just I dont have much experience with linux. I just purchased a jetson nano board and the problem I am facing is that while installing dlib for face_recognition, running the final step-installing python extensions using “python3 setup.py” install always gets stuck at 75% or somewhere above that, the whole system hangs and I cannot even move my mouse pointer.Can you please guide me on what to do? Should I wait even if the system is not responding?

Hey sreehari.mi3,

it is good to read, that i am not the only one struggeling with this. :-)

I had similiar experience while the installation process, until i increased the swapfile to 4GB.

sudo dd if=/dev/zero of=/swapfile bs=1M count=4096
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

After this my installation problems where gone.

Best of luck :-)

If you have any information about applying this workaround mentioned in #16, please let me know.
Thx.

Hi Flaty,
Thanks for the suggeston of increasing swap file size and a special Thank you for including the code to do it in your reply. But I am using a 16gb card and I think it was due to this that I ran into some trouble while trying to increase swap file size. I have flashed jetpack onto a 32 GB card and I am going to try it out tomorrow. Did you use a 32gb card? Do you think this increase of swap file is necessary if I use a big card?

As for the workaround mentioned in #16, I tried to do it today. What I did was I opened Cuda Folder and opened “cudnn_dlibapi.cpp” file using a text editor(I couldnt find any a or b directories or whatever). Then I commented out //forward_algo = forward_best_algo; and saved the file.Thats what I could make out from what they have written above about making changes. Is that all, NVIDIA Team?Do I or anybody else need to do anything else? Can you please please confirm? Anybody having knowledge about this , please do reply? graves4life55?

Hi,

i use a 32GB card and had no problems by increasing the swapfile to 4GB.

I did the same as you and built dlib as mentioned, but the result is the same.
Face detections works, but no face recognition. I don’t get any errors.
I used the same code on my raspberry pi environment without any trouble.

I hope @AastaLLL can give us the right hint. :-)

@Sreehari.m13

After you edit the file, you need to compile the library by following step 3 in the instructions that AastaLLL provided. Just saving the file does not change anything.

I do not believe that the Jetson nano has swap enabled by default so you will need to add at least 4GB of swap space as mentioned in the other comment. This is due to the fact that it takes more memory than what’s available the nano to compile dlib. I’d recommend disabling the manually created swapspace after completing the compiling as using an SD card for swap allegedly is not good for the life of the SD card.

I mentioned this before but, I also had to uninstall the existing dlib via pip after manually compiling dlib. (I’d recommend doing this first)

This can be done via:

sudo pip uninstall dlib

It may not hurt to reinstall face_recognition after manually compiling dlib. Or uninstall it before compiling and reinstall after.

Another thing that may help with resource usage during compiling if the swap space is not enough is using another tty by pressing Ctrl+alt+f5 (as an example you can use almost any of the f keys to select a tty session).

This will take you to a CLI interface where you can login and compile without worrying about unity freezing from trying to render your window manager during compilation. One of the Ctrl alt f key combinations will take you back to your UI. I don’t recommend doing this during compiling.

Personally, I’d also recommend using a barrel jack power supply instead of microUSB as it’ll provide more power, as well as using as fast of an SD card as possible. I’ve seen issues with the device freezing quite a bit without using a minimum recommended class 10 SD card.

Hope that helps.

One other thing to take into consideration to determine whether or not your issue is extending from this bug is to print out your numpy array for the result you receive for the face_encodings function.

If you have large positive numbers or receive NaN for each of the numbers as the response, this is the indicator that you are having issues with this bug.

e.g.

f_encoding = face_recognition.face_encodings(known_image)[0]
print(f_encoding)

Expected result should be small decimals, not large integers or ‘NaN’

When I do step 3 I get a failure on the final bit. I am using python3 instead of python…is that an issue? Should I install pip for 2.7? EDIT: This happens on both 19.16 and 19.17…

sudo python3 setup.py install

Output (error message):

In file included from /home/drew/dlib-19.17/dlib/external/pybind11/include/pybind11/pytypes.h:12:0,
                 from /home/drew/dlib-19.17/dlib/external/pybind11/include/pybind11/cast.h:13,
                 from /home/drew/dlib-19.17/dlib/external/pybind11/include/pybind11/attr.h:13,
                 from /home/drew/dlib-19.17/dlib/external/pybind11/include/pybind11/pybind11.h:43,
                 from /home/drew/dlib-19.17/dlib/../dlib/python/pybind_utils.h:6,
                 from /home/drew/dlib-19.17/dlib/../dlib/python.h:6,
                 from /home/drew/dlib-19.17/tools/python/src/opaque_types.h:6,
                 from /home/drew/dlib-19.17/tools/python/src/dlib.cpp:4:
/home/drew/dlib-19.17/dlib/external/pybind11/include/pybind11/detail/common.h:111:10: fatal error: Python.h: No such file or directory
 #include <Python.h>

When using python(2.7) I get:

sudo python setup.py install
Traceback (most recent call last):
  File "setup.py", line 42, in <module>
    from setuptools import setup, Extension
ImportError: No module named setuptools

I can confirm that one must use python2.7 and have pip installed to build the process.

sudo python setup.py install

So the file you need to edit is “dlib/cuda/cudnn_dlibapi.cpp”. I used vi to edit the file. Scroll down to line 851 or so and you’ll see the line that needs to be commented out.

Python3 won’t work for the build, I tested it and got the same error multiple times. It has to be done with Python2, and you have to have pip installed for python2.

I think some of these questions for compiling may be better fitted for the dlib github. Not sure honestly.

Either way,

Your ‘missing python.h’ error is because you don’t have python3-dev package installed. This provides the C headers required to compile for python.

https://stackoverflow.com/questions/21530577/fatal-error-python-h-no-such-file-or-directory

You can run the command below to resolve this.

sudo apt-get install python3-dev

You will probably run into additional missing dependencies.

Your second error is because you’re missing setup tools for python2.

sudo apt-get install python-setuptools

https://stackoverflow.com/questions/14426491/python-3-importerror-no-module-named-setuptools

My array looks like:

[array([-1.77543244e-01, 1.4254684e-01, 1.75235632e-02, -4.31025678e-02, ... ])

Hmm, strange. I did exact the steps. I uninstalled dlib, commented the line and build dlib.
i ran setup.py with python3. should i try this with python2 and works this later with my python3 script?

Hey @Flaty,

That appears to be correct.

If the code was not working due to the bug being discussed in this thread, you would receive a large number like 1.13017666e+18 (note the e+18) or NaN in your array.

Below is the result from a sample photo that I used…

[array([-3.64976637e-02,  8.59122425e-02,... ])

I would double check that you do not have an issue somewhere else in your code if you are still experiencing problems.

Maybe my encodings.pickle file is not correct.
Do you have an code example to create this file?

I use this one:

# USAGE
# When encoding on laptop, desktop, or GPU (slower, more accurate):
# python encode_faces.py --dataset dataset --encodings encodings.pickle --detection-method cnn
# When encoding on Raspberry Pi (faster, more accurate):
# python encode_faces.py --dataset dataset --encodings encodings.pickle --detection-method hog

# import the necessary packages
from imutils import paths
import face_recognition
import argparse
import pickle
import cv2
import os

# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--dataset", required=True,
	help="path to input directory of faces + images")
ap.add_argument("-e", "--encodings", required=True,
	help="path to serialized db of facial encodings")
ap.add_argument("-d", "--detection-method", type=str, default="cnn",
	help="face detection model to use: either `hog` or `cnn`")
args = vars(ap.parse_args())

# grab the paths to the input images in our dataset
print("[INFO] quantifying faces...")
imagePaths = list(paths.list_images(args["dataset"]))

# initialize the list of known encodings and known names
knownEncodings = []
knownNames = []

# loop over the image paths
for (i, imagePath) in enumerate(imagePaths):
	# extract the person name from the image path
	print("[INFO] processing image {}/{}".format(i + 1,
		len(imagePaths)))
	name = imagePath.split(os.path.sep)[-2]

	# load the input image and convert it from RGB (OpenCV ordering)
	# to dlib ordering (RGB)
	image = cv2.imread(imagePath)
	rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

	# detect the (x, y)-coordinates of the bounding boxes
	# corresponding to each face in the input image
	boxes = face_recognition.face_locations(rgb,
		model=args["detection_method"])

	# compute the facial embedding for the face
	encodings = face_recognition.face_encodings(rgb, boxes)

	# loop over the encodings
	for encoding in encodings:
		# add each encoding + name to our set of known names and
		# encodings
		knownEncodings.append(encoding)
		knownNames.append(name)

# dump the facial encodings + names to disk
print("[INFO] serializing encodings...")
data = {"encodings": knownEncodings, "names": knownNames}
f = open(args["encodings"], "wb")
f.write(pickle.dumps(data))
f.close()

I use the detection_method hog, because cnn is not working.

EDIT:
Ok, i didn’t recognize it, but i get an error when a face is detected:

/usr/local/lib/python3.6/dist-packages/face_recognition/api.py:222: RuntimeWarning: invalid value encountered in less_equal
return list(face_distance[known_face_encodings, face_encoding_to_check) <= tolerance)

I get this error once, when the first face is detected.

@Flaty

Would you be able to open a new forum thread for this? I’ll try to answer your question there if you include the code you listed above along with the error you receive when trying to run it.

I think this is getting off track of the dlib bug which was the focus of this thread; as well as notifying everyone involved on this thread with these questions.

Thanks,

Matthew

I opend a new thread

Thank you for your support.

Hi,

We have confirmed that this issue is fixed in the cuDNN v7.6.1.
Thanks.

on Jetson Nano Developer Kit

How can i update to cuDNN v7.6.1?