Merge pull request #20 from uriafranko/No-Redetect

Prevent re-detection on 224
This commit is contained in:
Sefik Ilkin Serengil 2020-04-21 17:40:01 +03:00 committed by GitHub
commit 62f612050c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -207,6 +207,7 @@ def analyze(img_path, actions = [], models = {}):
pbar = tqdm(range(0,len(actions)), desc='Finding actions')
action_idx = 0
img_224 = 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_224 is None:
img_224 = 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_224)[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_224 is None:
img_224 = 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_224)[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_224 is None:
img_224 = functions.detectFace(img_path, (224, 224), False) #just emotion model expects grayscale images
race_predictions = race_model.predict(img_224)[0,:]
race_labels = ['asian', 'indian', 'black', 'white', 'middle eastern', 'latino hispanic']
sum_of_predictions = race_predictions.sum()