Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 18 |
-
image =
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
| 20 |
# Predict
|
| 21 |
-
prediction = model.predict(image[None, ...]) #
|
| 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
|
| 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()
|