mirror of
https://github.com/serengil/deepface.git
synced 2025-06-06 19:45:21 +00:00
[fix] check for input number of faces
This commit is contained in:
parent
041773232f
commit
c44af00269
@ -192,7 +192,7 @@ def analyze(
|
|||||||
for idx, predictions in enumerate(emotion_predictions):
|
for idx, predictions in enumerate(emotion_predictions):
|
||||||
sum_of_predictions = predictions.sum()
|
sum_of_predictions = predictions.sum()
|
||||||
resp_objects[idx]["emotion"] = {}
|
resp_objects[idx]["emotion"] = {}
|
||||||
|
|
||||||
# Calculate emotion probabilities and store in response
|
# Calculate emotion probabilities and store in response
|
||||||
for i, emotion_label in enumerate(Emotion.labels):
|
for i, emotion_label in enumerate(Emotion.labels):
|
||||||
emotion_probability = 100 * predictions[i] / sum_of_predictions
|
emotion_probability = 100 * predictions[i] / sum_of_predictions
|
||||||
@ -205,14 +205,16 @@ def analyze(
|
|||||||
# Build the age model
|
# Build the age model
|
||||||
model = modeling.build_model(task="facial_attribute", model_name="Age")
|
model = modeling.build_model(task="facial_attribute", model_name="Age")
|
||||||
age_predictions = model.predict(faces_array)
|
age_predictions = model.predict(faces_array)
|
||||||
|
|
||||||
# Handle single vs multiple age predictions
|
|
||||||
if len(age_predictions.shape) == 1:
|
|
||||||
# Single face case - reshape predictions to 2D array for consistent handling
|
|
||||||
age_predictions = age_predictions.reshape(1, -1)
|
|
||||||
|
|
||||||
for idx, age in enumerate(age_predictions):
|
# Handle single vs multiple age predictions
|
||||||
resp_objects[idx]["age"] = np.argmax(age)
|
if faces_array.shape[0] == 1:
|
||||||
|
# Single face case - reshape predictions to 2D array for consistent handling
|
||||||
|
resp_objects[idx]["age"] = int(np.argmax(age_predictions))
|
||||||
|
else:
|
||||||
|
# Multiple face case - iterate over each prediction
|
||||||
|
for idx, age in enumerate(age_predictions):
|
||||||
|
resp_objects[idx]["age"] = int(age)
|
||||||
|
|
||||||
|
|
||||||
elif action == "gender":
|
elif action == "gender":
|
||||||
# Build the gender model
|
# Build the gender model
|
||||||
|
Loading…
x
Reference in New Issue
Block a user