SivaResearch
commited on
Commit
·
6620552
1
Parent(s):
482d917
Files Added
Browse files
README.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1 |
---
|
2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
---
|
|
|
|
|
|
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.ipynb
ADDED
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"name": "stderr",
|
10 |
+
"output_type": "stream",
|
11 |
+
"text": [
|
12 |
+
"c:\\Users\\iitsi\\anaconda3\\lib\\site-packages\\gradio\\blocks.py:503: UserWarning: Cannot load huggingface. Caught Exception: The space huggingface does not exist\n",
|
13 |
+
" warnings.warn(f\"Cannot load {theme}. Caught Exception: {str(e)}\")\n",
|
14 |
+
"c:\\Users\\iitsi\\anaconda3\\lib\\site-packages\\gradio\\deprecation.py:40: UserWarning: `layout` parameter is deprecated, and it has no effect\n",
|
15 |
+
" warnings.warn(value)\n",
|
16 |
+
"ERROR: [Errno 10048] error while attempting to bind on address ('127.0.0.1', 7864): only one usage of each socket address (protocol/network address/port) is normally permitted\n"
|
17 |
+
]
|
18 |
+
}
|
19 |
+
],
|
20 |
+
"source": [
|
21 |
+
"import gradio as gr\n",
|
22 |
+
"from transformers import pipeline\n",
|
23 |
+
"\n",
|
24 |
+
"model_names = [\n",
|
25 |
+
" \"apple/mobilevit-small\",\n",
|
26 |
+
" \"facebook/deit-base-patch16-224\",\n",
|
27 |
+
" \"facebook/convnext-base-224\",\n",
|
28 |
+
" \"google/vit-base-patch16-224\",\n",
|
29 |
+
" \"google/mobilenet_v2_1.4_224\",\n",
|
30 |
+
" \"microsoft/resnet-50\",\n",
|
31 |
+
" \"microsoft/swin-base-patch4-window7-224\",\n",
|
32 |
+
" \"microsoft/beit-base-patch16-224\",\n",
|
33 |
+
" \"nvidia/mit-b0\",\n",
|
34 |
+
" \"shi-labs/nat-base-in1k-224\",\n",
|
35 |
+
" \"shi-labs/dinat-base-in1k-224\",\n",
|
36 |
+
"]\n",
|
37 |
+
"\n",
|
38 |
+
"\n",
|
39 |
+
"def process(image_file, top_k):\n",
|
40 |
+
" labels = []\n",
|
41 |
+
" for m in model_names:\n",
|
42 |
+
" p = pipeline(\"image-classification\", model=m)\n",
|
43 |
+
" pred = p(image_file)\n",
|
44 |
+
" labels.append({x[\"label\"]: x[\"score\"] for x in pred[:top_k]})\n",
|
45 |
+
" return labels\n",
|
46 |
+
"\n",
|
47 |
+
"\n",
|
48 |
+
"# Inputs\n",
|
49 |
+
"image = gr.Image(type=\"filepath\", label=\"Upload an image\")\n",
|
50 |
+
"top_k = gr.Slider(minimum=1, maximum=5, step=1, value=5, label=\"Top k classes\")\n",
|
51 |
+
"\n",
|
52 |
+
"# Output\n",
|
53 |
+
"labels = [gr.Label(label=m) for m in model_names]\n",
|
54 |
+
"\n",
|
55 |
+
"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 :)\"\n",
|
56 |
+
"\n",
|
57 |
+
"iface = gr.Interface(\n",
|
58 |
+
" theme=\"huggingface\",\n",
|
59 |
+
" description=description,\n",
|
60 |
+
" layout=\"horizontal\",\n",
|
61 |
+
" fn=process,\n",
|
62 |
+
" inputs=[image, top_k],\n",
|
63 |
+
" outputs=labels,\n",
|
64 |
+
" examples=[\n",
|
65 |
+
" [\"bike.jpg\", 5],\n",
|
66 |
+
" [\"car.jpg\", 5],\n",
|
67 |
+
" [\"food.jpg\", 5],\n",
|
68 |
+
" ],\n",
|
69 |
+
" allow_flagging=\"never\",\n",
|
70 |
+
")\n",
|
71 |
+
"\n",
|
72 |
+
"iface.launch()\n"
|
73 |
+
]
|
74 |
+
},
|
75 |
+
{
|
76 |
+
"cell_type": "code",
|
77 |
+
"execution_count": null,
|
78 |
+
"metadata": {},
|
79 |
+
"outputs": [],
|
80 |
+
"source": []
|
81 |
+
}
|
82 |
+
],
|
83 |
+
"metadata": {
|
84 |
+
"kernelspec": {
|
85 |
+
"display_name": "base",
|
86 |
+
"language": "python",
|
87 |
+
"name": "python3"
|
88 |
+
},
|
89 |
+
"language_info": {
|
90 |
+
"codemirror_mode": {
|
91 |
+
"name": "ipython",
|
92 |
+
"version": 3
|
93 |
+
},
|
94 |
+
"file_extension": ".py",
|
95 |
+
"mimetype": "text/x-python",
|
96 |
+
"name": "python",
|
97 |
+
"nbconvert_exporter": "python",
|
98 |
+
"pygments_lexer": "ipython3",
|
99 |
+
"version": "3.9.13"
|
100 |
+
},
|
101 |
+
"orig_nbformat": 4,
|
102 |
+
"vscode": {
|
103 |
+
"interpreter": {
|
104 |
+
"hash": "a10896378c7586fe060a2352f1f55c7416a5095f8b10e25e98ff567d7ae9c79d"
|
105 |
+
}
|
106 |
+
}
|
107 |
+
},
|
108 |
+
"nbformat": 4,
|
109 |
+
"nbformat_minor": 2
|
110 |
+
}
|
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
|