Chizoba Obasi commited on
Commit
4d4c21b
·
1 Parent(s): 8b093fc

clean up output format of classifier

Browse files
Files changed (3) hide show
  1. .ipynb_checkpoints/app-checkpoint.ipynb +55 -32
  2. app.ipynb +55 -32
  3. app.py +5 -3
.ipynb_checkpoints/app-checkpoint.ipynb CHANGED
@@ -2,7 +2,7 @@
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
- "execution_count": 1,
6
  "id": "49f8a125",
7
  "metadata": {},
8
  "outputs": [],
@@ -12,7 +12,7 @@
12
  },
13
  {
14
  "cell_type": "code",
15
- "execution_count": 2,
16
  "id": "71c3904e",
17
  "metadata": {},
18
  "outputs": [
@@ -22,7 +22,7 @@
22
  "'/Users/CEO/miniconda3/envs/py37/bin/python'"
23
  ]
24
  },
25
- "execution_count": 2,
26
  "metadata": {},
27
  "output_type": "execute_result"
28
  }
@@ -42,7 +42,7 @@
42
  },
43
  {
44
  "cell_type": "code",
45
- "execution_count": 3,
46
  "id": "41471e63",
47
  "metadata": {},
48
  "outputs": [],
@@ -57,7 +57,7 @@
57
  },
58
  {
59
  "cell_type": "code",
60
- "execution_count": 4,
61
  "id": "f2e432ef",
62
  "metadata": {},
63
  "outputs": [
@@ -68,7 +68,7 @@
68
  "PILImage mode=RGB size=192x192"
69
  ]
70
  },
71
- "execution_count": 4,
72
  "metadata": {},
73
  "output_type": "execute_result"
74
  }
@@ -81,7 +81,7 @@
81
  },
82
  {
83
  "cell_type": "code",
84
- "execution_count": 5,
85
  "id": "20cf1910",
86
  "metadata": {},
87
  "outputs": [],
@@ -92,7 +92,29 @@
92
  },
93
  {
94
  "cell_type": "code",
95
- "execution_count": 6,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  "id": "91133a4e",
97
  "metadata": {},
98
  "outputs": [
@@ -100,8 +122,8 @@
100
  "name": "stdout",
101
  "output_type": "stream",
102
  "text": [
103
- "CPU times: user 3 µs, sys: 1 µs, total: 4 µs\n",
104
- "Wall time: 6.91 µs\n"
105
  ]
106
  },
107
  {
@@ -147,7 +169,7 @@
147
  "('False', tensor(0), tensor([9.9996e-01, 4.0008e-05]))"
148
  ]
149
  },
150
- "execution_count": 6,
151
  "metadata": {},
152
  "output_type": "execute_result"
153
  }
@@ -159,7 +181,7 @@
159
  },
160
  {
161
  "cell_type": "code",
162
- "execution_count": 7,
163
  "id": "fbfb35f2",
164
  "metadata": {},
165
  "outputs": [],
@@ -169,12 +191,13 @@
169
  "\n",
170
  "def classify_image(img):\n",
171
  " pred, idx, probs = learn.predict(img)\n",
172
- " return dict(zip(categories, map(float, probs)))"
 
173
  ]
174
  },
175
  {
176
  "cell_type": "code",
177
- "execution_count": 8,
178
  "id": "607bdfc9",
179
  "metadata": {},
180
  "outputs": [
@@ -221,7 +244,7 @@
221
  "{'Dog': 0.9999599456787109, 'Cat': 4.000756598543376e-05}"
222
  ]
223
  },
224
- "execution_count": 8,
225
  "metadata": {},
226
  "output_type": "execute_result"
227
  }
@@ -232,7 +255,7 @@
232
  },
