Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,10 @@ from PIL import Image
|
|
| 6 |
model_path = "DogClassifier2.2.keras"
|
| 7 |
model = tf.keras.models.load_model(model_path)
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
# Define the core prediction function
|
| 10 |
def predict_bmwX(image):
|
| 11 |
# Preprocess image
|
|
@@ -21,8 +25,11 @@ def predict_bmwX(image):
|
|
| 21 |
# Debug statement to check the raw prediction values
|
| 22 |
print(f"Raw prediction: {raw_prediction}")
|
| 23 |
|
| 24 |
-
# Apply softmax to get probabilities for each class
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
# Debug statement to check the shape of the prediction
|
| 28 |
print(f"Prediction after softmax: {prediction}")
|
|
|
|
| 6 |
model_path = "DogClassifier2.2.keras"
|
| 7 |
model = tf.keras.models.load_model(model_path)
|
| 8 |
|
| 9 |
+
# Ensure the model's output layer is correct
|
| 10 |
+
if not isinstance(model.layers[-1], tf.keras.layers.Softmax):
|
| 11 |
+
print("The last layer of the model is not a Softmax layer. The model might not be properly configured.")
|
| 12 |
+
|
| 13 |
# Define the core prediction function
|
| 14 |
def predict_bmwX(image):
|
| 15 |
# Preprocess image
|
|
|
|
| 25 |
# Debug statement to check the raw prediction values
|
| 26 |
print(f"Raw prediction: {raw_prediction}")
|
| 27 |
|
| 28 |
+
# Apply softmax to get probabilities for each class if not already applied
|
| 29 |
+
if raw_prediction.shape[-1] != 1:
|
| 30 |
+
prediction = tf.nn.softmax(raw_prediction).numpy()[0]
|
| 31 |
+
else:
|
| 32 |
+
prediction = raw_prediction[0]
|
| 33 |
|
| 34 |
# Debug statement to check the shape of the prediction
|
| 35 |
print(f"Prediction after softmax: {prediction}")
|