[fix] check for input number of faces

This commit is contained in:
NatLee 2025-01-07 05:26:27 +08:00
parent 041773232f
commit c44af00269

View File

@ -207,12 +207,14 @@ def analyze(
age_predictions = model.predict(faces_array)
# Handle single vs multiple age predictions
if len(age_predictions.shape) == 1:
if faces_array.shape[0] == 1:
# Single face case - reshape predictions to 2D array for consistent handling
age_predictions = age_predictions.reshape(1, -1)
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"] = np.argmax(age)
resp_objects[idx]["age"] = int(age)
elif action == "gender":
# Build the gender model