Skip to content

Commit

Permalink
Remove mutable objects from analyze arguments. Add tests to validate
Browse files Browse the repository at this point in the history
  • Loading branch information
fpaludi committed Sep 22, 2021
1 parent 4ffb7ba commit dbfebea
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
10 changes: 7 additions & 3 deletions deepface/DeepFace.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,17 +264,17 @@ def verify(img1_path, img2_path = '', model_name = 'VGG-Face', distance_metric =

return resp_obj

def analyze(img_path, actions = ['emotion', 'age', 'gender', 'race'] , models = {}, enforce_detection = True, detector_backend = 'opencv', prog_bar = True):
def analyze(img_path, actions = ('emotion', 'age', 'gender', 'race') , models = None, enforce_detection = True, detector_backend = 'opencv', prog_bar = True):

"""
This function analyzes facial attributes including age, gender, emotion and race
Parameters:
img_path: exact image path, numpy array or base64 encoded image could be passed. If you are going to analyze lots of images, then set this to list. e.g. img_path = ['img1.jpg', 'img2.jpg']
actions (list): The default is ['age', 'gender', 'emotion', 'race']. You can drop some of those attributes.
actions (tuple): The default is ('age', 'gender', 'emotion', 'race'). You can drop some of those attributes.
models: facial attribute analysis models are built in every call of analyze function. You can pass pre-built models to speed the function up.
models: (Optional[dict]) facial attribute analysis models are built in every call of analyze function. You can pass pre-built models to speed the function up.
models = {}
models['age'] = DeepFace.build_model('Age')
Expand Down Expand Up @@ -317,6 +317,10 @@ def analyze(img_path, actions = ['emotion', 'age', 'gender', 'race'] , models =
"""

actions = list(actions)
if not models:
models = {}

img_paths, bulkProcess = functions.initialize_input(img_path)

#---------------------------------
Expand Down
11 changes: 11 additions & 0 deletions tests/unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,17 @@
print("Race: ", demography["dominant_race"])
print("Emotion: ", demography["dominant_emotion"])

print("-----------------------------------------")

print("Facial analysis test 2. Remove some actions and check they are not computed")
demography = DeepFace.analyze(img, ['age', 'gender'])

print("Age: ", demography.get("age"))
print("Gender: ", demography.get("gender"))
print("Race: ", demography.get("dominant_race"))
print("Emotion: ", demography.get("dominant_emotion"))


print("-----------------------------------------")

print("Face recognition tests")
Expand Down

0 comments on commit dbfebea

Please sign in to comment.