Spaces:
Build error
Build error
SivaResearch
commited on
Commit
·
062f571
1
Parent(s):
0589a37
Added Files
Browse files
README.md
CHANGED
@@ -1,13 +1,12 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 3.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
-
license: openrail
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: Battle Of The Image Classifiers
|
3 |
+
emoji: 🐨
|
4 |
+
colorFrom: green
|
5 |
+
colorTo: gray
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 3.16.1
|
8 |
app_file: app.py
|
9 |
pinned: false
|
|
|
10 |
---
|
11 |
|
12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
model_names = [
|
5 |
+
"apple/mobilevit-small",
|
6 |
+
"facebook/deit-base-patch16-224",
|
7 |
+
"facebook/convnext-base-224",
|
8 |
+
"google/vit-base-patch16-224",
|
9 |
+
"google/mobilenet_v2_1.4_224",
|
10 |
+
"microsoft/resnet-50",
|
11 |
+
"microsoft/swin-base-patch4-window7-224",
|
12 |
+
"microsoft/beit-base-patch16-224",
|
13 |
+
"nvidia/mit-b0",
|
14 |
+
"shi-labs/nat-base-in1k-224",
|
15 |
+
"shi-labs/dinat-base-in1k-224",
|
16 |
+
]
|
17 |
+
|
18 |
+
|
19 |
+
def process(image_file, top_k):
|
20 |
+
labels = []
|
21 |
+
for m in model_names:
|
22 |
+
p = pipeline("image-classification", model=m)
|
23 |
+
pred = p(image_file)
|
24 |
+
labels.append({x["label"]: x["score"] for x in pred[:top_k]})
|
25 |
+
return labels
|
26 |
+
|
27 |
+
|
28 |
+
# Inputs
|
29 |
+
image = gr.Image(type="filepath", label="Upload an image")
|
30 |
+
top_k = gr.Slider(minimum=1, maximum=5, step=1, value=5, label="Top k classes")
|
31 |
+
|
32 |
+
# Output
|
33 |
+
labels = [gr.Label(label=m) for m in model_names]
|
34 |
+
|
35 |
+
description = "This Space lets you quickly compare the most popular image classifiers available on the hub, including the recent NAT and DINAT models. All of them have been fine-tuned on the ImageNet-1k dataset. Anecdotally, the three sample images have been generated with a Stable Diffusion model :)"
|
36 |
+
|
37 |
+
iface = gr.Interface(
|
38 |
+
theme="huggingface",
|
39 |
+
description=description,
|
40 |
+
layout="horizontal",
|
41 |
+
fn=process,
|
42 |
+
inputs=[image, top_k],
|
43 |
+
outputs=labels,
|
44 |
+
examples=[
|
45 |
+
["bike.jpg", 5],
|
46 |
+
["car.jpg", 5],
|
47 |
+
["food.jpg", 5],
|
48 |
+
],
|
49 |
+
allow_flagging="never",
|
50 |
+
)
|
51 |
+
|
52 |
+
iface.launch()
|
bike.jpg
ADDED
car.jpg
ADDED
food.jpg
ADDED
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
torch==1.13.1
|
2 |
+
transformers>=4.25.1
|
3 |
+
https://shi-labs.com/natten/wheels/cpu/torch1.13/natten-0.14.4%2Btorch1130cpu-cp38-cp38-linux_x86_64.whl
|