233
  {
234
  "cell_type": "code",
235
- "execution_count": 50,
236
  "id": "abd33e96",
237
  "metadata": {},
238
  "outputs": [
@@ -252,7 +275,7 @@
252
  "text": [
253
  "IMPORTANT: You are using gradio version 3.34.0, however version 4.29.0 is available, please upgrade.\n",
254
  "--------\n",
255
- "Running on local URL: http://127.0.0.1:7864\n",
256
  "\n",
257
  "To create a public link, set `share=True` in `launch()`.\n"
258
  ]
@@ -261,7 +284,7 @@
261
  "data": {
262
  "text/plain": []
263
  },
264
- "execution_count": 50,
265
  "metadata": {},
266
  "output_type": "execute_result"
267
  }
@@ -270,7 +293,7 @@
270
  "#|export\n",
271
  "# image = gr.Image(shape=(192, 192))\n",
272
  "image = gr.Image(width=192, height=192)\n",
273
- "label = gr.Label()\n",
274
  "examples = ['dog.jpeg', 'cat.jpeg', 'bear.jpeg', 'dog2.jpeg']\n",
275
  "\n",
276
  "intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)\n",
@@ -279,7 +302,7 @@
279
  },
280
  {
281
  "cell_type": "code",
282
- "execution_count": 51,
283
  "id": "f0d25829",
284
  "metadata": {},
285
  "outputs": [],
@@ -289,7 +312,7 @@
289
  },
290
  {
291
  "cell_type": "code",
292
- "execution_count": 52,
293
  "id": "c75b8ca4",
294
  "metadata": {},
295
  "outputs": [],
@@ -299,7 +322,7 @@
299
  },
300
  {
301
  "cell_type": "code",
302
- "execution_count": 53,
303
  "id": "a1bd98e0",
304
  "metadata": {},
305
  "outputs": [
@@ -323,7 +346,7 @@
323
  " requires_grad=True)"
324
  ]
325
  },
326
- "execution_count": 53,
327
  "metadata": {},
328
  "output_type": "execute_result"
329
  }
@@ -334,7 +357,7 @@
334
  },
335
  {
336
  "cell_type": "code",
337
- "execution_count": 54,
338
  "id": "9a09b2fd",
339
  "metadata": {},
340
  "outputs": [
@@ -344,7 +367,7 @@
344
  "torch.Size([64, 3, 7, 7])"
345
  ]
346
  },
347
- "execution_count": 54,
348
  "metadata": {},
349
  "output_type": "execute_result"
350
  }
@@ -355,7 +378,7 @@
355
  },
356
  {
357
  "cell_type": "code",
358
- "execution_count": 55,
359
  "id": "a05ca56d",
360
  "metadata": {},
361
  "outputs": [
@@ -624,7 +647,7 @@
624
  " -7.1066e-02, -6.6630e-02]]]], requires_grad=True)"
625
  ]
626
  },
627
- "execution_count": 55,
628
  "metadata": {},
629
  "output_type": "execute_result"
630
  }
@@ -643,7 +666,7 @@
643
  },
644
  {
645
  "cell_type": "code",
646
- "execution_count": 56,
647
  "id": "416da297",
648
  "metadata": {},
649
  "outputs": [],
@@ -656,7 +679,7 @@
656
  },
657
  {
658
  "cell_type": "code",
659
- "execution_count": 57,
660
  "id": "a0d2f5c6",
661
  "metadata": {},
662
  "outputs": [],
@@ -667,7 +690,7 @@
667
  },
668
  {
669
  "cell_type": "code",
670
- "execution_count": 58,
671
  "id": "4d5c5a92",
672
  "metadata": {},
673
  "outputs": [],
@@ -678,7 +701,7 @@
678
  },
