Aspiring Astro commited on
Commit
9935a4c
1 Parent(s): 1633182

big cats classifier model on HF

Browse files
african leopard.jpg ADDED
app.ipynb ADDED
@@ -0,0 +1,586 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "a3278dc9-0d83-4a37-aece-e46ac416988f",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "#| default_exp app"
11
+ ]
12
+ },
13
+ {
14
+ "cell_type": "code",
15
+ "execution_count": 2,
16
+ "id": "d6810835-d62a-4f94-a52e-0e0cd163fb98",
17
+ "metadata": {},
18
+ "outputs": [],
19
+ "source": [
20
+ "#| export\n",
21
+ "from fastai.vision.all import *\n",
22
+ "import gradio as gr\n",
23
+ "title = \"FastAI - Big Cats Classifier\"\n",
24
+ "description = \"Classify big cats using all Resnet models available pre-trained in FastAI\""
25
+ ]
26
+ },
27
+ {
28
+ "cell_type": "code",
29
+ "execution_count": 5,
30
+ "id": "6092ad61-d5cd-40f7-b2d2-20a77b0c8b0f",
31
+ "metadata": {},
32
+ "outputs": [],
33
+ "source": [
34
+ "#| export\n",
35
+ "learners = {\n",
36
+ " \"resnet-18\" : 'models/resnet18-model.pkl',\n",
37
+ " \"resnet-34\" : 'models/resnet34-model.pkl',\n",
38
+ " \"resnet-50\" : 'models/resnet50-model.pkl',\n",
39
+ " \"resnet-101\": 'models/resnet101-model.pkl',\n",
40
+ " \"resnet-152\": 'models/resnet152-model.pkl'\n",
41
+ "}\n",
42
+ "models = list(learners.keys())\n",
43
+ "\n",
44
+ " "
45
+ ]
46
+ },
47
+ {
48
+ "cell_type": "code",
49
+ "execution_count": 6,
50
+ "id": "632cbc1b-73b5-4992-8956-d4ae40f6b80b",
51
+ "metadata": {},
52
+ "outputs": [],
53
+ "source": [
54
+ "#| export\n",
55
+ " \n",
56
+ "def classify_image(img, model_file=\"resnet-101\"):\n",
57
+ " learn = load_learner(learners[model_file])\n",
58
+ " pred,idx,probs = learn.predict(img)\n",
59
+ " print(pred, idx, probs)\n",
60
+ " return dict(zip(learn.dls.vocab, map(float, probs)))\n"
61
+ ]
62
+ },
63
+ {
64
+ "cell_type": "code",
65
+ "execution_count": 7,
66
+ "id": "9b5f1cc6-5173-475a-9365-0cab11db2d03",
67
+ "metadata": {},
68
+ "outputs": [
69
+ {
70
+ "data": {
71
+ "text/html": [
72
+ "\n",
73
+ "<style>\n",
74
+ " /* Turns off some styling */\n",
75
+ " progress {\n",
76
+ " /* gets rid of default border in Firefox and Opera. */\n",
77
+ " border: none;\n",
78
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
79
+ " background-size: auto;\n",
80
+ " }\n",
81
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
82
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
83
+ " }\n",
84
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
85
+ " background: #F44336;\n",
86
+ " }\n",
87
+ "</style>\n"
88
+ ],
89
+ "text/plain": [
90
+ "<IPython.core.display.HTML object>"
91
+ ]
92
+ },
93
+ "metadata": {},
94
+ "output_type": "display_data"
95
+ },
96
+ {
97
+ "data": {
98
+ "text/html": [],
99
+ "text/plain": [
100
+ "<IPython.core.display.HTML object>"
101
+ ]
102
+ },
103
+ "metadata": {},
104
+ "output_type": "display_data"
105
+ },
106
+ {
107
+ "name": "stdout",
108
+ "output_type": "stream",
109
+ "text": [
110
+ "cheetah TensorBase(1) TensorBase([2.9325e-08, 9.9999e-01, 1.2872e-09, 1.3284e-05, 3.6218e-08,\n",
111
+ " 6.6378e-07, 1.2428e-08, 7.0062e-09])\n",
112
+ "{'african leopard': 2.932508635922204e-08, 'cheetah': 0.9999860525131226, 'clouded leopard': 1.2872064525382143e-09, 'cougar': 1.3283532098284923e-05, 'jaguar': 3.6217517873637917e-08, 'lion': 6.637808382947696e-07, 'snow leopard': 1.242834812842375e-08, 'tiger': 7.0062102786039304e-09}\n"
113
+ ]
114
+ },
115
+ {
116
+ "data": {
117
+ "text/html": [
118
+ "\n",
119
+ "<style>\n",
120
+ " /* Turns off some styling */\n",
121
+ " progress {\n",
122
+ " /* gets rid of default border in Firefox and Opera. */\n",
123
+ " border: none;\n",
124
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
125
+ " background-size: auto;\n",
126
+ " }\n",
127
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
128
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
129
+ " }\n",
130
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
131
+ " background: #F44336;\n",
132
+ " }\n",
133
+ "</style>\n"
134
+ ],
135
+ "text/plain": [
136
+ "<IPython.core.display.HTML object>"
137
+ ]
138
+ },
139
+ "metadata": {},
140
+ "output_type": "display_data"
141
+ },
142
+ {
143
+ "data": {
144
+ "text/html": [],
145
+ "text/plain": [
146
+ "<IPython.core.display.HTML object>"
147
+ ]
148
+ },
149
+ "metadata": {},
150
+ "output_type": "display_data"
151
+ },
152
+ {
153
+ "name": "stdout",
154
+ "output_type": "stream",
155
+ "text": [
156
+ "jaguar TensorBase(4) TensorBase([2.2414e-06, 4.8124e-07, 1.5911e-08, 1.5741e-08, 1.0000e+00,\n",
157
+ " 8.4150e-10, 2.4537e-08, 4.5623e-07])\n",
158
+ "{'african leopard': 2.241393531221547e-06, 'cheetah': 4.812366114492761e-07, 'clouded leopard': 1.5911437500903958e-08, 'cougar': 1.5740527103957902e-08, 'jaguar': 0.9999967813491821, 'lion': 8.415030339214979e-10, 'snow leopard': 2.453731973162121e-08, 'tiger': 4.562308788536029e-07}\n"
159
+ ]
160
+ },
161
+ {
162
+ "data": {
163
+ "text/html": [
164
+ "\n",
165
+ "<style>\n",
166
+ " /* Turns off some styling */\n",
167
+ " progress {\n",
168
+ " /* gets rid of default border in Firefox and Opera. */\n",
169
+ " border: none;\n",
170
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
171
+ " background-size: auto;\n",
172
+ " }\n",
173
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
174
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
175
+ " }\n",
176
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
177
+ " background: #F44336;\n",
178
+ " }\n",
179
+ "</style>\n"
180
+ ],
181
+ "text/plain": [
182
+ "<IPython.core.display.HTML object>"
183
+ ]
184
+ },
185
+ "metadata": {},
186
+ "output_type": "display_data"
187
+ },
188
+ {
189
+ "data": {
190
+ "text/html": [],
191
+ "text/plain": [
192
+ "<IPython.core.display.HTML object>"
193
+ ]
194
+ },
195
+ "metadata": {},
196
+ "output_type": "display_data"
197
+ },
198
+ {
199
+ "name": "stdout",
200
+ "output_type": "stream",
201
+ "text": [
202
+ "tiger TensorBase(7) TensorBase([2.0140e-08, 3.2289e-10, 3.0278e-07, 1.7037e-07, 2.8471e-08,\n",
203
+ " 3.1560e-08, 5.5170e-08, 1.0000e+00])\n",
204
+ "{'african leopard': 2.0139752976433556e-08, 'cheetah': 3.228871059413052e-10, 'clouded leopard': 3.0278118856585934e-07, 'cougar': 1.7037031341260445e-07, 'jaguar': 2.8470973134631095e-08, 'lion': 3.15602726175257e-08, 'snow leopard': 5.5169955714973185e-08, 'tiger': 0.9999994039535522}\n"
205
+ ]
206
+ },
207
+ {
208
+ "data": {
209
+ "text/html": [
210
+ "\n",
211
+ "<style>\n",
212
+ " /* Turns off some styling */\n",
213
+ " progress {\n",
214
+ " /* gets rid of default border in Firefox and Opera. */\n",
215
+ " border: none;\n",
216
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
217
+ " background-size: auto;\n",
218
+ " }\n",
219
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
220
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
221
+ " }\n",
222
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
223
+ " background: #F44336;\n",
224
+ " }\n",
225
+ "</style>\n"
226
+ ],
227
+ "text/plain": [
228
+ "<IPython.core.display.HTML object>"
229
+ ]
230
+ },
231
+ "metadata": {},
232
+ "output_type": "display_data"
233
+ },
234
+ {
235
+ "data": {
236
+ "text/html": [],
237
+ "text/plain": [
238
+ "<IPython.core.display.HTML object>"
239
+ ]
240
+ },
241
+ "metadata": {},
242
+ "output_type": "display_data"
243
+ },
244
+ {
245
+ "name": "stdout",
246
+ "output_type": "stream",
247
+ "text": [
248
+ "cougar TensorBase(3) TensorBase([7.7202e-04, 9.6453e-05, 3.6239e-04, 9.9550e-01, 5.8073e-04,\n",
249
+ " 1.0296e-03, 1.6978e-04, 1.4883e-03])\n",
250
+ "{'african leopard': 0.0007720203138887882, 'cheetah': 9.645262616686523e-05, 'clouded leopard': 0.00036238841130398214, 'cougar': 0.9955006241798401, 'jaguar': 0.0005807342822663486, 'lion': 0.0010295877000316978, 'snow leopard': 0.000169777573319152, 'tiger': 0.0014882636023685336}\n"
251
+ ]
252
+ },
253
+ {
254
+ "data": {
255
+ "text/html": [
256
+ "\n",
257
+ "<style>\n",
258
+ " /* Turns off some styling */\n",
259
+ " progress {\n",
260
+ " /* gets rid of default border in Firefox and Opera. */\n",
261
+ " border: none;\n",
262
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
263
+ " background-size: auto;\n",
264
+ " }\n",
265
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
266
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
267
+ " }\n",
268
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
269
+ " background: #F44336;\n",
270
+ " }\n",
271
+ "</style>\n"
272
+ ],
273
+ "text/plain": [
274
+ "<IPython.core.display.HTML object>"
275
+ ]
276
+ },
277
+ "metadata": {},
278
+ "output_type": "display_data"
279
+ },
280
+ {
281
+ "data": {
282
+ "text/html": [],
283
+ "text/plain": [
284
+ "<IPython.core.display.HTML object>"
285
+ ]
286
+ },
287
+ "metadata": {},
288
+ "output_type": "display_data"
289
+ },
290
+ {
291
+ "name": "stdout",
292
+ "output_type": "stream",
293
+ "text": [
294
+ "lion TensorBase(5) TensorBase([6.3666e-10, 2.1585e-07, 6.5407e-09, 1.1020e-08, 1.3697e-08,\n",
295
+ " 9.9998e-01, 5.2166e-09, 1.6965e-05])\n",
296
+ "{'african leopard': 6.366598359619502e-10, 'cheetah': 2.1584540377261874e-07, 'clouded leopard': 6.540694652557022e-09, 'cougar': 1.1020346413204152e-08, 'jaguar': 1.3696873857327319e-08, 'lion': 0.9999828338623047, 'snow leopard': 5.2166360120509125e-09, 'tiger': 1.696465005807113e-05}\n"
297
+ ]
298
+ },
299
+ {
300
+ "data": {
301
+ "text/html": [
302
+ "\n",
303
+ "<style>\n",
304
+ " /* Turns off some styling */\n",
305
+ " progress {\n",
306
+ " /* gets rid of default border in Firefox and Opera. */\n",
307
+ " border: none;\n",
308
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
309
+ " background-size: auto;\n",
310
+ " }\n",
311
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
312
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
313
+ " }\n",
314
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
315
+ " background: #F44336;\n",
316
+ " }\n",
317
+ "</style>\n"
318
+ ],
319
+ "text/plain": [
320
+ "<IPython.core.display.HTML object>"
321
+ ]
322
+ },
323
+ "metadata": {},
324
+ "output_type": "display_data"
325
+ },
326
+ {
327
+ "data": {
328
+ "text/html": [],
329
+ "text/plain": [
330
+ "<IPython.core.display.HTML object>"
331
+ ]
332
+ },
333
+ "metadata": {},
334
+ "output_type": "display_data"
335
+ },
336
+ {
337
+ "name": "stdout",
338
+ "output_type": "stream",
339
+ "text": [
340
+ "african leopard TensorBase(0) TensorBase([9.7809e-01, 1.9370e-03, 5.1859e-04, 1.8196e-05, 1.5251e-02,\n",
341
+ " 1.8402e-04, 3.8208e-03, 1.8130e-04])\n",
342
+ "{'african leopard': 0.9780895113945007, 'cheetah': 0.0019370485097169876, 'clouded leopard': 0.0005185850313864648, 'cougar': 1.819587851059623e-05, 'jaguar': 0.015250639989972115, 'lion': 0.00018402353452984244, 'snow leopard': 0.0038208006881177425, 'tiger': 0.00018130325770471245}\n"
343
+ ]
344
+ },
345
+ {
346
+ "data": {
347
+ "text/html": [
348
+ "\n",
349
+ "<style>\n",
350
+ " /* Turns off some styling */\n",
351
+ " progress {\n",
352
+ " /* gets rid of default border in Firefox and Opera. */\n",
353
+ " border: none;\n",
354
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
355
+ " background-size: auto;\n",
356
+ " }\n",
357
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
358
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
359
+ " }\n",
360
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
361
+ " background: #F44336;\n",
362
+ " }\n",
363
+ "</style>\n"
364
+ ],
365
+ "text/plain": [
366
+ "<IPython.core.display.HTML object>"
367
+ ]
368
+ },
369
+ "metadata": {},
370
+ "output_type": "display_data"
371
+ },
372
+ {
373
+ "data": {
374
+ "text/html": [],
375
+ "text/plain": [
376
+ "<IPython.core.display.HTML object>"
377
+ ]
378
+ },
379
+ "metadata": {},
380
+ "output_type": "display_data"
381
+ },
382
+ {
383
+ "name": "stdout",
384
+ "output_type": "stream",
385
+ "text": [
386
+ "clouded leopard TensorBase(2) TensorBase([3.5035e-05, 2.8548e-06, 9.9938e-01, 1.8297e-06, 5.6521e-04,\n",
387
+ " 1.3141e-06, 7.5178e-06, 1.0570e-05])\n",
388
+ "{'african leopard': 3.5035314795095474e-05, 'cheetah': 2.8547888177854475e-06, 'clouded leopard': 0.9993757605552673, 'cougar': 1.8296907455805922e-06, 'jaguar': 0.0005652108229696751, 'lion': 1.314112978434423e-06, 'snow leopard': 7.517839094361989e-06, 'tiger': 1.0569940059212968e-05}\n"
389
+ ]
390
+ },
391
+ {
392
+ "data": {
393
+ "text/html": [
394
+ "\n",
395
+ "<style>\n",
396
+ " /* Turns off some styling */\n",
397
+ " progress {\n",
398
+ " /* gets rid of default border in Firefox and Opera. */\n",
399
+ " border: none;\n",
400
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
401
+ " background-size: auto;\n",
402
+ " }\n",
403
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
404
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
405
+ " }\n",
406
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
407
+ " background: #F44336;\n",
408
+ " }\n",
409
+ "</style>\n"
410
+ ],
411
+ "text/plain": [
412
+ "<IPython.core.display.HTML object>"
413
+ ]
414
+ },
415
+ "metadata": {},
416
+ "output_type": "display_data"
417
+ },
418
+ {
419
+ "data": {
420
+ "text/html": [],
421
+ "text/plain": [
422
+ "<IPython.core.display.HTML object>"
423
+ ]
424
+ },
425
+ "metadata": {},
426
+ "output_type": "display_data"
427
+ },
428
+ {
429
+ "name": "stdout",
430
+ "output_type": "stream",
431
+ "text": [
432
+ "snow leopard TensorBase(6) TensorBase([1.9796e-07, 5.2659e-07, 1.7047e-04, 2.0246e-07, 1.5801e-08,\n",
433
+ " 5.4288e-06, 9.9982e-01, 6.8012e-09])\n",
434
+ "{'african leopard': 1.9796296157892357e-07, 'cheetah': 5.265908384899376e-07, 'clouded leopard': 0.00017047168512362987, 'cougar': 2.024643492859468e-07, 'jaguar': 1.5801049357833108e-08, 'lion': 5.4287702369038016e-06, 'snow leopard': 0.9998231530189514, 'tiger': 6.801158747293812e-09}\n"
435
+ ]
436
+ }
437
+ ],
438
+ "source": [
439
+ "example_images = [ 'cheetah.jpg', 'jaguar.jpg', 'tiger.jpg', 'cougar.jpg', 'lion.jpg', 'african leopard.jpg', 'clouded leopard.jpg', 'snow leopard.jpg' ]\n",
440
+ "\n",
441
+ "for c in example_images:\n",
442
+ " im = PILImage.create(c)\n",
443
+ " result = classify_image(im)\n",
444
+ " print(result)"
445
+ ]
446
+ },
447
+ {
448
+ "cell_type": "code",
449
+ "execution_count": 8,
450
+ "id": "a48e7483-c04b-4048-a1ae-34a8c7986a57",
451
+ "metadata": {},
452
+ "outputs": [
453
+ {
454
+ "name": "stderr",
455
+ "output_type": "stream",
456
+ "text": [
457
+ "/Users/ajithj/Library/Python/3.8/lib/python/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",
458
+ " warnings.warn(\n",
459
+ "/Users/ajithj/Library/Python/3.8/lib/python/site-packages/gradio/deprecation.py:40: UserWarning: `optional` parameter is deprecated, and it has no effect\n",
460
+ " warnings.warn(value)\n",
461
+ "/Users/ajithj/Library/Python/3.8/lib/python/site-packages/gradio/inputs.py:216: UserWarning: Usage of gradio.inputs is deprecated, and will not be supported in the future, please import your component from gradio.components\n",
462
+ " warnings.warn(\n",
463
+ "/Users/ajithj/Library/Python/3.8/lib/python/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",
464
+ " warnings.warn(\n",
465
+ "/Users/ajithj/Library/Python/3.8/lib/python/site-packages/gradio/deprecation.py:40: UserWarning: The 'type' parameter has been deprecated. Use the Number component instead.\n",
466
+ " warnings.warn(value)\n"
467
+ ]
468
+ },
469
+ {
470
+ "name": "stdout",
471
+ "output_type": "stream",
472
+ "text": [
473
+ "Running on local URL: http://127.0.0.1:7860\n",
474
+ "\n",
475
+ "To create a public link, set `share=True` in `launch()`.\n"
476
+ ]
477
+ },
478
+ {
479
+ "name": "stderr",
480
+ "output_type": "stream",
481
+ "text": [
482
+ "Traceback (most recent call last):\n",
483
+ " File \"/Users/ajithj/Library/Python/3.8/lib/python/site-packages/gradio/routes.py\", line 321, in run_predict\n",
484
+ " output = await app.blocks.process_api(\n",
485
+ " File \"/Users/ajithj/Library/Python/3.8/lib/python/site-packages/gradio/blocks.py\", line 1013, in process_api\n",
486
+ " inputs = self.preprocess_data(fn_index, inputs, state)\n",
487
+ " File \"/Users/ajithj/Library/Python/3.8/lib/python/site-packages/gradio/blocks.py\", line 923, in preprocess_data\n",
488
+ " processed_input.append(block.preprocess(inputs[i]))\n",
489
+ " File \"/Users/ajithj/Library/Python/3.8/lib/python/site-packages/gradio/components.py\", line 1434, in preprocess\n",
490
+ " im = processing_utils.resize_and_crop(im, self.shape)\n",
491
+ " File \"/Users/ajithj/Library/Python/3.8/lib/python/site-packages/gradio/processing_utils.py\", line 173, in resize_and_crop\n",
492
+ " resize = list(size)\n",
493
+ "TypeError: 'float' object is not iterable\n"
494
+ ]
495
+ },
496
+ {
497
+ "name": "stdout",
498
+ "output_type": "stream",
499
+ "text": [
500
+ "Keyboard interruption in main thread... closing server.\n"
501
+ ]
502
+ }
503
+ ],
504
+ "source": [
505
+ "#| export\n",
506
+ "image = gr.inputs.Image(shape=(192.192))\n",
507
+ "model = gr.inputs.Dropdown(choices=models)\n",
508
+ "label = gr.outputs.Label()\n",
509
+ "example_images = [ 'cheetah.jpg', 'jaguar.jpg', 'tiger.jpg', 'cougar.jpg', 'lion.jpg', 'african leopard.jpg', 'clouded leopard.jpg', 'snow leopard.jpg' ]\n",
510
+ "example_models = [] #list(learners.values())\n",
511
+ "intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=example_images, title=title, description=description )\n",
512
+ "if __name__ == \"__main__\":\n",
513
+ " intf.launch(debug=True, inline=False)\n"
514
+ ]
515
+ },
516
+ {
517
+ "cell_type": "code",
518
+ "execution_count": 20,
519
+ "id": "cab071f9-7c3b-4b35-a0d1-3687731ffce5",
520
+ "metadata": {},
521
+ "outputs": [
522
+ {
523
+ "name": "stdout",
524
+ "output_type": "stream",
525
+ "text": [
526
+ "Export successful\n"
527
+ ]
528
+ }
529
+ ],
530
+ "source": [
531
+ "import nbdev\n",
532
+ "nbdev.export.nb_export('app.ipynb', './')\n",
533
+ "print('Export successful')"
534
+ ]
535
+ },
536
+ {
537
+ "cell_type": "code",
538
+ "execution_count": 16,
539
+ "id": "c7e6ddfb-9919-4a35-aac7-674d6fc5fd96",
540
+ "metadata": {},
541
+ "outputs": [
542
+ {
543
+ "ename": "NameError",
544
+ "evalue": "name 'notebook2script' is not defined",
545
+ "output_type": "error",
546
+ "traceback": [
547
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
548
+ "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
549
+ "Cell \u001b[0;32mIn [16], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mnotebook2script\u001b[49m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mapp.ipynb\u001b[39m\u001b[38;5;124m'\u001b[39m)\n",
550
+ "\u001b[0;31mNameError\u001b[0m: name 'notebook2script' is not defined"
551
+ ]
552
+ }
553
+ ],
554
+ "source": []
555
+ },
556
+ {
557
+ "cell_type": "code",
558
+ "execution_count": null,
559
+ "id": "e56bc359-81c7-4e70-a84a-5f81a0713cd3",
560
+ "metadata": {},
561
+ "outputs": [],
562
+ "source": []
563
+ }
564
+ ],
565
+ "metadata": {
566
+ "kernelspec": {
567
+ "display_name": "Python 3 (ipykernel)",
568
+ "language": "python",
569
+ "name": "python3"
570
+ },
571
+ "language_info": {
572
+ "codemirror_mode": {
573
+ "name": "ipython",
574
+ "version": 3
575
+ },
576
+ "file_extension": ".py",
577
+ "mimetype": "text/x-python",
578
+ "name": "python",
579
+ "nbconvert_exporter": "python",
580
+ "pygments_lexer": "ipython3",
581
+ "version": "3.8.2"
582
+ }
583
+ },
584
+ "nbformat": 4,
585
+ "nbformat_minor": 5
586
+ }
app.py CHANGED
@@ -1,7 +1,42 @@
 
 
 
 
 
 
 
 
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
 
 
 
 
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
1
+ # AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
2
+
3
+ # %% auto 0
4
+ __all__ = ['title', 'description', 'learners', 'models', 'image', 'model', 'label', 'example_images', 'example_models', 'intf',
5
+ 'classify_image']
6
+
7
+ # %% app.ipynb 1
8
+ from fastai.vision.all import *
9
  import gradio as gr
