Spaces:
Runtime error
Runtime error
CRITICAL FIX: Correct preprocessing normalization mismatch - Replace ResNet50 preprocess_input with simple /255.0 normalization - Fixes negative age predictions
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import os
|
|
| 2 |
import numpy as np
|
| 3 |
from PIL import Image
|
| 4 |
import tensorflow as tf
|
| 5 |
-
|
| 6 |
import gradio as gr
|
| 7 |
|
| 8 |
# Load model from Hugging Face Hub
|
|
@@ -69,7 +69,8 @@ def predict_age(image: Image.Image):
|
|
| 69 |
image = image.convert('RGB')
|
| 70 |
image = image.resize(INPUT_SIZE)
|
| 71 |
arr = np.array(image).astype(np.float32)
|
| 72 |
-
|
|
|
|
| 73 |
arr = np.expand_dims(arr, 0)
|
| 74 |
|
| 75 |
pred = model.predict(arr)[0]
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
from PIL import Image
|
| 4 |
import tensorflow as tf
|
| 5 |
+
# Remove ResNet50 preprocessing - using simple normalization instead
|
| 6 |
import gradio as gr
|
| 7 |
|
| 8 |
# Load model from Hugging Face Hub
|
|
|
|
| 69 |
image = image.convert('RGB')
|
| 70 |
image = image.resize(INPUT_SIZE)
|
| 71 |
arr = np.array(image).astype(np.float32)
|
| 72 |
+
# Use same normalization as training: [0,1] range instead of ResNet50 preprocessing
|
| 73 |
+
arr = arr / 255.0
|
| 74 |
arr = np.expand_dims(arr, 0)
|
| 75 |
|
| 76 |
pred = model.predict(arr)[0]
|