unit tests for find and ensemble

This commit is contained in:
Şefik Serangil 2020-06-08 10:26:56 +03:00
parent 2f9815a1fc
commit f95f5acbe8
6 changed files with 25 additions and 3 deletions

3
.gitignore vendored
View File

@ -13,4 +13,5 @@ deepface/__pycache__/*
deepface/commons/__pycache__/*
deepface/basemodels/__pycache__/*
deepface/extendedmodels/__pycache__/*
deepface/subsidiarymodels/__pycache__/*
deepface/subsidiarymodels/__pycache__/*
deepface/tests/dataset/*.pkl

View File

@ -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.

View File

@ -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

Binary file not shown.

Binary file not shown.

View File

@ -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 = [