Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,25 +4,20 @@ import numpy as np
|
|
| 4 |
import tensorflow as tf
|
| 5 |
import tensorflow_hub as hub
|
| 6 |
import cv2
|
| 7 |
-
import os
|
| 8 |
-
|
| 9 |
-
# Path to the model file and label file
|
| 10 |
-
model_path = os.path.join(os.getcwd(), 'bird_model4.h5')
|
| 11 |
-
label_file_path = os.path.join(os.getcwd(), 'labelwithspace.txt')
|
| 12 |
|
| 13 |
# Register KerasLayer from TensorFlow Hub
|
| 14 |
tf.keras.utils.get_custom_objects().update({'KerasLayer': hub.KerasLayer})
|
| 15 |
|
| 16 |
-
#
|
| 17 |
try:
|
| 18 |
-
model = tf.keras.models.load_model(
|
| 19 |
except Exception as e:
|
| 20 |
print("Error loading the model:", e)
|
| 21 |
exit()
|
| 22 |
|
| 23 |
# Load class labels from the text file
|
| 24 |
train_info = []
|
| 25 |
-
with open(
|
| 26 |
train_info = [line.strip() for line in file.readlines()]
|
| 27 |
|
| 28 |
# Function to preprocess the image and make predictions
|
|
|
|
| 4 |
import tensorflow as tf
|
| 5 |
import tensorflow_hub as hub
|
| 6 |
import cv2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# Register KerasLayer from TensorFlow Hub
|
| 9 |
tf.keras.utils.get_custom_objects().update({'KerasLayer': hub.KerasLayer})
|
| 10 |
|
| 11 |
+
# Attempt to load the model with custom objects
|
| 12 |
try:
|
| 13 |
+
model = tf.keras.models.load_model('bird_model4.h5', custom_objects={'KerasLayer': hub.KerasLayer})
|
| 14 |
except Exception as e:
|
| 15 |
print("Error loading the model:", e)
|
| 16 |
exit()
|
| 17 |
|
| 18 |
# Load class labels from the text file
|
| 19 |
train_info = []
|
| 20 |
+
with open('labelwithspace.txt', 'r') as file:
|
| 21 |
train_info = [line.strip() for line in file.readlines()]
|
| 22 |
|
| 23 |
# Function to preprocess the image and make predictions
|