679
  {
680
  "cell_type": "code",
681
- "execution_count": 59,
682
  "id": "3debd079",
683
  "metadata": {},
684
  "outputs": [],
@@ -691,7 +714,7 @@
691
  {
692
  "cell_type": "code",
693
  "execution_count": null,
694
- "id": "ca15bb94",
695
  "metadata": {},
696
  "outputs": [],
697
  "source": []
 
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
+ "execution_count": 2,
6
  "id": "49f8a125",
7
  "metadata": {},
8
  "outputs": [],
 
12
  },
13
  {
14
  "cell_type": "code",
15
+ "execution_count": 3,
16
  "id": "71c3904e",
17
  "metadata": {},
18
  "outputs": [
 
22
  "'/Users/CEO/miniconda3/envs/py37/bin/python'"
23
  ]
24
  },
25
+ "execution_count": 3,
26
  "metadata": {},
27
  "output_type": "execute_result"
28
  }
 
42
  },
43
  {
44
  "cell_type": "code",
45
+ "execution_count": 4,
46
  "id": "41471e63",
47
  "metadata": {},
48
  "outputs": [],
 
57
  },
58
  {
59
  "cell_type": "code",
60
+ "execution_count": 5,
61
  "id": "f2e432ef",
62
  "metadata": {},
63
  "outputs": [
 
68
  "PILImage mode=RGB size=192x192"
69
  ]
70
  },
71
+ "execution_count": 5,
72
  "metadata": {},
73
  "output_type": "execute_result"
74
  }
 
81
  },
82
  {
83
  "cell_type": "code",
84
+ "execution_count": 6,
85
  "id": "20cf1910",
86
  "metadata": {},
87
  "outputs": [],
 
92
  },
93
  {
94
  "cell_type": "code",
95
+ "execution_count": 10,
96
+ "id": "7e80fd71",
97
+ "metadata": {},
98
+ "outputs": [
99
+ {
100
+ "data": {
101
+ "text/plain": [
102
+ "[False, True]"
103
+ ]
104
+ },
105
+ "execution_count": 10,
106
+ "metadata": {},
107
+ "output_type": "execute_result"
108
+ }
109
+ ],
110
+ "source": [
111
+ "LABELS = learn.dls.vocab\n",
112
+ "LABELS"
113
+ ]
114
+ },
115
+ {
116
+ "cell_type": "code",
117
+ "execution_count": 11,
118
  "id": "91133a4e",
119
  "metadata": {},
120
  "outputs": [
 
122
  "name": "stdout",
123
  "output_type": "stream",
124
  "text": [
125
+ "CPU times: user 3 µs, sys: 1e+03 ns, total: 4 µs\n",
126
+ "Wall time: 4.77 µs\n"
127
  ]
128
  },
129
  {
 
169
  "('False', tensor(0), tensor([9.9996e-01, 4.0008e-05]))"
170
  ]
171
  },
172
+ "execution_count": 11,
173
  "metadata": {},
174
  "output_type": "execute_result"
175
  }
 
181
  },
182
  {
183
  "cell_type": "code",
184
+ "execution_count": 16,
185
  "id": "fbfb35f2",
186
  "metadata": {},
187
  "outputs": [],
 
191
  "\n",
192
  "def classify_image(img):\n",
193
  " pred, idx, probs = learn.predict(img)\n",
194
+ " return dict(zip(categories, map(float, probs)))\n",
195
+ "# return {LABELS[i]: float(probs[i]) for i, _ in enumerate(LABELS)}"
196
  ]
197
  },
198
  {
199
  "cell_type": "code",
200
+ "execution_count": 17,
201
  "id": "607bdfc9",
202
  "metadata": {},
203
  "outputs": [
 
244
  "{'Dog': 0.9999599456787109, 'Cat': 4.000756598543376e-05}"
245
  ]
246
  },
247
+ "execution_count": 17,
248
  "metadata": {},
249
  "output_type": "execute_result"
250
  }
 
255
  },
