From 70b61a7f4fd7b9a8c0d17702462b096a2841f96c Mon Sep 17 00:00:00 2001 From: galthran-wq Date: Tue, 18 Feb 2025 10:03:27 +0000 Subject: [PATCH] change interface in a special case --- deepface/models/face_detection/CenterFace.py | 12 ++++++------ deepface/models/face_detection/Dlib.py | 14 +++++++------- deepface/models/face_detection/FastMtCnn.py | 12 ++++++------ deepface/models/face_detection/MediaPipe.py | 12 ++++++------ deepface/models/face_detection/YuNet.py | 12 ++++++------ 5 files changed, 31 insertions(+), 31 deletions(-) diff --git a/deepface/models/face_detection/CenterFace.py b/deepface/models/face_detection/CenterFace.py index 7e7d72e..03faa97 100644 --- a/deepface/models/face_detection/CenterFace.py +++ b/deepface/models/face_detection/CenterFace.py @@ -44,12 +44,12 @@ class CenterFaceClient(Detector): 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.") + if not isinstance(img, list): + img = [img] + results = [self._process_single_image(single_img) for single_img in img] + if len(results) == 1: + return results[0] + return results def _process_single_image(self, single_img: np.ndarray) -> List[FacialAreaRegion]: """ diff --git a/deepface/models/face_detection/Dlib.py b/deepface/models/face_detection/Dlib.py index 2ff9c86..7500fff 100644 --- a/deepface/models/face_detection/Dlib.py +++ b/deepface/models/face_detection/Dlib.py @@ -57,14 +57,14 @@ class DlibClient(Detector): 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._detect_faces_in_single_image(img) - elif isinstance(img, list): - return [self._detect_faces_in_single_image(single_img) for single_img in img] - else: - raise ValueError("Input must be a numpy array or a list of numpy arrays.") + if not isinstance(img, list): + img = [img] + results = [self._process_single_image(single_img) for single_img in img] + if len(results) == 1: + return results[0] + return results - def _detect_faces_in_single_image(self, img: np.ndarray) -> List[FacialAreaRegion]: + def _process_single_image(self, img: np.ndarray) -> List[FacialAreaRegion]: """ Helper function to detect faces in a single image. diff --git a/deepface/models/face_detection/FastMtCnn.py b/deepface/models/face_detection/FastMtCnn.py index 8315b6d..2228220 100644 --- a/deepface/models/face_detection/FastMtCnn.py +++ b/deepface/models/face_detection/FastMtCnn.py @@ -27,12 +27,12 @@ class FastMtCnnClient(Detector): 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.") + if not isinstance(img, list): + img = [img] + results = [self._process_single_image(single_img) for single_img in img] + if len(results) == 1: + return results[0] + return results def _process_single_image(self, img: np.ndarray) -> List[FacialAreaRegion]: """ diff --git a/deepface/models/face_detection/MediaPipe.py b/deepface/models/face_detection/MediaPipe.py index 86311bc..9e20c8d 100644 --- a/deepface/models/face_detection/MediaPipe.py +++ b/deepface/models/face_detection/MediaPipe.py @@ -53,12 +53,12 @@ class MediaPipeClient(Detector): 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.") + if not isinstance(img, list): + img = [img] + results = [self._process_single_image(single_img) for single_img in img] + if len(results) == 1: + return results[0] + return results def _process_single_image(self, img: np.ndarray) -> List[FacialAreaRegion]: """ diff --git a/deepface/models/face_detection/YuNet.py b/deepface/models/face_detection/YuNet.py index e3d310f..4086f17 100644 --- a/deepface/models/face_detection/YuNet.py +++ b/deepface/models/face_detection/YuNet.py @@ -67,12 +67,12 @@ class YuNetClient(Detector): 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.") + if not isinstance(img, list): + img = [img] + results = [self._process_single_image(single_img) for single_img in img] + if len(results) == 1: + return results[0] + return results def _process_single_image(self, img: np.ndarray) -> List[FacialAreaRegion]: """