arihantvyavhare commited on
Commit
4f0a716
1 Parent(s): f645cb7

added mode_training.ipynb

Browse files
Files changed (2) hide show
  1. model_training.ipynb +733 -0
  2. tips.ipynb +155 -0
model_training.ipynb ADDED
@@ -0,0 +1,733 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "# #hide\n",
10
+ "# ! [ -e /content ] && pip install -Uqq fastbook\n",
11
+ "# import fastbook\n",
12
+ "# fastbook.setup_book()"
13
+ ]
14
+ },
15
+ {
16
+ "cell_type": "code",
17
+ "execution_count": null,
18
+ "metadata": {},
19
+ "outputs": [],
20
+ "source": [
21
+ "#hide\n",
22
+ "from fastbook import *\n",
23
+ "from fastai.vision.widgets import *"
24
+ ]
25
+ },
26
+ {
27
+ "attachments": {},
28
+ "cell_type": "markdown",
29
+ "metadata": {},
30
+ "source": [
31
+ "# From Model to Production"
32
+ ]
33
+ },
34
+ {
35
+ "attachments": {},
36
+ "cell_type": "markdown",
37
+ "metadata": {},
38
+ "source": [
39
+ "## The Practice of Deep Learning"
40
+ ]
41
+ },
42
+ {
43
+ "attachments": {},
44
+ "cell_type": "markdown",
45
+ "metadata": {},
46
+ "source": [
47
+ "### Starting Your Project"
48
+ ]
49
+ },
50
+ {
51
+ "attachments": {},
52
+ "cell_type": "markdown",
53
+ "metadata": {},
54
+ "source": [
55
+ "### The State of Deep Learning"
56
+ ]
57
+ },
58
+ {
59
+ "attachments": {},
60
+ "cell_type": "markdown",
61
+ "metadata": {},
62
+ "source": [
63
+ "#### Computer vision"
64
+ ]
65
+ },
66
+ {
67
+ "attachments": {},
68
+ "cell_type": "markdown",
69
+ "metadata": {},
70
+ "source": [
71
+ "#### Text (natural language processing)"
72
+ ]
73
+ },
74
+ {
75
+ "attachments": {},
76
+ "cell_type": "markdown",
77
+ "metadata": {},
78
+ "source": [
79
+ "#### Combining text and images"
80
+ ]
81
+ },
82
+ {
83
+ "attachments": {},
84
+ "cell_type": "markdown",
85
+ "metadata": {},
86
+ "source": [
87
+ "#### Tabular data"
88
+ ]
89
+ },
90
+ {
91
+ "attachments": {},
92
+ "cell_type": "markdown",
93
+ "metadata": {},
94
+ "source": [
95
+ "#### Recommendation systems"
96
+ ]
97
+ },
98
+ {
99
+ "attachments": {},
100
+ "cell_type": "markdown",
101
+ "metadata": {},
102
+ "source": [
103
+ "#### Other data types"
104
+ ]
105
+ },
106
+ {
107
+ "attachments": {},
108
+ "cell_type": "markdown",
109
+ "metadata": {},
110
+ "source": [
111
+ "### The Drivetrain Approach"
112
+ ]
113
+ },
114
+ {
115
+ "attachments": {},
116
+ "cell_type": "markdown",
117
+ "metadata": {},
118
+ "source": [
119
+ "## Gathering Data"
120
+ ]
121
+ },
122
+ {
123
+ "attachments": {},
124
+ "cell_type": "markdown",
125
+ "metadata": {},
126
+ "source": [
127
+ "# clean\n",
128
+ "To download images with Bing Image Search, sign up at [Microsoft Azure](https://azure.microsoft.com/en-us/services/cognitive-services/bing-web-search-api/) for a free account. You will be given a key, which you can copy and enter in a cell as follows (replacing 'XXX' with your key and executing it):"
129
+ ]
130
+ },
131
+ {
132
+ "cell_type": "code",
133
+ "execution_count": null,
134
+ "metadata": {},
135
+ "outputs": [],
136
+ "source": [
137
+ "key = os.environ.get('AZURE_SEARCH_KEY', 'XXX')"
138
+ ]
139
+ },
140
+ {
141
+ "cell_type": "code",
142
+ "execution_count": null,
143
+ "metadata": {},
144
+ "outputs": [],
145
+ "source": [
146
+ "search_images_bing"
147
+ ]
148
+ },
149
+ {
150
+ "cell_type": "code",
151
+ "execution_count": null,
152
+ "metadata": {},
153
+ "outputs": [],
154
+ "source": [
155
+ "results = search_images_bing(key, 'grizzly bear')\n",
156
+ "ims = results.attrgot('contentUrl')\n",
157
+ "len(ims)"
158
+ ]
159
+ },
160
+ {
161
+ "cell_type": "code",
162
+ "execution_count": null,
163
+ "metadata": {},
164
+ "outputs": [],
165
+ "source": [
166
+ "#hide\n",
167
+ "ims = ['http://3.bp.blogspot.com/-S1scRCkI3vY/UHzV2kucsPI/AAAAAAAAA-k/YQ5UzHEm9Ss/s1600/Grizzly%2BBear%2BWildlife.jpg']"
168
+ ]
169
+ },
170
+ {
171
+ "cell_type": "code",
172
+ "execution_count": null,
173
+ "metadata": {},
174
+ "outputs": [],
175
+ "source": [
176
+ "dest = 'images/grizzly.jpg'\n",
177
+ "download_url(ims[0], dest)"
178
+ ]
179
+ },
180
+ {
181
+ "cell_type": "code",
182
+ "execution_count": null,
183
+ "metadata": {},
184
+ "outputs": [],
185
+ "source": [
186
+ "im = Image.open(dest)\n",
187
+ "im.to_thumb(128,128)"
188
+ ]
189
+ },
190
+ {
191
+ "cell_type": "code",
192
+ "execution_count": null,
193
+ "metadata": {},
194
+ "outputs": [],
195
+ "source": [
196
+ "bear_types = 'grizzly','black','teddy'\n",
197
+ "path = Path('bears')"
198
+ ]
199
+ },
200
+ {
201
+ "cell_type": "code",
202
+ "execution_count": null,
203
+ "metadata": {},
204
+ "outputs": [],
205
+ "source": [
206
+ "if not path.exists():\n",
207
+ " path.mkdir()\n",
208
+ " for o in bear_types:\n",
209
+ " dest = (path/o)\n",
210
+ " dest.mkdir(exist_ok=True)\n",
211
+ " results = search_images_bing(key, f'{o} bear')\n",
212
+ " download_images(dest, urls=results.attrgot('contentUrl'))"
213
+ ]
214
+ },
215
+ {
216
+ "cell_type": "code",
217
+ "execution_count": null,
218
+ "metadata": {},
219
+ "outputs": [],
220
+ "source": [
221
+ "fns = get_image_files(path)\n",
222
+ "fns"
223
+ ]
224
+ },
225
+ {
226
+ "cell_type": "code",
227
+ "execution_count": null,
228
+ "metadata": {},
229
+ "outputs": [],
230
+ "source": [
231
+ "failed = verify_images(fns)\n",
232
+ "failed"
233
+ ]
234
+ },
235
+ {
236
+ "cell_type": "code",
237
+ "execution_count": null,
238
+ "metadata": {},
239
+ "outputs": [],
240
+ "source": [
241
+ "failed.map(Path.unlink);"
242
+ ]
243
+ },
244
+ {
245
+ "attachments": {},
246
+ "cell_type": "markdown",
247
+ "metadata": {},
248
+ "source": [
249
+ "### Sidebar: Getting Help in Jupyter Notebooks"
250
+ ]
251
+ },
252
+ {
253
+ "attachments": {},
254
+ "cell_type": "markdown",
255
+ "metadata": {},
256
+ "source": [
257
+ "### End sidebar"
258
+ ]
259
+ },
260
+ {
261
+ "attachments": {},
262
+ "cell_type": "markdown",
263
+ "metadata": {},
264
+ "source": [
265
+ "## From Data to DataLoaders"
266
+ ]
267
+ },
268
+ {
269
+ "cell_type": "code",
270
+ "execution_count": null,
271
+ "metadata": {},
272
+ "outputs": [],
273
+ "source": [
274
+ "bears = DataBlock(\n",
275
+ " blocks=(ImageBlock, CategoryBlock), \n",
276
+ " get_items=get_image_files, \n",
277
+ " splitter=RandomSplitter(valid_pct=0.2, seed=42),\n",
278
+ " get_y=parent_label,\n",
279
+ " item_tfms=Resize(128))"
280
+ ]
281
+ },
282
+ {
283
+ "cell_type": "code",
284
+ "execution_count": null,
285
+ "metadata": {},
286
+ "outputs": [],
287
+ "source": [
288
+ "dls = bears.dataloaders(path)"
289
+ ]
290
+ },
291
+ {
292
+ "cell_type": "code",
293
+ "execution_count": null,
294
+ "metadata": {},
295
+ "outputs": [],
296
+ "source": [
297
+ "dls.valid.show_batch(max_n=4, nrows=1)"
298
+ ]
299
+ },
300
+ {
301
+ "cell_type": "code",
302
+ "execution_count": null,
303
+ "metadata": {},
304
+ "outputs": [],
305
+ "source": [
306
+ "bears = bears.new(item_tfms=Resize(128, ResizeMethod.Squish))\n",
307
+ "dls = bears.dataloaders(path)\n",
308
+ "dls.valid.show_batch(max_n=4, nrows=1)"
309
+ ]
310
+ },
311
+ {
312
+ "cell_type": "code",
313
+ "execution_count": null,
314
+ "metadata": {},
315
+ "outputs": [],
316
+ "source": [
317
+ "bears = bears.new(item_tfms=Resize(128, ResizeMethod.Pad, pad_mode='zeros'))\n",
318
+ "dls = bears.dataloaders(path)\n",
319
+ "dls.valid.show_batch(max_n=4, nrows=1)"
320
+ ]
321
+ },
322
+ {
323
+ "cell_type": "code",
324
+ "execution_count": null,
325
+ "metadata": {},
326
+ "outputs": [],
327
+ "source": [
328
+ "bears = bears.new(item_tfms=RandomResizedCrop(128, min_scale=0.3))\n",
329
+ "dls = bears.dataloaders(path)\n",
330
+ "dls.train.show_batch(max_n=4, nrows=1, unique=True)"
331
+ ]
332
+ },
333
+ {
334
+ "attachments": {},
335
+ "cell_type": "markdown",
336
+ "metadata": {},
337
+ "source": [
338
+ "### Data Augmentation"
339
+ ]
340
+ },
341
+ {
342
+ "cell_type": "code",
343
+ "execution_count": null,
344
+ "metadata": {},
345
+ "outputs": [],
346
+ "source": [
347
+ "bears = bears.new(item_tfms=Resize(128), batch_tfms=aug_transforms(mult=2))\n",
348
+ "dls = bears.dataloaders(path)\n",
349
+ "dls.train.show_batch(max_n=8, nrows=2, unique=True)"
350
+ ]
351
+ },
352
+ {
353
+ "attachments": {},
354
+ "cell_type": "markdown",
355
+ "metadata": {},
356
+ "source": [
357
+ "## Training Your Model, and Using It to Clean Your Data"
358
+ ]
359
+ },
360
+ {
361
+ "cell_type": "code",
362
+ "execution_count": null,
363
+ "metadata": {},
364
+ "outputs": [],
365
+ "source": [
366
+ "bears = bears.new(\n",
367
+ " item_tfms=RandomResizedCrop(224, min_scale=0.5),\n",
368
+ " batch_tfms=aug_transforms())\n",
369
+ "dls = bears.dataloaders(path)"
370
+ ]
371
+ },
372
+ {
373
+ "cell_type": "code",
374
+ "execution_count": null,
375
+ "metadata": {},
376
+ "outputs": [],
377
+ "source": [
378
+ "learn = vision_learner(dls, resnet18, metrics=error_rate)\n",
379
+ "learn.fine_tune(4)"
380
+ ]
381
+ },
382
+ {
383
+ "cell_type": "code",
384
+ "execution_count": null,
385
+ "metadata": {},
386
+ "outputs": [],
387
+ "source": [
388
+ "interp = ClassificationInterpretation.from_learner(learn)\n",
389
+ "interp.plot_confusion_matrix()"
390
+ ]
391
+ },
392
+ {
393
+ "cell_type": "code",
394
+ "execution_count": null,
395
+ "metadata": {},
396
+ "outputs": [],
397
+ "source": [
398
+ "interp.plot_top_losses(5, nrows=1)"
399
+ ]
400
+ },
401
+ {
402
+ "cell_type": "code",
403
+ "execution_count": null,
404
+ "metadata": {},
405
+ "outputs": [],
406
+ "source": [
407
+ "cleaner = ImageClassifierCleaner(learn)\n",
408
+ "cleaner"
409
+ ]
410
+ },
411
+ {
412
+ "cell_type": "code",
413
+ "execution_count": null,
414
+ "metadata": {},
415
+ "outputs": [],
416
+ "source": [
417
+ "#hide\n",
418
+ "# for idx in cleaner.delete(): cleaner.fns[idx].unlink()\n",
419
+ "# for idx,cat in cleaner.change(): shutil.move(str(cleaner.fns[idx]), path/cat)"
420
+ ]
421
+ },
422
+ {
423
+ "attachments": {},
424
+ "cell_type": "markdown",
425
+ "metadata": {},
426
+ "source": [
427
+ "## Turning Your Model into an Online Application"
428
+ ]
429
+ },
430
+ {
431
+ "attachments": {},
432
+ "cell_type": "markdown",
433
+ "metadata": {},
434
+ "source": [
435
+ "### Using the Model for Inference"
436
+ ]
437
+ },
438
+ {
439
+ "cell_type": "code",
440
+ "execution_count": null,
441
+ "metadata": {},
442
+ "outputs": [],
443
+ "source": [
444
+ "learn.export()"
445
+ ]
446
+ },
447
+ {
448
+ "cell_type": "code",
449
+ "execution_count": null,
450
+ "metadata": {},
451
+ "outputs": [],
452
+ "source": [
453
+ "path = Path()\n",
454
+ "path.ls(file_exts='.pkl')"
455
+ ]
456
+ },
457
+ {
458
+ "cell_type": "code",
459
+ "execution_count": null,
460
+ "metadata": {},
461
+ "outputs": [],
462
+ "source": [
463
+ "learn_inf = load_learner(path/'export.pkl')"
464
+ ]
465
+ },
466
+ {
467
+ "cell_type": "code",
468
+ "execution_count": null,
469
+ "metadata": {},
470
+ "outputs": [],
471
+ "source": [
472
+ "learn_inf.predict('images/grizzly.jpg')"
473
+ ]
474
+ },
475
+ {
476
+ "cell_type": "code",
477
+ "execution_count": null,
478
+ "metadata": {},
479
+ "outputs": [],
480
+ "source": [
481
+ "learn_inf.dls.vocab"
482
+ ]
483
+ },
484
+ {
485
+ "attachments": {},
486
+ "cell_type": "markdown",
487
+ "metadata": {},
488
+ "source": [
489
+ "### Creating a Notebook App from the Model"
490
+ ]
491
+ },
492
+ {
493
+ "cell_type": "code",
494
+ "execution_count": null,
495
+ "metadata": {},
496
+ "outputs": [],
497
+ "source": [
498
+ "btn_upload = widgets.FileUpload()\n",
499
+ "btn_upload"
500
+ ]
501
+ },
502
+ {
503
+ "cell_type": "code",
504
+ "execution_count": null,
505
+ "metadata": {},
506
+ "outputs": [],
507
+ "source": [
508
+ "#hide\n",
509
+ "# For the book, we can't actually click an upload button, so we fake it\n",
510
+ "btn_upload = SimpleNamespace(data = ['images/grizzly.jpg'])"
511
+ ]
512
+ },
513
+ {
514
+ "cell_type": "code",
515
+ "execution_count": null,
516
+ "metadata": {},
517
+ "outputs": [],
518
+ "source": [
519
+ "img = PILImage.create(btn_upload.data[-1])"
520
+ ]
521
+ },
522
+ {
523
+ "cell_type": "code",
524
+ "execution_count": null,
525
+ "metadata": {},
526
+ "outputs": [],
527
+ "source": [
528
+ "out_pl = widgets.Output()\n",
529
+ "out_pl.clear_output()\n",
530
+ "with out_pl: display(img.to_thumb(128,128))\n",
531
+ "out_pl"
532
+ ]
533
+ },
534
+ {
535
+ "cell_type": "code",
536
+ "execution_count": null,
537
+ "metadata": {},
538
+ "outputs": [],
539
+ "source": [
540
+ "pred,pred_idx,probs = learn_inf.predict(img)"
541
+ ]
542
+ },
543
+ {
544
+ "cell_type": "code",
545
+ "execution_count": null,
546
+ "metadata": {},
547
+ "outputs": [],
548
+ "source": [
549
+ "lbl_pred = widgets.Label()\n",
550
+ "lbl_pred.value = f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'\n",
551
+ "lbl_pred"
552
+ ]
553
+ },
554
+ {
555
+ "cell_type": "code",
556
+ "execution_count": null,
557
+ "metadata": {},
558
+ "outputs": [],
559
+ "source": [
560
+ "btn_run = widgets.Button(description='Classify')\n",
561
+ "btn_run"
562
+ ]
563
+ },
564
+ {
565
+ "cell_type": "code",
566
+ "execution_count": null,
567
+ "metadata": {},
568
+ "outputs": [],
569
+ "source": [
570
+ "def on_click_classify(change):\n",
571
+ " img = PILImage.create(btn_upload.data[-1])\n",
572
+ " out_pl.clear_output()\n",
573
+ " with out_pl: display(img.to_thumb(128,128))\n",
574
+ " pred,pred_idx,probs = learn_inf.predict(img)\n",
575
+ " lbl_pred.value = f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'\n",
576
+ "\n",
577
+ "btn_run.on_click(on_click_classify)"
578
+ ]
579
+ },
580
+ {
581
+ "cell_type": "code",
582
+ "execution_count": null,
583
+ "metadata": {},
584
+ "outputs": [],
585
+ "source": [
586
+ "#hide\n",
587
+ "#Putting back btn_upload to a widget for next cell\n",
588
+ "btn_upload = widgets.FileUpload()"
589
+ ]
590
+ },
591
+ {
592
+ "cell_type": "code",
593
+ "execution_count": null,
594
+ "metadata": {},
595
+ "outputs": [],
596
+ "source": [
597
+ "VBox([widgets.Label('Select your bear!'), \n",
598
+ " btn_upload, btn_run, out_pl, lbl_pred])"
599
+ ]
600
+ },
601
+ {
602
+ "attachments": {},
603
+ "cell_type": "markdown",
604
+ "metadata": {},
605
+ "source": [
606
+ "### Turning Your Notebook into a Real App"
607
+ ]
608
+ },
609
+ {
610
+ "cell_type": "code",
611
+ "execution_count": null,
612
+ "metadata": {},
613
+ "outputs": [],
614
+ "source": [
615
+ "#hide\n",
616
+ "# !pip install voila\n",
617
+ "# !jupyter serverextension enable --sys-prefix voila "
618
+ ]
619
+ },
620
+ {
621
+ "attachments": {},
622
+ "cell_type": "markdown",
623
+ "metadata": {},
624
+ "source": [
625
+ "### Deploying your app"
626
+ ]
627
+ },
628
+ {
629
+ "attachments": {},
630
+ "cell_type": "markdown",
631
+ "metadata": {},
632
+ "source": [
633
+ "## How to Avoid Disaster"
634
+ ]
635
+ },
636
+ {
637
+ "attachments": {},
638
+ "cell_type": "markdown",
639
+ "metadata": {},
640
+ "source": [
641
+ "### Unforeseen Consequences and Feedback Loops"
642
+ ]
643
+ },
644
+ {
645
+ "attachments": {},
646
+ "cell_type": "markdown",
647
+ "metadata": {},
648
+ "source": [
649
+ "## Get Writing!"
650
+ ]
651
+ },
652
+ {
653
+ "attachments": {},
654
+ "cell_type": "markdown",
655
+ "metadata": {},
656
+ "source": [
657
+ "## Questionnaire"
658
+ ]
659
+ },
660
+ {
661
+ "attachments": {},
662
+ "cell_type": "markdown",
663
+ "metadata": {},
664
+ "source": [
665
+ "1. Provide an example of where the bear classification model might work poorly in production, due to structural or style differences in the training data.\n",
666
+ "1. Where do text models currently have a major deficiency?\n",
667
+ "1. What are possible negative societal implications of text generation models?\n",
668
+ "1. In situations where a model might make mistakes, and those mistakes could be harmful, what is a good alternative to automating a process?\n",
669
+ "1. What kind of tabular data is deep learning particularly good at?\n",
670
+ "1. What's a key downside of directly using a deep learning model for recommendation systems?\n",
671
+ "1. What are the steps of the Drivetrain Approach?\n",
672
+ "1. How do the steps of the Drivetrain Approach map to a recommendation system?\n",
673
+ "1. Create an image recognition model using data you curate, and deploy it on the web.\n",
674
+ "1. What is `DataLoaders`?\n",
675
+ "1. What four things do we need to tell fastai to create `DataLoaders`?\n",
676
+ "1. What does the `splitter` parameter to `DataBlock` do?\n",
677
+ "1. How do we ensure a random split always gives the same validation set?\n",
678
+ "1. What letters are often used to signify the independent and dependent variables?\n",
679
+ "1. What's the difference between the crop, pad, and squish resize approaches? When might you choose one over the others?\n",
680
+ "1. What is data augmentation? Why is it needed?\n",
681
+ "1. What is the difference between `item_tfms` and `batch_tfms`?\n",
682
+ "1. What is a confusion matrix?\n",
683
+ "1. What does `export` save?\n",
684
+ "1. What is it called when we use a model for getting predictions, instead of training?\n",
685
+ "1. What are IPython widgets?\n",
686
+ "1. When might you want to use CPU for deployment? When might GPU be better?\n",
687
+ "1. What are the downsides of deploying your app to a server, instead of to a client (or edge) device such as a phone or PC?\n",
688
+ "1. What are three examples of problems that could occur when rolling out a bear warning system in practice?\n",
689
+ "1. What is \"out-of-domain data\"?\n",
690
+ "1. What is \"domain shift\"?\n",
691
+ "1. What are the three steps in the deployment process?"
692
+ ]
693
+ },
694
+ {
695
+ "attachments": {},
696
+ "cell_type": "markdown",
697
+ "metadata": {},
698
+ "source": [
699
+ "### Further Research"
700
+ ]
701
+ },
702
+ {
703
+ "attachments": {},
704
+ "cell_type": "markdown",
705
+ "metadata": {},
706
+ "source": [
707
+ "1. Consider how the Drivetrain Approach maps to a project or problem you're interested in.\n",
708
+ "1. When might it be best to avoid certain types of data augmentation?\n",
709
+ "1. For a project you're interested in applying deep learning to, consider the thought experiment \"What would happen if it went really, really well?\"\n",
710
+ "1. Start a blog, and write your first blog post. For instance, write about what you think deep learning might be useful for in a domain you're interested in."
711
+ ]
712
+ },
713
+ {
714
+ "cell_type": "code",
715
+ "execution_count": null,
716
+ "metadata": {},
717
+ "outputs": [],
718
+ "source": []
719
+ }
720
+ ],
721
+ "metadata": {
722
+ "jupytext": {
723
+ "split_at_heading": true
724
+ },
725
+ "kernelspec": {
726
+ "display_name": "Python 3",
727
+ "language": "python",
728
+ "name": "python3"
729
+ }
730
+ },
731
+ "nbformat": 4,
732
+ "nbformat_minor": 4
733
+ }
tips.ipynb ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "attachments": {},
5
+ "cell_type": "markdown",
6
+ "metadata": {},
7
+ "source": [
8
+ "# Tips:\n",
9
+ "## downloading images using duckduckgo and fastbook"
10
+ ]
11
+ },
12
+ {
13
+ "cell_type": "code",
14
+ "execution_count": 35,
15
+ "metadata": {},
16
+ "outputs": [
17
+ {
18
+ "name": "stdout",
19
+ "output_type": "stream",
20
+ "text": [
21
+ "/home/demonhunter/git/fastbook_tests/damaged_car_detection\n"
22
+ ]
23
+ }
24
+ ],
25
+ "source": [
26
+ "\n",
27
+ "import os \n",
28
+ "print(os.getcwd())"
29
+ ]
30
+ },
31
+ {
32
+ "cell_type": "code",
33
+ "execution_count": 2,
34
+ "metadata": {
35
+ "slideshow": {
36
+ "slide_type": "slide"
37
+ },
38
+ "tags": []
39
+ },
40
+ "outputs": [
41
+ {
42
+ "data": {
43
+ "text/plain": [
44
+ "5"
45
+ ]
46
+ },
47
+ "execution_count": 2,
48
+ "metadata": {},
49
+ "output_type": "execute_result"
50
+ }
51
+ ],
52
+ "source": [
53
+ "#| export\n",
54
+ "from fastbook import *\n",
55
+ "\n",
56
+ "query = \"joker\"\n",
57
+ "\n",
58
+ "urls = search_images_ddg(query, max_images = 5 )\n",
59
+ "\n",
60
+ "len(urls)\n",
61
+ "#| export \n",
62
+ "# for url in urls : print(url)"
63
+ ]
64
+ },
65
+ {
66
+ "cell_type": "code",
67
+ "execution_count": 37,
68
+ "metadata": {
69
+ "slideshow": {
70
+ "slide_type": "fragment"
71
+ },
72
+ "tags": []
73
+ },
74
+ "outputs": [],
75
+ "source": [
76
+ "#| export \n",
77
+ "for i,url in enumerate(urls):\n",
78
+ " download_url(url,f\"data/{query}/{query}_{i+1}.jpg\")"
79
+ ]
80
+ },
81
+ {
82
+ "cell_type": "code",
83
+ "execution_count": 38,
84
+ "metadata": {},
85
+ "outputs": [],
86
+ "source": [
87
+ "#| export\n",
88
+ "import shutil \n",
89
+ "\n",
90
+ "shutil.rmtree(f\"data/{query}\")"
91
+ ]
92
+ },
93
+ {
94
+ "cell_type": "code",
95
+ "execution_count": 39,
96
+ "metadata": {},
97
+ "outputs": [],
98
+ "source": [
99
+ "# download_url(urls[0], 'images/bear.jpg')\n",
100
+ "# img = Image.open('images/bear.jpg')\n",
101
+ "# img.thumbnail((256,256))\n",
102
+ "# img"
103
+ ]
104
+ },
105
+ {
106
+ "cell_type": "code",
107
+ "execution_count": 40,
108
+ "metadata": {},
109
+ "outputs": [],
110
+ "source": [
111
+ "# import os\n",
112
+ "# rmdir only removes empty directory\n",
113
+ "# os.rmdir(f\"./{query}\")\n",
114
+ "# os.listdir(\".\")"
115
+ ]
116
+ },
117
+ {
118
+ "cell_type": "code",
119
+ "execution_count": 42,
120
+ "metadata": {},
121
+ "outputs": [],
122
+ "source": [
123
+ "!nbdev_export"
124
+ ]
125
+ },
126
+ {
127
+ "cell_type": "code",
128
+ "execution_count": null,
129
+ "metadata": {},
130
+ "outputs": [],
131
+ "source": []
132
+ }
133
+ ],
134
+ "metadata": {
135
+ "kernelspec": {
136
+ "display_name": "Python 3 (ipykernel)",
137
+ "language": "python",
138
+ "name": "python3"
139
+ },
140
+ "language_info": {
141
+ "codemirror_mode": {
142
+ "name": "ipython",
143
+ "version": 3
144
+ },
145
+ "file_extension": ".py",
146
+ "mimetype": "text/x-python",
147
+ "name": "python",
148
+ "nbconvert_exporter": "python",
149
+ "pygments_lexer": "ipython3",
150
+ "version": "3.10.10"
151
+ }
152
+ },
153
+ "nbformat": 4,
154
+ "nbformat_minor": 4
155
+ }