256
  {
257
  "cell_type": "code",
258
+ "execution_count": 19,
259
  "id": "abd33e96",
260
  "metadata": {},
261
  "outputs": [
 
275
  "text": [
276
  "IMPORTANT: You are using gradio version 3.34.0, however version 4.29.0 is available, please upgrade.\n",
277
  "--------\n",
278
+ "Running on local URL: http://127.0.0.1:7861\n",
279
  "\n",
280
  "To create a public link, set `share=True` in `launch()`.\n"
281
  ]
 
284
  "data": {
285
  "text/plain": []
286
  },
287
+ "execution_count": 19,
288
  "metadata": {},
289
  "output_type": "execute_result"
290
  }
 
293
  "#|export\n",
294
  "# image = gr.Image(shape=(192, 192))\n",
295
  "image = gr.Image(width=192, height=192)\n",
296
+ "label = gr.Label(num_top_classes=2)\n",
297
  "examples = ['dog.jpeg', 'cat.jpeg', 'bear.jpeg', 'dog2.jpeg']\n",
298
  "\n",
299
  "intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)\n",
 
302
  },
303
  {
304
  "cell_type": "code",
305
+ "execution_count": 20,
306
  "id": "f0d25829",
307
  "metadata": {},
308
  "outputs": [],
 
312
  },
313
  {
314
  "cell_type": "code",
315
+ "execution_count": 21,
316
  "id": "c75b8ca4",
317
  "metadata": {},
318
  "outputs": [],
 
322
  },
323
  {
324
  "cell_type": "code",
325
+ "execution_count": 22,
326
  "id": "a1bd98e0",
327
  "metadata": {},
328
  "outputs": [
 
346
  " requires_grad=True)"
347
  ]
348
  },
349
+ "execution_count": 22,
350
  "metadata": {},
351
  "output_type": "execute_result"
352
  }
 
357
  },
358
  {
359
  "cell_type": "code",
360
+ "execution_count": 23,
361
  "id": "9a09b2fd",
362
  "metadata": {},
363
  "outputs": [
 
367
  "torch.Size([64, 3, 7, 7])"
368
  ]
369
  },
370
+ "execution_count": 23,
371
  "metadata": {},
372
  "output_type": "execute_result"
373
  }
 
378
  },
379
  {
380
  "cell_type": "code",
381
+ "execution_count": 24,
382
  "id": "a05ca56d",
383
  "metadata": {},
384
  "outputs": [
 
647
  " -7.1066e-02, -6.6630e-02]]]], requires_grad=True)"
648
  ]
649
  },
650
+ "execution_count": 24,
651
  "metadata": {},
652
  "output_type": "execute_result"
653
  }
 
666
  },
667
  {
668
  "cell_type": "code",
669
+ "execution_count": 25,
670
  "id": "416da297",
671
  "metadata": {},
672
  "outputs": [],
 
679
  },
680
  {
681
  "cell_type": "code",
682
+ "execution_count": 26,
683
  "id": "a0d2f5c6",
684
  "metadata": {},
685
  "outputs": [],
 
690
  },
691
  {
692
  "cell_type": "code",
693
+ "execution_count": 27,
694
  "id": "4d5c5a92",
695
  "metadata": {},
696
  "outputs": [],
 
701
  },
702
  {
703
  "cell_type": "code",
704
+ "execution_count": 28,
705
  "id": "3debd079",
706
  "metadata": {},
707
  "outputs": [],
 
714
  {
715
  "cell_type": "code",
716
  "execution_count": null,
717
+ "id": "359ae4e2",
718
  "metadata": {},
719
  "outputs": [],
720
  "source": []
app.ipynb CHANGED
@@ -2,7 +2,7 @@
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
- "execution_count": 1,
6
  "id": "49f8a125",
7
  "metadata": {},
8
  "outputs": [],
@@ -12,7 +12,7 @@
12
  },
13
  {
14
  "cell_type": "code",
15
- "execution_count": 2,
16
  "id": "71c3904e",
17
  "metadata": {},
18
  "outputs": [
@@ -22,7 +22,7 @@
22
  "'/Users/CEO/miniconda3/envs/py37/bin/python'"
23
  ]
24
  },
25
- "execution_count": 2,
26
  "metadata": {},
27
  "output_type": "execute_result"
28
  }
