Ahmadkhan12 commited on
Commit
d71fc08
·
verified ·
1 Parent(s): 1f130ae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -5
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
- image = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2GRAY) # Convert to grayscale
14
- image_resized = cv2.resize(image, (48, 48)) # Resize to 48x48
15
- image_input = np.expand_dims(image_resized, axis=0) # Add batch dimension
16
- image_input = np.expand_dims(image_input, axis=3) # Add channel dimension
17
- image_input = image_input.astype(np.float32) / 255.0 # Normalize
 
 
 
 
 
 
 
 
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