diff --git a/.gitignore b/.gitignore index 761448d..bb324db 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,5 @@ deepface/__pycache__/* deepface/commons/__pycache__/* deepface/basemodels/__pycache__/* deepface/extendedmodels/__pycache__/* -deepface/subsidiarymodels/__pycache__/* \ No newline at end of file +deepface/subsidiarymodels/__pycache__/* +deepface/tests/dataset/*.pkl \ No newline at end of file diff --git a/README.md b/README.md index 4c54eec..d020f72 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,15 @@ result = DeepFace.verify("img1.jpg", "img2.jpg", model_name = "VGG-Face", distan result = DeepFace.verify("img1.jpg", "img2.jpg", model_name = "VGG-Face", distance_metric = "euclidean_l2") ``` +** Ensemble learning for face recognition ** - Demo + +A face recognition task can be handled by several models and similarity metrics. There is no either absolute better model or metric. However, we can combine the precictions of all of those models and metrics to improve the accuracy of a face recognition task. This is called [ensemble learning](https://sefiks.com/2020/06/03/mastering-face-recognition-with-ensemble-learning/). This approach offers a huge improvement on accuracy, precision and recall but it runs much slower than single models. You might consider to apply ensemble learning if the accuracy is a more important KPI than running time in your case. Ensemble learning can be applied for both verification and finding functions in the deepface interface. + +```python +resp_obj = DeepFace.verify("img1.jpg", "img2.jpg", model_name = "Ensemble") +df = DeepFace.find(img_path = "img1.jpg", db_path = "my_db", model_name = "Ensemble") +``` + **Facial Attribute Analysis** - [`Demo`](https://youtu.be/GT2UeN85BdA) Deepface also offers facial attribute analysis including [`age`](https://sefiks.com/2019/02/13/apparent-age-and-gender-prediction-in-keras/), [`gender`](https://sefiks.com/2019/02/13/apparent-age-and-gender-prediction-in-keras/), [`facial expression`](https://sefiks.com/2018/01/01/facial-expression-recognition-with-keras/) (including angry, fear, neutral, sad, disgust, happy and surprise)and [`race`](https://sefiks.com/2019/11/11/race-and-ethnicity-prediction-in-keras/) (including asian, white, middle eastern, indian, latino and black) predictions. Analysis function under the DeepFace interface is used to find demography of a face. diff --git a/deepface/DeepFace.py b/deepface/DeepFace.py index 5554077..4c9e50b 100644 --- a/deepface/DeepFace.py +++ b/deepface/DeepFace.py @@ -695,6 +695,7 @@ def find(img_path, db_path df = df[df.verified == True] df = df[df.score > 0.99] #confidence score df = df.sort_values(by = ["score"], ascending=False).reset_index(drop=True) + df = df[['identity', 'verified', 'score']] resp_obj.append(df) df = df_base.copy() #restore df for the next iteration diff --git a/tests/dataset/representations_ensemble.pkl b/tests/dataset/representations_ensemble.pkl new file mode 100644 index 0000000..0ca6dee Binary files /dev/null and b/tests/dataset/representations_ensemble.pkl differ diff --git a/tests/dataset/representations_vgg_face.pkl b/tests/dataset/representations_vgg_face.pkl new file mode 100644 index 0000000..e551ac4 Binary files /dev/null and b/tests/dataset/representations_vgg_face.pkl differ diff --git a/tests/unit_tests.py b/tests/unit_tests.py index 8aa280c..d8718b7 100644 --- a/tests/unit_tests.py +++ b/tests/unit_tests.py @@ -5,12 +5,23 @@ import os os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' #----------------------------------------- -#TODO: add find function in unit tests - print("Bulk tests") print("-----------------------------------------") +print("Large scale face recognition") + +df = DeepFace.find(img_path = "dataset/img1.jpg", db_path = "dataset") +print(df.head()) + +print("-----------------------------------------") + +print("Ensemble for find function") +df = DeepFace.find(img_path = "dataset/img1.jpg", db_path = "dataset", model_name = "Ensemble") +print(df.head()) + +print("-----------------------------------------") + print("Bulk face recognition tests") dataset = [