Upload 2 files
Browse files- .gitattributes +1 -0
- app.py +42 -0
- pokemon_model_loretmar.keras +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
pokemon_model_loretmar.keras filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import numpy as np
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
model_path = "pokemon_model_loretmar.keras"
|
| 7 |
+
model = tf.keras.models.load_model(model_path)
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def predict_pokemon(image):
|
| 11 |
+
# Preprocess image
|
| 12 |
+
print(type(image))
|
| 13 |
+
image = Image.fromarray(image.astype('uint8')) # Convert numpy array to PIL image
|
| 14 |
+
image = image.resize((150, 150)) #resize the image to 28x28 and converts it to gray scale
|
| 15 |
+
image = np.array(image)
|
| 16 |
+
image = np.expand_dims(image, axis=0) # same as image[None, ...]
|
| 17 |
+
|
| 18 |
+
prediction = model.predict(image)
|
| 19 |
+
|
| 20 |
+
# No need to apply sigmoid, as the output layer already uses softmax
|
| 21 |
+
# Convert the probabilities to rounded values
|
| 22 |
+
prediction = np.round(prediction, 2)
|
| 23 |
+
|
| 24 |
+
# Separate the probabilities for each class
|
| 25 |
+
p_abra = prediction[0][0] # Probability for class 'articuno'
|
| 26 |
+
p_aerodactyl = prediction[0][1] # Probability for class 'moltres'
|
| 27 |
+
p_eevee = prediction[0][2] # Probability for class 'zapdos'
|
| 28 |
+
|
| 29 |
+
# return {'charmander': p_charmander, 'mewtwo': p_mewtwo, 'squirtle': p_squirtle}
|
| 30 |
+
return {'Abra': p_abra, 'Aerodactyl': p_aerodactyl, 'Eevee': p_eevee}
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
input_image = gr.Image()
|
| 34 |
+
iface = gr.Interface(
|
| 35 |
+
fn=predict_pokemon,
|
| 36 |
+
inputs=input_image,
|
| 37 |
+
outputs=gr.Label(),
|
| 38 |
+
examples=["images/00000000.png", "images/00000001.png", "images/00000002.png", "images/00000003.png", "images/00000004.png", "images/00000005.jpg"],
|
| 39 |
+
#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"],
|
| 40 |
+
description="TEST.")
|
| 41 |
+
|
| 42 |
+
iface.launch()
|
pokemon_model_loretmar.keras
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:06bbf77efb8ae87038ee257c1347e6349bfaf08fa016815c1db968ccc68bde99
|
| 3 |
+
size 250560147
|