Andy1621 commited on
Commit
ffe2dca
1 Parent(s): 42494b1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -46,14 +46,15 @@ def inference(img):
46
 
47
  prediction = model(image)
48
  prediction = F.softmax(prediction, dim=1)
49
- pred_classes = prediction.topk(k=5).indices
50
-
51
- pred_class_names = [imagenet_id_to_classname[str(i.item())] for i in pred_classes[0]]
52
- pred_class_probs = [prediction[0][i.item()].item() * 100 for i in pred_classes[0]]
53
- res = "Top 5 predicted labels:\n"
54
- for name, prob in zip(pred_class_names, pred_class_probs):
55
- res += f"[{prob:2.2f}%]\t{name}\n"
56
- return res
 
57
 
58
  inputs = gr.inputs.Image(type='pil')
59
  outputs = gr.outputs.Textbox(label="Output")
 
46
 
47
  prediction = model(image)
48
  prediction = F.softmax(prediction, dim=1)
49
+
50
+ # pred_classes = prediction.topk(k=5).indices
51
+ # pred_class_names = [imagenet_id_to_classname[str(i.item())] for i in pred_classes[0]]
52
+ # pred_class_probs = [prediction[0][i.item()].item() * 100 for i in pred_classes[0]]
53
+ # res = "Top 5 predicted labels:\n"
54
+ # for name, prob in zip(pred_class_names, pred_class_probs):
55
+ # res += f"[{prob:2.2f}%]\t{name}\n"
56
+
57
+ return {imagenet_id_to_classname[str(i)]: float(prediction[i]) for i in range(1000)}
58
 
59
  inputs = gr.inputs.Image(type='pil')
60
  outputs = gr.outputs.Textbox(label="Output")