File size: 1,766 Bytes
528e68c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
40
41
42
import gradio as gr
import tensorflow as tf
import numpy as np
from PIL import Image
 
model_path = "pokemon_model_loretmar.keras"
model = tf.keras.models.load_model(model_path)
 

def predict_pokemon(image):
    # Preprocess image
    print(type(image))
    image = Image.fromarray(image.astype('uint8'))  # Convert numpy array to PIL image
    image = image.resize((150, 150)) #resize the image to 28x28 and converts it to gray scale
    image = np.array(image)
    image = np.expand_dims(image, axis=0) # same as image[None, ...]

    prediction = model.predict(image)
 
    # No need to apply sigmoid, as the output layer already uses softmax
    # Convert the probabilities to rounded values
    prediction = np.round(prediction, 2)
 
    # Separate the probabilities for each class
    p_abra = prediction[0][0]  # Probability for class 'articuno'
    p_aerodactyl = prediction[0][1]   # Probability for class 'moltres'
    p_eevee = prediction[0][2]    # Probability for class 'zapdos'
 
  #  return {'charmander':  p_charmander, 'mewtwo': p_mewtwo, 'squirtle': p_squirtle}
    return {'Abra':  p_abra, 'Aerodactyl': p_aerodactyl, 'Eevee': p_eevee}
 
 
input_image = gr.Image()
iface = gr.Interface(
    fn=predict_pokemon,
    inputs=input_image,
    outputs=gr.Label(),
    examples=["images/00000000.png", "images/00000001.png", "images/00000002.png", "images/00000003.png", "images/00000004.png", "images/00000005.jpg"],
    #examples=["pokemon\train\Abra\00000000.png", "pokemon\train\Abra\00000001.png.png", "pokemon\train\Dragonite\00000000.png", "pokemon\train\Dragonite\00000001.png", "pokemon\train\Jigglypuff\00000000.png", "pokemon\train\Jigglypuff\00000001.png"],
    description="TEST.")
 
iface.launch()