loretmar commited on
Commit
02af144
·
verified ·
1 Parent(s): d6a33f5

Upload 2 files

Browse files
Files changed (3) hide show
  1. .gitattributes +1 -0
  2. app.py +43 -0
  3. loretmar_ResNet50.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
+ loretmar_ResNet50.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
+ import numpy as np
4
+ from PIL import Image
5
+
6
+ model_path = "loretmar_ResNet50.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((200, 200)) #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_1 = prediction[0][0] # Probability for class 'articuno'
26
+ p_2 = prediction[0][1] # Probability for class 'moltres'
27
+ p_3 = prediction[0][2] # Probability for class 'zapdos'
28
+ p_4 = prediction[0][3] # Probability for class 'zapdos'
29
+
30
+ # return {'charmander': p_charmander, 'mewtwo': p_mewtwo, 'squirtle': p_squirtle}
31
+ return {'Agkistrodon contortrix (venomous)': p_1, 'Agkistrodon piscivorus (venomous)': p_2, 'Ahaetulla nasuta (not venomous)': p_3, 'Ahaetulla prasina (not venomous)': p_4}
32
+
33
+
34
+ input_image = gr.Image()
35
+ iface = gr.Interface(
36
+ fn=predict_pokemon,
37
+ inputs=input_image,
38
+ outputs=gr.Label(),
39
+ examples=["train/18/0bd1af4119054513917caa7944efd082.jpg", "train/20/0b103c4331bb47f4890d6e0ec96bf9bf.jpg", "train/25/0b4ef7c358044df1b734ea188811e684.jpg", "train/26/0f13f1c263c94602b0462353ff3d188b.jpg"],
40
+ #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"],
41
+ description="TEST.")
42
+
43
+ iface.launch()
loretmar_ResNet50.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0cac66650e3dc323dc233a0ee275837e84055db7a31b9317ef8f510ce6573988
3
+ size 283497154