Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -10,11 +10,19 @@ onnx_model = ort.InferenceSession("onnx_model.onnx")
|
|
10 |
# Preprocess image function
|
11 |
def preprocess_image(image):
|
12 |
"""Preprocess image to match model input requirements"""
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
return image_input
|
19 |
|
20 |
# Predict emotion using the ONNX model
|
|
|
10 |
# Preprocess image function
|
11 |
def preprocess_image(image):
|
12 |
"""Preprocess image to match model input requirements"""
|
13 |
+
# Convert the image to grayscale
|
14 |
+
image = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2GRAY)
|
15 |
+
|
16 |
+
# Resize image to 48x48 (model's expected input size)
|
17 |
+
image_resized = cv2.resize(image, (48, 48))
|
18 |
+
|
19 |
+
# Add batch dimension and channels (for grayscale: 1 channel)
|
20 |
+
image_input = np.expand_dims(image_resized, axis=0) # Add batch dimension (1, 48, 48)
|
21 |
+
image_input = np.expand_dims(image_input, axis=1) # Add channel dimension (1, 1, 48, 48)
|
22 |
+
|
23 |
+
# Normalize the image
|
24 |
+
image_input = image_input.astype(np.float32) / 255.0
|
25 |
+
|
26 |
return image_input
|
27 |
|
28 |
# Predict emotion using the ONNX model
|