|
import gradio as gr |
|
import tensorflow as tf |
|
from PIL import Image |
|
import numpy as np |
|
|
|
|
|
model_path = "trainpokemon_model_transferlearning.weights.h5" |
|
model_path = "pokemon_model_transferlearning.keras" |
|
|
|
|
|
model = tf.keras.models.load_model(model_path) |
|
|
|
labels = ['Ditto','Venomoth','Venusaur'] |
|
|
|
|
|
def predict_regression(image): |
|
|
|
image = Image.fromarray(image.astype('uint8')) |
|
image = image.resize((150, 150)) |
|
image = np.array(image) |
|
print(image.shape) |
|
|
|
prediction = model.predict(image[None, ...]) |
|
confidences = {labels[i]: np.round(float(prediction[0][i]), 2) for i in range(len(labels))} |
|
return confidences |
|
|
|
|
|
input_image = gr.Image() |
|
output_text = gr.Textbox(label="Predicted Pokemon") |
|
interface = gr.Interface(fn=predict_regression, |
|
inputs=input_image, |
|
outputs=gr.Label(), |
|
examples=["pokemons/train/Ditto/00000008.jpg", "images/Venomoth.jpeg", "images/Venusaur.jpeg"], |
|
description="A simple mlp classification model for image classification using the mnist dataset.") |
|
interface.launch() |
|
|