From 58b0b0a037cf5b3f30b88e8db48f3d065daf02ba Mon Sep 17 00:00:00 2001 From: Uria Franko Date: Tue, 21 Apr 2020 16:02:03 +0300 Subject: [PATCH] Prevent re-detect on 224 --- deepface/DeepFace.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/deepface/DeepFace.py b/deepface/DeepFace.py index 87e1286..8fa2d51 100644 --- a/deepface/DeepFace.py +++ b/deepface/DeepFace.py @@ -207,6 +207,7 @@ def analyze(img_path, actions = [], models = {}): pbar = tqdm(range(0,len(actions)), desc='Finding actions') action_idx = 0 + img_244 = None # Set to prevent re-detection #for action in actions: for index in pbar: action = actions[index] @@ -239,18 +240,20 @@ def analyze(img_path, actions = [], models = {}): resp_obj += emotion_obj elif action == 'age': - img = functions.detectFace(img_path, (224, 224), False) #just emotion model expects grayscale images + if img_244 is None: + img_244 = functions.detectFace(img_path, (224, 224), False) #just emotion model expects grayscale images #print("age prediction") - age_predictions = age_model.predict(img)[0,:] + age_predictions = age_model.predict(img_244)[0,:] apparent_age = Age.findApparentAge(age_predictions) resp_obj += "\"age\": %s" % (apparent_age) elif action == 'gender': - img = functions.detectFace(img_path, (224, 224), False) #just emotion model expects grayscale images + if img_244 is None: + img_244 = functions.detectFace(img_path, (224, 224), False) #just emotion model expects grayscale images #print("gender prediction") - gender_prediction = gender_model.predict(img)[0,:] + gender_prediction = gender_model.predict(img_244)[0,:] if np.argmax(gender_prediction) == 0: gender = "Woman" @@ -260,8 +263,9 @@ def analyze(img_path, actions = [], models = {}): resp_obj += "\"gender\": \"%s\"" % (gender) elif action == 'race': - img = functions.detectFace(img_path, (224, 224), False) #just emotion model expects grayscale images - race_predictions = race_model.predict(img)[0,:] + if img_244 is None: + img_244 = functions.detectFace(img_path, (224, 224), False) #just emotion model expects grayscale images + race_predictions = race_model.predict(img_244)[0,:] race_labels = ['asian', 'indian', 'black', 'white', 'middle eastern', 'latino hispanic'] sum_of_predictions = race_predictions.sum()