Skip to content

Question about multiple image analysis #441

Closed

Description

@ligujie123

Hi Sefik! Thanks for sharing the library. I use your library for race detection for about 1000 images. As you suggested in some comments below the YouTube video, I use list to store image names, and in this way, it will not kill much memory.

My python code is like this:

from deepface import DeepFace
backends = ['opencv', 'ssd', 'dlib', 'mtcnn', 'retinaface', 'mediapipe']
obj = DeepFace.analyze(["testface1.jpg", "testface2.jpg", "testface3.png"], actions = ['race'], enforce_detection = True, detector_backend = backends[3])

My goal is to obtain the predicted race information in obj, which is a dictionary produced by the DeepFace.analyze function. However, for some images (for example, testface2 and testface3), there is no face detected, so there shows error message "Face could not be detected. Please confirm that the picture is a face photo or consider to set enforce_detection param to False." The obj function cannot be obtained. I tried to turn enforce_detection to False but to ensure my result is accurate enough, I hope to turn it to be True. I am wondering if there is a way that I still can get obj, but for the images for which face not detected, it just produce a value like "not detected" instead of terminating the function without any obj produced.

Hope my question is explained clearly.

Thanks!

Activity

  1. serengil commented on Mar 16, 2022

    @serengil
    Owner

    facial_imgs = ["testface1.jpg", "testface2.jpg", "testface3.png"]

    Method 1: Set enforce detection the False. In this way, you will not have any trouble. However, accuracy will be down.

    obj = DeepFace.analyze(facial_imgs, actions = ['race'], enforce_detection = False, detector_backend = backends[3])

    Method 2: Build a for loop. Previous versions of deepface had a memory error in this approach but now you can call it in a for loop. It is totally fine.

    facial_imgs = ["testface1.jpg", "testface2.jpg", "testface3.png"]
    
    for facial_img in facial_imgs:
       try:
          obj = DeepFace.analyze(facial_img, actions = ['race'], enforce_detection = True, detector_backend = backends[3])
       except:
          print("not detected - " + facial_img)
    
  2. added
    help wanted
    on Mar 16, 2022
  3. ligujie123 commented on Mar 16, 2022

    @ligujie123
    Author

    Thanks a lot! Really helpful suggestions!

  4. CodeofDutyAI commented on Oct 15, 2024

    @CodeofDutyAI

    Hello, thanks for your work. One question: Does using for loop for predicting attributes for batch of images slow down the overall computation, since the model will be loaded and unloaded for every function call?

  5. serengil commented on Oct 15, 2024

    @serengil
    Owner

    @CodeOfDuty44 no it is singletonish, it is loaded once and be reused from the 2nd iteration

  6. CodeofDutyAI commented on Oct 15, 2024

    @CodeofDutyAI

    Thanks for prompt reply @serengil. There is one thing I do not understand then. I migrated to H100 gpu from a worse one, and other DL applications like kohya lora training got 3x faster. But feature extraction using deepface did not. I thought that model loading might be a bottleneck, but as you said it seems it is not. Do you have any insight why deepface library did not get faster when a better gpu used?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wanted

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions