glenn-jocher commited on
Commit
46c43b7
1 Parent(s): 394131c

Creado con Colaboratory

Browse files
Files changed (1) hide show
  1. tutorial.ipynb +117 -121
tutorial.ipynb CHANGED
@@ -16,7 +16,7 @@
16
  "accelerator": "GPU",
17
  "widgets": {
18
  "application/vnd.jupyter.widget-state+json": {
19
- "9cb5be61e41144ef9dbc9339c2f46eb1": {
20
  "model_module": "@jupyter-widgets/controls",
21
  "model_name": "HBoxModel",
22
  "state": {
@@ -28,15 +28,15 @@
28
  "_view_count": null,
29
  "_view_module_version": "1.5.0",
30
  "box_style": "",
31
- "layout": "IPY_MODEL_a6ba87512fd04622b9948571d330d9c0",
32
  "_model_module": "@jupyter-widgets/controls",
33
  "children": [
34
- "IPY_MODEL_ed1a514c303b49c0a23745f4ff17344b",
35
- "IPY_MODEL_79edc4bba71748338f58660262c569a9"
36
  ]
37
  }
38
  },
39
- "a6ba87512fd04622b9948571d330d9c0": {
40
  "model_module": "@jupyter-widgets/base",
41
  "model_name": "LayoutModel",
42
  "state": {
@@ -87,12 +87,12 @@
87
  "left": null
88
  }
89
  },
90
- "ed1a514c303b49c0a23745f4ff17344b": {
91
  "model_module": "@jupyter-widgets/controls",
92
  "model_name": "FloatProgressModel",
93
  "state": {
94
  "_view_name": "ProgressView",
95
- "style": "IPY_MODEL_cbbf6780f4f048feb2644ed4e3fed9c7",
96
  "_dom_classes": [],
97
  "description": "100%",
98
  "_model_name": "FloatProgressModel",
@@ -107,30 +107,30 @@
107
  "min": 0,
108
  "description_tooltip": null,
109
  "_model_module": "@jupyter-widgets/controls",
110
- "layout": "IPY_MODEL_e40fc489500f4e4891025c59b2b1fa8d"
111
  }
112
  },
113
- "79edc4bba71748338f58660262c569a9": {
114
  "model_module": "@jupyter-widgets/controls",
115
  "model_name": "HTMLModel",
116
  "state": {
117
  "_view_name": "HTMLView",
118
- "style": "IPY_MODEL_191c687c120f4aab9a112697124fe444",
119
  "_dom_classes": [],
120
  "description": "",
121
  "_model_name": "HTMLModel",
122
  "placeholder": "​",
123
  "_view_module": "@jupyter-widgets/controls",
124
  "_model_module_version": "1.5.0",
125
- "value": " 781M/781M [05:01<00:00, 2.71MB/s]",
126
  "_view_count": null,
127
  "_view_module_version": "1.5.0",
128
  "description_tooltip": null,
129
  "_model_module": "@jupyter-widgets/controls",
130
- "layout": "IPY_MODEL_6b21efad6db4407eb253f819f279671a"
131
  }
132
  },
133
- "cbbf6780f4f048feb2644ed4e3fed9c7": {
134
  "model_module": "@jupyter-widgets/controls",
135
  "model_name": "ProgressStyleModel",
136
  "state": {
@@ -145,7 +145,7 @@
145
  "_model_module": "@jupyter-widgets/controls"
146
  }
147
  },
148
- "e40fc489500f4e4891025c59b2b1fa8d": {
149
  "model_module": "@jupyter-widgets/base",
150
  "model_name": "LayoutModel",
151
  "state": {
@@ -196,7 +196,7 @@
196
  "left": null
197
  }
198
  },
199
- "191c687c120f4aab9a112697124fe444": {
200
  "model_module": "@jupyter-widgets/controls",
201
  "model_name": "DescriptionStyleModel",
202
  "state": {
@@ -210,7 +210,7 @@
210
  "_model_module": "@jupyter-widgets/controls"
211
  }
212
  },
213
- "6b21efad6db4407eb253f819f279671a": {
214
  "model_module": "@jupyter-widgets/base",
215
  "model_name": "LayoutModel",
216
  "state": {
@@ -261,7 +261,7 @@
261
  "left": null
262
  }
263
  },
264
- "b434b178be4b41b3881e237e19f49b45": {
265
  "model_module": "@jupyter-widgets/controls",
266
  "model_name": "HBoxModel",
267
  "state": {
@@ -273,15 +273,15 @@
273
  "_view_count": null,
274
  "_view_module_version": "1.5.0",
275
  "box_style": "",
276
- "layout": "IPY_MODEL_72db749d8e3840238e1ceeec58a2cb4c",
277
  "_model_module": "@jupyter-widgets/controls",
278
  "children": [
279
- "IPY_MODEL_4459ef1aa32e422c9f1bc152a2aba7dc",
280
- "IPY_MODEL_b658312802194c1d86383e444af6ade4"
281
  ]
282
  }
283
  },
284
- "72db749d8e3840238e1ceeec58a2cb4c": {
285
  "model_module": "@jupyter-widgets/base",
286
  "model_name": "LayoutModel",
287
  "state": {
@@ -332,12 +332,12 @@
332
  "left": null
333
  }
334
  },
335
- "4459ef1aa32e422c9f1bc152a2aba7dc": {
336
  "model_module": "@jupyter-widgets/controls",
337
  "model_name": "FloatProgressModel",
338
  "state": {
339
  "_view_name": "ProgressView",
340
- "style": "IPY_MODEL_e24e99052e1a4f9ea794081fc6c42d80",
341
  "_dom_classes": [],
342
  "description": "100%",
343
  "_model_name": "FloatProgressModel",
@@ -352,30 +352,30 @@
352
  "min": 0,
353
  "description_tooltip": null,
354
  "_model_module": "@jupyter-widgets/controls",
355
- "layout": "IPY_MODEL_a08dda95df7441739105f5b59b8ea882"
356
  }
357
  },
358
- "b658312802194c1d86383e444af6ade4": {
359
  "model_module": "@jupyter-widgets/controls",
360
  "model_name": "HTMLModel",
361
  "state": {
362
  "_view_name": "HTMLView",
363
- "style": "IPY_MODEL_1abb5618e7134f0eb976857e126fda0d",
364
  "_dom_classes": [],
365
  "description": "",
366
  "_model_name": "HTMLModel",
367
  "placeholder": "​",
368
  "_view_module": "@jupyter-widgets/controls",
369
  "_model_module_version": "1.5.0",
370
- "value": " 21.1M/21.1M [22:51<00:00, 16.1kB/s]",
371
  "_view_count": null,
372
  "_view_module_version": "1.5.0",
373
  "description_tooltip": null,
374
  "_model_module": "@jupyter-widgets/controls",
375
- "layout": "IPY_MODEL_67e56da5b8574fc7a715422bdfeaeab4"
376
  }
377
  },
378
- "e24e99052e1a4f9ea794081fc6c42d80": {
379
  "model_module": "@jupyter-widgets/controls",
380
  "model_name": "ProgressStyleModel",
381
  "state": {
@@ -390,7 +390,7 @@
390
  "_model_module": "@jupyter-widgets/controls"
391
  }
392
  },
393
- "a08dda95df7441739105f5b59b8ea882": {
394
  "model_module": "@jupyter-widgets/base",
395
  "model_name": "LayoutModel",
396
  "state": {
@@ -441,7 +441,7 @@
441
  "left": null
442
  }
443
  },
444
- "1abb5618e7134f0eb976857e126fda0d": {
445
  "model_module": "@jupyter-widgets/controls",
446
  "model_name": "DescriptionStyleModel",
447
  "state": {
@@ -455,7 +455,7 @@
455
  "_model_module": "@jupyter-widgets/controls"
456
  }
457
  },
458
- "67e56da5b8574fc7a715422bdfeaeab4": {
459
  "model_module": "@jupyter-widgets/base",
460
  "model_name": "LayoutModel",
461
  "state": {
@@ -547,10 +547,10 @@
547
  "cell_type": "code",
548
  "metadata": {
549
  "id": "wbvMlHd_QwMG",
550
- "outputId": "7e5e09a2-892e-4999-9e6c-567ea329eb38",
551
  "colab": {
552
  "base_uri": "https://localhost:8080/"
553
- }
 
554
  },
555
  "source": [
556
  "!git clone https://github.com/ultralytics/yolov5 # clone repo\n",
@@ -563,7 +563,7 @@
563
  "clear_output()\n",
564
  "print('Setup complete. Using torch %s %s' % (torch.__version__, torch.cuda.get_device_properties(0) if torch.cuda.is_available() else 'CPU'))"
565
  ],
566
- "execution_count": null,
567
  "outputs": [
568
  {
569
  "output_type": "stream",
@@ -589,11 +589,11 @@
589
  "cell_type": "code",
590
  "metadata": {
591
  "id": "zR9ZbuQCH7FX",
592
- "outputId": "c9a308f7-2216-4805-8003-eca8dd0dc30d",
593
  "colab": {
594
  "base_uri": "https://localhost:8080/",
595
  "height": 534
596
- }
 
597
  },
598
  "source": [
599
  "!python detect.py --weights yolov5s.pt --img 640 --conf 0.25 --source data/images/\n",
@@ -668,34 +668,34 @@
668
  "cell_type": "code",
669
  "metadata": {
670
  "id": "WQPtK1QYVaD_",
671
- "outputId": "12268ac4-b9eb-44de-b3a7-2bd3e2fea46f",
672
  "colab": {
673
  "base_uri": "https://localhost:8080/",
674
  "height": 66,
675
  "referenced_widgets": [
676
- "9cb5be61e41144ef9dbc9339c2f46eb1",
677
- "a6ba87512fd04622b9948571d330d9c0",
678
- "ed1a514c303b49c0a23745f4ff17344b",
679
- "79edc4bba71748338f58660262c569a9",
680
- "cbbf6780f4f048feb2644ed4e3fed9c7",
681
- "e40fc489500f4e4891025c59b2b1fa8d",
682
- "191c687c120f4aab9a112697124fe444",
683
- "6b21efad6db4407eb253f819f279671a"
684
  ]
685
- }
 
686
  },
687
  "source": [
688
  "# Download COCO val2017\n",
689
  "torch.hub.download_url_to_file('https://github.com/ultralytics/yolov5/releases/download/v1.0/coco2017val.zip', 'tmp.zip')\n",
690
  "!unzip -q tmp.zip -d ../ && rm tmp.zip"
691
  ],
692
- "execution_count": null,
693
  "outputs": [
694
  {
695
  "output_type": "display_data",
696
  "data": {
697
  "application/vnd.jupyter.widget-view+json": {
698
- "model_id": "9cb5be61e41144ef9dbc9339c2f46eb1",
699
  "version_minor": 0,
700
  "version_major": 2
701
  },
@@ -720,47 +720,47 @@
720
  "cell_type": "code",
721
  "metadata": {
722
  "id": "X58w8JLpMnjH",
723
- "outputId": "30601131-102c-4702-fc13-572cc6087330",
724
  "colab": {
725
  "base_uri": "https://localhost:8080/"
726
- }
 
727
  },
728
  "source": [
729
  "# Run YOLOv5x on COCO val2017\n",
730
  "!python test.py --weights yolov5x.pt --data coco.yaml --img 640"
731
  ],
732
- "execution_count": null,
733
  "outputs": [
734
  {
735
  "output_type": "stream",
736
  "text": [
737
- "Namespace(augment=False, batch_size=32, conf_thres=0.001, data='./data/coco.yaml', device='', img_size=640, iou_thres=0.65, save_conf=False, save_dir='runs/test', save_json=True, save_txt=False, single_cls=False, task='val', verbose=False, weights=['yolov5x.pt'])\n",
738
  "Using torch 1.7.0+cu101 CUDA:0 (Tesla V100-SXM2-16GB, 16130MB)\n",
739
  "\n",
740
  "Downloading https://github.com/ultralytics/yolov5/releases/download/v3.1/yolov5x.pt to yolov5x.pt...\n",
741
- "100% 170M/170M [00:05<00:00, 32.2MB/s]\n",
742
  "\n",
743
  "Fusing layers... \n",
744
- "Model Summary: 284 layers, 8.89222e+07 parameters, 0 gradients\n",
745
- "Scanning labels ../coco/labels/val2017.cache (4952 found, 0 missing, 48 empty, 0 duplicate, for 5000 images): 5000it [00:00, 16239.02it/s]\n",
746
- " Class Images Targets P R [email protected] [email protected]:.95: 100% 157/157 [01:22<00:00, 1.89it/s]\n",
747
- " all 5e+03 3.63e+04 0.409 0.754 0.672 0.483\n",
748
- "Speed: 5.9/2.0/7.9 ms inference/NMS/total per 640x640 image at batch-size 32\n",
749
  "\n",
750
- "COCO mAP with pycocotools... saving runs/test/detections_val2017_yolov5x_results.json...\n",
751
  "loading annotations into memory...\n",
752
- "Done (t=0.73s)\n",
753
  "creating index...\n",
754
  "index created!\n",
755
  "Loading and preparing results...\n",
756
- "DONE (t=4.48s)\n",
757
  "creating index...\n",
758
  "index created!\n",
759
  "Running per image evaluation...\n",
760
  "Evaluate annotation type *bbox*\n",
761
- "DONE (t=86.55s).\n",
762
  "Accumulating evaluation results...\n",
763
- "DONE (t=13.15s).\n",
764
  " Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.492\n",
765
  " Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.676\n",
766
  " Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.534\n",
@@ -773,7 +773,7 @@
773
  " Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.493\n",
774
  " Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.723\n",
775
  " Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.812\n",
776
- "Results saved to runs/test\n"
777
  ],
778
  "name": "stdout"
779
  }
@@ -831,34 +831,34 @@
831
  "cell_type": "code",
832
  "metadata": {
833
  "id": "Knxi2ncxWffW",
834
- "outputId": "8c237907-6c62-4273-ce27-d5035fc6f5ac",
835
  "colab": {
836
  "base_uri": "https://localhost:8080/",
837
  "height": 66,
838
  "referenced_widgets": [
839
- "b434b178be4b41b3881e237e19f49b45",
840
- "72db749d8e3840238e1ceeec58a2cb4c",
841
- "4459ef1aa32e422c9f1bc152a2aba7dc",
842
- "b658312802194c1d86383e444af6ade4",
843
- "e24e99052e1a4f9ea794081fc6c42d80",
844
- "a08dda95df7441739105f5b59b8ea882",
845
- "1abb5618e7134f0eb976857e126fda0d",
846
- "67e56da5b8574fc7a715422bdfeaeab4"
847
  ]
848
- }
 
849
  },
850
  "source": [
851
  "# Download COCO128\n",
852
  "torch.hub.download_url_to_file('https://github.com/ultralytics/yolov5/releases/download/v1.0/coco128.zip', 'tmp.zip')\n",
853
  "!unzip -q tmp.zip -d ../ && rm tmp.zip"
854
  ],
855
- "execution_count": null,
856
  "outputs": [
857
  {
858
  "output_type": "display_data",
859
  "data": {
860
  "application/vnd.jupyter.widget-view+json": {
861
- "model_id": "b434b178be4b41b3881e237e19f49b45",
862
  "version_minor": 0,
863
  "version_major": 2
864
  },
@@ -907,27 +907,29 @@
907
  "cell_type": "code",
908
  "metadata": {
909
  "id": "1NcFxRcFdJ_O",
910
- "outputId": "a98e611d-979b-4e8c-d61c-8e219958ed33",
911
  "colab": {
912
  "base_uri": "https://localhost:8080/"
913
- }
 
914
  },
915
  "source": [
916
  "# Train YOLOv5s on COCO128 for 3 epochs\n",
917
  "!python train.py --img 640 --batch 16 --epochs 3 --data coco128.yaml --weights yolov5s.pt --nosave --cache"
918
  ],
919
- "execution_count": null,
920
  "outputs": [
921
  {
922
  "output_type": "stream",
923
  "text": [
924
  "Using torch 1.7.0+cu101 CUDA:0 (Tesla V100-SXM2-16GB, 16130MB)\n",
925
  "\n",
926
- "Namespace(adam=False, batch_size=16, bucket='', cache_images=True, cfg='', data='./data/coco128.yaml', device='', epochs=3, evolve=False, global_rank=-1, hyp='data/hyp.scratch.yaml', image_weights=False, img_size=[640, 640], local_rank=-1, log_imgs=10, logdir='runs/', multi_scale=False, name='', noautoanchor=False, nosave=True, notest=False, rect=False, resume=False, single_cls=False, sync_bn=False, total_batch_size=16, weights='yolov5s.pt', workers=8, world_size=1)\n",
927
- "Start Tensorboard with \"tensorboard --logdir runs/\", view at http://localhost:6006/\n",
928
- "2020-11-05 16:39:40.555423: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudart.so.10.1\n",
929
- "Install Weights & Biases for experiment logging via 'pip install wandb' (recommended)\n",
930
  "Hyperparameters {'lr0': 0.01, 'lrf': 0.2, 'momentum': 0.937, 'weight_decay': 0.0005, 'warmup_epochs': 3.0, 'warmup_momentum': 0.8, 'warmup_bias_lr': 0.1, 'box': 0.05, 'cls': 0.5, 'cls_pw': 1.0, 'obj': 1.0, 'obj_pw': 1.0, 'iou_t': 0.2, 'anchor_t': 4.0, 'fl_gamma': 0.0, 'hsv_h': 0.015, 'hsv_s': 0.7, 'hsv_v': 0.4, 'degrees': 0.0, 'translate': 0.1, 'scale': 0.5, 'shear': 0.0, 'perspective': 0.0, 'flipud': 0.0, 'fliplr': 0.5, 'mosaic': 1.0, 'mixup': 0.0}\n",
 
 
 
931
  "\n",
932
  " from n params module arguments \n",
933
  " 0 -1 1 3520 models.common.Focus [3, 32, 3] \n",
@@ -955,15 +957,15 @@
955
  " 22 [-1, 10] 1 0 models.common.Concat [1] \n",
956
  " 23 -1 1 1248768 models.common.BottleneckCSP [512, 512, 1, False] \n",
957
  " 24 [17, 20, 23] 1 229245 models.yolo.Detect [80, [[10, 13, 16, 30, 33, 23], [30, 61, 62, 45, 59, 119], [116, 90, 156, 198, 373, 326]], [128, 256, 512]]\n",
958
- "Model Summary: 191 layers, 7.46816e+06 parameters, 7.46816e+06 gradients\n",
959
  "\n",
960
  "Transferred 370/370 items from yolov5s.pt\n",
961
  "Optimizer groups: 62 .bias, 70 conv.weight, 59 other\n",
962
- "Scanning images: 100% 128/128 [00:00<00:00, 5375.86it/s]\n",
963
- "Scanning labels ../coco128/labels/train2017.cache (126 found, 0 missing, 2 empty, 0 duplicate, for 128 images): 128it [00:00, 15114.61it/s]\n",
964
- "Caching images (0.1GB): 100% 128/128 [00:00<00:00, 141.99it/s]\n",
965
- "Scanning labels ../coco128/labels/train2017.cache (126 found, 0 missing, 2 empty, 0 duplicate, for 128 images): 128it [00:00, 12572.50it/s]\n",
966
- "Caching images (0.1GB): 100% 128/128 [00:01<00:00, 79.68it/s] \n",
967
  "NumExpr defaulting to 2 threads.\n",
968
  "\n",
969
  "Analyzing anchors... anchors/target = 4.26, Best Possible Recall (BPR) = 0.9946\n",
@@ -973,22 +975,21 @@
973
  "Starting training for 3 epochs...\n",
974
  "\n",
975
  " Epoch gpu_mem box obj cls total targets img_size\n",
976
- " 0/2 3.22G 0.04202 0.06746 0.01503 0.1245 194 640: 100% 8/8 [00:03<00:00, 2.51it/s]\n",
977
- " Class Images Targets P R [email protected] [email protected]:.95: 100% 8/8 [00:03<00:00, 2.42it/s]\n",
978
- " all 128 929 0.405 0.762 0.701 0.449\n",
979
  "\n",
980
  " Epoch gpu_mem box obj cls total targets img_size\n",
981
- " 1/2 3.17G 0.04461 0.05873 0.01689 0.1202 142 640: 100% 8/8 [00:01<00:00, 4.14it/s]\n",
982
- " Class Images Targets P R [email protected] [email protected]:.95: 100% 8/8 [00:01<00:00, 6.49it/s]\n",
983
- " all 128 929 0.402 0.772 0.703 0.452\n",
984
  "\n",
985
  " Epoch gpu_mem box obj cls total targets img_size\n",
986
- " 2/2 3.17G 0.04445 0.06545 0.01666 0.1266 149 640: 100% 8/8 [00:01<00:00, 4.33it/s]\n",
987
- " Class Images Targets P R [email protected] [email protected]:.95: 100% 8/8 [00:02<00:00, 2.78it/s]\n",
988
- " all 128 929 0.395 0.766 0.701 0.455\n",
989
  "Optimizer stripped from runs/train/exp/weights/last.pt, 15.2MB\n",
990
- "Optimizer stripped from runs/train/exp/weights/best.pt, 15.2MB\n",
991
- "3 epochs completed in 0.005 hours.\n",
992
  "\n"
993
  ],
994
  "name": "stdout"
@@ -1140,10 +1141,9 @@
1140
  "id": "mcKoSIK2WSzj"
1141
  },
1142
  "source": [
1143
- "# Test all models\n",
1144
  "%%shell\n",
1145
- "for x in s m l x\n",
1146
- "do\n",
1147
  " python test.py --weights yolov5$x.pt --data coco.yaml --img 640\n",
1148
  "done"
1149
  ],
@@ -1156,26 +1156,22 @@
1156
  "id": "FGH0ZjkGjejy"
1157
  },
1158
  "source": [
1159
- "# Run unit tests\n",
1160
  "%%shell\n",
1161
- "# git clone https://github.com/ultralytics/yolov5\n",
1162
- "# cd yolov5\n",
1163
- "pip install -qr requirements.txt onnx\n",
1164
  "\n",
1165
- "export PYTHONPATH=\"$PWD\" # to run *.py. files in subdirectories\n",
1166
- "for x in yolov5s #yolov5m yolov5l yolov5x # models\n",
1167
- "do\n",
1168
- " rm -rf runs\n",
1169
- " python train.py --weights $x.pt --cfg $x.yaml --epochs 3 --img 320 --device 0 # train\n",
1170
- " for di in 0 cpu # inference devices\n",
1171
- " do\n",
1172
- " python detect.py --weights $x.pt --device $di # detect official\n",
1173
- " python detect.py --weights runs/train/exp/weights/last.pt --device $di # detect custom\n",
1174
- " python test.py --weights $x.pt --device $di # test official\n",
1175
- " python test.py --weights runs/train/exp/weights/last.pt --device $di # test custom\n",
1176
  " done\n",
1177
- " python models/yolo.py --cfg $x.yaml # inspect\n",
1178
- " python models/export.py --weights $x.pt --img 640 --batch 1 # export\n",
 
1179
  "done"
1180
  ],
1181
  "execution_count": null,
 
16
  "accelerator": "GPU",
17
  "widgets": {
18
  "application/vnd.jupyter.widget-state+json": {
19
+ "02ac0588602847eea00a0205f87bcce2": {
20
  "model_module": "@jupyter-widgets/controls",
21
  "model_name": "HBoxModel",
22
  "state": {
 
28
  "_view_count": null,
29
  "_view_module_version": "1.5.0",
30
  "box_style": "",
31
+ "layout": "IPY_MODEL_c472ea49806447a68b5a9221a4ddae85",
32
  "_model_module": "@jupyter-widgets/controls",
33
  "children": [
34
+ "IPY_MODEL_091fdf499bd44a80af7281d16da4aa93",
35
+ "IPY_MODEL_c79f69c959de4427ba102a87a9f46d80"
36
  ]
37
  }
38
  },
39
+ "c472ea49806447a68b5a9221a4ddae85": {
40
  "model_module": "@jupyter-widgets/base",
41
  "model_name": "LayoutModel",
42
  "state": {
 
87
  "left": null
88
  }
89
  },
90
+ "091fdf499bd44a80af7281d16da4aa93": {
91
  "model_module": "@jupyter-widgets/controls",
92
  "model_name": "FloatProgressModel",
93
  "state": {
94
  "_view_name": "ProgressView",
95
+ "style": "IPY_MODEL_c42ae5af74a0491187827d0a1fc259bb",
96
  "_dom_classes": [],
97
  "description": "100%",
98
  "_model_name": "FloatProgressModel",
 
107
  "min": 0,
108
  "description_tooltip": null,
109
  "_model_module": "@jupyter-widgets/controls",
110
+ "layout": "IPY_MODEL_5a90f72d3a2d46cb9ad915daa3ead8b4"
111
  }
112
  },
113
+ "c79f69c959de4427ba102a87a9f46d80": {
114
  "model_module": "@jupyter-widgets/controls",
115
  "model_name": "HTMLModel",
116
  "state": {
117
  "_view_name": "HTMLView",
118
+ "style": "IPY_MODEL_2a7ed6611da34662b10e37fd4f4e4438",
119
  "_dom_classes": [],
120
  "description": "",
121
  "_model_name": "HTMLModel",
122
  "placeholder": "​",
123
  "_view_module": "@jupyter-widgets/controls",
124
  "_model_module_version": "1.5.0",
125
+ "value": " 781M/781M [00:23&lt;00:00, 35.1MB/s]",
126
  "_view_count": null,
127
  "_view_module_version": "1.5.0",
128
  "description_tooltip": null,
129
  "_model_module": "@jupyter-widgets/controls",
130
+ "layout": "IPY_MODEL_fead0160658445bf9e966daa4481cad0"
131
  }
132
  },
133
+ "c42ae5af74a0491187827d0a1fc259bb": {
134
  "model_module": "@jupyter-widgets/controls",
135
  "model_name": "ProgressStyleModel",
136
  "state": {
 
145
  "_model_module": "@jupyter-widgets/controls"
146
  }
147
  },
148
+ "5a90f72d3a2d46cb9ad915daa3ead8b4": {
149
  "model_module": "@jupyter-widgets/base",
150
  "model_name": "LayoutModel",
151
  "state": {
 
196
  "left": null
197
  }
198
  },
199
+ "2a7ed6611da34662b10e37fd4f4e4438": {
200
  "model_module": "@jupyter-widgets/controls",
201
  "model_name": "DescriptionStyleModel",
202
  "state": {
 
210
  "_model_module": "@jupyter-widgets/controls"
211
  }
212
  },
213
+ "fead0160658445bf9e966daa4481cad0": {
214
  "model_module": "@jupyter-widgets/base",
215
  "model_name": "LayoutModel",
216
  "state": {
 
261
  "left": null
262
  }
263
  },
264
+ "cf1ab9fde7444d3e874fcd407ba8f0f8": {
265
  "model_module": "@jupyter-widgets/controls",
266
  "model_name": "HBoxModel",
267
  "state": {
 
273
  "_view_count": null,
274
  "_view_module_version": "1.5.0",
275
  "box_style": "",
276
+ "layout": "IPY_MODEL_9ee03f9c85f34155b2645e89c9211547",
277
  "_model_module": "@jupyter-widgets/controls",
278
  "children": [
279
+ "IPY_MODEL_933ebc451c09490aadf71afbbb3dff2a",
280
+ "IPY_MODEL_8e7c55cbca624432a84fa7ad8f3a4016"
281
  ]
282
  }
283
  },
284
+ "9ee03f9c85f34155b2645e89c9211547": {
285
  "model_module": "@jupyter-widgets/base",
286
  "model_name": "LayoutModel",
287
  "state": {
 
332
  "left": null
333
  }
334
  },
335
+ "933ebc451c09490aadf71afbbb3dff2a": {
336
  "model_module": "@jupyter-widgets/controls",
337
  "model_name": "FloatProgressModel",
338
  "state": {
339
  "_view_name": "ProgressView",
340
+ "style": "IPY_MODEL_dd62d83b35d04a178840772e82bd2f2e",
341
  "_dom_classes": [],
342
  "description": "100%",
343
  "_model_name": "FloatProgressModel",
 
352
  "min": 0,
353
  "description_tooltip": null,
354
  "_model_module": "@jupyter-widgets/controls",
355
+ "layout": "IPY_MODEL_d5c4f3d1c8b046e3a163faaa6b3a51ab"
356
  }
357
  },
358
+ "8e7c55cbca624432a84fa7ad8f3a4016": {
359
  "model_module": "@jupyter-widgets/controls",
360
  "model_name": "HTMLModel",
361
  "state": {
362
  "_view_name": "HTMLView",
363
+ "style": "IPY_MODEL_78d1da8efb504b03878ca9ce5b404006",
364
  "_dom_classes": [],
365
  "description": "",
366
  "_model_name": "HTMLModel",
367
  "placeholder": "​",
368
  "_view_module": "@jupyter-widgets/controls",
369
  "_model_module_version": "1.5.0",
370
+ "value": " 21.1M/21.1M [00:01&lt;00:00, 16.9MB/s]",
371
  "_view_count": null,
372
  "_view_module_version": "1.5.0",
373
  "description_tooltip": null,
374
  "_model_module": "@jupyter-widgets/controls",
375
+ "layout": "IPY_MODEL_d28208ba1213436a93926a01d99d97ae"
376
  }
377
  },
378
+ "dd62d83b35d04a178840772e82bd2f2e": {
379
  "model_module": "@jupyter-widgets/controls",
380
  "model_name": "ProgressStyleModel",
381
  "state": {
 
390
  "_model_module": "@jupyter-widgets/controls"
391
  }
392
  },
393
+ "d5c4f3d1c8b046e3a163faaa6b3a51ab": {
394
  "model_module": "@jupyter-widgets/base",
395
  "model_name": "LayoutModel",
396
  "state": {
 
441
  "left": null
442
  }
443
  },
444
+ "78d1da8efb504b03878ca9ce5b404006": {
445
  "model_module": "@jupyter-widgets/controls",
446
  "model_name": "DescriptionStyleModel",
447
  "state": {
 
455
  "_model_module": "@jupyter-widgets/controls"
456
  }
457
  },
458
+ "d28208ba1213436a93926a01d99d97ae": {
459
  "model_module": "@jupyter-widgets/base",
460
  "model_name": "LayoutModel",
461
  "state": {
 
547
  "cell_type": "code",
548
  "metadata": {
549
  "id": "wbvMlHd_QwMG",
 
550
  "colab": {
551
  "base_uri": "https://localhost:8080/"
552
+ },
553
+ "outputId": "888d5c41-00e9-47d8-d230-dded99325bea"
554
  },
555
  "source": [
556
  "!git clone https://github.com/ultralytics/yolov5 # clone repo\n",
 
563
  "clear_output()\n",
564
  "print('Setup complete. Using torch %s %s' % (torch.__version__, torch.cuda.get_device_properties(0) if torch.cuda.is_available() else 'CPU'))"
565
  ],
566
+ "execution_count": 1,
567
  "outputs": [
568
  {
569
  "output_type": "stream",
 
589
  "cell_type": "code",
590
  "metadata": {
591
  "id": "zR9ZbuQCH7FX",
 
592
  "colab": {
593
  "base_uri": "https://localhost:8080/",
594
  "height": 534
595
+ },
596
+ "outputId": "c9a308f7-2216-4805-8003-eca8dd0dc30d"
597
  },
598
  "source": [
599
  "!python detect.py --weights yolov5s.pt --img 640 --conf 0.25 --source data/images/\n",
 
668
  "cell_type": "code",
669
  "metadata": {
670
  "id": "WQPtK1QYVaD_",
 
671
  "colab": {
672
  "base_uri": "https://localhost:8080/",
673
  "height": 66,
674
  "referenced_widgets": [
675
+ "02ac0588602847eea00a0205f87bcce2",
676
+ "c472ea49806447a68b5a9221a4ddae85",
677
+ "091fdf499bd44a80af7281d16da4aa93",
678
+ "c79f69c959de4427ba102a87a9f46d80",
679
+ "c42ae5af74a0491187827d0a1fc259bb",
680
+ "5a90f72d3a2d46cb9ad915daa3ead8b4",
681
+ "2a7ed6611da34662b10e37fd4f4e4438",
682
+ "fead0160658445bf9e966daa4481cad0"
683
  ]
684
+ },
685
+ "outputId": "780d8f5f-766e-4b99-e370-11f9b884c27a"
686
  },
687
  "source": [
688
  "# Download COCO val2017\n",
689
  "torch.hub.download_url_to_file('https://github.com/ultralytics/yolov5/releases/download/v1.0/coco2017val.zip', 'tmp.zip')\n",
690
  "!unzip -q tmp.zip -d ../ && rm tmp.zip"
691
  ],
692
+ "execution_count": 2,
693
  "outputs": [
694
  {
695
  "output_type": "display_data",
696
  "data": {
697
  "application/vnd.jupyter.widget-view+json": {
698
+ "model_id": "02ac0588602847eea00a0205f87bcce2",
699
  "version_minor": 0,
700
  "version_major": 2
701
  },
 
720
  "cell_type": "code",
721
  "metadata": {
722
  "id": "X58w8JLpMnjH",
 
723
  "colab": {
724
  "base_uri": "https://localhost:8080/"
725
+ },
726
+ "outputId": "013935a5-ba81-4810-b723-0cb01cf7bc79"
727
  },
728
  "source": [
729
  "# Run YOLOv5x on COCO val2017\n",
730
  "!python test.py --weights yolov5x.pt --data coco.yaml --img 640"
731
  ],
732
+ "execution_count": 3,
733
  "outputs": [
734
  {
735
  "output_type": "stream",
736
  "text": [
737
+ "Namespace(augment=False, batch_size=32, conf_thres=0.001, data='./data/coco.yaml', device='', exist_ok=False, img_size=640, iou_thres=0.65, name='exp', project='runs/test', save_conf=False, save_json=True, save_txt=False, single_cls=False, task='val', verbose=False, weights=['yolov5x.pt'])\n",
738
  "Using torch 1.7.0+cu101 CUDA:0 (Tesla V100-SXM2-16GB, 16130MB)\n",
739
  "\n",
740
  "Downloading https://github.com/ultralytics/yolov5/releases/download/v3.1/yolov5x.pt to yolov5x.pt...\n",
741
+ "100% 170M/170M [00:05<00:00, 32.6MB/s]\n",
742
  "\n",
743
  "Fusing layers... \n",
744
+ "Model Summary: 484 layers, 88922205 parameters, 0 gradients\n",
745
+ "Scanning labels ../coco/labels/val2017.cache (4952 found, 0 missing, 48 empty, 0 duplicate, for 5000 images): 5000it [00:00, 14785.71it/s]\n",
746
+ " Class Images Targets P R [email protected] [email protected]:.95: 100% 157/157 [01:30<00:00, 1.74it/s]\n",
747
+ " all 5e+03 3.63e+04 0.409 0.754 0.672 0.484\n",
748
+ "Speed: 5.9/2.1/7.9 ms inference/NMS/total per 640x640 image at batch-size 32\n",
749
  "\n",
750
+ "Evaluating pycocotools mAP... saving runs/test/exp/yolov5x_predictions.json...\n",
751
  "loading annotations into memory...\n",
752
+ "Done (t=0.43s)\n",
753
  "creating index...\n",
754
  "index created!\n",
755
  "Loading and preparing results...\n",
756
+ "DONE (t=4.67s)\n",
757
  "creating index...\n",
758
  "index created!\n",
759
  "Running per image evaluation...\n",
760
  "Evaluate annotation type *bbox*\n",
761
+ "DONE (t=92.11s).\n",
762
  "Accumulating evaluation results...\n",
763
+ "DONE (t=13.24s).\n",
764
  " Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.492\n",
765
  " Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.676\n",
766
  " Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.534\n",
 
773
  " Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.493\n",
774
  " Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.723\n",
775
  " Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.812\n",
776
+ "Results saved to runs/test/exp\n"
777
  ],
778
  "name": "stdout"
779
  }
 
831
  "cell_type": "code",
832
  "metadata": {
833
  "id": "Knxi2ncxWffW",
 
834
  "colab": {
835
  "base_uri": "https://localhost:8080/",
836
  "height": 66,
837
  "referenced_widgets": [
838
+ "cf1ab9fde7444d3e874fcd407ba8f0f8",
839
+ "9ee03f9c85f34155b2645e89c9211547",
840
+ "933ebc451c09490aadf71afbbb3dff2a",
841
+ "8e7c55cbca624432a84fa7ad8f3a4016",
842
+ "dd62d83b35d04a178840772e82bd2f2e",
843
+ "d5c4f3d1c8b046e3a163faaa6b3a51ab",
844
+ "78d1da8efb504b03878ca9ce5b404006",
845
+ "d28208ba1213436a93926a01d99d97ae"
846
  ]
847
+ },
848
+ "outputId": "59f9a94b-21e1-4626-f36a-a8e1b1e5c8f6"
849
  },
850
  "source": [
851
  "# Download COCO128\n",
852
  "torch.hub.download_url_to_file('https://github.com/ultralytics/yolov5/releases/download/v1.0/coco128.zip', 'tmp.zip')\n",
853
  "!unzip -q tmp.zip -d ../ && rm tmp.zip"
854
  ],
855
+ "execution_count": 4,
856
  "outputs": [
857
  {
858
  "output_type": "display_data",
859
  "data": {
860
  "application/vnd.jupyter.widget-view+json": {
861
+ "model_id": "cf1ab9fde7444d3e874fcd407ba8f0f8",
862
  "version_minor": 0,
863
  "version_major": 2
864
  },
 
907
  "cell_type": "code",
908
  "metadata": {
909
  "id": "1NcFxRcFdJ_O",
 
910
  "colab": {
911
  "base_uri": "https://localhost:8080/"
912
+ },
913
+ "outputId": "138f2d1d-364c-405a-cf13-ea91a2aff915"
914
  },
915
  "source": [
916
  "# Train YOLOv5s on COCO128 for 3 epochs\n",
917
  "!python train.py --img 640 --batch 16 --epochs 3 --data coco128.yaml --weights yolov5s.pt --nosave --cache"
918
  ],
919
+ "execution_count": 5,
920
  "outputs": [
921
  {
922
  "output_type": "stream",
923
  "text": [
924
  "Using torch 1.7.0+cu101 CUDA:0 (Tesla V100-SXM2-16GB, 16130MB)\n",
925
  "\n",
926
+ "Namespace(adam=False, batch_size=16, bucket='', cache_images=True, cfg='', data='./data/coco128.yaml', device='', epochs=3, evolve=False, exist_ok=False, global_rank=-1, hyp='data/hyp.scratch.yaml', image_weights=False, img_size=[640, 640], local_rank=-1, log_imgs=16, multi_scale=False, name='exp', noautoanchor=False, nosave=True, notest=False, project='runs/train', rect=False, resume=False, save_dir='runs/train/exp', single_cls=False, sync_bn=False, total_batch_size=16, weights='yolov5s.pt', workers=8, world_size=1)\n",
927
+ "Start Tensorboard with \"tensorboard --logdir runs/train\", view at http://localhost:6006/\n",
928
+ "2020-11-20 11:45:17.042357: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudart.so.10.1\n",
 
929
  "Hyperparameters {'lr0': 0.01, 'lrf': 0.2, 'momentum': 0.937, 'weight_decay': 0.0005, 'warmup_epochs': 3.0, 'warmup_momentum': 0.8, 'warmup_bias_lr': 0.1, 'box': 0.05, 'cls': 0.5, 'cls_pw': 1.0, 'obj': 1.0, 'obj_pw': 1.0, 'iou_t': 0.2, 'anchor_t': 4.0, 'fl_gamma': 0.0, 'hsv_h': 0.015, 'hsv_s': 0.7, 'hsv_v': 0.4, 'degrees': 0.0, 'translate': 0.1, 'scale': 0.5, 'shear': 0.0, 'perspective': 0.0, 'flipud': 0.0, 'fliplr': 0.5, 'mosaic': 1.0, 'mixup': 0.0}\n",
930
+ "Downloading https://github.com/ultralytics/yolov5/releases/download/v3.1/yolov5s.pt to yolov5s.pt...\n",
931
+ "100% 14.5M/14.5M [00:01<00:00, 14.8MB/s]\n",
932
+ "\n",
933
  "\n",
934
  " from n params module arguments \n",
935
  " 0 -1 1 3520 models.common.Focus [3, 32, 3] \n",
 
957
  " 22 [-1, 10] 1 0 models.common.Concat [1] \n",
958
  " 23 -1 1 1248768 models.common.BottleneckCSP [512, 512, 1, False] \n",
959
  " 24 [17, 20, 23] 1 229245 models.yolo.Detect [80, [[10, 13, 16, 30, 33, 23], [30, 61, 62, 45, 59, 119], [116, 90, 156, 198, 373, 326]], [128, 256, 512]]\n",
960
+ "Model Summary: 283 layers, 7468157 parameters, 7468157 gradients\n",
961
  "\n",
962
  "Transferred 370/370 items from yolov5s.pt\n",
963
  "Optimizer groups: 62 .bias, 70 conv.weight, 59 other\n",
964
+ "Scanning images: 100% 128/128 [00:00<00:00, 5395.63it/s]\n",
965
+ "Scanning labels ../coco128/labels/train2017.cache (126 found, 0 missing, 2 empty, 0 duplicate, for 128 images): 128it [00:00, 13972.28it/s]\n",
966
+ "Caching images (0.1GB): 100% 128/128 [00:00<00:00, 173.55it/s]\n",
967
+ "Scanning labels ../coco128/labels/train2017.cache (126 found, 0 missing, 2 empty, 0 duplicate, for 128 images): 128it [00:00, 8693.98it/s]\n",
968
+ "Caching images (0.1GB): 100% 128/128 [00:00<00:00, 133.30it/s]\n",
969
  "NumExpr defaulting to 2 threads.\n",
970
  "\n",
971
  "Analyzing anchors... anchors/target = 4.26, Best Possible Recall (BPR) = 0.9946\n",
 
975
  "Starting training for 3 epochs...\n",
976
  "\n",
977
  " Epoch gpu_mem box obj cls total targets img_size\n",
978
+ " 0/2 5.24G 0.04202 0.06745 0.01503 0.1245 194 640: 100% 8/8 [00:03<00:00, 2.01it/s]\n",
979
+ " Class Images Targets P R [email protected] [email protected]:.95: 100% 8/8 [00:03<00:00, 2.40it/s]\n",
980
+ " all 128 929 0.404 0.758 0.701 0.45\n",
981
  "\n",
982
  " Epoch gpu_mem box obj cls total targets img_size\n",
983
+ " 1/2 5.12G 0.04461 0.05874 0.0169 0.1202 142 640: 100% 8/8 [00:01<00:00, 4.14it/s]\n",
984
+ " Class Images Targets P R [email protected] [email protected]:.95: 100% 8/8 [00:01<00:00, 5.75it/s]\n",
985
+ " all 128 929 0.403 0.772 0.703 0.453\n",
986
  "\n",
987
  " Epoch gpu_mem box obj cls total targets img_size\n",
988
+ " 2/2 5.12G 0.04445 0.06545 0.01667 0.1266 149 640: 100% 8/8 [00:01<00:00, 4.15it/s]\n",
989
+ " Class Images Targets P R [email protected] [email protected]:.95: 100% 8/8 [00:06<00:00, 1.18it/s]\n",
990
+ " all 128 929 0.395 0.767 0.702 0.452\n",
991
  "Optimizer stripped from runs/train/exp/weights/last.pt, 15.2MB\n",
992
+ "3 epochs completed in 0.006 hours.\n",
 
993
  "\n"
994
  ],
995
  "name": "stdout"
 
1141
  "id": "mcKoSIK2WSzj"
1142
  },
1143
  "source": [
1144
+ "# Test all\n",
1145
  "%%shell\n",
1146
+ "for x in s m l x; do\n",
 
1147
  " python test.py --weights yolov5$x.pt --data coco.yaml --img 640\n",
1148
  "done"
1149
  ],
 
1156
  "id": "FGH0ZjkGjejy"
1157
  },
1158
  "source": [
1159
+ "# Unit tests\n",
1160
  "%%shell\n",
1161
+ "export PYTHONPATH=\"$PWD\" # to run *.py. files in subdirectories\n",
 
 
1162
  "\n",
1163
+ "for m in yolov5s; do # models\n",
1164
+ " python train.py --weights $m.pt --epochs 3 --img 320 --device 0 # train pretrained\n",
1165
+ " python train.py --cfg $m.yaml --epochs 3 --img 320 --device 0 # train scratch\n",
1166
+ " for d in 0 cpu; do # devices\n",
1167
+ " python detect.py --weights $m.pt --device $d # detect official\n",
1168
+ " python detect.py --weights runs/train/exp/weights/best.pt --device $d # detect custom\n",
1169
+ " python test.py --weights $m.pt --device $d # test official\n",
1170
+ " python test.py --weights runs/train/exp/weights/best.pt --device $d # test custom\n",
 
 
 
1171
  " done\n",
1172
+ " python hubconf.py # hub\n",
1173
+ " python models/yolo.py --cfg $m.yaml # inspect\n",
1174
+ " python models/export.py --weights $m.pt --img 640 --batch 1 # export\n",
1175
  "done"
1176
  ],
1177
  "execution_count": null,