Update app.py
Browse files
app.py
CHANGED
@@ -9,16 +9,15 @@ from PIL import Image
|
|
9 |
MODEL_PATH = "setosys_dogs_model.h5"
|
10 |
model = tf.keras.models.load_model(MODEL_PATH)
|
11 |
|
12 |
-
#
|
13 |
-
#
|
14 |
-
class_labels = ["Labrador Retriever", "German Shepherd", "Golden Retriever", "Bulldog", "Poodle"] # Adjust with actual labels
|
15 |
|
16 |
# Image preprocessing function using EfficientNetV2S
|
17 |
def preprocess_image(img: Image.Image) -> np.ndarray:
|
18 |
"""Preprocess the image to match the model's input requirements."""
|
19 |
img = img.resize((224, 224)) # Resize image to model input size
|
20 |
img_array = np.array(img)
|
21 |
-
img_array = preprocess_input(img_array) # EfficientNetV2 preprocessing
|
22 |
img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
|
23 |
return img_array
|
24 |
|
@@ -27,6 +26,10 @@ def predict_dog_breed(img: Image.Image) -> dict:
|
|
27 |
"""Predict the breed of the dog in the uploaded image."""
|
28 |
img_array = preprocess_image(img)
|
29 |
predictions = model.predict(img_array)
|
|
|
|
|
|
|
|
|
30 |
class_idx = np.argmax(predictions) # Index of the highest prediction probability
|
31 |
confidence = float(np.max(predictions)) # Confidence score
|
32 |
|
|
|
9 |
MODEL_PATH = "setosys_dogs_model.h5"
|
10 |
model = tf.keras.models.load_model(MODEL_PATH)
|
11 |
|
12 |
+
# Get class labels from the model (assuming the model has a 'class_indices' attribute)
|
13 |
+
class_labels = list(model.class_indices.keys()) # Fetch class labels from the model
|
|
|
14 |
|
15 |
# Image preprocessing function using EfficientNetV2S
|
16 |
def preprocess_image(img: Image.Image) -> np.ndarray:
|
17 |
"""Preprocess the image to match the model's input requirements."""
|
18 |
img = img.resize((224, 224)) # Resize image to model input size
|
19 |
img_array = np.array(img)
|
20 |
+
img_array = preprocess_input(img_array) # EfficientNetV2 preprocessing
|
21 |
img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
|
22 |
return img_array
|
23 |
|
|
|
26 |
"""Predict the breed of the dog in the uploaded image."""
|
27 |
img_array = preprocess_image(img)
|
28 |
predictions = model.predict(img_array)
|
29 |
+
|
30 |
+
# Check the shape of the predictions to make sure the output is correct
|
31 |
+
print("Predictions Shape:", predictions.shape)
|
32 |
+
|
33 |
class_idx = np.argmax(predictions) # Index of the highest prediction probability
|
34 |
confidence = float(np.max(predictions)) # Confidence score
|
35 |
|