streiluc commited on
Commit
c8a1d50
·
verified ·
1 Parent(s): c30623a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -14,11 +14,14 @@ def predict_regression(image):
14
  # Preprocess image
15
  image = Image.fromarray(image.astype('uint8')) # Convert numpy array to PIL image
16
  image = image.resize((150, 150))
17
- image = image.convert('L')#resize the image to 28x28 and converts it to gray scale
18
- image = np.array(image)
19
- print(image.shape)
 
 
 
20
  # Predict
21
- prediction = model.predict(image[None, ...]) # Assuming single regression value
22
  confidences = {labels[i]: np.round(float(prediction[0][i]), 2) for i in range(len(labels))}
23
  return confidences
24
 
@@ -28,6 +31,6 @@ output_text = gr.Textbox(label="Predicted Value")
28
  interface = gr.Interface(fn=predict_regression,
29
  inputs=input_image,
30
  outputs=gr.Label(),
31
- examples=["images/Aerodactyl.png", "images/arbok.jpg", "images/Alakazam.png", "images/abra.gif","images/Arcanine.png"],
32
- description="A simple mlp classification model for image classification using the mnist dataset.")
33
- interface.launch()
 
14
  # Preprocess image
15
  image = Image.fromarray(image.astype('uint8')) # Convert numpy array to PIL image
16
  image = image.resize((150, 150))
17
+ # If model expects RGB, convert to RGB
18
+ image = image.convert('RGB') # Ensure image is in RGB format
19
+ image = np.array(image, dtype=np.float32) # Convert image to float32
20
+ image /= 255.0 # Normalize image data to 0-1 range
21
+
22
+ print(image.shape) # Debugging: Check the shape to ensure it's correct
23
  # Predict
24
+ prediction = model.predict(image[None, ...]) # Adjusted to include batch dimension properly
25
  confidences = {labels[i]: np.round(float(prediction[0][i]), 2) for i in range(len(labels))}
26
  return confidences
27
 
 
31
  interface = gr.Interface(fn=predict_regression,
32
  inputs=input_image,
33
  outputs=gr.Label(),
34
+ examples=["images/Aerodactyl.png", "images/arbok.jpg", "images/Alakazam.png", "images/abra.gif", "images/Arcanine.png"],
35
+ description="A simple mlp classification model for image classification using a few pokemons.")
36
+ interface.launch()