update for newer versions of gradio and the update model
Browse files- app.py +14 -7
- guaraci.jpg +0 -0
- kasimir.jpg +0 -0
- labels.txt +17 -2
- test.jpg +0 -0
app.py
CHANGED
@@ -2,21 +2,28 @@ import gradio as gr
|
|
2 |
import tensorflow as tf
|
3 |
import numpy as np
|
4 |
import requests
|
|
|
5 |
|
6 |
-
|
|
|
7 |
with open('labels.txt','r') as f:
|
8 |
labels = f.read().splitlines()
|
9 |
|
|
|
|
|
|
|
|
|
10 |
def classify_image(inp):
|
11 |
-
model = tf.keras.models.load_model('saved_model')
|
12 |
inp = inp.resize((480,480))
|
13 |
inp = np.array(inp)
|
14 |
inp = np.reshape(inp,(-1, 480, 480, 3)).astype(np.float32)
|
15 |
inp = np.divide(inp,255.0)
|
16 |
-
prediction = model.predict(inp).flatten()
|
17 |
-
|
|
|
|
|
18 |
|
19 |
-
image = gr.
|
20 |
-
label = gr.
|
21 |
|
22 |
-
gr.Interface(fn=classify_image, inputs=image, outputs=label,
|
|
|
2 |
import tensorflow as tf
|
3 |
import numpy as np
|
4 |
import requests
|
5 |
+
from huggingface_hub import snapshot_download
|
6 |
|
7 |
+
label_count = 51
|
8 |
+
labels = ["missing"] * label_count
|
9 |
with open('labels.txt','r') as f:
|
10 |
labels = f.read().splitlines()
|
11 |
|
12 |
+
model_path = extractor_path = snapshot_download(repo_id="eshieh2/jaguarid_pantanal")
|
13 |
+
model = tf.saved_model.load(f"{model_path}/saved_model")
|
14 |
+
serving = model.signatures['serving_default']
|
15 |
+
#model = tf.keras.models.load_model(f"{model_path}/saved_model")
|
16 |
def classify_image(inp):
|
|
|
17 |
inp = inp.resize((480,480))
|
18 |
inp = np.array(inp)
|
19 |
inp = np.reshape(inp,(-1, 480, 480, 3)).astype(np.float32)
|
20 |
inp = np.divide(inp,255.0)
|
21 |
+
#prediction = model.predict(inp).flatten()
|
22 |
+
prediction = serving(tf.convert_to_tensor(inp))['model']
|
23 |
+
prediction = tf.squeeze(prediction)
|
24 |
+
return {labels[i]: float(prediction[i]) for i in range(label_count)}
|
25 |
|
26 |
+
image = gr.Image(type='pil')
|
27 |
+
label = gr.Label(num_top_classes=3)
|
28 |
|
29 |
+
gr.Interface(fn=classify_image, inputs=image, outputs=label, examples = [["kasimir.jpg","guaraci.jpg"]]).launch()
|
guaraci.jpg
ADDED
![]() |
kasimir.jpg
ADDED
![]() |
labels.txt
CHANGED
@@ -9,7 +9,7 @@ Courtney
|
|
9 |
Donal
|
10 |
Estella
|
11 |
Forasteiro
|
12 |
-
|
13 |
Hero
|
14 |
Ibaca
|
15 |
Inca
|
@@ -33,4 +33,19 @@ Tomas
|
|
33 |
Tusk
|
34 |
Xando
|
35 |
Xingu
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
Donal
|
10 |
Estella
|
11 |
Forasteiro
|
12 |
+
Guaraci
|
13 |
Hero
|
14 |
Ibaca
|
15 |
Inca
|
|
|
33 |
Tusk
|
34 |
Xando
|
35 |
Xingu
|
36 |
+
negative
|
37 |
+
Antares
|
38 |
+
Carvarinha
|
39 |
+
Kyyaverá
|
40 |
+
Ousado
|
41 |
+
aju
|
42 |
+
brady
|
43 |
+
branco
|
44 |
+
buraca
|
45 |
+
xingua
|
46 |
+
alira
|
47 |
+
chevo
|
48 |
+
acerola
|
49 |
+
nusa
|
50 |
+
surya
|
51 |
+
|
test.jpg
DELETED
Binary file (9.8 kB)
|
|