10
+ title = "FastAI - Big Cats Classifier"
11
+ description = "Classify big cats using all Resnet models available pre-trained in FastAI"
12
+
13
+ # %% app.ipynb 2
14
+ learners = {
15
+ "resnet-18" : 'models/resnet18-model.pkl',
16
+ "resnet-34" : 'models/resnet34-model.pkl',
17
+ "resnet-50" : 'models/resnet50-model.pkl',
18
+ "resnet-101": 'models/resnet101-model.pkl',
19
+ "resnet-152": 'models/resnet152-model.pkl'
20
+ }
21
+ models = list(learners.keys())
22
+
23
+
24
+
25
+ # %% app.ipynb 3
26
+ def classify_image(img, model_file="resnet-101"):
27
+ learn = load_learner(learners[model_file])
28
+ pred,idx,probs = learn.predict(img)
29
+ print(pred, idx, probs)
30
+ return dict(zip(learn.dls.vocab, map(float, probs)))
31
+
32
 
33
+ # %% app.ipynb 5
34
+ image = gr.inputs.Image(shape=(192.192))
35
+ model = gr.inputs.Dropdown(choices=models)
36
+ label = gr.outputs.Label()
37
+ example_images = [ 'cheetah.jpg', 'jaguar.jpg', 'tiger.jpg', 'cougar.jpg', 'lion.jpg', 'african leopard.jpg', 'clouded leopard.jpg', 'snow leopard.jpg' ]
38
+ example_models = [] #list(learners.values())
39
+ intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=example_images, title=title, description=description )
40
+ if __name__ == "__main__":
41
+ intf.launch(debug=True, inline=False)
42
 
 
 
cheetah.jpg ADDED
clouded leopard.jpg ADDED
cougar.jpg ADDED
jaguar.jpg ADDED
lion.jpg ADDED
models/resnet101-model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c1a971ebff585a4d1da9ca66825aa8f6fb3950fde8399685fac0d3dbeca8b525
3
+ size 179221672
models/resnet152-model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8b1ede57eef01832ff6e2c547d0cc22e89dc53451428719194d4e5ad058054ce
3
+ size 242110662
models/resnet18-model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3dd42e423a4d5975d40f58f95ae99f9eb987e1fd311ba84d1e0981eb3a68608b
3
+ size 46990035
models/resnet34-model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:01e324fe98232953da00d2d6f77738a33a866928298cce8b40b93d711e2eebb8
3
+ size 87494099
models/resnet50-model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:73da7a73680b7b140091264f1eeff0414c3e46a71c9152519ebccd9619284b54
3
+ size 102913719
snow leopard.jpg ADDED
tiger.jpg ADDED