@@ -42,7 +42,7 @@
42
  },
43
  {
44
  "cell_type": "code",
45
- "execution_count": 3,
46
  "id": "41471e63",
47
  "metadata": {},
48
  "outputs": [],
@@ -57,7 +57,7 @@
57
  },
58
  {
59
  "cell_type": "code",
60
- "execution_count": 4,
61
  "id": "f2e432ef",
62
  "metadata": {},
63
  "outputs": [
@@ -68,7 +68,7 @@
68
  "PILImage mode=RGB size=192x192"
69
  ]
70
  },
71
- "execution_count": 4,
72
  "metadata": {},
73
  "output_type": "execute_result"
74
  }
@@ -81,7 +81,7 @@
81
  },
82
  {
83
  "cell_type": "code",
84
- "execution_count": 5,
85
  "id": "20cf1910",
86
  "metadata": {},
87
  "outputs": [],
@@ -92,7 +92,29 @@
92
  },
93
  {
94
  "cell_type": "code",
95
- "execution_count": 6,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  "id": "91133a4e",
97
  "metadata": {},
98
  "outputs": [
@@ -100,8 +122,8 @@
100
  "name": "stdout",
101
  "output_type": "stream",
102
  "text": [
103
- "CPU times: user 3 µs, sys: 1 µs, total: 4 µs\n",
104
- "Wall time: 6.91 µs\n"
105
  ]
106
  },
107
  {
@@ -147,7 +169,7 @@
147
  "('False', tensor(0), tensor([9.9996e-01, 4.0008e-05]))"
148
  ]
149
  },
150
- "execution_count": 6,
151
  "metadata": {},
152
  "output_type": "execute_result"
153
  }
@@ -159,7 +181,7 @@
159
  },
160
  {
161
  "cell_type": "code",
162
- "execution_count": 7,
163
  "id": "fbfb35f2",
164
  "metadata": {},
165
  "outputs": [],
@@ -169,12 +191,13 @@
169
  "\n",
170
  "def classify_image(img):\n",
171
  " pred, idx, probs = learn.predict(img)\n",
172
- " return dict(zip(categories, map(float, probs)))"
 
173
  ]
174
  },
175
  {
176
  "cell_type": "code",
177
- "execution_count": 8,
178
  "id": "607bdfc9",
179
  "metadata": {},
180
  "outputs": [
@@ -221,7 +244,7 @@
221
  "{'Dog': 0.9999599456787109, 'Cat': 4.000756598543376e-05}"
222
  ]
223
  },
224
- "execution_count": 8,
225
  "metadata": {},
226
  "output_type": "execute_result"
227
  }
@@ -232,7 +255,7 @@
232
  },
233
  {
234
  "cell_type": "code",
235
- "execution_count": 50,
236
  "id": "abd33e96",
237
  "metadata": {},
238
  "outputs": [
@@ -252,7 +275,7 @@
252
  "text": [
253
  "IMPORTANT: You are using gradio version 3.34.0, however version 4.29.0 is available, please upgrade.\n",
254
  "--------\n",
255
- "Running on local URL: http://127.0.0.1:7864\n",
256
  "\n",
257
  "To create a public link, set `share=True` in `launch()`.\n"
258
  ]
@@ -261,7 +284,7 @@
261
  "data": {
262
  "text/plain": []
263
  },
264
- "execution_count": 50,
265
  "metadata": {},
266
  "output_type": "execute_result"
267
  }
@@ -270,7 +293,7 @@
270
  "#|export\n",
271
  "# image = gr.Image(shape=(192, 192))\n",
272
  "image = gr.Image(width=192, height=192)\n",
273
- "label = gr.Label()\n",
274
  "examples = ['dog.jpeg', 'cat.jpeg', 'bear.jpeg', 'dog2.jpeg']\n",
275
  "\n",
276
  "intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)\n",
@@ -279,7 +302,7 @@
279
  },
