Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,9 +3,7 @@ import tensorflow as tf
|
|
| 3 |
from PIL import Image
|
| 4 |
import numpy as np
|
| 5 |
from tensorflow.keras import layers, models
|
| 6 |
-
|
| 7 |
-
import tensorflow as tf
|
| 8 |
-
from tensorflow.keras import layers, models
|
| 9 |
|
| 10 |
def identity_block(x, filters):
|
| 11 |
x_shortcut = x
|
|
@@ -92,23 +90,23 @@ model.load_weights('model_weights.h5') # Replace with the actual path
|
|
| 92 |
# Define a function for making predictions
|
| 93 |
def predict(input_img):
|
| 94 |
# Preprocess the input image
|
| 95 |
-
input_img = input_img.resize((224, 224))
|
| 96 |
-
input_img_array = np.array(input_img)
|
| 97 |
-
input_img_array =
|
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
# Make predictions
|
| 100 |
predictions = model.predict(input_img_array)
|
| 101 |
predicted_class = np.argmax(predictions)
|
| 102 |
|
| 103 |
return input_img, {
|
| 104 |
-
"Predicted Class":
|
| 105 |
-
"Probabilities": {
|
| 106 |
}
|
| 107 |
|
| 108 |
# Create a Gradio interface
|
| 109 |
gr.Interface(
|
| 110 |
predict,
|
| 111 |
-
inputs=gr.Image(label="Select an image", type="
|
| 112 |
-
outputs=[gr.Image(label="Processed Image"), gr.Label(label="Predicted Class"), gr.Bar(label="Probabilities")],
|
| 113 |
-
title="ResNet15 Image Classification"
|
| 114 |
-
).launch()
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
import numpy as np
|
| 5 |
from tensorflow.keras import layers, models
|
| 6 |
+
from tensorflow.keras.applications.resnet import preprocess_input
|
|
|
|
|
|
|
| 7 |
|
| 8 |
def identity_block(x, filters):
|
| 9 |
x_shortcut = x
|
|
|
|
| 90 |
# Define a function for making predictions
|
| 91 |
def predict(input_img):
|
| 92 |
# Preprocess the input image
|
| 93 |
+
input_img = input_img.resize((224, 224))
|
| 94 |
+
input_img_array = np.array(input_img)
|
| 95 |
+
input_img_array = preprocess_input(input_img_array)
|
| 96 |
+
|
| 97 |
+
# Add batch dimension
|
| 98 |
+
input_img_array = np.expand_dims(input_img_array, axis=0)
|
| 99 |
|
| 100 |
# Make predictions
|
| 101 |
predictions = model.predict(input_img_array)
|
| 102 |
predicted_class = np.argmax(predictions)
|
| 103 |
|
| 104 |
return input_img, {
|
| 105 |
+
"Predicted Class": str(predicted_class),
|
| 106 |
+
"Probabilities": {str(i): float(predictions[0][i]) for i in range(len(predictions[0]))}
|
| 107 |
}
|
| 108 |
|
| 109 |
# Create a Gradio interface
|
| 110 |
gr.Interface(
|
| 111 |
predict,
|
| 112 |
+
inputs=gr.Image(label="Select an image", type="p
|
|
|
|
|
|
|
|
|