From 26e537d2a56ec601a5baca29ae62b6f85ff810d9 Mon Sep 17 00:00:00 2001 From: galthran-wq Date: Tue, 18 Feb 2025 09:48:01 +0000 Subject: [PATCH] psedu-batching fastmtcnn --- deepface/models/face_detection/FastMtCnn.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/deepface/models/face_detection/FastMtCnn.py b/deepface/models/face_detection/FastMtCnn.py index 5259036..8315b6d 100644 --- a/deepface/models/face_detection/FastMtCnn.py +++ b/deepface/models/face_detection/FastMtCnn.py @@ -17,10 +17,27 @@ class FastMtCnnClient(Detector): def __init__(self): self.model = self.build_model() - def detect_faces(self, img: np.ndarray) -> List[FacialAreaRegion]: + def detect_faces(self, img: Union[np.ndarray, List[np.ndarray]]) -> Union[List[FacialAreaRegion], List[List[FacialAreaRegion]]]: """ Detect and align face with mtcnn + Args: + img (Union[np.ndarray, List[np.ndarray]]): pre-loaded image as numpy array or a list of those + + Returns: + results (Union[List[FacialAreaRegion], List[List[FacialAreaRegion]]]): A list or a list of lists of FacialAreaRegion objects + """ + if isinstance(img, np.ndarray): + return self._process_single_image(img) + elif isinstance(img, list): + return [self._process_single_image(single_img) for single_img in img] + else: + raise ValueError("Input must be a numpy array or a list of numpy arrays.") + + def _process_single_image(self, img: np.ndarray) -> List[FacialAreaRegion]: + """ + Helper function to detect faces in a single image. + Args: img (np.ndarray): pre-loaded image as numpy array