280
  {
281
  "cell_type": "code",
282
- "execution_count": 51,
283
  "id": "f0d25829",
284
  "metadata": {},
285
  "outputs": [],
@@ -289,7 +312,7 @@
289
  },
290
  {
291
  "cell_type": "code",
292
- "execution_count": 52,
293
  "id": "c75b8ca4",
294
  "metadata": {},
295
  "outputs": [],
@@ -299,7 +322,7 @@
299
  },
300
  {
301
  "cell_type": "code",
302
- "execution_count": 53,
303
  "id": "a1bd98e0",
304
  "metadata": {},
305
  "outputs": [
@@ -323,7 +346,7 @@
323
  " requires_grad=True)"
324
  ]
325
  },
326
- "execution_count": 53,
327
  "metadata": {},
328
  "output_type": "execute_result"
329
  }
@@ -334,7 +357,7 @@
334
  },
335
  {
336
  "cell_type": "code",
337
- "execution_count": 54,
338
  "id": "9a09b2fd",
339
  "metadata": {},
340
  "outputs": [
@@ -344,7 +367,7 @@
344
  "torch.Size([64, 3, 7, 7])"
345
  ]
346
  },
347
- "execution_count": 54,
348
  "metadata": {},
349
  "output_type": "execute_result"
350
  }
@@ -355,7 +378,7 @@
355
  },
356
  {
357
  "cell_type": "code",
358
- "execution_count": 55,
359
  "id": "a05ca56d",
360
  "metadata": {},
361
  "outputs": [
@@ -624,7 +647,7 @@
624
  " -7.1066e-02, -6.6630e-02]]]], requires_grad=True)"
625
  ]
626
  },
627
- "execution_count": 55,
628
  "metadata": {},
629
  "output_type": "execute_result"
630
  }
@@ -643,7 +666,7 @@
643
  },
644
  {
645
  "cell_type": "code",
646
- "execution_count": 56,
647
  "id": "416da297",
648
  "metadata": {},
649
  "outputs": [],
@@ -656,7 +679,7 @@
656
  },
657
  {
658
  "cell_type": "code",
659
- "execution_count": 57,
660
  "id": "a0d2f5c6",
661
  "metadata": {},
662
  "outputs": [],
@@ -667,7 +690,7 @@
667
  },
668
  {
669
  "cell_type": "code",
670
- "execution_count": 58,
671
  "id": "4d5c5a92",
672
  "metadata": {},
673
  "outputs": [],
@@ -678,7 +701,7 @@
678
  },
679
  {
680
  "cell_type": "code",
681
- "execution_count": 59,
682
  "id": "3debd079",
683
  "metadata": {},
684
  "outputs": [],
@@ -691,7 +714,7 @@
691
  {
692
  "cell_type": "code",
693
  "execution_count": null,
694
- "id": "ca15bb94",
695
  "metadata": {},
696
  "outputs": [],
697
  "source": []
 
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
+ "execution_count": 2,
6
  "id": "49f8a125",
7
  "metadata": {},
8
  "outputs": [],
 
12
  },
13
  {
14
  "cell_type": "code",
15
+ "execution_count": 3,
16
  "id": "71c3904e",
17
  "metadata": {},
18
  "outputs": [
 
22
  "'/Users/CEO/miniconda3/envs/py37/bin/python'"
23
  ]
24
  },
25
+ "execution_count": 3,
26
  "metadata": {},
27
  "output_type": "execute_result"
28
  }
 
42
  },
43
  {
44
  "cell_type": "code",
45
+ "execution_count": 4,
46
  "id": "41471e63",
47
  "metadata": {},
48
  "outputs": [],
 
57
  },
58
  {
59
  "cell_type": "code",
60
+ "execution_count": 5,
61
  "id": "f2e432ef",
62
  "metadata": {},
63
  "outputs": [
 
68
  "PILImage mode=RGB size=192x192"
69
  ]
70
  },
