|
import gradio as gr |
|
import tensorflow as tf |
|
import numpy as np |
|
from PIL import Image |
|
|
|
|
|
|
|
model_path = "Dogs-model_transferlearning.keras" |
|
model = tf.keras.models.load_model(model_path) |
|
|
|
|
|
def predict_dogs(image): |
|
|
|
image = Image.fromarray(image.astype('uint8')) |
|
image = image.resize((150, 150)) |
|
image = np.array(image) |
|
image = np.expand_dims(image, axis=0) |
|
|
|
|
|
prediction = model.predict(image) |
|
|
|
|
|
probabilities = tf.nn.softmax(prediction) |
|
|
|
|
|
dogs_classes = ['Goldie', 'Beagle', 'Husky'] |
|
probabilities_dict = {dogs_class: round(float(probability), 2) for dogs_class, probability in zip(dogs_classes, probabilities[0])} |
|
|
|
return probabilities_dict |
|
|
|
|
|
input_image = gr.Image() |
|
iface = gr.Interface( |
|
fn=predict_dogs, |
|
inputs=input_image, |
|
outputs=gr.Label(), |
|
live=True, |
|
examples=["images/01.jpg", "images/02.jpg", "images/03.jpg", "images/04.jpg", "images/06.jpg", "images/06.jpg"], |
|
description="A simple mlp classification model for image classification using the mnist dataset.") |
|
iface.launch() |