hb-setosys commited on
Commit
5ab5708
·
verified ·
1 Parent(s): 3a813cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -11,10 +11,12 @@ def predict(image):
11
  # Convert image to a numpy array
12
  image = np.array(image)
13
 
14
- # Resize the image to the expected shape (28, 28, 3)
15
  image = tf.image.resize(image, (28, 28)) # Resize to 28x28 pixels
16
- image = np.expand_dims(image, axis=-1) # Add the channel dimension if grayscale
17
- image = np.repeat(image, 3, axis=-1) # Convert grayscale to RGB (if model was trained on RGB images)
 
 
18
 
19
  # Normalize the image
20
  image = image / 255.0
 
11
  # Convert image to a numpy array
12
  image = np.array(image)
13
 
14
+ # Resize the image to the expected shape (28, 28, 3) for RGB images
15
  image = tf.image.resize(image, (28, 28)) # Resize to 28x28 pixels
16
+
17
+ # Check if the image is grayscale (single channel), and convert to RGB if necessary
18
+ if image.shape[-1] == 1: # If it's grayscale (single channel)
19
+ image = np.repeat(image, 3, axis=-1) # Convert grayscale to RGB by repeating the channel
20
 
21
  # Normalize the image
22
  image = image / 255.0