Update app.py
Browse files
app.py
CHANGED
@@ -16,14 +16,15 @@ def segment(image):
|
|
16 |
logits = model(**inputs).logits
|
17 |
probs = torch.nn.Softmax(dim=1)(logits)
|
18 |
# labels = [(prob, model.config.id2label[idx]) for idx, prob in enumerate(probs[0])]
|
19 |
-
labels = {model.config.id2label[idx] :
|
20 |
print(labels)
|
21 |
|
22 |
# model predicts one of the 1000 ImageNet classes
|
23 |
-
predicted_label = logits.argmax(-1).item()
|
24 |
return labels # model.config.id2label[predicted_label]
|
25 |
|
26 |
-
gr.Interface(fn=segment, inputs="image", outputs="
|
|
|
27 |
|
28 |
# with torch.no_grad():
|
29 |
# prediction = torch.nn.functional.softmax(model(**inputs)[0], dim=0)
|
16 |
logits = model(**inputs).logits
|
17 |
probs = torch.nn.Softmax(dim=1)(logits)
|
18 |
# labels = [(prob, model.config.id2label[idx]) for idx, prob in enumerate(probs[0])]
|
19 |
+
labels = {model.config.id2label[idx] : float(prob) for idx, prob in enumerate(probs[0])}
|
20 |
print(labels)
|
21 |
|
22 |
# model predicts one of the 1000 ImageNet classes
|
23 |
+
# predicted_label = logits.argmax(-1).item()
|
24 |
return labels # model.config.id2label[predicted_label]
|
25 |
|
26 |
+
gr.Interface(fn=segment, inputs="image", outputs="label").launch()
|
27 |
+
#gr.Interface(fn=segment, inputs="image", outputs="text").launch()
|
28 |
|
29 |
# with torch.no_grad():
|
30 |
# prediction = torch.nn.functional.softmax(model(**inputs)[0], dim=0)
|