Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,10 +8,11 @@ import cv2
|
|
| 8 |
# Register KerasLayer from TensorFlow Hub
|
| 9 |
tf.keras.utils.get_custom_objects().update({'KerasLayer': hub.KerasLayer})
|
| 10 |
|
| 11 |
-
# Load the model
|
| 12 |
try:
|
|
|
|
| 13 |
model = tf.keras.models.load_model('bird_model4.h5', custom_objects={'KerasLayer': hub.KerasLayer})
|
| 14 |
-
except
|
| 15 |
print("Error loading the model:", e)
|
| 16 |
exit()
|
| 17 |
|
|
@@ -25,7 +26,7 @@ def predict_image(image):
|
|
| 25 |
# Resize and normalize the image
|
| 26 |
img = cv2.resize(image, (224, 224))
|
| 27 |
img = img / 255.0
|
| 28 |
-
|
| 29 |
# Make predictions
|
| 30 |
predictions = model.predict(img[np.newaxis, ...])[0]
|
| 31 |
top_classes = np.argsort(predictions)[-3:][::-1] # Indices of top 3 predictions
|
|
|
|
| 8 |
# Register KerasLayer from TensorFlow Hub
|
| 9 |
tf.keras.utils.get_custom_objects().update({'KerasLayer': hub.KerasLayer})
|
| 10 |
|
| 11 |
+
# Load the model using the Functional API
|
| 12 |
try:
|
| 13 |
+
# Load the model with custom objects
|
| 14 |
model = tf.keras.models.load_model('bird_model4.h5', custom_objects={'KerasLayer': hub.KerasLayer})
|
| 15 |
+
except Exception as e:
|
| 16 |
print("Error loading the model:", e)
|
| 17 |
exit()
|
| 18 |
|
|
|
|
| 26 |
# Resize and normalize the image
|
| 27 |
img = cv2.resize(image, (224, 224))
|
| 28 |
img = img / 255.0
|
| 29 |
+
|
| 30 |
# Make predictions
|
| 31 |
predictions = model.predict(img[np.newaxis, ...])[0]
|
| 32 |
top_classes = np.argsort(predictions)[-3:][::-1] # Indices of top 3 predictions
|