Spaces:
Sleeping
Sleeping
Update app.py
Browse files7 unmodified lines8910111213141516177 unmodified lines252627282930317 unmodified lines# Register KerasLayer from TensorFlow Hubtf.keras.utils.get_custom_objects().update({'KerasLayer': hub.KerasLayer})# Load the model and specify custom objectstry:model = tf.keras.models.load_model('bird_model4.h5', custom_objects={'KerasLayer': hub.KerasLayer})except ValueError as e:print("Error loading the model:", e)exit()7 unmodified lines# Resize and normalize the imageimg = cv2.resize(image, (224, 224))img = img / 255.0# Make predictionspredictions = model.predict(img[np.newaxis, ...])[0]top_classes = np.argsort(predictions)[-3:][::-1] # Indices of top 3 predictions7 unmodified lines891011121314151617187 unmodified lines262728293031327 unmodified lines# Register KerasLayer from TensorFlow Hubtf.keras.utils.get_custom_objects().update({'KerasLayer': hub.KerasLayer})# Load the model using the Functional APItry:# Load the model with custom objectsmodel = tf.keras.models.load_model('bird_model4.h5', custom_objects={'KerasLayer': hub.KerasLayer})except Exception as e:print("Error loading the model:", e)exit()7 unmodified lines# Resize and normalize the imageimg = cv2.resize(image, (224, 224))img = img / 255.0# Make predictionspredictions = model.predict(img[np.newaxis, ...])[0]top_classes = np.argsort(predictions)[-3:][::-1] # Indices of top 3 predictions
app.py+4-3