Spaces:
Runtime error
Runtime error
Julien Simon
commited on
Commit
•
5a39643
1
Parent(s):
04dd97f
Initial version
Browse files
README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
---
|
2 |
-
title: Battle Of Image Classifiers
|
3 |
emoji: 🐨
|
4 |
colorFrom: green
|
5 |
colorTo: gray
|
|
|
1 |
---
|
2 |
+
title: Battle Of The Image Classifiers
|
3 |
emoji: 🐨
|
4 |
colorFrom: green
|
5 |
colorTo: gray
|
app.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
model_names = [
|
5 |
+
"facebook/deit-base-patch16-224",
|
6 |
+
"facebook/convnext-base-224",
|
7 |
+
"google/vit-base-patch16-224",
|
8 |
+
"microsoft/resnet-50",
|
9 |
+
"microsoft/swin-base-patch4-window7-224",
|
10 |
+
"microsoft/beit-base-patch16-224",
|
11 |
+
"nvidia/mit-b0",
|
12 |
+
"shi-labs/nat-base-in1k-224",
|
13 |
+
"shi-labs/dinat-base-in1k-224"
|
14 |
+
]
|
15 |
+
|
16 |
+
|
17 |
+
def process(image_file, top_k, model_name):
|
18 |
+
p = pipeline("image-classification", model=model_name)
|
19 |
+
pred = p(image_file)
|
20 |
+
return {x["label"]: x["score"] for x in pred[:top_k]}
|
21 |
+
|
22 |
+
# Inputs
|
23 |
+
image = gr.Image(type="filepath", label="Upload an image")
|
24 |
+
top_k = gr.Slider(minimum=1, maximum=10, step=1, value=5, label="Top k classes")
|
25 |
+
model_selection = gr.Dropdown(model_names, label="Pick a model")
|
26 |
+
|
27 |
+
# Output
|
28 |
+
labels = gr.Label()
|
29 |
+
|
30 |
+
description = "This Space lets you quickly compare the most popular image classifier models available on the hub. 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 :)"
|
31 |
+
|
32 |
+
iface = gr.Interface(
|
33 |
+
theme="huggingface",
|
34 |
+
description=description,
|
35 |
+
fn=process,
|
36 |
+
inputs=[image, top_k, model_selection],
|
37 |
+
outputs=[labels],
|
38 |
+
examples=[
|
39 |
+
["bike.jpg", 5, "google/vit-base-patch16-224"],
|
40 |
+
["car.jpg", 5, "microsoft/swin-base-patch4-window7-224"],
|
41 |
+
["food.jpg", 5, "facebook/convnext-base-224"]
|
42 |
+
],
|
43 |
+
allow_flagging="never",
|
44 |
+
)
|
45 |
+
|
46 |
+
iface.launch()
|
bike.jpg
ADDED
car.jpg
ADDED
food.jpg
ADDED
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
transformers>=4.25.1
|
3 |
+
natten
|