|
import gradio as gr |
|
import tensorflow as tf |
|
import numpy as np |
|
from PIL import Image |
|
|
|
model_path = "Abra-vs-Pikachu-vs-Zubat-model_transferlearning.keras" |
|
model = tf.keras.models.load_model(model_path) |
|
|
|
|
|
|
|
|
|
def predict_pokemon(image): |
|
|
|
print(type(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) |
|
|
|
|
|
prediction_prob = tf.sigmoid(prediction).numpy() |
|
|
|
|
|
p_Abra = round(prediction_prob[0][0], 2) |
|
p_Pikachu = round(prediction_prob[0][1], 2) |
|
p_Zubat = round(prediction_prob[0][2], 2) |
|
|
|
return {'Abra': p_Abra, 'Pikachu': p_Pikachu, 'Zubat': p_Zubat} |
|
|
|
|
|
|
|
input_image = gr.Image() |
|
iface = gr.Interface( |
|
fn=predict_pokemon, |
|
inputs=input_image, |
|
outputs=gr.Label(), |
|
examples=["Abra1.png", "Abra2.jpg", "Abra3.jpg", "Pikachu1.jpg", |
|
"Pikachu2.png", "Pikachu3.jpg", "Zubat1.jpg", "Zubat2.jpg", "Zubat3.jpg"], |
|
description="Image classification pokemon!!!ππ.") |
|
iface.launch() |
|
|