Sharris commited on
Commit
aa3e2d2
Β·
verified Β·
1 Parent(s): aded04f

CRITICAL FIX: Correct preprocessing normalization mismatch - Replace ResNet50 preprocess_input with simple /255.0 normalization - Fixes negative age predictions

Browse files
Files changed (1) hide show
  1. app.py +3 -2
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
- from tensorflow.keras.applications.resnet50 import preprocess_input
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
- arr = preprocess_input(arr)
 
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]