|
import tensorflow as tf |
|
import gradio as gr |
|
import numpy as np |
|
import os |
|
from PIL import Image |
|
|
|
print(tf.__version__) |
|
|
|
print(f"Current working directory: {os.getcwd()}") |
|
|
|
model_path = 'transferlearning_pokemon.h5' |
|
|
|
|
|
if os.path.exists(model_path): |
|
print(f"Model found at {model_path}") |
|
try: |
|
|
|
model = tf.keras.models.load_model(model_path) |
|
print("Model loaded successfully.") |
|
except Exception as e: |
|
print(f"Error loading model: {e}") |
|
else: |
|
print(f"Model not found at {model_path}. Please check the path.") |
|
|
|
|
|
|
|
class_names = ['Machamp', 'Raichu', 'Vulpix'] |
|
|
|
|
|
def predict(image): |
|
image = Image.fromarray(image.astype('uint8')) |
|
image = image.resize((150, 150)) |
|
image = np.array(image) |
|
image = np.expand_dims(image, axis=0) |
|
predictions = model.predict(image) |
|
predicted_class = np.argmax(predictions, axis=1)[0] |
|
confidence = np.max(predictions) |
|
return {class_names[predicted_class]: float(confidence)} |
|
|
|
|
|
input_image = gr.Image() |
|
output_text = gr.Textbox(label="Predicted Value") |
|
interface = gr.Interface(fn=predict, |
|
inputs=input_image, |
|
outputs=gr.Label(), |
|
examples=["00000000.jpg", "00000001.jpg", "00000010.png", "00000017.jpg", "00000021.jpg", "00000067.jpg"], |
|
description="A simple mlp classification model for image classification using the mnist dataset.") |
|
|
|
|
|
interface.launch() |