From e14d7d6afc1c84dc055d519a06e3b2341a282522 Mon Sep 17 00:00:00 2001 From: Ronald Pereira Date: Thu, 26 Jan 2023 10:54:24 -0300 Subject: [PATCH 1/3] .represent model parameter was being ignored if built and passed to function call --- deepface/DeepFace.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/deepface/DeepFace.py b/deepface/DeepFace.py index 75346d4..2d0509e 100644 --- a/deepface/DeepFace.py +++ b/deepface/DeepFace.py @@ -502,10 +502,19 @@ def represent(img_path, model_name = 'VGG-Face', model = None, enforce_detection Parameters: img_path (string): exact image path. Alternatively, numpy array (BGR) or based64 encoded images could be passed. - enforce_detection (boolean): If any face could not be detected in an image, then verify function will return exception. Set this to False not to have this exception. This might be convenient for low resolution images. + model_name (string): VGG-Face, Facenet, Facenet512, OpenFace, DeepFace, DeepID, Dlib, ArcFace, SFace + + model: Built deepface model. A face recognition model is built every call of verify function. You can pass pre-built face recognition model optionally if you will call verify function several times. Consider to pass model if you are going to call represent function in a for loop. + + model = DeepFace.build_model('VGG-Face') + + enforce_detection (boolean): If no face could not be detected in an image, then this function will return exception by default. + Set this to False not to have this exception. This might be convenient for low resolution images. 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: @@ -513,7 +522,8 @@ def represent(img_path, model_name = 'VGG-Face', model = None, enforce_detection """ resp_objs = [] - model = build_model(model_name) + if model is None: + model = build_model(model_name) #--------------------------------- # we started to run pre-process in verification. so, this can be skipped if it is coming from verification. From d24aeae030a7f52a229f7462cef7da0012351976 Mon Sep 17 00:00:00 2001 From: Ronald Pereira Date: Thu, 26 Jan 2023 10:56:58 -0300 Subject: [PATCH 2/3] updated docstring indentation --- deepface/DeepFace.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deepface/DeepFace.py b/deepface/DeepFace.py index 2d0509e..f0e2b8b 100644 --- a/deepface/DeepFace.py +++ b/deepface/DeepFace.py @@ -502,7 +502,7 @@ def represent(img_path, model_name = 'VGG-Face', model = None, enforce_detection Parameters: img_path (string): exact image path. Alternatively, numpy array (BGR) or based64 encoded images could be passed. - model_name (string): VGG-Face, Facenet, Facenet512, OpenFace, DeepFace, DeepID, Dlib, ArcFace, SFace + model_name (string): VGG-Face, Facenet, Facenet512, OpenFace, DeepFace, DeepID, Dlib, ArcFace, SFace model: Built deepface model. A face recognition model is built every call of verify function. You can pass pre-built face recognition model optionally if you will call verify function several times. Consider to pass model if you are going to call represent function in a for loop. @@ -513,7 +513,7 @@ def represent(img_path, model_name = 'VGG-Face', model = None, enforce_detection detector_backend (string): set face detector backend to opencv, retinaface, mtcnn, ssd, dlib or mediapipe - align (boolean): alignment according to the eye positions. + align (boolean): alignment according to the eye positions. normalization (string): normalize the input image before feeding to model From 6e6215e4b9bf0895521e8be0adc28c2525caa71f Mon Sep 17 00:00:00 2001 From: Ronald Pereira Date: Thu, 26 Jan 2023 11:49:56 -0300 Subject: [PATCH 3/3] updated PR to remove model parameter --- deepface/DeepFace.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/deepface/DeepFace.py b/deepface/DeepFace.py index f0e2b8b..7aa4d8a 100644 --- a/deepface/DeepFace.py +++ b/deepface/DeepFace.py @@ -494,7 +494,7 @@ def find(img_path, db_path, model_name ='VGG-Face', distance_metric = 'cosine', return resp_obj -def represent(img_path, model_name = 'VGG-Face', model = None, enforce_detection = True, detector_backend = 'opencv', align = True, normalization = 'base'): +def represent(img_path, model_name = 'VGG-Face', enforce_detection = True, detector_backend = 'opencv', align = True, normalization = 'base'): """ This function represents facial images as vectors. The function uses convolutional neural networks models to generate vector embeddings. @@ -504,10 +504,6 @@ def represent(img_path, model_name = 'VGG-Face', model = None, enforce_detection model_name (string): VGG-Face, Facenet, Facenet512, OpenFace, DeepFace, DeepID, Dlib, ArcFace, SFace - model: Built deepface model. A face recognition model is built every call of verify function. You can pass pre-built face recognition model optionally if you will call verify function several times. Consider to pass model if you are going to call represent function in a for loop. - - model = DeepFace.build_model('VGG-Face') - enforce_detection (boolean): If no face could not be detected in an image, then this function will return exception by default. Set this to False not to have this exception. This might be convenient for low resolution images. @@ -522,8 +518,7 @@ def represent(img_path, model_name = 'VGG-Face', model = None, enforce_detection """ resp_objs = [] - if model is None: - model = build_model(model_name) + model = build_model(model_name) #--------------------------------- # we started to run pre-process in verification. so, this can be skipped if it is coming from verification.