hb-setosys commited on
Commit
d9323d9
·
verified ·
1 Parent(s): f89da7b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -1
app.py CHANGED
@@ -9,13 +9,21 @@ model = tf.keras.models.load_model("denis_mnist_cnn_model.h5")
9
  def preprocess_image(image):
10
  # Resize the image to 28x28 as expected by the model
11
  image = tf.image.resize(image, (28, 28)) # Resize to 28x28
 
12
 
13
- # Convert image to float32 and normalize pixel values to [0, 1]
 
 
 
 
 
14
  image = tf.cast(image, tf.float32) / 255.0
15
 
16
  # Add batch dimension (model expects batch of images)
17
  image = tf.expand_dims(image, axis=0)
 
18
  print(f"Image shape after adding batch dimension: {image.shape}")
 
19
  return image
20
 
21
  # Function to make predictions
 
9
  def preprocess_image(image):
10
  # Resize the image to 28x28 as expected by the model
11
  image = tf.image.resize(image, (28, 28)) # Resize to 28x28
12
+ print(f"Image shape after resizing: {image.shape}")
13
 
14
+ # Convert the image to grayscale (1 channel)
15
+ image = tf.image.rgb_to_grayscale(image) # Convert RGB to grayscale
16
+
17
+ print(f"Image shape after converting to grayscale: {image.shape}")
18
+
19
+ # Normalize pixel values to [0, 1]
20
  image = tf.cast(image, tf.float32) / 255.0
21
 
22
  # Add batch dimension (model expects batch of images)
23
  image = tf.expand_dims(image, axis=0)
24
+
25
  print(f"Image shape after adding batch dimension: {image.shape}")
26
+
27
  return image
28
 
29
  # Function to make predictions