File size: 1,278 Bytes
6086bf9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
37
38
39
import gradio as gr
import tensorflow as tf
from PIL import Image
import numpy as np
 
# Load the Pokémon classifier model
model_path = "pokemon_classifier_finetuned.keras"
model = tf.keras.models.load_model(model_path)
 
labels = ['Dodrio', 'Arbok', 'Gengar']
 
# Define function for Pokémon classification
def preprocess_image(image):
    # Preprocess image
    image = Image.fromarray(image.astype('uint8'))
    image = image.resize((224, 224))
    image = np.array(image)
    image = image / 255.0  # Normalize pixel values
    return image
 
# Prediction
def predict_pokemon(image):
    image = preprocess_image(image)
    prediction = model.predict(image[None, ...])
    predicted_class = labels[np.argmax(prediction)]
    confidence = np.round(np.max(prediction) * 100, 2)
    result = f"Label: {predicted_class}, Confidence: {confidence}%"
    return result
 
# Create Gradio interface
input_image = gr.Image()
output_text = gr.Textbox(label="Pokemon")
interface = gr.Interface(fn=predict_pokemon, 
                         inputs=input_image, 
                         outputs=output_text,   
                         description="A Pokémon classifier using transfer learning and fine-tuning with EfficientNetB0.")
 
if __name__ == "__main__":
    interface.launch()