From e643f56b75449c67b048459f9767332fa90eba70 Mon Sep 17 00:00:00 2001 From: Vincent STRAGIER Date: Tue, 23 May 2023 14:47:22 +0200 Subject: [PATCH 1/6] Unlinted changes --- .vscode/settings.json | 4 +++- deepface/DeepFace.py | 34 ++++++++++++++++++---------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index f5d9a83..e223550 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,5 +9,7 @@ "python.formatting.provider": "black", "python.formatting.blackArgs": ["--line-length=100"], "editor.fontWeight": "normal", - "python.analysis.extraPaths": ["./deepface"] + "python.analysis.extraPaths": ["./deepface"], + "stylelint.autoFixOnSave": false, + "standard.autoFixOnSave": false } diff --git a/deepface/DeepFace.py b/deepface/DeepFace.py index b96becf..a68bd01 100644 --- a/deepface/DeepFace.py +++ b/deepface/DeepFace.py @@ -41,7 +41,6 @@ if tf_version == 2: def build_model(model_name): - """ This function builds a deepface model Parameters: @@ -96,7 +95,6 @@ def verify( align=True, normalization="base", ): - """ This function verifies an image pair is same person or different persons. In the background, verification function represents facial images as vectors and then calculates the similarity @@ -119,9 +117,9 @@ def verify( detector_backend (string): set face detector backend to opencv, retinaface, mtcnn, ssd, dlib or mediapipe - + align (boolean): alignment according to the eye positions. - + normalization (string): normalize the input image before feeding to model Returns: @@ -235,9 +233,8 @@ def analyze( align=True, silent=False, ): - """ - This function analyzes facial attributes including age, gender, emotion and race. + This function analyze facial attributes including age, gender, emotion and race. In the background, analysis function builds convolutional neural network models to classify age, gender, emotion and race of the input image. @@ -255,7 +252,7 @@ def analyze( detector_backend (string): set face detector backend to opencv, retinaface, mtcnn, ssd, dlib or mediapipe. - + align (boolean): alignment according to the eye positions. silent (boolean): disable (some) log messages @@ -300,6 +297,16 @@ def analyze( actions = (actions,) actions = list(actions) + + if not actions: + raise ValueError("`actions` must be a list of strings.") + + for action in actions: + if action not in ("emotion", "age", "gender", "race"): + raise ValueError( + f"Invalid action passed ({action})). " + "Valid actions are `emotion`, `age`, `gender`, `race`." + ) # --------------------------------- # build models models = {} @@ -398,7 +405,6 @@ def find( normalization="base", silent=False, ): - """ This function applies verification several times and find the identities in a database @@ -422,9 +428,9 @@ def find( detector_backend (string): set face detector backend to opencv, retinaface, mtcnn, ssd, dlib or mediapipe - + align (boolean): alignment according to the eye positions. - + normalization (string): normalize the input image before feeding to model silent (boolean): disable some logging and progress bars @@ -448,7 +454,6 @@ def find( file_name = file_name.replace("-", "_").lower() if path.exists(db_path + "/" + file_name): - if not silent: print( f"WARNING: Representations for images in {db_path} folder were previously stored" @@ -616,7 +621,6 @@ def represent( align=True, normalization="base", ): - """ This function represents facial images as vectors. The function uses convolutional neural networks models to generate vector embeddings. @@ -710,7 +714,6 @@ def stream( time_threshold=5, frame_threshold=5, ): - """ This function applies real time face recognition and facial attribute analysis @@ -765,7 +768,6 @@ def extract_faces( align=True, grayscale=False, ): - """ This function applies pre-processing stages of a face recognition pipeline including detection and alignment @@ -830,7 +832,7 @@ def detectFace( ): """ Deprecated function. Use extract_faces for same functionality. - + This function applies pre-processing stages of a face recognition pipeline including detection and alignment @@ -855,7 +857,7 @@ def detectFace( Returns: detected and aligned face as numpy array - + """ print("⚠️ Function detectFace is deprecated. Use extract_faces instead.") face_objs = extract_faces( From c09fc43d455715e4e6ac1835952a0cf926f12966 Mon Sep 17 00:00:00 2001 From: Vincent STRAGIER Date: Mon, 5 Jun 2023 12:27:18 +0200 Subject: [PATCH 2/6] Add some comments about the changes. --- deepface/DeepFace.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/deepface/DeepFace.py b/deepface/DeepFace.py index a68bd01..a820741 100644 --- a/deepface/DeepFace.py +++ b/deepface/DeepFace.py @@ -297,10 +297,12 @@ def analyze( actions = (actions,) actions = list(actions) - + + # Check if actions have been passed correctly if not actions: raise ValueError("`actions` must be a list of strings.") + # For each action, check if it is valid for action in actions: if action not in ("emotion", "age", "gender", "race"): raise ValueError( From 4ff75ecfc23c7b8aa7c45c0ad324d6529f6b955a Mon Sep 17 00:00:00 2001 From: Vincent STRAGIER Date: Mon, 5 Jun 2023 14:06:10 +0200 Subject: [PATCH 3/6] Remove unwanted changes and fix linting. --- .vscode/settings.json | 4 +--- deepface/DeepFace.py | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index e223550..f5d9a83 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,7 +9,5 @@ "python.formatting.provider": "black", "python.formatting.blackArgs": ["--line-length=100"], "editor.fontWeight": "normal", - "python.analysis.extraPaths": ["./deepface"], - "stylelint.autoFixOnSave": false, - "standard.autoFixOnSave": false + "python.analysis.extraPaths": ["./deepface"] } diff --git a/deepface/DeepFace.py b/deepface/DeepFace.py index a820741..c430030 100644 --- a/deepface/DeepFace.py +++ b/deepface/DeepFace.py @@ -297,7 +297,7 @@ def analyze( actions = (actions,) actions = list(actions) - + # Check if actions have been passed correctly if not actions: raise ValueError("`actions` must be a list of strings.") From e845c00c24f7c0db6a24899670aa2f3a26797135 Mon Sep 17 00:00:00 2001 From: Vincent STRAGIER Date: Mon, 5 Jun 2023 14:30:19 +0200 Subject: [PATCH 4/6] Partial grammatical uniformisation of `analys**`. --- deepface/DeepFace.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deepface/DeepFace.py b/deepface/DeepFace.py index c430030..6671df7 100644 --- a/deepface/DeepFace.py +++ b/deepface/DeepFace.py @@ -234,7 +234,7 @@ def analyze( silent=False, ): """ - This function analyze facial attributes including age, gender, emotion and race. + This function analyses facial attributes including age, gender, emotion and race. In the background, analysis function builds convolutional neural network models to classify age, gender, emotion and race of the input image. @@ -733,7 +733,7 @@ def stream( source: Set this to 0 for access web cam. Otherwise, pass exact video path. - time_threshold (int): how many second analyzed image will be displayed + time_threshold (int): how many second analysed image will be displayed frame_threshold (int): how many frames required to focus on face From 1506a67725203c3ddfcbadc3f950a5d647c33071 Mon Sep 17 00:00:00 2001 From: Vincent STRAGIER Date: Fri, 23 Jun 2023 16:53:34 +0200 Subject: [PATCH 5/6] Revert some grammar changes. --- deepface/DeepFace.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deepface/DeepFace.py b/deepface/DeepFace.py index 6671df7..e1d1eac 100644 --- a/deepface/DeepFace.py +++ b/deepface/DeepFace.py @@ -234,7 +234,7 @@ def analyze( silent=False, ): """ - This function analyses facial attributes including age, gender, emotion and race. + This function analyzes facial attributes including age, gender, emotion and race. In the background, analysis function builds convolutional neural network models to classify age, gender, emotion and race of the input image. @@ -733,7 +733,7 @@ def stream( source: Set this to 0 for access web cam. Otherwise, pass exact video path. - time_threshold (int): how many second analysed image will be displayed + time_threshold (int): how many second analyzed image will be displayed frame_threshold (int): how many frames required to focus on face From 1a3e86973753e84112c3d0bd7cd852d3cca1a00c Mon Sep 17 00:00:00 2001 From: Vincent STRAGIER Date: Fri, 23 Jun 2023 17:37:19 +0200 Subject: [PATCH 6/6] Better type checking. --- deepface/DeepFace.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/deepface/DeepFace.py b/deepface/DeepFace.py index e1d1eac..d38a810 100644 --- a/deepface/DeepFace.py +++ b/deepface/DeepFace.py @@ -296,17 +296,17 @@ def analyze( if isinstance(actions, str): actions = (actions,) - actions = list(actions) - - # Check if actions have been passed correctly - if not actions: + # check if actions is not an iterable or empty. + if not hasattr(actions, "__getitem__") or not actions: raise ValueError("`actions` must be a list of strings.") + actions = list(actions) + # For each action, check if it is valid for action in actions: if action not in ("emotion", "age", "gender", "race"): raise ValueError( - f"Invalid action passed ({action})). " + f"Invalid action passed ({repr(action)})). " "Valid actions are `emotion`, `age`, `gender`, `race`." ) # ---------------------------------