Upload 13 files
Browse files- .gitattributes +1 -0
- app.py +43 -0
- images/charmander1.png +0 -0
- images/charmander2.png +0 -0
- images/charmander3.jpg +0 -0
- images/metwo3.jpg +0 -0
- images/mewto.jpg +0 -0
- images/mewto1.jpg +0 -0
- images/mewto2.jpg +0 -0
- images/mewto4.png +0 -0
- images/squirtle1.png +0 -0
- images/squirtle2.jpg +0 -0
- images/squirtle3.jpg +0 -0
- pokemon_transferlearning.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_transferlearning.keras filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import tensorflow as tf
|
3 |
+
print(tf.__version__)
|
4 |
+
import numpy as np
|
5 |
+
from PIL import Image
|
6 |
+
|
7 |
+
model_path = "pokemon_transferlearning.keras"
|
8 |
+
model = tf.keras.models.load_model(model_path)
|
9 |
+
|
10 |
+
# Define the core prediction function
|
11 |
+
def predict_pokemon(image):
|
12 |
+
# Preprocess image
|
13 |
+
print(type(image))
|
14 |
+
image = Image.fromarray(image.astype('uint8')) # Convert numpy array to PIL image
|
15 |
+
image = image.resize((150, 150)) #resize the image to 28x28 and converts it to gray scale
|
16 |
+
image = np.array(image)
|
17 |
+
image = np.expand_dims(image, axis=0) # same as image[None, ...]
|
18 |
+
|
19 |
+
# Predict
|
20 |
+
prediction = model.predict(image)
|
21 |
+
|
22 |
+
# No need to apply sigmoid, as the output layer already uses softmax
|
23 |
+
# Convert the probabilities to rounded values
|
24 |
+
prediction = np.round(prediction, 2)
|
25 |
+
|
26 |
+
# Separate the probabilities for each class
|
27 |
+
p_charmander = prediction[0][0] # Probability for class 'charmander'
|
28 |
+
p_mewto = prediction[0][1] # Probability for class 'mewto'
|
29 |
+
p_squirtle = prediction[0][2] # Probability for class 'squirtle'
|
30 |
+
|
31 |
+
return {'charmander': p_charmander, 'mewto': p_mewto, 'squirtle': p_squirtle}
|
32 |
+
|
33 |
+
|
34 |
+
# Create the Gradio interface
|
35 |
+
input_image = gr.Image()
|
36 |
+
iface = gr.Interface(
|
37 |
+
fn=predict_pokemon,
|
38 |
+
inputs=input_image,
|
39 |
+
outputs=gr.Label(),
|
40 |
+
examples=["images/charmander1.png", "images/charmander2.png", "images/charmander3.jpg", "images/mewto.jpg", "images/mewto2.jpg", "images/mewto4.png", "images/squirtle1.png", "images/squirtle2.jpg", "images/squirtle3.jpg"],
|
41 |
+
description="TEST.")
|
42 |
+
|
43 |
+
iface.launch()
|
images/charmander1.png
ADDED
![]() |
images/charmander2.png
ADDED
![]() |
images/charmander3.jpg
ADDED
![]() |
images/metwo3.jpg
ADDED
![]() |
images/mewto.jpg
ADDED
![]() |
images/mewto1.jpg
ADDED
![]() |
images/mewto2.jpg
ADDED
![]() |
images/mewto4.png
ADDED
![]() |
images/squirtle1.png
ADDED
![]() |
images/squirtle2.jpg
ADDED
![]() |
images/squirtle3.jpg
ADDED
![]() |
pokemon_transferlearning.keras
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:57e111c38b92e8f97f3628ff504528d95a99e67803bdcd871d79c67960e9c585
|
3 |
+
size 250560262
|