Spaces:
Runtime error
Runtime error
Adding probs
Browse files
app.py
CHANGED
@@ -5,6 +5,7 @@ Repo.clone_from("https://github.com/dimitreOliveira/hub.git", "./hub")
|
|
5 |
sys.path.append("/hub")
|
6 |
|
7 |
import gradio as gr
|
|
|
8 |
from hub.tensorflow_hub.hf_utils import pull_from_hub
|
9 |
|
10 |
import requests
|
@@ -20,26 +21,12 @@ def preprocess(image):
|
|
20 |
|
21 |
def postprocess(prediction):
|
22 |
return {labels[i]: float(prediction[i]) for i in range(len(labels))}
|
23 |
-
# return {labels[i]: 0 for i in range(len(labels))}
|
24 |
|
25 |
def predict_fn(image):
|
26 |
image = preprocess(image)
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
try:
|
31 |
-
print("default")
|
32 |
-
print({labels[i]: float(prediction[i]) for i in range(len(labels))})
|
33 |
-
except:
|
34 |
-
print("default gives error")
|
35 |
-
print('****************')
|
36 |
-
print(list(prediction))
|
37 |
-
try:
|
38 |
-
print("list")
|
39 |
-
print({labels[i]: list(prediction)[i] for i in range(len(labels))})
|
40 |
-
except:
|
41 |
-
print("list gives error")
|
42 |
-
scores = postprocess(prediction)
|
43 |
return scores
|
44 |
|
45 |
iface = gr.Interface(fn=predict_fn,
|
|
|
5 |
sys.path.append("/hub")
|
6 |
|
7 |
import gradio as gr
|
8 |
+
import tensorflow as tf
|
9 |
from hub.tensorflow_hub.hf_utils import pull_from_hub
|
10 |
|
11 |
import requests
|
|
|
21 |
|
22 |
def postprocess(prediction):
|
23 |
return {labels[i]: float(prediction[i]) for i in range(len(labels))}
|
|
|
24 |
|
25 |
def predict_fn(image):
|
26 |
image = preprocess(image)
|
27 |
+
logits = model(image)
|
28 |
+
probs = tf.nn.softmax(logits, axis=1)[0].numpy()
|
29 |
+
scores = postprocess(probs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
return scores
|
31 |
|
32 |
iface = gr.Interface(fn=predict_fn,
|