serengil / deepface

A Lightweight Face Recognition and Facial Attribute Analysis (Age, Gender, Emotion and Race) Library for Python
https://www.youtube.com/watch?v=WnUVYQP4h44&list=PLsS_1RYmYQQFdWqxQggXHynP1rqaYXv_E&index=1
MIT License
12.83k stars 2.09k forks source link

[FEATURE]: More settings for YOLO8 face detector #1356

Closed alex-rsk closed 1 week ago

alex-rsk commented 2 weeks ago

Description

I use Yolo8 as detector backend for DeepFace. Looking to sources I see that Yolo initialization lacks of parameters:

 return YOLO(weight_file)

    def detect_faces(self, img: np.ndarray) -> List[FacialAreaRegion]:
        """
        Detect and align face with yolo

        Args:
            img (np.ndarray): pre-loaded image as numpy array

        Returns:
            results (List[FacialAreaRegion]): A list of FacialAreaRegion objects
        """
        resp = []

        # Detect faces
        results = self.model.predict(img, verbose=False, show=False, conf=0.25)[0]

I'd like to fine tune Yolo8 params without overriding classes, for example, I'd want to run Yolo detector on GPU instead of CPU, so I need device parameter. Also it would be good to setup confidence, IoU and augment.

Probably it should be some dictionary with parameters forwarding from DeepFace constructor to detector backend's.

Additional Info

No response

serengil commented 2 weeks ago

We may consider to manage them with env vars

Most probably, we will not able to add these features soon. Still, requests are fair enough and worth to stay opened status.

serengil commented 1 week ago

I confirmed that yolo is using gpu with the current implementation if you have a gpu. So, you don't have to do anything for this task.

If you have many gpus and wanted to enforce specific one to be used, you can set the following env var.

export CUDA_VISIBLE_DEVICES=1
serengil commented 1 week ago

will handle confidence score with another environment variable