Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -27,6 +27,7 @@ imagenet_id_to_classname = {}
|
|
27 |
for k, v in imagenet_classnames.items():
|
28 |
imagenet_id_to_classname[k] = v[1]
|
29 |
|
|
|
30 |
def inference(img):
|
31 |
image = img
|
32 |
image_transform = T.Compose(
|
@@ -39,28 +40,24 @@ def inference(img):
|
|
39 |
)
|
40 |
image = image_transform(image)
|
41 |
|
42 |
-
# The model expects inputs of shape: B x C x
|
43 |
image = image.unsqueeze(0)
|
44 |
|
45 |
prediction = model(image)
|
46 |
-
prediction = F.softmax(prediction, dim=1)
|
47 |
|
48 |
-
return {imagenet_id_to_classname[str(i)]: float(prediction[
|
49 |
|
|
|
50 |
inputs = gr.inputs.Image(type='pil')
|
51 |
-
# outputs = gr.outputs.Textbox(label="Output")
|
52 |
label = gr.outputs.Label(num_top_classes=5)
|
53 |
|
54 |
title = "UniFormer-S"
|
55 |
-
|
56 |
description = "Gradio demo for UniFormer: To use it, simply upload your image, or click one of the examples to load them. Read more at the links below."
|
57 |
-
|
58 |
article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2201.09450' target='_blank'>UniFormer: Unifying Convolution and Self-attention for Visual Recognition</a> | <a href='https://github.com/Sense-X/UniFormer' target='_blank'>Github Repo</a></p>"
|
59 |
|
60 |
-
|
61 |
gr.Interface(
|
62 |
inference, inputs, outputs=label,
|
63 |
-
title=title, description=description,
|
64 |
-
article=article,
|
65 |
examples=[['library.jpeg'], ['cat.png'], ['dog.png'], ['panda.png']]
|
66 |
).launch(enable_queue=True, cache_examples=True)
|
|
|
27 |
for k, v in imagenet_classnames.items():
|
28 |
imagenet_id_to_classname[k] = v[1]
|
29 |
|
30 |
+
|
31 |
def inference(img):
|
32 |
image = img
|
33 |
image_transform = T.Compose(
|
|
|
40 |
)
|
41 |
image = image_transform(image)
|
42 |
|
43 |
+
# The model expects inputs of shape: B x C x H x W
|
44 |
image = image.unsqueeze(0)
|
45 |
|
46 |
prediction = model(image)
|
47 |
+
prediction = F.softmax(prediction, dim=1).flatten()
|
48 |
|
49 |
+
return {imagenet_id_to_classname[str(i)]: float(prediction[i]) for i in range(1000)}
|
50 |
|
51 |
+
|
52 |
inputs = gr.inputs.Image(type='pil')
|
|
|
53 |
label = gr.outputs.Label(num_top_classes=5)
|
54 |
|
55 |
title = "UniFormer-S"
|
|
|
56 |
description = "Gradio demo for UniFormer: To use it, simply upload your image, or click one of the examples to load them. Read more at the links below."
|
|
|
57 |
article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2201.09450' target='_blank'>UniFormer: Unifying Convolution and Self-attention for Visual Recognition</a> | <a href='https://github.com/Sense-X/UniFormer' target='_blank'>Github Repo</a></p>"
|
58 |
|
|
|
59 |
gr.Interface(
|
60 |
inference, inputs, outputs=label,
|
61 |
+
title=title, description=description, article=article,
|
|
|
62 |
examples=[['library.jpeg'], ['cat.png'], ['dog.png'], ['panda.png']]
|
63 |
).launch(enable_queue=True, cache_examples=True)
|