Spaces:
Runtime error
Runtime error
File size: 1,092 Bytes
367f5a2 04087ed 367f5a2 bcc19f8 367f5a2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
import numpy as np
import tensorflow as tf
from tensorflow.keras.layers import BatchNormalization
model = tf.keras.models.load_model('best_model.h5')
labels = ['Clams', 'Corals', 'Crabs', 'Dolphin', 'Eel', 'Fish',
'Jelly Fish', 'Lobster', 'Nudibranchs', 'Octopus', 'Otter',
'Penguin', 'Puffers', 'Sea Rays', 'Sea Urchins', 'Seahorse',
'Seal', 'Sharks', 'Shrimp', 'Squid', 'Starfish',
'Turtle_Tortoise', 'Whale']
def classify_image(image):
# Resize the image to 224x224 as expected by your model
image = tf.image.resize(image, (224, 224))
# Add a batch dimension and make prediction
image = tf.expand_dims(image, 0) # model expects a batch of images
preds = model.predict(image)
# Assuming the output is a softmax layer, get the predicted class index
predicted_class = tf.argmax(preds, axis=1).numpy()[0]
return labels[predicted_class]
import gradio as gr
# Define the interface
iface = gr.Interface(fn=classify_image, inputs="image", outputs="text")
# Launch the application
iface.launch() |