archietram
commited on
Commit
•
c1a13fc
1
Parent(s):
c7c7783
upload files
Browse files- app.ipynb +624 -0
- app.py +31 -0
- examples/000001.jpg +0 -0
- examples/000008.jpg +0 -0
- examples/000009.jpg +0 -0
- examples/000016.jpg +0 -0
- examples/000019.jpg +0 -0
- examples/000032.jpg +0 -0
- examples/000046.jpg +0 -0
- examples/000052.jpg +0 -0
- examples/000056.jpg +0 -0
- examples/000121.jpg +0 -0
- export.pkl +3 -0
- requirements.txt +1 -0
app.ipynb
ADDED
@@ -0,0 +1,624 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [],
|
8 |
+
"source": [
|
9 |
+
"from fastai.vision.all import *\n",
|
10 |
+
"import gradio as gr\n",
|
11 |
+
"import pathlib\n",
|
12 |
+
"pathlib.PosixPath = pathlib.WindowsPath"
|
13 |
+
]
|
14 |
+
},
|
15 |
+
{
|
16 |
+
"cell_type": "code",
|
17 |
+
"execution_count": 2,
|
18 |
+
"metadata": {},
|
19 |
+
"outputs": [],
|
20 |
+
"source": [
|
21 |
+
"def get_x(r): return path/'train'/r['fname']\n",
|
22 |
+
"def get_y(r): return r['labels'].split(' ')"
|
23 |
+
]
|
24 |
+
},
|
25 |
+
{
|
26 |
+
"cell_type": "code",
|
27 |
+
"execution_count": 3,
|
28 |
+
"metadata": {},
|
29 |
+
"outputs": [],
|
30 |
+
"source": [
|
31 |
+
"learn = load_learner(\"export.pkl\")"
|
32 |
+
]
|
33 |
+
},
|
34 |
+
{
|
35 |
+
"cell_type": "code",
|
36 |
+
"execution_count": 11,
|
37 |
+
"metadata": {},
|
38 |
+
"outputs": [],
|
39 |
+
"source": [
|
40 |
+
"labels = learn.dls.vocab\n",
|
41 |
+
"def infer(img):\n",
|
42 |
+
" img = PILImage.create(img)\n",
|
43 |
+
" _pred, _pred_w_idx, probs = learn.predict(img)\n",
|
44 |
+
" # gradio doesn't support tensors, so converting to float\n",
|
45 |
+
" labels_probs = {labels[i]: float(probs[i]) for i, _ in enumerate(labels)}\n",
|
46 |
+
" return labels_probs"
|
47 |
+
]
|
48 |
+
},
|
49 |
+
{
|
50 |
+
"cell_type": "code",
|
51 |
+
"execution_count": 12,
|
52 |
+
"metadata": {},
|
53 |
+
"outputs": [
|
54 |
+
{
|
55 |
+
"data": {
|
56 |
+
"text/html": [
|
57 |
+
"\n",
|
58 |
+
"<style>\n",
|
59 |
+
" /* Turns off some styling */\n",
|
60 |
+
" progress {\n",
|
61 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
62 |
+
" border: none;\n",
|
63 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
64 |
+
" background-size: auto;\n",
|
65 |
+
" }\n",
|
66 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
67 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
68 |
+
" }\n",
|
69 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
70 |
+
" background: #F44336;\n",
|
71 |
+
" }\n",
|
72 |
+
"</style>\n"
|
73 |
+
],
|
74 |
+
"text/plain": [
|
75 |
+
"<IPython.core.display.HTML object>"
|
76 |
+
]
|
77 |
+
},
|
78 |
+
"metadata": {},
|
79 |
+
"output_type": "display_data"
|
80 |
+
},
|
81 |
+
{
|
82 |
+
"data": {
|
83 |
+
"text/html": [],
|
84 |
+
"text/plain": [
|
85 |
+
"<IPython.core.display.HTML object>"
|
86 |
+
]
|
87 |
+
},
|
88 |
+
"metadata": {},
|
89 |
+
"output_type": "display_data"
|
90 |
+
},
|
91 |
+
{
|
92 |
+
"data": {
|
93 |
+
"text/plain": [
|
94 |
+
"{'aeroplane': 0.00040097636519931257,\n",
|
95 |
+
" 'bicycle': 0.003079020883888006,\n",
|
96 |
+
" 'bird': 0.007594174239784479,\n",
|
97 |
+
" 'boat': 0.0019870696123689413,\n",
|
98 |
+
" 'bottle': 0.0077136121690273285,\n",
|
99 |
+
" 'bus': 0.0002228342927992344,\n",
|
100 |
+
" 'car': 0.002796210814267397,\n",
|
101 |
+
" 'cat': 0.011337166652083397,\n",
|
102 |
+
" 'chair': 0.027877626940608025,\n",
|
103 |
+
" 'cow': 0.0004105104599148035,\n",
|
104 |
+
" 'diningtable': 0.0014102141140028834,\n",
|
105 |
+
" 'dog': 0.9442074298858643,\n",
|
106 |
+
" 'horse': 0.00014107774768490344,\n",
|
107 |
+
" 'motorbike': 0.0004384420462884009,\n",
|
108 |
+
" 'person': 0.9861327409744263,\n",
|
109 |
+
" 'pottedplant': 0.002472719643265009,\n",
|
110 |
+
" 'sheep': 0.015349175781011581,\n",
|
111 |
+
" 'sofa': 0.008290301077067852,\n",
|
112 |
+
" 'train': 0.0043441057205200195,\n",
|
113 |
+
" 'tvmonitor': 0.007222974672913551}"
|
114 |
+
]
|
115 |
+
},
|
116 |
+
"execution_count": 12,
|
117 |
+
"metadata": {},
|
118 |
+
"output_type": "execute_result"
|
119 |
+
}
|
120 |
+
],
|
121 |
+
"source": [
|
122 |
+
"infer(\"000001.jpg\")"
|
123 |
+
]
|
124 |
+
},
|
125 |
+
{
|
126 |
+
"cell_type": "code",
|
127 |
+
"execution_count": 13,
|
128 |
+
"metadata": {},
|
129 |
+
"outputs": [
|
130 |
+
{
|
131 |
+
"name": "stderr",
|
132 |
+
"output_type": "stream",
|
133 |
+
"text": [
|
134 |
+
"c:\\Users\\Loc\\anaconda3\\lib\\site-packages\\gradio\\inputs.py:256: UserWarning: Usage of gradio.inputs is deprecated, and will not be supported in the future, please import your component from gradio.components\n",
|
135 |
+
" warnings.warn(\n",
|
136 |
+
"c:\\Users\\Loc\\anaconda3\\lib\\site-packages\\gradio\\deprecation.py:40: UserWarning: `optional` parameter is deprecated, and it has no effect\n",
|
137 |
+
" warnings.warn(value)\n",
|
138 |
+
"c:\\Users\\Loc\\anaconda3\\lib\\site-packages\\gradio\\outputs.py:196: UserWarning: Usage of gradio.outputs is deprecated, and will not be supported in the future, please import your components from gradio.components\n",
|
139 |
+
" warnings.warn(\n",
|
140 |
+
"c:\\Users\\Loc\\anaconda3\\lib\\site-packages\\gradio\\deprecation.py:40: UserWarning: The 'type' parameter has been deprecated. Use the Number component instead.\n",
|
141 |
+
" warnings.warn(value)\n"
|
142 |
+
]
|
143 |
+
},
|
144 |
+
{
|
145 |
+
"name": "stdout",
|
146 |
+
"output_type": "stream",
|
147 |
+
"text": [
|
148 |
+
"Running on local URL: http://127.0.0.1:7861\n",
|
149 |
+
"\n",
|
150 |
+
"To create a public link, set `share=True` in `launch()`.\n"
|
151 |
+
]
|
152 |
+
},
|
153 |
+
{
|
154 |
+
"data": {
|
155 |
+
"text/plain": [
|
156 |
+
"(<gradio.routes.App at 0x21cd0e54970>, 'http://127.0.0.1:7861/', None)"
|
157 |
+
]
|
158 |
+
},
|
159 |
+
"execution_count": 13,
|
160 |
+
"metadata": {},
|
161 |
+
"output_type": "execute_result"
|
162 |
+
},
|
163 |
+
{
|
164 |
+
"data": {
|
165 |
+
"text/html": [
|
166 |
+
"\n",
|
167 |
+
"<style>\n",
|
168 |
+
" /* Turns off some styling */\n",
|
169 |
+
" progress {\n",
|
170 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
171 |
+
" border: none;\n",
|
172 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
173 |
+
" background-size: auto;\n",
|
174 |
+
" }\n",
|
175 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
176 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
177 |
+
" }\n",
|
178 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
179 |
+
" background: #F44336;\n",
|
180 |
+
" }\n",
|
181 |
+
"</style>\n"
|
182 |
+
],
|
183 |
+
"text/plain": [
|
184 |
+
"<IPython.core.display.HTML object>"
|
185 |
+
]
|
186 |
+
},
|
187 |
+
"metadata": {},
|
188 |
+
"output_type": "display_data"
|
189 |
+
},
|
190 |
+
{
|
191 |
+
"data": {
|
192 |
+
"text/html": [],
|
193 |
+
"text/plain": [
|
194 |
+
"<IPython.core.display.HTML object>"
|
195 |
+
]
|
196 |
+
},
|
197 |
+
"metadata": {},
|
198 |
+
"output_type": "display_data"
|
199 |
+
},
|
200 |
+
{
|
201 |
+
"data": {
|
202 |
+
"text/html": [
|
203 |
+
"\n",
|
204 |
+
"<style>\n",
|
205 |
+
" /* Turns off some styling */\n",
|
206 |
+
" progress {\n",
|
207 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
208 |
+
" border: none;\n",
|
209 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
210 |
+
" background-size: auto;\n",
|
211 |
+
" }\n",
|
212 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
213 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
214 |
+
" }\n",
|
215 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
216 |
+
" background: #F44336;\n",
|
217 |
+
" }\n",
|
218 |
+
"</style>\n"
|
219 |
+
],
|
220 |
+
"text/plain": [
|
221 |
+
"<IPython.core.display.HTML object>"
|
222 |
+
]
|
223 |
+
},
|
224 |
+
"metadata": {},
|
225 |
+
"output_type": "display_data"
|
226 |
+
},
|
227 |
+
{
|
228 |
+
"data": {
|
229 |
+
"text/html": [],
|
230 |
+
"text/plain": [
|
231 |
+
"<IPython.core.display.HTML object>"
|
232 |
+
]
|
233 |
+
},
|
234 |
+
"metadata": {},
|
235 |
+
"output_type": "display_data"
|
236 |
+
},
|
237 |
+
{
|
238 |
+
"data": {
|
239 |
+
"text/html": [
|
240 |
+
"\n",
|
241 |
+
"<style>\n",
|
242 |
+
" /* Turns off some styling */\n",
|
243 |
+
" progress {\n",
|
244 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
245 |
+
" border: none;\n",
|
246 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
247 |
+
" background-size: auto;\n",
|
248 |
+
" }\n",
|
249 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
250 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
251 |
+
" }\n",
|
252 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
253 |
+
" background: #F44336;\n",
|
254 |
+
" }\n",
|
255 |
+
"</style>\n"
|
256 |
+
],
|
257 |
+
"text/plain": [
|
258 |
+
"<IPython.core.display.HTML object>"
|
259 |
+
]
|
260 |
+
},
|
261 |
+
"metadata": {},
|
262 |
+
"output_type": "display_data"
|
263 |
+
},
|
264 |
+
{
|
265 |
+
"data": {
|
266 |
+
"text/html": [],
|
267 |
+
"text/plain": [
|
268 |
+
"<IPython.core.display.HTML object>"
|
269 |
+
]
|
270 |
+
},
|
271 |
+
"metadata": {},
|
272 |
+
"output_type": "display_data"
|
273 |
+
},
|
274 |
+
{
|
275 |
+
"data": {
|
276 |
+
"text/html": [
|
277 |
+
"\n",
|
278 |
+
"<style>\n",
|
279 |
+
" /* Turns off some styling */\n",
|
280 |
+
" progress {\n",
|
281 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
282 |
+
" border: none;\n",
|
283 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
284 |
+
" background-size: auto;\n",
|
285 |
+
" }\n",
|
286 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
287 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
288 |
+
" }\n",
|
289 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
290 |
+
" background: #F44336;\n",
|
291 |
+
" }\n",
|
292 |
+
"</style>\n"
|
293 |
+
],
|
294 |
+
"text/plain": [
|
295 |
+
"<IPython.core.display.HTML object>"
|
296 |
+
]
|
297 |
+
},
|
298 |
+
"metadata": {},
|
299 |
+
"output_type": "display_data"
|
300 |
+
},
|
301 |
+
{
|
302 |
+
"data": {
|
303 |
+
"text/html": [],
|
304 |
+
"text/plain": [
|
305 |
+
"<IPython.core.display.HTML object>"
|
306 |
+
]
|
307 |
+
},
|
308 |
+
"metadata": {},
|
309 |
+
"output_type": "display_data"
|
310 |
+
},
|
311 |
+
{
|
312 |
+
"data": {
|
313 |
+
"text/html": [
|
314 |
+
"\n",
|
315 |
+
"<style>\n",
|
316 |
+
" /* Turns off some styling */\n",
|
317 |
+
" progress {\n",
|
318 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
319 |
+
" border: none;\n",
|
320 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
321 |
+
" background-size: auto;\n",
|
322 |
+
" }\n",
|
323 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
324 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
325 |
+
" }\n",
|
326 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
327 |
+
" background: #F44336;\n",
|
328 |
+
" }\n",
|
329 |
+
"</style>\n"
|
330 |
+
],
|
331 |
+
"text/plain": [
|
332 |
+
"<IPython.core.display.HTML object>"
|
333 |
+
]
|
334 |
+
},
|
335 |
+
"metadata": {},
|
336 |
+
"output_type": "display_data"
|
337 |
+
},
|
338 |
+
{
|
339 |
+
"data": {
|
340 |
+
"text/html": [],
|
341 |
+
"text/plain": [
|
342 |
+
"<IPython.core.display.HTML object>"
|
343 |
+
]
|
344 |
+
},
|
345 |
+
"metadata": {},
|
346 |
+
"output_type": "display_data"
|
347 |
+
},
|
348 |
+
{
|
349 |
+
"data": {
|
350 |
+
"text/html": [
|
351 |
+
"\n",
|
352 |
+
"<style>\n",
|
353 |
+
" /* Turns off some styling */\n",
|
354 |
+
" progress {\n",
|
355 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
356 |
+
" border: none;\n",
|
357 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
358 |
+
" background-size: auto;\n",
|
359 |
+
" }\n",
|
360 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
361 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
362 |
+
" }\n",
|
363 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
364 |
+
" background: #F44336;\n",
|
365 |
+
" }\n",
|
366 |
+
"</style>\n"
|
367 |
+
],
|
368 |
+
"text/plain": [
|
369 |
+
"<IPython.core.display.HTML object>"
|
370 |
+
]
|
371 |
+
},
|
372 |
+
"metadata": {},
|
373 |
+
"output_type": "display_data"
|
374 |
+
},
|
375 |
+
{
|
376 |
+
"data": {
|
377 |
+
"text/html": [],
|
378 |
+
"text/plain": [
|
379 |
+
"<IPython.core.display.HTML object>"
|
380 |
+
]
|
381 |
+
},
|
382 |
+
"metadata": {},
|
383 |
+
"output_type": "display_data"
|
384 |
+
},
|
385 |
+
{
|
386 |
+
"data": {
|
387 |
+
"text/html": [
|
388 |
+
"\n",
|
389 |
+
"<style>\n",
|
390 |
+
" /* Turns off some styling */\n",
|
391 |
+
" progress {\n",
|
392 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
393 |
+
" border: none;\n",
|
394 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
395 |
+
" background-size: auto;\n",
|
396 |
+
" }\n",
|
397 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
398 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
399 |
+
" }\n",
|
400 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
401 |
+
" background: #F44336;\n",
|
402 |
+
" }\n",
|
403 |
+
"</style>\n"
|
404 |
+
],
|
405 |
+
"text/plain": [
|
406 |
+
"<IPython.core.display.HTML object>"
|
407 |
+
]
|
408 |
+
},
|
409 |
+
"metadata": {},
|
410 |
+
"output_type": "display_data"
|
411 |
+
},
|
412 |
+
{
|
413 |
+
"data": {
|
414 |
+
"text/html": [],
|
415 |
+
"text/plain": [
|
416 |
+
"<IPython.core.display.HTML object>"
|
417 |
+
]
|
418 |
+
},
|
419 |
+
"metadata": {},
|
420 |
+
"output_type": "display_data"
|
421 |
+
},
|
422 |
+
{
|
423 |
+
"data": {
|
424 |
+
"text/html": [
|
425 |
+
"\n",
|
426 |
+
"<style>\n",
|
427 |
+
" /* Turns off some styling */\n",
|
428 |
+
" progress {\n",
|
429 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
430 |
+
" border: none;\n",
|
431 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
432 |
+
" background-size: auto;\n",
|
433 |
+
" }\n",
|
434 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
435 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
436 |
+
" }\n",
|
437 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
438 |
+
" background: #F44336;\n",
|
439 |
+
" }\n",
|
440 |
+
"</style>\n"
|
441 |
+
],
|
442 |
+
"text/plain": [
|
443 |
+
"<IPython.core.display.HTML object>"
|
444 |
+
]
|
445 |
+
},
|
446 |
+
"metadata": {},
|
447 |
+
"output_type": "display_data"
|
448 |
+
},
|
449 |
+
{
|
450 |
+
"data": {
|
451 |
+
"text/html": [],
|
452 |
+
"text/plain": [
|
453 |
+
"<IPython.core.display.HTML object>"
|
454 |
+
]
|
455 |
+
},
|
456 |
+
"metadata": {},
|
457 |
+
"output_type": "display_data"
|
458 |
+
},
|
459 |
+
{
|
460 |
+
"data": {
|
461 |
+
"text/html": [
|
462 |
+
"\n",
|
463 |
+
"<style>\n",
|
464 |
+
" /* Turns off some styling */\n",
|
465 |
+
" progress {\n",
|
466 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
467 |
+
" border: none;\n",
|
468 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
469 |
+
" background-size: auto;\n",
|
470 |
+
" }\n",
|
471 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
472 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
473 |
+
" }\n",
|
474 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
475 |
+
" background: #F44336;\n",
|
476 |
+
" }\n",
|
477 |
+
"</style>\n"
|
478 |
+
],
|
479 |
+
"text/plain": [
|
480 |
+
"<IPython.core.display.HTML object>"
|
481 |
+
]
|
482 |
+
},
|
483 |
+
"metadata": {},
|
484 |
+
"output_type": "display_data"
|
485 |
+
},
|
486 |
+
{
|
487 |
+
"data": {
|
488 |
+
"text/html": [],
|
489 |
+
"text/plain": [
|
490 |
+
"<IPython.core.display.HTML object>"
|
491 |
+
]
|
492 |
+
},
|
493 |
+
"metadata": {},
|
494 |
+
"output_type": "display_data"
|
495 |
+
},
|
496 |
+
{
|
497 |
+
"data": {
|
498 |
+
"text/html": [
|
499 |
+
"\n",
|
500 |
+
"<style>\n",
|
501 |
+
" /* Turns off some styling */\n",
|
502 |
+
" progress {\n",
|
503 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
504 |
+
" border: none;\n",
|
505 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
506 |
+
" background-size: auto;\n",
|
507 |
+
" }\n",
|
508 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
509 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
510 |
+
" }\n",
|
511 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
512 |
+
" background: #F44336;\n",
|
513 |
+
" }\n",
|
514 |
+
"</style>\n"
|
515 |
+
],
|
516 |
+
"text/plain": [
|
517 |
+
"<IPython.core.display.HTML object>"
|
518 |
+
]
|
519 |
+
},
|
520 |
+
"metadata": {},
|
521 |
+
"output_type": "display_data"
|
522 |
+
},
|
523 |
+
{
|
524 |
+
"data": {
|
525 |
+
"text/html": [],
|
526 |
+
"text/plain": [
|
527 |
+
"<IPython.core.display.HTML object>"
|
528 |
+
]
|
529 |
+
},
|
530 |
+
"metadata": {},
|
531 |
+
"output_type": "display_data"
|
532 |
+
},
|
533 |
+
{
|
534 |
+
"data": {
|
535 |
+
"text/html": [
|
536 |
+
"\n",
|
537 |
+
"<style>\n",
|
538 |
+
" /* Turns off some styling */\n",
|
539 |
+
" progress {\n",
|
540 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
541 |
+
" border: none;\n",
|
542 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
543 |
+
" background-size: auto;\n",
|
544 |
+
" }\n",
|
545 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
546 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
547 |
+
" }\n",
|
548 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
549 |
+
" background: #F44336;\n",
|
550 |
+
" }\n",
|
551 |
+
"</style>\n"
|
552 |
+
],
|
553 |
+
"text/plain": [
|
554 |
+
"<IPython.core.display.HTML object>"
|
555 |
+
]
|
556 |
+
},
|
557 |
+
"metadata": {},
|
558 |
+
"output_type": "display_data"
|
559 |
+
},
|
560 |
+
{
|
561 |
+
"data": {
|
562 |
+
"text/html": [],
|
563 |
+
"text/plain": [
|
564 |
+
"<IPython.core.display.HTML object>"
|
565 |
+
]
|
566 |
+
},
|
567 |
+
"metadata": {},
|
568 |
+
"output_type": "display_data"
|
569 |
+
}
|
570 |
+
],
|
571 |
+
"source": [
|
572 |
+
"# get the inputs\n",
|
573 |
+
"inputs = gr.inputs.Image(shape=(192, 192))\n",
|
574 |
+
"\n",
|
575 |
+
"# the app outputs two segmented images\n",
|
576 |
+
"outputs = gr.outputs.Label(num_top_classes=3)\n",
|
577 |
+
"\n",
|
578 |
+
"EXAMPLES_PATH = Path('./examples')\n",
|
579 |
+
"examples = [f'{EXAMPLES_PATH}/{f.name}' for f in EXAMPLES_PATH.iterdir()]\n",
|
580 |
+
"\n",
|
581 |
+
"# it's good practice to pass examples, description and a title to guide users\n",
|
582 |
+
"title = 'Multiple_Object Detector'\n",
|
583 |
+
"description = 'This app detects objects that appear in the image'\n",
|
584 |
+
"article = \"Author: <a href=\\\"https://huggingface.co/archietram\\\">Archie Tram</a>. \"\n",
|
585 |
+
"intf = gr.Interface(fn=infer, inputs=inputs, outputs=outputs, examples=examples, title=title, description=description, article=article)\n",
|
586 |
+
"intf.launch(inline=False)"
|
587 |
+
]
|
588 |
+
},
|
589 |
+
{
|
590 |
+
"cell_type": "code",
|
591 |
+
"execution_count": null,
|
592 |
+
"metadata": {},
|
593 |
+
"outputs": [],
|
594 |
+
"source": []
|
595 |
+
}
|
596 |
+
],
|
597 |
+
"metadata": {
|
598 |
+
"kernelspec": {
|
599 |
+
"display_name": "Python 3.8.5 ('base')",
|
600 |
+
"language": "python",
|
601 |
+
"name": "python3"
|
602 |
+
},
|
603 |
+
"language_info": {
|
604 |
+
"codemirror_mode": {
|
605 |
+
"name": "ipython",
|
606 |
+
"version": 3
|
607 |
+
},
|
608 |
+
"file_extension": ".py",
|
609 |
+
"mimetype": "text/x-python",
|
610 |
+
"name": "python",
|
611 |
+
"nbconvert_exporter": "python",
|
612 |
+
"pygments_lexer": "ipython3",
|
613 |
+
"version": "3.8.5"
|
614 |
+
},
|
615 |
+
"orig_nbformat": 4,
|
616 |
+
"vscode": {
|
617 |
+
"interpreter": {
|
618 |
+
"hash": "8390c3163ce2a2b50e270659ce53992de79de8e8bac3e92aa142b72a0dae5de6"
|
619 |
+
}
|
620 |
+
}
|
621 |
+
},
|
622 |
+
"nbformat": 4,
|
623 |
+
"nbformat_minor": 2
|
624 |
+
}
|
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastai.vision.all import *
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
def get_x(): return _
|
5 |
+
def get_y(): return _
|
6 |
+
|
7 |
+
learn = load_learner("export.pkl")
|
8 |
+
|
9 |
+
labels = learn.dls.vocab
|
10 |
+
def infer(img):
|
11 |
+
img = PILImage.create(img)
|
12 |
+
_pred, _pred_w_idx, probs = learn.predict(img)
|
13 |
+
# gradio doesn't support tensors, so converting to float
|
14 |
+
labels_probs = {labels[i]: float(probs[i]) for i, _ in enumerate(labels)}
|
15 |
+
return labels_probs
|
16 |
+
|
17 |
+
# get the inputs
|
18 |
+
inputs = gr.inputs.Image(shape=(192, 192))
|
19 |
+
|
20 |
+
# the app outputs two segmented images
|
21 |
+
outputs = gr.outputs.Label(num_top_classes=3)
|
22 |
+
|
23 |
+
EXAMPLES_PATH = Path('./examples')
|
24 |
+
examples = [f'{EXAMPLES_PATH}/{f.name}' for f in EXAMPLES_PATH.iterdir()]
|
25 |
+
|
26 |
+
# it's good practice to pass examples, description and a title to guide users
|
27 |
+
title = 'Multiple_Object Detector'
|
28 |
+
description = 'This app detects objects that appear in the image'
|
29 |
+
article = "Author: <a href=\"https://huggingface.co/archietram\">Archie Tram</a>. "
|
30 |
+
intf = gr.Interface(fn=infer, inputs=inputs, outputs=outputs, examples=examples, title=title, description=description, article=article)
|
31 |
+
intf.launch(inline=False)
|
examples/000001.jpg
ADDED
![]() |
examples/000008.jpg
ADDED
![]() |
examples/000009.jpg
ADDED
![]() |
examples/000016.jpg
ADDED
![]() |
examples/000019.jpg
ADDED
![]() |
examples/000032.jpg
ADDED
![]() |
examples/000046.jpg
ADDED
![]() |
examples/000052.jpg
ADDED
![]() |
examples/000056.jpg
ADDED
![]() |
examples/000121.jpg
ADDED
![]() |
export.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8bcc9dc43d9a3b7bca0b1393b7d1095a6886fc549959211298930e41a5e53b0a
|
3 |
+
size 102988063
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
fastai
|