bauckluc commited on
Commit
656a7fb
·
verified ·
1 Parent(s): 9bfcf87

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -5,7 +5,6 @@ import numpy as np
5
 
6
  # Load your custom regression model
7
  model_path = "pokemon_transferlearning.keras"
8
-
9
  model = tf.keras.models.load_model(model_path)
10
 
11
  labels = ['Porygon', 'Seel', 'Vaporeon']
@@ -14,11 +13,13 @@ labels = ['Porygon', 'Seel', 'Vaporeon']
14
  def predict_regression(image):
15
  # Preprocess image
16
  image = Image.fromarray(image.astype('uint8')) # Convert numpy array to PIL image
17
- image = image.resize((150, 150)).convert('L') # Resize the image to 150x150 and convert it to RGB
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
 
@@ -29,5 +30,5 @@ interface = gr.Interface(fn=predict_regression,
29
  inputs=input_image,
30
  outputs=gr.Label(),
31
  examples=["images/porygon.png", "images/seel.jpg", "images/vaporeon.png"],
32
- description="A simple mlp classification model for pokemon classification.")
33
- interface.launch()
 
5
 
6
  # Load your custom regression model
7
  model_path = "pokemon_transferlearning.keras"
 
8
  model = tf.keras.models.load_model(model_path)
9
 
10
  labels = ['Porygon', 'Seel', 'Vaporeon']
 
13
  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)).convert('RGB') # Resize the image to 150x150 and convert it to RGB
17
  image = np.array(image)
18
+ image = image / 255.0 # Normalize image to [0, 1] range
19
+ image = np.expand_dims(image, axis=0) # Add batch dimension
20
+
21
  # Predict
22
+ prediction = model.predict(image) # Assuming single regression value
23
  confidences = {labels[i]: np.round(float(prediction[0][i]), 2) for i in range(len(labels))}
24
  return confidences
25
 
 
30
  inputs=input_image,
31
  outputs=gr.Label(),
32
  examples=["images/porygon.png", "images/seel.jpg", "images/vaporeon.png"],
33
+ description="A simple MLP classification model for Pokemon classification.")
34
+ interface.launch()