face_recognition icon indicating copy to clipboard operation
face_recognition copied to clipboard

Landmark detection is pretty slow :(

Open schwarzwals opened this issue 3 years ago • 4 comments

  • face_recognition version: 1.3.0
  • Python version: 3.9.5
  • Operating System: Mac OS 10.14.6

I am detecting face landmarks. Mostly nose bridge in order to crop the images later. I found it pretty slow to do it. About 6 seconds per image.

Is there a way to speed up the process ? Can I look only for the nose bridge landmarks somehow ? Would that be faster ? Also file size might be a problem ?

Any help is appreciated !

test3

`from PIL import Image, ImageDraw
import face_recognition

# Load the jpg file into a numpy array
image = face_recognition.load_image_file("test.jpg")

# Find all facial features in all the faces in the image
face_landmarks_list = face_recognition.face_landmarks(image)

print("I found {} face(s) in this photograph.".format(len(face_landmarks_list)))

# Create a PIL imagedraw object so we can draw on the picture
pil_image = Image.fromarray(image)
d = ImageDraw.Draw(pil_image)

for face_landmarks in face_landmarks_list:

    # Print the location of each facial feature in this image
    for facial_feature in face_landmarks.keys():
        print("The {} in this face has the following points: {}".format(facial_feature, face_landmarks[facial_feature]))

    # Let's trace out each facial feature in the image with a line!
    for facial_feature in face_landmarks.keys():
        d.line(face_landmarks[facial_feature], width=2)

# Show the picturew
pil_image.show()
cv2.imwrite('result.png', test)`

schwarzwals avatar Jul 09 '21 11:07 schwarzwals

any ideas anyone ?

schwarzwals avatar Jul 22 '21 12:07 schwarzwals

hmm, how about you resize the image you're trying to analyze?

VirusEnabled avatar Jul 27 '21 13:07 VirusEnabled

I also have this issue. But I'm surprised by the time you have, 6 seconds! Mine is about 1 second, however I have to run it twice.
I also think that time could be sped up if we called for less landmarks. But the thing is, dlib (Which an entire different program/database which is implemented in python to get face_landmarks) is locating the landmarks, and I have no idea if dlib supports this feature. Also, resizing the image should help, but not too much. I will try to look into how this could be fixed. If anyone who knows more about dlib could help, that would be appreciated!

Follow Up

I found out that face landmarks are being detected by this model. However, I cannot dissect this as I have no experience in C++ and .dat files. I also found out that dlib is not detecting landmarks. Dlib is instead loading this model. I do not see any parameter to limit the amount of landmarks in the method used to locate the landmarks. However I believe that it is possible. We may have to modify the model and/or use an alternative to dlib. I will look into the model and follow up again.

simplyrohan avatar Jun 25 '22 01:06 simplyrohan

I looked into the model used to detect face landmarks. It uses a .dat file as the model. However, I looked into DLib once again to see if DLib was causing the issue. The model is called using the class dlib.shape_predictor, and this may be the issue. I looked for alternatives to detecting face landmarks and found this. However I do not think this is the answer and will return the same speed. If anyone else knows more about dlib and/or the models used, your help would be appreciated.

simplyrohan avatar Jul 01 '22 19:07 simplyrohan