71
+ "execution_count": 5,
72
  "metadata": {},
73
  "output_type": "execute_result"
74
  }
 
81
  },
82
  {
83
  "cell_type": "code",
84
+ "execution_count": 6,
85
  "id": "20cf1910",
86
  "metadata": {},
87
  "outputs": [],
 
92
  },
93
  {
94
  "cell_type": "code",
95
+ "execution_count": 10,
96
+ "id": "7e80fd71",
97
+ "metadata": {},
98
+ "outputs": [
99
+ {
100
+ "data": {
101
+ "text/plain": [
102
+ "[False, True]"
103
+ ]
104
+ },
105
+ "execution_count": 10,
106
+ "metadata": {},
107
+ "output_type": "execute_result"
108
+ }
109
+ ],
110
+ "source": [
111
+ "LABELS = learn.dls.vocab\n",
112
+ "LABELS"
113
+ ]
114
+ },
115
+ {
116
+ "cell_type": "code",
117
+ "execution_count": 11,
118
  "id": "91133a4e",
119
  "metadata": {},
120
  "outputs": [
 
122
  "name": "stdout",
123
  "output_type": "stream",
124
  "text": [
125
+ "CPU times: user 3 µs, sys: 1e+03 ns, total: 4 µs\n",
126
+ "Wall time: 4.77 µs\n"
127
  ]
128
  },
129
  {
 
169
  "('False', tensor(0), tensor([9.9996e-01, 4.0008e-05]))"
170
  ]
171
  },
172
+ "execution_count": 11,
173
  "metadata": {},
174
  "output_type": "execute_result"
175
  }
 
181
  },
182
  {
183
  "cell_type": "code",
184
+ "execution_count": 16,
185
  "id": "fbfb35f2",
186
  "metadata": {},
187
  "outputs": [],
 
191
  "\n",
192
  "def classify_image(img):\n",
193
  " pred, idx, probs = learn.predict(img)\n",
194
+ " return dict(zip(categories, map(float, probs)))\n",
195
+ "# return {LABELS[i]: float(probs[i]) for i, _ in enumerate(LABELS)}"
196
  ]
197
  },
198
  {
199
  "cell_type": "code",
200
+ "execution_count": 17,
201
  "id": "607bdfc9",
202
  "metadata": {},
203
  "outputs": [
 
244
  "{'Dog': 0.9999599456787109, 'Cat': 4.000756598543376e-05}"
245
  ]
246
  },
247
+ "execution_count": 17,
248
  "metadata": {},
249
  "output_type": "execute_result"
250
  }
 
255
  },
256
  {
257
  "cell_type": "code",
258
+ "execution_count": 19,
259
  "id": "abd33e96",
260
  "metadata": {},
261
  "outputs": [
 
275
  "text": [
276
  "IMPORTANT: You are using gradio version 3.34.0, however version 4.29.0 is available, please upgrade.\n",
277
  "--------\n",
278
+ "Running on local URL: http://127.0.0.1:7861\n",
279
  "\n",
280
  "To create a public link, set `share=True` in `launch()`.\n"
281
  ]
 
284
  "data": {
285
  "text/plain": []
286
  },
287
+ "execution_count": 19,
288
  "metadata": {},
289
  "output_type": "execute_result"
290
  }
 
293
  "#|export\n",
294
  "# image = gr.Image(shape=(192, 192))\n",
295
  "image = gr.Image(width=192, height=192)\n",
296
+ "label = gr.Label(num_top_classes=2)\n",
297
  "examples = ['dog.jpeg', 'cat.jpeg', 'bear.jpeg', 'dog2.jpeg']\n",
298
  "\n",
299
  "intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)\n",
 
302
  },
303
  {
304
  "cell_type": "code",
305
+ "execution_count": 20,
306
  "id": "f0d25829",
307
  "metadata": {},
308
  "outputs": [],
 
312
  },
