Update app.py
Browse files
app.py
CHANGED
@@ -110,11 +110,15 @@ def predict(image_path, model, device, margin=0.4, input_size=224):
|
|
110 |
input_blob = torch.from_numpy(np.transpose(face.astype(np.float32), (2, 0, 1))).unsqueeze(0).to(device)
|
111 |
output = F.softmax(model(input_blob), dim=-1).cpu().numpy()
|
112 |
ages = np.arange(0, 101)
|
113 |
-
predicted_age = (output * ages).sum(axis=-1)
|
114 |
|
115 |
# draw results
|
116 |
age_text = f'{int(predicted_age)}'
|
117 |
-
age_data.append({
|
|
|
|
|
|
|
|
|
118 |
|
119 |
# Optionally, draw bounding boxes and age labels on the image
|
120 |
# cv2.rectangle(image, (startX, startY), (endX, endY), (0, 255, 0), 2)
|
|
|
110 |
input_blob = torch.from_numpy(np.transpose(face.astype(np.float32), (2, 0, 1))).unsqueeze(0).to(device)
|
111 |
output = F.softmax(model(input_blob), dim=-1).cpu().numpy()
|
112 |
ages = np.arange(0, 101)
|
113 |
+
predicted_age = (output * ages).sum(axis=-1).item() # Convert to native Python datatype
|
114 |
|
115 |
# draw results
|
116 |
age_text = f'{int(predicted_age)}'
|
117 |
+
age_data.append({
|
118 |
+
'age': int(predicted_age), # Ensure this is a native Python int, not numpy int64
|
119 |
+
'text': age_text,
|
120 |
+
'face_coordinates': (int(startX), int(startY)) # Convert to native Python datatype
|
121 |
+
})
|
122 |
|
123 |
# Optionally, draw bounding boxes and age labels on the image
|
124 |
# cv2.rectangle(image, (startX, startY), (endX, endY), (0, 255, 0), 2)
|