prasanth.thangavel commited on
Commit
312cd8f
1 Parent(s): 6d1b006

Minor bug fix in extracting the predicted superhero

Browse files
Files changed (2) hide show
  1. app.ipynb +137 -23
  2. app.py +3 -3
app.ipynb CHANGED
@@ -171,12 +171,12 @@
171
  },
172
  {
173
  "cell_type": "code",
174
- "execution_count": 5,
175
  "id": "12b3519f",
176
  "metadata": {
177
  "ExecuteTime": {
178
- "end_time": "2023-06-04T04:18:14.466326Z",
179
- "start_time": "2023-06-04T04:18:14.460213Z"
180
  }
181
  },
182
  "outputs": [
@@ -198,10 +198,10 @@
198
  " pred, idx, probs = learn.predict(img)\n",
199
  " \n",
200
  " prediction = dict(zip(categories, map(float, probs)))\n",
201
- " #print (f\"prediction = {prediction}\")\n",
202
  " \n",
203
- " predicted_hero = categories[np.argsort(prediction.values())[0]]\n",
204
- " #print (f\"predicted_hero = {predicted_hero}\")\n",
205
  " \n",
206
  " if predicted_hero == 'Superman':\n",
207
  " alter_ego = \"Clark Kent Jr\"\n",
@@ -217,12 +217,12 @@
217
  },
218
  {
219
  "cell_type": "code",
220
- "execution_count": 6,
221
  "id": "0be42346",
222
  "metadata": {
223
  "ExecuteTime": {
224
- "end_time": "2023-06-04T04:18:15.324202Z",
225
- "start_time": "2023-06-04T04:18:15.281352Z"
226
  }
227
  },
228
  "outputs": [
@@ -263,6 +263,14 @@
263
  "metadata": {},
264
  "output_type": "display_data"
265
  },
 
 
 
 
 
 
 
 
266
  {
267
  "data": {
268
  "text/plain": [
@@ -272,7 +280,7 @@
272
  " 'Bruce Wayne')"
273
  ]
274
  },
275
- "execution_count": 6,
276
  "metadata": {},
277
  "output_type": "execute_result"
278
  }
@@ -283,12 +291,12 @@
283
  },
284
  {
285
  "cell_type": "code",
286
- "execution_count": 7,
287
- "id": "826388a1",
288
  "metadata": {
289
  "ExecuteTime": {
290
- "end_time": "2023-06-04T04:18:16.173080Z",
291
- "start_time": "2023-06-04T04:18:15.829127Z"
292
  }
293
  },
294
  "outputs": [
@@ -308,12 +316,12 @@
308
  },
309
  {
310
  "cell_type": "code",
311
- "execution_count": 8,
312
  "id": "d845ec5f",
313
  "metadata": {
314
  "ExecuteTime": {
315
- "end_time": "2023-06-04T04:18:18.233242Z",
316
- "start_time": "2023-06-04T04:18:16.393046Z"
317
  }
318
  },
319
  "outputs": [
@@ -321,7 +329,7 @@
321
  "name": "stdout",
322
  "output_type": "stream",
323
  "text": [
324
- "Running on local URL: http://127.0.0.1:7860\n",
325
  "\n",
326
  "To create a public link, set `share=True` in `launch()`.\n"
327
  ]
@@ -329,7 +337,7 @@
329
  {
330
  "data": {
331
  "text/html": [
332
- "<div><iframe src=\"http://127.0.0.1:7860/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
333
  ],
334
  "text/plain": [
335
  "<IPython.core.display.HTML object>"
@@ -342,7 +350,7 @@
342
  "data": {
343
  "text/plain": []
344
  },
345
- "execution_count": 8,
346
  "metadata": {},
347
  "output_type": "execute_result"
348
  },
@@ -383,6 +391,104 @@
383
  "metadata": {},
384
  "output_type": "display_data"
385
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
386
  {
387
  "data": {
388
  "text/html": [
@@ -419,6 +525,14 @@
419
  },
420
  "metadata": {},
421
  "output_type": "display_data"
 
 
 
 
 
 
 
 
422
  }
423
  ],
424
  "source": [
@@ -450,12 +564,12 @@
450
  },
451
  {
452
  "cell_type": "code",
453
- "execution_count": 9,
454
  "id": "b942385f",
455
  "metadata": {
456
  "ExecuteTime": {
457
- "end_time": "2023-06-04T04:18:28.883975Z",
458
- "start_time": "2023-06-04T04:18:28.532380Z"
459
  }
460
  },
461
  "outputs": [
 
171
  },
172
  {
173
  "cell_type": "code",
174
+ "execution_count": 32,
175
  "id": "12b3519f",
176
  "metadata": {
177
  "ExecuteTime": {
178
+ "end_time": "2023-06-04T04:27:08.756981Z",
179
+ "start_time": "2023-06-04T04:27:08.748813Z"
180
  }
181
  },
182
  "outputs": [
 
198
  " pred, idx, probs = learn.predict(img)\n",
199
  " \n",
200
  " prediction = dict(zip(categories, map(float, probs)))\n",
201
+ " print (f\"prediction = {prediction}\")\n",
202
  " \n",
203
+ " predicted_hero = max(prediction, key=lambda key: prediction[key])\n",
204
+ " print (f\"predicted_hero = {predicted_hero}\")\n",
205
  " \n",
206
  " if predicted_hero == 'Superman':\n",
207
  " alter_ego = \"Clark Kent Jr\"\n",
 
217
  },
218
  {
219
  "cell_type": "code",
220
+ "execution_count": 33,
221
  "id": "0be42346",
222
  "metadata": {
223
  "ExecuteTime": {
224
+ "end_time": "2023-06-04T04:27:08.982499Z",
225
+ "start_time": "2023-06-04T04:27:08.904473Z"
226
  }
227
  },
228
  "outputs": [
 
263
  "metadata": {},
264
  "output_type": "display_data"
265
  },
266
+ {
267
+ "name": "stdout",
268
+ "output_type": "stream",
269
+ "text": [
270
+ "prediction = {'Batman': 0.940523087978363, 'Flash': 0.00284947850741446, 'Superman': 0.05662744119763374}\n",
271
+ "predicted_hero = Batman\n"
272
+ ]
273
+ },
274
  {
275
  "data": {
276
  "text/plain": [
 
280
  " 'Bruce Wayne')"
281
  ]
282
  },
283
+ "execution_count": 33,
284
  "metadata": {},
285
  "output_type": "execute_result"
286
  }
 
291
  },
292
  {
293
  "cell_type": "code",
294
+ "execution_count": 34,
295
+ "id": "ad2873f2",
296
  "metadata": {
297
  "ExecuteTime": {
298
+ "end_time": "2023-06-04T04:27:09.939658Z",
299
+ "start_time": "2023-06-04T04:27:09.574763Z"
300
  }
301
  },
302
  "outputs": [
 
316
  },
317
  {
318
  "cell_type": "code",
319
+ "execution_count": 35,
320
  "id": "d845ec5f",
321
  "metadata": {
322
  "ExecuteTime": {
323
+ "end_time": "2023-06-04T04:27:11.072944Z",
324
+ "start_time": "2023-06-04T04:27:09.942171Z"
325
  }
326
  },
327
  "outputs": [
 
329
  "name": "stdout",
330
  "output_type": "stream",
331
  "text": [
332
+ "Running on local URL: http://127.0.0.1:7864\n",
333
  "\n",
334
  "To create a public link, set `share=True` in `launch()`.\n"
335
  ]
 
337
  {
338
  "data": {
339
  "text/html": [
340
+ "<div><iframe src=\"http://127.0.0.1:7864/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
341
  ],
342
  "text/plain": [
343
  "<IPython.core.display.HTML object>"
 
350
  "data": {
351
  "text/plain": []
352
  },
353
+ "execution_count": 35,
354
  "metadata": {},
355
  "output_type": "execute_result"
356
  },
 
391
  "metadata": {},
392
  "output_type": "display_data"
393
  },
394
+ {
395
+ "name": "stdout",
396
+ "output_type": "stream",
397
+ "text": [
398
+ "prediction = {'Batman': 5.742020903198863e-07, 'Flash': 3.5911152735934593e-06, 'Superman': 0.9999958276748657}\n",
399
+ "predicted_hero = Superman\n"
400
+ ]
401
+ },
402
+ {
403
+ "data": {
404
+ "text/html": [
405
+ "\n",
406
+ "<style>\n",
407
+ " /* Turns off some styling */\n",
408
+ " progress {\n",
409
+ " /* gets rid of default border in Firefox and Opera. */\n",
410
+ " border: none;\n",
411
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
412
+ " background-size: auto;\n",
413
+ " }\n",
414
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
415
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
416
+ " }\n",
417
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
418
+ " background: #F44336;\n",
419
+ " }\n",
420
+ "</style>\n"
421
+ ],
422
+ "text/plain": [
423
+ "<IPython.core.display.HTML object>"
424
+ ]
425
+ },
426
+ "metadata": {},
427
+ "output_type": "display_data"
428
+ },
429
+ {
430
+ "data": {
431
+ "text/html": [],
432
+ "text/plain": [
433
+ "<IPython.core.display.HTML object>"
434
+ ]
435
+ },
436
+ "metadata": {},
437
+ "output_type": "display_data"
438
+ },
439
+ {
440
+ "name": "stdout",
441
+ "output_type": "stream",
442
+ "text": [
443
+ "prediction = {'Batman': 2.2285334125626832e-05, 'Flash': 0.9998688697814941, 'Superman': 0.00010885472147492692}\n",
444
+ "predicted_hero = Flash\n"
445
+ ]
446
+ },
447
+ {
448
+ "data": {
449
+ "text/html": [
450
+ "\n",
451
+ "<style>\n",
452
+ " /* Turns off some styling */\n",
453
+ " progress {\n",
454
+ " /* gets rid of default border in Firefox and Opera. */\n",
455
+ " border: none;\n",
456
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
457
+ " background-size: auto;\n",
458
+ " }\n",
459
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
460
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
461
+ " }\n",
462
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
463
+ " background: #F44336;\n",
464
+ " }\n",
465
+ "</style>\n"
466
+ ],
467
+ "text/plain": [
468
+ "<IPython.core.display.HTML object>"
469
+ ]
470
+ },
471
+ "metadata": {},
472
+ "output_type": "display_data"
473
+ },
474
+ {
475
+ "data": {
476
+ "text/html": [],
477
+ "text/plain": [
478
+ "<IPython.core.display.HTML object>"
479
+ ]
480
+ },
481
+ "metadata": {},
482
+ "output_type": "display_data"
483
+ },
484
+ {
485
+ "name": "stdout",
486
+ "output_type": "stream",
487
+ "text": [
488
+ "prediction = {'Batman': 0.016343194991350174, 'Flash': 0.002146175829693675, 'Superman': 0.981510579586029}\n",
489
+ "predicted_hero = Superman\n"
490
+ ]
491
+ },
492
  {
493
  "data": {
494
  "text/html": [
 
525
  },
526
  "metadata": {},
527
  "output_type": "display_data"
528
+ },
529
+ {
530
+ "name": "stdout",
531
+ "output_type": "stream",
532
+ "text": [
533
+ "prediction = {'Batman': 0.9863764643669128, 'Flash': 0.0022053574211895466, 'Superman': 0.011418282985687256}\n",
534
+ "predicted_hero = Batman\n"
535
+ ]
536
  }
537
  ],
538
  "source": [
 
564
  },
565
  {
566
  "cell_type": "code",
567
+ "execution_count": 36,
568
  "id": "b942385f",
569
  "metadata": {
570
  "ExecuteTime": {
571
+ "end_time": "2023-06-04T04:27:21.444358Z",
572
+ "start_time": "2023-06-04T04:27:21.433263Z"
573
  }
574
  },
575
  "outputs": [
app.py CHANGED
@@ -22,10 +22,10 @@ def classify_image(img):
22
  pred, idx, probs = learn.predict(img)
23
 
24
  prediction = dict(zip(categories, map(float, probs)))
25
- #print (f"prediction = {prediction}")
26
 
27
- predicted_hero = categories[np.argsort(prediction.values())[0]]
28
- #print (f"predicted_hero = {predicted_hero}")
29
 
30
  if predicted_hero == 'Superman':
31
  alter_ego = "Clark Kent Jr"
 
22
  pred, idx, probs = learn.predict(img)
23
 
24
  prediction = dict(zip(categories, map(float, probs)))
25
+ print (f"prediction = {prediction}")
26
 
27
+ predicted_hero = max(prediction, key=lambda key: prediction[key])
28
+ print (f"predicted_hero = {predicted_hero}")
29
 
30
  if predicted_hero == 'Superman':
31
  alter_ego = "Clark Kent Jr"