313
  {
314
  "cell_type": "code",
315
+ "execution_count": 21,
316
  "id": "c75b8ca4",
317
  "metadata": {},
318
  "outputs": [],
 
322
  },
323
  {
324
  "cell_type": "code",
325
+ "execution_count": 22,
326
  "id": "a1bd98e0",
327
  "metadata": {},
328
  "outputs": [
 
346
  " requires_grad=True)"
347
  ]
348
  },
349
+ "execution_count": 22,
350
  "metadata": {},
351
  "output_type": "execute_result"
352
  }
 
357
  },
358
  {
359
  "cell_type": "code",
360
+ "execution_count": 23,
361
  "id": "9a09b2fd",
362
  "metadata": {},
363
  "outputs": [
 
367
  "torch.Size([64, 3, 7, 7])"
368
  ]
369
  },
370
+ "execution_count": 23,
371
  "metadata": {},
372
  "output_type": "execute_result"
373
  }
 
378
  },
379
  {
380
  "cell_type": "code",
381
+ "execution_count": 24,
382
  "id": "a05ca56d",
383
  "metadata": {},
384
  "outputs": [
 
647
  " -7.1066e-02, -6.6630e-02]]]], requires_grad=True)"
648
  ]
649
  },
650
+ "execution_count": 24,
651
  "metadata": {},
652
  "output_type": "execute_result"
653
  }
 
666
  },
667
  {
668
  "cell_type": "code",
669
+ "execution_count": 25,
670
  "id": "416da297",
671
  "metadata": {},
672
  "outputs": [],
 
679
  },
680
  {
681
  "cell_type": "code",
682
+ "execution_count": 26,
683
  "id": "a0d2f5c6",
684
  "metadata": {},
685
  "outputs": [],
 
690
  },
691
  {
692
  "cell_type": "code",
693
+ "execution_count": 27,
694
  "id": "4d5c5a92",
695
  "metadata": {},
696
  "outputs": [],
 
701
  },
702
  {
703
  "cell_type": "code",
704
+ "execution_count": 28,
705
  "id": "3debd079",
706
  "metadata": {},
707
  "outputs": [],
 
714
  {
715
  "cell_type": "code",
716
  "execution_count": null,
717
+ "id": "359ae4e2",
718
  "metadata": {},
719
  "outputs": [],
720
  "source": []
app.py CHANGED
@@ -13,16 +13,18 @@ def is_cat(x):
13
  # %% app.ipynb 5
14
  learn = load_learner('model.pkl')
15
 
16
- # %% app.ipynb 7
17
  categories = ('Dog', 'Cat')
18
 
19
  def classify_image(img):
20
  pred, idx, probs = learn.predict(img)
21
  return dict(zip(categories, map(float, probs)))
 
22
 
23
- # %% app.ipynb 9
 
24
  image = gr.Image(width=192, height=192)
25
- label = gr.Label()
26
  examples = ['dog.jpeg', 'cat.jpeg', 'bear.jpeg', 'dog2.jpeg']
27
 
28
  intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
 
13
  # %% app.ipynb 5
14
  learn = load_learner('model.pkl')
15
 
16
+ # %% app.ipynb 8
17
  categories = ('Dog', 'Cat')
18
 
19
  def classify_image(img):
20
  pred, idx, probs = learn.predict(img)
21
  return dict(zip(categories, map(float, probs)))
22
+ # return {LABELS[i]: float(probs[i]) for i, _ in enumerate(LABELS)}
23
 
24
+ # %% app.ipynb 10
25
+ # image = gr.Image(shape=(192, 192))
26
  image = gr.Image(width=192, height=192)
27
+ label = gr.Label(num_top_classes=2)
28
  examples = ['dog.jpeg', 'cat.jpeg', 'bear.jpeg', 'dog2.jpeg']
29
 
30
  intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)