File size: 1,338 Bytes
551812e 1ea602b 3d9abc6 551812e 4691a60 551812e 1ea602b 551812e 3d9abc6 551812e 4691a60 551812e 1ea602b 551812e 4691a60 551812e 1ea602b 3d9abc6 b4ee810 3d9abc6 551812e fa5d609 |
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 34 35 36 |
import gradio as gr
import tensorflow as tf
from PIL import Image
import numpy as np
# Load the dog breed classifier model
model_path = "best_model.keras"
model = tf.keras.models.load_model(model_path)
labels = ['Beagle', 'French Bulldog', 'German Shepherd', 'Golden Retriever', 'Labrador Retriever']
# Define function for dog breed classification with data augmentation
def preprocess_image(image):
image = Image.fromarray(image.astype('uint8'), 'RGB')
image = image.resize((150, 150))
image = np.array(image)
image = image / 255.0 # Normalization of pixel values
return image
# Prediction function
def predict_dog_breed(image):
image = preprocess_image(image)
prediction = model.predict(np.expand_dims(image, axis=0))
predicted_class = labels[np.argmax(prediction)]
confidence = np.round(np.max(prediction) * 100, 2)
result = f"{predicted_class}, Confidence: {confidence}%"
return result
# Create Gradio interface
input_image = gr.Image()
output_text = gr.Textbox(label="Dog Breed")
interface = gr.Interface(fn=predict_dog_breed, inputs=input_image, outputs=output_text,
description="A dog breed classifier using a custom CNN model with data augmentation.",
theme="default")
if __name__ == "__main__":
interface.launch(share=True) |