Spaces:
Runtime error
Runtime error
update
Browse files
app.py
CHANGED
@@ -48,17 +48,16 @@ def inference(img):
|
|
48 |
prediction = model(image)
|
49 |
prediction = F.softmax(prediction, dim=1).flatten()
|
50 |
|
51 |
-
#
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
-
|
54 |
-
pred_class_names = [imagenet_id_to_classname[str(i.item())] for i in pred_classes[0]]
|
55 |
-
pred_class_probs = [prediction[0][i.item()].item() * 100 for i in pred_classes[0]]
|
56 |
-
res = "Top 5 predicted labels:\n"
|
57 |
-
for name, prob in zip(pred_class_names, pred_class_probs):
|
58 |
-
res += f"[{prob:2.2f}%]\t{name}\n"
|
59 |
-
|
60 |
-
return res
|
61 |
|
|
|
62 |
|
63 |
def set_example_image(example: list) -> dict:
|
64 |
return gr.Image.update(value=example[0])
|
@@ -77,11 +76,11 @@ with demo:
|
|
77 |
with gr.Row():
|
78 |
with gr.Column():
|
79 |
with gr.Row():
|
80 |
-
input_image = gr.Image(label='Input Image', type='
|
81 |
with gr.Row():
|
82 |
submit_button = gr.Button('Submit')
|
83 |
with gr.Column():
|
84 |
-
label = gr.Label()
|
85 |
with gr.Row():
|
86 |
example_images = gr.Dataset(components=[input_image], samples=[['library.jpeg'], ['cat.png'], ['dog.png'], ['panda.png']])
|
87 |
|
|
|
48 |
prediction = model(image)
|
49 |
prediction = F.softmax(prediction, dim=1).flatten()
|
50 |
|
51 |
+
# pred_classes = prediction.topk(k=5).indices
|
52 |
+
# pred_class_names = [imagenet_id_to_classname[str(i.item())] for i in pred_classes[0]]
|
53 |
+
# pred_class_probs = [prediction[0][i.item()].item() * 100 for i in pred_classes[0]]
|
54 |
+
# res = "Top 5 predicted labels:\n"
|
55 |
+
# for name, prob in zip(pred_class_names, pred_class_probs):
|
56 |
+
# res += f"[{prob:2.2f}%]\t{name}\n"
|
57 |
|
58 |
+
# return res
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
+
return {imagenet_id_to_classname[str(i)]: float(prediction[i]) for i in range(1000)}
|
61 |
|
62 |
def set_example_image(example: list) -> dict:
|
63 |
return gr.Image.update(value=example[0])
|
|
|
76 |
with gr.Row():
|
77 |
with gr.Column():
|
78 |
with gr.Row():
|
79 |
+
input_image = gr.Image(label='Input Image', type='numpy')
|
80 |
with gr.Row():
|
81 |
submit_button = gr.Button('Submit')
|
82 |
with gr.Column():
|
83 |
+
label = gr.Label(num_top_classes=5)
|
84 |
with gr.Row():
|
85 |
example_images = gr.Dataset(components=[input_image], samples=[['library.jpeg'], ['cat.png'], ['dog.png'], ['panda.png']])
|
86 |
|