Created using Colaboratory

This commit is contained in:
Glenn Jocher committed 2020-07-11 15:16:24 -07:00
1 parent a5818b280e
commit 9d7c7784f2
1 file changed
+228 -261
+228 -261
View File
@@ -6,6 +6,7 @@
"name": "YOLOv5 Tutorial",
"provenance": [],
"collapsed_sections": [],
"toc_visible": true,
"include_colab_link": true
},
"kernelspec": {
@@ -34,7 +35,8 @@
"source": [
"<img src=\"https://user-images.githubusercontent.com/26833433/82952157-51b7db00-9f5d-11ea-8f4b-dda1ffecf992.jpg\">\n",
"\n",
"This notebook was developed by Ultralytics LLC, and **is freely available for redistribution under the GPL-3.0 license**. For more information please visit https://github.com/ultralytics/yolov5 and https://www.ultralytics.com."
"This notebook was written by Ultralytics LLC, and is freely available for redistribution under the [GPL-3.0 license](https://choosealicense.com/licenses/gpl-3.0/). \n",
"For more information please visit https://github.com/ultralytics/yolov5 and https://www.ultralytics.com."
]
},
{
@@ -44,7 +46,7 @@
"colab_type": "text"
},
"source": [
"#Initial Setup\n",
"# Setup\n",
"\n",
"Clone repo, install dependencies, `%cd` into `./yolov5` folder and check GPU."
]
@@ -54,11 +56,15 @@
"metadata": {
"id": "wbvMlHd_QwMG",
"colab_type": "code",
"colab": {}
"colab": {
"base_uri": "https://localhost:8080/",
"height": 53
},
"outputId": "669566b2-391f-4596-f290-110e2e177946"
},
"source": [
"!git clone https://github.com/ultralytics/yolov5 # clone repo\n",
"!pip install -r yolov5/requirements.txt # install dependencies\n",
"!pip install -qr yolov5/requirements.txt # install dependencies (ignore errors)\n",
"%cd yolov5\n",
"\n",
"import torch\n",
@@ -68,8 +74,16 @@
"clear_output()\n",
"print('Setup complete. Using torch %s %s' % (torch.__version__, torch.cuda.get_device_properties(0) if torch.cuda.is_available() else 'CPU'))"
],
"execution_count": 0,
"outputs": []
"execution_count": 1,
"outputs": [
{
"output_type": "stream",
"text": [
"Setup complete. Using torch 1.5.1+cu101 _CudaDeviceProperties(name='Tesla T4', major=7, minor=5, total_memory=15079MB, multi_processor_count=40)\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "markdown",
@@ -78,9 +92,9 @@
"colab_type": "text"
},
"source": [
"#1. Inference\n",
"# 1. Inference\n",
"\n",
"Run inference with a pretrained checkpoint on contents of `/inference/images` folder. Models are downloaded automatically from our Google Drive [folder](https://drive.google.com/open?id=1Drs_Aiu7xx6S-ix95f9kNsA6ueKRpN2J) if available."
"Run inference with a pretrained checkpoint on contents of `/inference/images` folder. Models are auto-downloaded from [Google Drive](https://drive.google.com/open?id=1Drs_Aiu7xx6S-ix95f9kNsA6ueKRpN2J)."
]
},
{
@@ -88,17 +102,17 @@
"metadata": {
"id": "zR9ZbuQCH7FX",
"colab_type": "code",
"outputId": "528fcc04-2393-437a-84d2-092becbaefbe",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 488
}
},
"outputId": "528fcc04-2393-437a-84d2-092becbaefbe"
},
"source": [
"!python detect.py --weights yolov5s.pt --img 416 --conf 0.4 --source ./inference/images/\n",
"!python detect.py --weights yolov5s.pt --img 416 --conf 0.4 --source inference/images/\n",
"Image(filename='inference/output/zidane.jpg', width=600)"
],
"execution_count": 14,
"execution_count": null,
"outputs": [
{
"output_type": "stream",
@@ -150,14 +164,14 @@
},
"source": [
"# Example syntax (do not run cell)\n",
"!python detect.py --source ./file.jpg # image \n",
" ./file.mp4 # video\n",
" ./dir # directory\n",
"!python detect.py --source file.jpg # image \n",
" file.mp4 # video\n",
" dir/ # directory\n",
" 0 # webcam\n",
" 'rtsp://170.93.143.139/rtplive/470011e600ef003a004ee33696235daa' # rtsp\n",
" 'http://112.50.243.8/PLTV/88888888/224/3221225900/1.m3u8' # http"
],
"execution_count": 0,
"execution_count": null,
"outputs": []
},
{
@@ -167,8 +181,8 @@
"colab_type": "text"
},
"source": [
"#2. Test\n",
"Test a model on COCO val or test-dev dataset to determine trained accuracy. Models are downloaded automatically from our Google Drive [folder](https://drive.google.com/open?id=1Drs_Aiu7xx6S-ix95f9kNsA6ueKRpN2J) if available. To show results by class use the `--verbose` flag. Note that `pycocotools` metrics may be 1-2% better than the equivalent repo metrics, as is visible below, due to slight differences in mAP computation."
"# 2. Test\n",
"Test a model on COCO val or test-dev dataset to determine trained accuracy. Models are auto-downloaded from [Google Drive](https://drive.google.com/open?id=1Drs_Aiu7xx6S-ix95f9kNsA6ueKRpN2J). To show results by class use the `--verbose` flag. Note that `pycocotools` metrics may be 1-2% better than the equivalent repo metrics, as is visible below, due to slight differences in mAP computation."
]
},
{
@@ -178,7 +192,7 @@
"colab_type": "text"
},
"source": [
"###2.1 val2017\n",
"### 2.1 val2017\n",
"Download COCO val 2017 dataset, 1GB, 5000 images, and test model accuracy."
]
},
@@ -191,80 +205,19 @@
"base_uri": "https://localhost:8080/",
"height": 33
},
"outputId": "e49d6899-0feb-4bc7-e384-513c7d384060"
"outputId": "df037a5d-efae-4687-9ff7-22a48fd7f801"
},
"source": [
"# Download COCO val2017\n",
"gdrive_download('1Y6Kou6kEB0ZEMCCpJSKStCor4KAReE43','coco2017val.zip') # val2017 dataset\n",
"!mv ./coco ../ # move folder alongside /yolov5"
],
"execution_count": 7,
"execution_count": 10,
"outputs": [
{
"output_type": "stream",
"text": [
"Downloading https://drive.google.com/uc?export=download&id=1Y6Kou6kEB0ZEMCCpJSKStCor4KAReE43 as coco2017val.zip... unzipping... Done (37.1s)\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "WBWS_QSc__se",
"colab_type": "code",
"outputId": "02b54431-b993-4acd-c8a3-9c3231662718",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 602
}
},
"source": [
"# Run YOLOv5s on COCO val2017\n",
"!python test.py --weights yolov5s.pt --data ./data/coco.yaml --img 640"
],
"execution_count": 8,
"outputs": [
{
"output_type": "stream",
"text": [
"Namespace(augment=False, batch_size=32, conf_thres=0.001, data='././data/coco.yaml', device='', img_size=640, iou_thres=0.65, save_json=True, single_cls=False, task='val', verbose=False, weights='yolov5s.pt')\n",
"Using CUDA device0 _CudaDeviceProperties(name='Tesla T4', total_memory=15079MB)\n",
"\n",
"Model Summary: 165 layers, 7.07417e+06 parameters, 7.07417e+06 gradients\n",
"Caching labels ../coco/val2017.txt (4952 found, 48 missing, 0 empty, 0 duplicate, for 5000 images): 100% 5000/5000 [00:00<00:00, 7822.09it/s]\n",
"Saving labels to ../coco/labels/val2017.npy for faster future loading\n",
" Class Images Targets P R mAP@.5 mAP@.5:.95: 100% 157/157 [01:33<00:00, 1.67it/s]\n",
" all 5e+03 3.63e+04 0.334 0.633 0.534 0.336\n",
"Speed: 6.0/2.9/8.9 ms inference/NMS/total per 640x640 image at batch-size 32\n",
"\n",
"COCO mAP with pycocotools... saving detections_val2017_yolov5s_results.json...\n",
"loading annotations into memory...\n",
"Done (t=0.41s)\n",
"creating index...\n",
"index created!\n",
"Loading and preparing results...\n",
"DONE (t=5.70s)\n",
"creating index...\n",
"index created!\n",
"Running per image evaluation...\n",
"Evaluate annotation type *bbox*\n",
"DONE (t=89.04s).\n",
"Accumulating evaluation results...\n",
"DONE (t=14.04s).\n",
" Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.352\n",
" Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.544\n",
" Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.378\n",
" Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.188\n",
" Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.397\n",
" Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.459\n",
" Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.296\n",
" Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.496\n",
" Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.557\n",
" Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.358\n",
" Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.618\n",
" Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.700\n"
"Downloading https://drive.google.com/uc?export=download&id=1Y6Kou6kEB0ZEMCCpJSKStCor4KAReE43 as coco2017val.zip... unzipping... Done (11.2s)\n"
],
"name": "stdout"
}
@@ -275,56 +228,56 @@
"metadata": {
"id": "X58w8JLpMnjH",
"colab_type": "code",
"outputId": "1cc32887-1fe3-4079-f66e-b6b756f96527",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 586
}
"height": 606
},
"outputId": "8c62a086-e312-46d1-b475-d90542eae545"
},
"source": [
"# Run YOLOv5x on COCO val2017\n",
"!python test.py --weights yolov5x.pt --data ./data/coco.yaml --img 640"
"!python test.py --weights yolov5x.pt --data coco.yaml --img 672"
],
"execution_count": 10,
"execution_count": 15,
"outputs": [
{
"output_type": "stream",
"text": [
"Namespace(augment=False, batch_size=32, conf_thres=0.001, data='././data/coco.yaml', device='', img_size=640, iou_thres=0.65, save_json=True, single_cls=False, task='val', verbose=False, weights='yolov5x.pt')\n",
"Namespace(augment=False, batch_size=32, conf_thres=0.001, data='./data/coco.yaml', device='', img_size=672, iou_thres=0.65, merge=False, save_json=True, single_cls=False, task='val', verbose=False, weights=['yolov5x.pt'])\n",
"Using CUDA device0 _CudaDeviceProperties(name='Tesla T4', total_memory=15079MB)\n",
"\n",
"Model Summary: 381 layers, 9.59219e+07 parameters, 9.59219e+07 gradients\n",
"Caching labels ../coco/labels/val2017.npy (4952 found, 0 missing, 48 empty, 0 duplicate, for 5000 images): 100% 5000/5000 [00:00<00:00, 16516.13it/s]\n",
" Class Images Targets P R mAP@.5 mAP@.5:.95: 100% 157/157 [05:05<00:00, 1.95s/it]\n",
" all 5e+03 3.63e+04 0.393 0.742 0.652 0.455\n",
"Speed: 51.1/2.2/53.3 ms inference/NMS/total per 640x640 image at batch-size 32\n",
"Fusing layers... Model Summary: 284 layers, 8.89222e+07 parameters, 8.89222e+07 gradients\n",
"Scanning labels ../coco/labels/val2017.cache (4952 found, 0 missing, 48 empty, 0 duplicate, for 5000 images): 100% 5000/5000 [00:00<00:00, 22899.17it/s]\n",
" Class Images Targets P R mAP@.5 mAP@.5:.95: 100% 157/157 [02:38<00:00, 1.01s/it]\n",
" all 5e+03 3.63e+04 0.426 0.746 0.66 0.469\n",
"Speed: 22.3/1.7/24.0 ms inference/NMS/total per 672x672 image at batch-size 32\n",
"\n",
"COCO mAP with pycocotools... saving detections_val2017_yolov5x_results.json...\n",
"COCO mAP with pycocotools... saving detections_val2017__results.json...\n",
"loading annotations into memory...\n",
"Done (t=0.39s)\n",
"Done (t=0.41s)\n",
"creating index...\n",
"index created!\n",
"Loading and preparing results...\n",
"DONE (t=3.59s)\n",
"DONE (t=4.39s)\n",
"creating index...\n",
"index created!\n",
"Running per image evaluation...\n",
"Evaluate annotation type *bbox*\n",
"DONE (t=79.47s).\n",
"DONE (t=76.56s).\n",
"Accumulating evaluation results...\n",
"DONE (t=12.20s).\n",
" Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.470\n",
" Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.659\n",
" Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.515\n",
" Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.310\n",
" Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.516\n",
" Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.610\n",
" Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.362\n",
" Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.597\n",
" Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.656\n",
" Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.504\n",
" Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.704\n",
" Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.787\n"
"DONE (t=11.02s).\n",
" Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.484\n",
" Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.668\n",
" Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.528\n",
" Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.311\n",
" Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.534\n",
" Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.628\n",
" Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.371\n",
" Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.609\n",
" Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.662\n",
" Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.501\n",
" Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.714\n",
" Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.807\n"
],
"name": "stdout"
}
@@ -337,7 +290,7 @@
"colab_type": "text"
},
"source": [
"###2.2 test-dev2017\n",
"### 2.2 test-dev2017\n",
"Download COCO test2017 dataset, 7GB, 40,000 images, to test model accuracy on test-dev set, 20,000 images. Results are saved to a `*.json` file which can be submitted to the evaluation server at https://competitions.codalab.org/competitions/20794."
]
},
@@ -354,7 +307,7 @@
"!f=\"test2017.zip\" && curl http://images.cocodataset.org/zips/$f -o $f && unzip -q $f && rm $f # 7GB, 41k images\n",
"!mv ./test2017 ./coco/images && mv ./coco ../ # move images into /coco and move /coco alongside /yolov5"
],
"execution_count": 0,
"execution_count": null,
"outputs": []
},
{
@@ -368,7 +321,7 @@
"# Run YOLOv5s on COCO test-dev2017 with argument --task test\n",
"!python test.py --weights yolov5s.pt --data ./data/coco.yaml --task test"
],
"execution_count": 0,
"execution_count": null,
"outputs": []
},
{
@@ -380,7 +333,7 @@
"source": [
"# 3. Train\n",
"\n",
"Download the 128-image tutorial training dataset `./data/coco128.yaml`, start tensorboard and train a `yolov5s.yaml` model for **5 epochs**. Note that actual training is typically much longer, around **300-1000 epochs**, depending on your dataset."
"Download https://www.kaggle.com/ultralytics/coco128, a small 128-image tutorial dataset, start tensorboard and train YOLOv5s from a pretrained checkpoint for 3 epochs (actual training is much longer, around **300-1000 epochs**, depending on your dataset)."
]
},
{
@@ -388,28 +341,40 @@
"metadata": {
"id": "Knxi2ncxWffW",
"colab_type": "code",
"outputId": "cbb574a9-861d-4f47-ca0c-32166bd3361e",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 33
}
},
"outputId": "35815e93-7d6e-4fee-c050-a4a565d51648"
},
"source": [
"# Download tutorial dataset coco128.yaml\n",
"gdrive_download('1n_oKgR81BJtqk75b00eAjdv03qVCQn2f','coco128.zip') # tutorial dataset\n",
"# Download coco128\n",
"gdrive_download('1n_oKgR81BJtqk75b00eAjdv03qVCQn2f','coco128.zip') # coco128 dataset\n",
"!mv ./coco128 ../ # move folder alongside /yolov5"
],
"execution_count": 2,
"execution_count": 16,
"outputs": [
{
"output_type": "stream",
"text": [
"Downloading https://drive.google.com/uc?export=download&id=1n_oKgR81BJtqk75b00eAjdv03qVCQn2f as coco128.zip... unzipping... Done (5.8s)\n"
"Downloading https://drive.google.com/uc?export=download&id=1n_oKgR81BJtqk75b00eAjdv03qVCQn2f as coco128.zip... unzipping... Done (5.3s)\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "_pOkGLv1dMqh",
"colab_type": "text"
},
"source": [
"Train a YOLOv5s model on coco128 by specifying model config file `--cfg models/yolo5s.yaml`, and dataset config file `--data data/coco128.yaml`. Start training from pretrained `--weights yolov5s.pt`, or from randomly initialized `--weights ''`. Pretrained weights are auto-downloaded from [Google Drive](https://drive.google.com/open?id=1Drs_Aiu7xx6S-ix95f9kNsA6ueKRpN2J).\n",
"\n",
"**All training results are saved to `runs/exp0`** for the first experiment, then `runs/exp1`, `runs/exp2` etc. for subsequent experiments.\n"
]
},
{
"cell_type": "code",
"metadata": {
@@ -418,115 +383,98 @@
"colab": {}
},
"source": [
"# Start tensorboard\n",
"# Start tensorboard (optional)\n",
"%load_ext tensorboard\n",
"%tensorboard --logdir runs"
],
"execution_count": 0,
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "_pOkGLv1dMqh",
"colab_type": "text"
},
"source": [
"Train a YOLOv5s model on the coco128 dataset by specifying model configuration file `--cfg ./models/yolo5s.yaml`, and a dataset configuration file `--data ./data/coco128.yaml`. Start training from pretrained `--weights yolov5s.pt`, or from scratch (randomly initialized weights) using `--weights ''`. Pretrained checkpoints are downloaded automatically from our Google Drive [folder](https://drive.google.com/open?id=1Drs_Aiu7xx6S-ix95f9kNsA6ueKRpN2J) if available.\n"
]
},
{
"cell_type": "code",
"metadata": {
"id": "1NcFxRcFdJ_O",
"colab_type": "code",
"outputId": "836944be-b677-4614-889b-da120cda0304",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 1000
}
},
"outputId": "121b5b2e-bc8e-4648-ee1c-8d2795176db6"
},
"source": [
"# Train YOLOv5s on coco128 for 5 epochs\n",
"!python train.py --img 640 --batch 16 --epochs 5 --data ./data/coco128.yaml --cfg ./models/yolov5s.yaml --weights yolov5s.pt --name tutorial --nosave --cache"
"# Train YOLOv5s on coco128 for 3 epochs\n",
"!python train.py --img 640 --batch 16 --epochs 3 --data coco128.yaml --cfg yolov5s.yaml --weights yolov5s.pt --nosave --cache"
],
"execution_count": 5,
"execution_count": 24,
"outputs": [
{
"output_type": "stream",
"text": [
"Apex recommended for faster mixed precision training: https://github.com/NVIDIA/apex\n",
"{'lr0': 0.01, 'momentum': 0.937, 'weight_decay': 0.0005, 'giou': 0.05, 'cls': 0.58, '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.014, 'hsv_s': 0.68, 'hsv_v': 0.36, 'degrees': 0.0, 'translate': 0.0, 'scale': 0.5, 'shear': 0.0}\n",
"Namespace(adam=False, batch_size=16, bucket='', cache_images=True, cfg='././models/yolov5s.yaml', data='././data/coco128.yaml', device='', epochs=5, evolve=False, img_size=[640], multi_scale=False, name='tutorial', nosave=True, notest=False, rect=False, resume=False, single_cls=False, weights='yolov5s.pt')\n",
"Namespace(batch_size=16, bucket='', cache_images=True, cfg='./models/yolov5s.yaml', data='./data/coco128.yaml', device='', epochs=3, evolve=False, hyp='', img_size=[640], multi_scale=False, name='', noautoanchor=False, nosave=True, notest=False, rect=False, resume=False, single_cls=False, weights='yolov5s.pt')\n",
"Using CUDA device0 _CudaDeviceProperties(name='Tesla T4', total_memory=15079MB)\n",
"\n",
"2020-06-14 19:45:19.668043: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1\n",
"2020-07-11 20:37:09.422496: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1\n",
"Start Tensorboard with \"tensorboard --logdir=runs\", view at http://localhost:6006/\n",
"Hyperparameters {'optimizer': 'SGD', 'lr0': 0.01, 'momentum': 0.937, 'weight_decay': 0.0005, 'giou': 0.05, 'cls': 0.58, '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.014, 'hsv_s': 0.68, 'hsv_v': 0.36, 'degrees': 0.0, 'translate': 0.0, 'scale': 0.5, 'shear': 0.0}\n",
"\n",
" from n params module arguments \n",
" 0 -1 1 3520 models.common.Focus [3, 32, 3] \n",
" 1 -1 1 18560 models.common.Conv [32, 64, 3, 2] \n",
" 2 -1 1 20672 models.common.Bottleneck [64, 64] \n",
" 3 -1 1 73984 models.common.Conv [64, 128, 3, 2] \n",
" 4 -1 1 161152 models.common.BottleneckCSP [128, 128, 3] \n",
" 5 -1 1 295424 models.common.Conv [128, 256, 3, 2] \n",
" 6 -1 1 641792 models.common.BottleneckCSP [256, 256, 3] \n",
" 7 -1 1 1180672 models.common.Conv [256, 512, 3, 2] \n",
" 8 -1 1 656896 models.common.SPP [512, 512, [5, 9, 13]] \n",
" 9 -1 1 1905152 models.common.BottleneckCSP [512, 512, 2] \n",
" 10 -1 1 1248768 models.common.BottleneckCSP [512, 512, 1, False] \n",
" 11 -1 1 130815 torch.nn.modules.conv.Conv2d [512, 255, 1, 1] \n",
" 12 -2 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest'] \n",
" 13 [-1, 6] 1 0 models.common.Concat [1] \n",
" 14 -1 1 197120 models.common.Conv [768, 256, 1, 1] \n",
" 15 -1 1 313088 models.common.BottleneckCSP [256, 256, 1, False] \n",
" 16 -1 1 65535 torch.nn.modules.conv.Conv2d [256, 255, 1, 1] \n",
" 17 -2 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest'] \n",
" 18 [-1, 4] 1 0 models.common.Concat [1] \n",
" 19 -1 1 49408 models.common.Conv [384, 128, 1, 1] \n",
" 20 -1 1 78720 models.common.BottleneckCSP [128, 128, 1, False] \n",
" 21 -1 1 32895 torch.nn.modules.conv.Conv2d [128, 255, 1, 1] \n",
" 22 [-1, 16, 11] 1 0 models.yolo.Detect [80, [[10, 13, 16, 30, 33, 23], [30, 61, 62, 45, 59, 119], [116, 90, 156, 198, 373, 326]]]\n",
"Model Summary: 165 layers, 7.07417e+06 parameters, 7.07417e+06 gradients\n",
" from n params module arguments \n",
" 0 -1 1 3520 models.common.Focus [3, 32, 3] \n",
" 1 -1 1 18560 models.common.Conv [32, 64, 3, 2] \n",
" 2 -1 1 19904 models.common.BottleneckCSP [64, 64, 1] \n",
" 3 -1 1 73984 models.common.Conv [64, 128, 3, 2] \n",
" 4 -1 1 161152 models.common.BottleneckCSP [128, 128, 3] \n",
" 5 -1 1 295424 models.common.Conv [128, 256, 3, 2] \n",
" 6 -1 1 641792 models.common.BottleneckCSP [256, 256, 3] \n",
" 7 -1 1 1180672 models.common.Conv [256, 512, 3, 2] \n",
" 8 -1 1 656896 models.common.SPP [512, 512, [5, 9, 13]] \n",
" 9 -1 1 1248768 models.common.BottleneckCSP [512, 512, 1, False] \n",
" 10 -1 1 131584 models.common.Conv [512, 256, 1, 1] \n",
" 11 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest'] \n",
" 12 [-1, 6] 1 0 models.common.Concat [1] \n",
" 13 -1 1 378624 models.common.BottleneckCSP [512, 256, 1, False] \n",
" 14 -1 1 33024 models.common.Conv [256, 128, 1, 1] \n",
" 15 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest'] \n",
" 16 [-1, 4] 1 0 models.common.Concat [1] \n",
" 17 -1 1 95104 models.common.BottleneckCSP [256, 128, 1, False] \n",
" 18 -1 1 32895 torch.nn.modules.conv.Conv2d [128, 255, 1, 1] \n",
" 19 -2 1 147712 models.common.Conv [128, 128, 3, 2] \n",
" 20 [-1, 14] 1 0 models.common.Concat [1] \n",
" 21 -1 1 313088 models.common.BottleneckCSP [256, 256, 1, False] \n",
" 22 -1 1 65535 torch.nn.modules.conv.Conv2d [256, 255, 1, 1] \n",
" 23 -2 1 590336 models.common.Conv [256, 256, 3, 2] \n",
" 24 [-1, 10] 1 0 models.common.Concat [1] \n",
" 25 -1 1 1248768 models.common.BottleneckCSP [512, 512, 1, False] \n",
" 26 -1 1 130815 torch.nn.modules.conv.Conv2d [512, 255, 1, 1] \n",
" 27 [-1, 22, 18] 1 0 models.yolo.Detect [80, [[116, 90, 156, 198, 373, 326], [30, 61, 62, 45, 59, 119], [10, 13, 16, 30, 33, 23]]]\n",
"Model Summary: 191 layers, 7.46816e+06 parameters, 7.46816e+06 gradients\n",
"\n",
"Optimizer groups: 54 .bias, 60 conv.weight, 51 other\n",
"Reading image shapes: 100% 128/128 [00:00<00:00, 8158.02it/s]\n",
"Caching labels ../coco128/labels/train2017 (126 found, 0 missing, 2 empty, 0 duplicate, for 128 images): 100% 128/128 [00:00<00:00, 7608.18it/s]\n",
"Caching images (0.1GB): 100% 128/128 [00:00<00:00, 149.70it/s]\n",
"Caching labels ../coco128/labels/train2017 (126 found, 0 missing, 2 empty, 0 duplicate, for 128 images): 100% 128/128 [00:00<00:00, 8165.09it/s]\n",
"Caching images (0.1GB): 100% 128/128 [00:00<00:00, 145.34it/s]\n",
"Label width-height: n mean min max matching recall\n",
" 929 105.8 1.23 640 0.4736 0.9903\n",
"Optimizer groups: 62 .bias, 70 conv.weight, 59 other\n",
"Scanning labels ../coco128/labels/train2017.cache (126 found, 0 missing, 2 empty, 0 duplicate, for 128 images): 100% 128/128 [00:00<00:00, 20484.22it/s]\n",
"Caching images (0.1GB): 100% 128/128 [00:00<00:00, 156.07it/s]\n",
"Scanning labels ../coco128/labels/train2017.cache (126 found, 0 missing, 2 empty, 0 duplicate, for 128 images): 100% 128/128 [00:00<00:00, 22082.55it/s]\n",
"Caching images (0.1GB): 100% 128/128 [00:00<00:00, 152.91it/s]\n",
"\n",
"Analyzing anchors... Best Possible Recall (BPR) = 0.9935\n",
"Image sizes 640 train, 640 test\n",
"Using 2 dataloader workers\n",
"Starting training for 5 epochs...\n",
"Starting training for 3 epochs...\n",
"\n",
" Epoch gpu_mem GIoU obj cls total targets img_size\n",
" 0/4 7.3G 0.04362 0.07954 0.02032 0.1435 208 640: 100% 8/8 [00:09<00:00, 1.24s/it]\n",
" Class Images Targets P R mAP@.5 mAP@.5:.95: 100% 8/8 [00:07<00:00, 1.03it/s]\n",
" all 128 929 0.421 0.704 0.66 0.42\n",
" 0/2 6.84G 0.04376 0.06831 0.02 0.1321 225 640: 100% 8/8 [00:09<00:00, 1.22s/it]\n",
" Class Images Targets P R mAP@.5 mAP@.5:.95: 100% 8/8 [00:09<00:00, 1.24s/it]\n",
" all 128 929 0.34 0.762 0.69 0.446\n",
"\n",
" Epoch gpu_mem GIoU obj cls total targets img_size\n",
" 1/4 13.9G 0.04609 0.07819 0.01886 0.1431 167 640: 100% 8/8 [00:03<00:00, 2.34it/s]\n",
" Class Images Targets P R mAP@.5 mAP@.5:.95: 100% 8/8 [00:02<00:00, 3.34it/s]\n",
" all 128 929 0.418 0.713 0.659 0.421\n",
" 1/2 6.06G 0.04333 0.08225 0.02207 0.1476 182 640: 100% 8/8 [00:03<00:00, 2.17it/s]\n",
" Class Images Targets P R mAP@.5 mAP@.5:.95: 100% 8/8 [00:02<00:00, 3.28it/s]\n",
" all 128 929 0.342 0.755 0.687 0.447\n",
"\n",
" Epoch gpu_mem GIoU obj cls total targets img_size\n",
" 2/4 13.9G 0.04508 0.07012 0.01977 0.135 198 640: 100% 8/8 [00:03<00:00, 2.33it/s]\n",
" Class Images Targets P R mAP@.5 mAP@.5:.95: 100% 8/8 [00:02<00:00, 3.50it/s]\n",
" all 128 929 0.409 0.71 0.664 0.421\n",
"\n",
" Epoch gpu_mem GIoU obj cls total targets img_size\n",
" 3/4 13.9G 0.04577 0.08308 0.02038 0.1492 222 640: 100% 8/8 [00:03<00:00, 2.34it/s]\n",
" Class Images Targets P R mAP@.5 mAP@.5:.95: 100% 8/8 [00:02<00:00, 3.50it/s]\n",
" all 128 929 0.429 0.71 0.67 0.426\n",
"\n",
" Epoch gpu_mem GIoU obj cls total targets img_size\n",
" 4/4 13.9G 0.04608 0.07352 0.01855 0.1382 149 640: 100% 8/8 [00:03<00:00, 2.32it/s]\n",
" 2/2 6.06G 0.0444 0.07251 0.01855 0.1355 216 640: 100% 8/8 [00:03<00:00, 2.15it/s]\n",
" Class Images Targets P R mAP@.5 mAP@.5:.95: 100% 8/8 [00:02<00:00, 3.46it/s]\n",
" all 128 929 0.423 0.716 0.663 0.422\n",
"Optimizer stripped from weights/last_tutorial.pt\n",
"5 epochs completed in 0.012 hours.\n",
" all 128 929 0.354 0.759 0.689 0.45\n",
"Optimizer stripped from runs/exp0/weights/last.pt, 15.2MB\n",
"3 epochs completed in 0.009 hours.\n",
"\n"
],
"name": "stdout"
@@ -540,9 +488,9 @@
"colab_type": "text"
},
"source": [
"#4. Visualize\n",
"# 4. Visualize\n",
"\n",
"After training starts, view `train*.jpg` images to see training images, labels and augmentation effects. Note a mosaic dataloader is used for training (shown below), a new dataloading concept developed by Ultralytics and first featured in [YOLOv4](https://arxiv.org/abs/2004.10934)."
"View `runs/exp0/train*.jpg` images to see training images, labels and augmentation effects. A **Mosaic Dataloader** is used for training (shown below), a new concept developed by Ultralytics and first featured in [YOLOv4](https://arxiv.org/abs/2004.10934)."
]
},
{
@@ -550,16 +498,16 @@
"metadata": {
"id": "W40tI99_7BcH",
"colab_type": "code",
"outputId": "1c838e44-79fe-433f-a334-59a037ee322e",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 917
}
},
"outputId": "1c838e44-79fe-433f-a334-59a037ee322e"
},
"source": [
"Image(filename='./train_batch1.jpg', width=900) # view augmented training mosaics"
"Image(filename='runs/exp0/train_batch1.jpg', width=900) # view augmented training mosaics"
],
"execution_count": 0,
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
@@ -586,7 +534,7 @@
"colab_type": "text"
},
"source": [
"View `test_batch0_gt.jpg` to see test batch 0 ground truth labels."
"View `test_batch0_gt.jpg` to see test batch 0 *ground truth* labels."
]
},
{
@@ -594,16 +542,16 @@
"metadata": {
"id": "PF9MLHDb7tB6",
"colab_type": "code",
"outputId": "b7a874f7-dad3-4611-e777-56c724c7ee81",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 647
}
},
"outputId": "b7a874f7-dad3-4611-e777-56c724c7ee81"
},
"source": [
"Image(filename='./test_batch0_gt.jpg', width=900) # view test image labels"
"Image(filename='runs/exp0/test_batch0_gt.jpg', width=900) # view test image labels"
],
"execution_count": 0,
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
@@ -630,7 +578,7 @@
"colab_type": "text"
},
"source": [
"View `test_batch0_pred.jpg` to see test batch 0 predictions."
"View `test_batch0_pred.jpg` to see test batch 0 *predictions*."
]
},
{
@@ -638,16 +586,16 @@
"metadata": {
"id": "ycP4UTEZ82_I",
"colab_type": "code",
"outputId": "c7c1238d-e0fa-4fc5-f393-bf5bce55d245",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 647
}
},
"outputId": "c7c1238d-e0fa-4fc5-f393-bf5bce55d245"
},
"source": [
"Image(filename='./test_batch0_pred.jpg', width=900) # view test image predictions"
"Image(filename='runs/exp0/test_batch0_pred.jpg', width=900) # view test image predictions"
],
"execution_count": 0,
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
@@ -674,30 +622,29 @@
"colab_type": "text"
},
"source": [
"Training losses and performance metrics are saved to Tensorboard and also to a `results.txt` logfile. `results.txt` is plotted as `results.png` after training completes. Partially completed `results.txt` files can be plotted with `from utils.utils import plot_results; plot_results()`. Here we show YOLOv5s trained on coco128 to 100 epochs, starting from scratch (orange), and starting from pretrained `yolov5s.pt` weights (blue)."
"Training losses and performance metrics are saved to Tensorboard and also to a `runs/exp0/results.txt` logfile. `results.txt` is plotted as `results.png` after training completes. Partially completed `results.txt` files can be plotted with `from utils.utils import plot_results; plot_results()`. Here we show YOLOv5s trained on coco128 to 300 epochs, starting from scratch (orange), and from pretrained `yolov5s.pt` (blue)."
]
},
{
"cell_type": "code",
"metadata": {
"id": "C60XAsyv6OPe",
"id": "MDznIqPF7nk3",
"colab_type": "code",
"outputId": "70c2254e-9caf-46b0-afbe-f7fe1967b19b",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 517
}
},
"outputId": "c1146425-643e-49ab-de25-73216f0dde23"
},
"source": [
"from utils.utils import plot_results; plot_results() # plot results.txt as results.png\n",
"Image(filename='./results.png', width=1000) # view results.png"
"from utils.utils import plot_results; plot_results() # plot results.txt files as results.png"
],
"execution_count": 0,
"execution_count": 29,
"outputs": [
{
"output_type": "execute_result",
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAACWAAAASwCAYAAAB/pHGBAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAewgAAHsIBbtB1PgAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAAgAElEQVR4nOzdd1gU1/oH8O/SQUE6IhYsKESMCopgVCDRJBpRYy9JbDGJMcbEFMuNPdZUNSZeS+TGRG+iJrF3QQXBBiJGxV5BiqAonWV+f/hj7g5sZ5cV+X6eh+eZs3vmnbO7umfO7DvnyARBEEBEREREREREREREREREREREREQ6MzN1A4iIiIiIiIiIiIiIiIiIiIiIiGoqJmARERERERERERERERERERERERHpiQlYREREREREREREREREREREREREemICFhERERERERERERERERERERERkZ6YgEVERERERERERERERERERERERKQnJmARERERERERERERERERERERERHpiQlYREREREREREREREREREREREREemICFhERERERERERERERERERERERkZ6YgEVERERERERERERERERERERERKQnJmARERERERERERERERERERERERHpiQlYREREREREREREREREREREREREemICFhERERERERERERERERERERERkZ6YgEVERERERERERERERERERERERKQnJmARERERERERERERERERERERERHpiQlYREREREREREREREREREREREREemICFhERERERERERERERERERERERkZ6YgEVERERERERERERERERERERERKQnJmARERERERERERERERERERERERHpiQlYREREREREREREREREREREREREemICFhERERERERERERERERERERERkZ6YgEVERERERERERERERERERERERKQnJmARERERERERERERERERERERERHpiQlYREREREREREREREREREREREREemICFhERERERERERERERERERERERkZ6YgEVERERERERERERERERERERERKQnJmARERERERERERERERERERERERHpiQlYREREREREREREREREREREREREemICFhERERERERERERERERERERERkZ6YgEVERERERERERERERERERERERKQnJmARERERERERERERERERERERERHpiQlYREREREREREREREREREREREREemICFtEz6tGjRzh06BA2bNiAZcuWYf78+Vi+fDnWr1+PuLg45OXlmbqJREREepHJZOJfdHS0QWPPnj1bjB0WFmbQ2ERERMZizL6xJouMjBTfF29vb632efjwIb7++muEhYXB3d0dlpaWSm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i1aCP/973+1jhkXFyeEh4cLMplM7Wv28vISJkyYIBQVFVVLLCKqfd577z3Jd4Uu32W60HaMc+3aNWHu3LlC+/btBTMzM5XfaVZWVsLo0aOFGzduaN2GO3fuCG+++aZgY2Oj9vvS3t5eGDRokHDlyhWjx1Ic/zVp0qTS802aNNGpr1RUsa/VhlwuF3799VehTZs2ao/TpEkTYfr06UJ2drbSOMnJycLnn38u+Pn5qY1Tp04d4eOPPxYyMjLUtkvXc4ZZs2ZJ9r9+/brk+evXr2t8L7Kzs4VJkyYJDLine truncated
"image/png": "iVBORw0KGgoAAAANSUhEUgAACWAAAASwCAYAAAB/pHGBAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAewgAAHsIBbtB1PgAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nOzdeVxU1f8/8NcAsinIjoooLigopoEiaAlUVi6ouZuVW2Zmatni8s3ccm1zyTS15JOZn0xLzS01QARxRRGTUFxyQxYBUVYZ7u8Pf9zPXJidGYbl9Xw8eDzumTn3fc/M6Jx77rzvOTJBEAQQERERERERERERERERERERERGRzsxM3QAiIiIiIiIiIiIiIiIiIiIiIqLaiglYREREREREREREREREREREREREemICFhERERERERERERERERERERERkZ6YgEVERERERERERERERERERERERKQnJmARERERERERERERERERERERERHpiQlYREREREREREREREREREREREREemICFhERERERERERERERERERERERkZ6YgEVERERERERERERERERERERERKQnJmARERERERERERERERERERERERHpiQlYREREREREREREREREREREREREemICFhERERERERERERERERERERERkZ6YgEVERERERERERERERERERERERKQnJmARERERERERERERERERERERERHpiQlYREREREREREREREREREREREREemICFhERERERERERERERERERERERkZ6YgEVERERERERERERERERERERERKQnJmARERERERERERERERERERERERHpiQlYREREREREREREREREREREREREemICFhERERERERERERERERERERERkZ6YgEVERERERERERERERERERERERKQnJmARERERERERERERERERERERERHpiQlYREREREREREREREREREREREREemICFhERERERERERERERERERERERkZ6YgEVERERERERERERERERERERERKQnJmARERERERERERERERERERERERHpiQlYREREREREREREREREREREREREemICFhERERERERERERERERERERERkZ6YgEVERERERERERERERERERERERKQnJmARERERERERERERERERERERERHpiQlYREREREREREREREREREREREREemICFhERERERERERERERERERERERkZ6YgEVEKj18+BCRkZH4+eefsXr1aixevBhr1qzBli1bEB8fj/z8fFM3kYiISCsymUz8i46ONmjs+fPni7FDQ0MNGpuIiMhQjNkX1mYRERHi++Ll5aXVPg8ePMAXX3yB0NBQuLm5oUGDBkpjREdHS973+uzGjRuS9+LGjRumbhIREdVSpjin8fLyEo8ZERFRLcckIiIi7a+96zO2JzIGC1M3gIhqlsLCQmzYsAG//vorTp48idLSUpV1zczM0KVLFwwdOhQjRoxA69atNcZXvOg8ZsyYah+wRkdHIywsTCxv3rwZY8eO1SlGREQExo0bJ5ajoqL4gzsRkYEIgoCEhARcu3YN6enpePjwIVxdXeHu7g5/f394eHiYuolERETVKjMzE2fOnEFGRgaysrLw+PFjODo6wt3dHQEBAfD09DR1E+uV5ORk9OnTB//++6+pm0JERERERERERDUIE7CISLRp0yZ8+umnSEtL06p+WVkZEhISkJCQgE8++QSjRo3CvHnz4O3tbeSWEhFRXXP9+nUsXboUf/zxB+7du6eynr+/P0aPHo0pU6bAysqqGltYv0RERIgzU4SGhjLRmIiomj18+BBr1qzBzp07ce7cOQiCoLKuh4cHRo0ahbFjx6Jjx47V2Mr6p6ysDEOHDpUkX9nY2MDd3R3m5uYAgObNm5uqedUiOjpanG3Ey8tL5xuaiIjofyre5KlMw4YN4eDgAG9vb3Tv3h2vvvoqnnrqqWpqIREREWmiTX9ua2uLxo0bo3Xr1ggICMDQoUPx7LPPVlMLiag6MQGLiPD48WNMmTIFGzdulDxuaWmJ4OBgBAUFwc3NDY6OjsjNzcW9e/eQlJSEqKgoFBUVAXhyIXrr1q0oKirCjh07TPEyiIioFnr8+DHmzp2LlStXori4WGP98sTfb775BmvXrkWfPn2qoZX1T0REBI4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/8cffxQaNGgg2U/Vn729vRAZGak2XlRUlGSfzZs36/waNm/eLIkRFRWlcwwiovpswoQJku/RrVu36hWnd+/ekjhxcXEq6yr73t67d6/QsWNHpX2Kq6ursGbNGqGsrExjO+bNmyfuFxISolXb8/LyhFmzZgkuLi5Kjy+TyYRevXoJZ86c0SqeouPHjwsvvviiYGFhobLPdHBwEMaNGyckJyeL+1XsI7X5q9gHKnsviouLhVmzZgkODg5KY3Tt2lU4ffq0Tq9RLpcLmzZtEry9vVW2rW3btsJ///tfrWPGx8cLYWFhgkwmU/uaPTw8hClTpgjFxcXVEouI6r63335b8t2gy3eXLrQdw1y7dk1YuHCh8PTTTwtmZmYqv8MsLS2FcePGCTdu3NC6Dbdv3xZef/11wdraWu33o52dnTBs2DAhNTXV6LEUx3ctW7as9HzLli116hsVVexbtSGXy4WffvpJ6NSpk9rjtGzZUpgzZ46QnZ2tNE5SUpLw8ccfC76+vmrjNGzYUHj//feFjIwMte3S9Rxh3rx5kv2vX78uef769esa34vs7Gxh+vTpgLine truncated
"text/plain": [
"<IPython.core.display.Image object>"
]
@@ -708,10 +655,27 @@
"width": 1000
}
},
"execution_count": 9
"execution_count": 29
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "Zelyeqbyt3GD",
"colab_type": "text"
},
"source": [
"# Environments\n",
"\n",
"YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):\n",
"\n",
"- **Google Colab Notebook** with free GPU: <a href=\"https://colab.research.google.com/github/ultralytics/yolov5/blob/master/tutorial.ipynb\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"></a>\n",
"- **Kaggle Notebook** with free GPU: [https://www.kaggle.com/ultralytics/yolov5](https://www.kaggle.com/ultralytics/yolov5)\n",
"- **Google Cloud** Deep Learning VM. See [GCP Quickstart Guide](https://github.com/ultralytics/yolov5/wiki/GCP-Quickstart) \n",
"- **Docker Image** https://hub.docker.com/r/ultralytics/yolov5. See [Docker Quickstart Guide](https://github.com/ultralytics/yolov5/wiki/Docker-Quickstart) ![Docker Pulls](https://img.shields.io/docker/pulls/ultralytics/yolov5?logo=docker)"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -719,7 +683,9 @@
"colab_type": "text"
},
"source": [
"## 5. Appendix"
"# Appendix\n",
"\n",
"Optional extras below. Unit tests validate repo functionality and should be run on any PRs submitted.\n"
]
},
{
@@ -730,61 +696,62 @@
"colab": {}
},
"source": [
"# Re-clone\n",
"# Re-clone repo\n",
"%cd ..\n",
"!rm -rf yolov5 && git clone https://github.com/ultralytics/yolov5\n",
"%cd yolov5"
],
"execution_count": 0,
"execution_count": 9,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "5OGhWlyAYQlS",
"id": "Z2AvpeKfrbsT",
"colab_type": "code",
"colab": {}
},
"source": [
"# Apex install\n",
"git clone https://github.com/NVIDIA/apex && cd apex && pip install -v --no-cache-dir --global-option=\"--cpp_ext\" --global-option=\"--cuda_ext\" . --user && cd .. && rm -rf apex"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "JaTFNJHvFBy4",
"colab_type": "code",
"colab": {}
},
"source": [
"# Test GCP checkpoint on COCO val2017\n",
"# Test GCP ckpt\n",
"%%shell\n",
"x=best*.pt\n",
"gsutil cp gs://*/*/weights/$x .\n",
"python test.py --weights $x --data ./data/coco.yaml --img 736"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "wuVlYvfBVTuD",
"colab_type": "code",
"colab": {}
},
"source": [
"# Test multiple models on COCO val2017\n",
"%%shell\n",
"for x in yolov5s yolov5m yolov5l yolov5x\n",
"do \n",
" python test.py --weights $x.pt --data ./data/coco.yaml --img 640 --conf 0.001\n",
"for x in best*\n",
"do\n",
" gsutil cp gs://*/*/*/$x.pt .\n",
" python test.py --weights $x.pt --data coco.yaml --img 672\n",
"done"
],
"execution_count": 0,
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "FGH0ZjkGjejy",
"colab_type": "code",
"colab": {}
},
"source": [
"# YOLOv5 unit tests\n",
"%%shell\n",
"cd .. && rm -rf yolov5 && git clone https://github.com/ultralytics/yolov5 && cd yolov5\n",
"export PYTHONPATH=\"$PWD\" # to run *.py. files in subdirectories\n",
"pip install -qr requirements.txt onnx\n",
"python3 -c \"from utils.google_utils import *; gdrive_download('1n_oKgR81BJtqk75b00eAjdv03qVCQn2f', 'coco128.zip')\" && mv ./coco128 ../\n",
"for x in yolov5s #yolov5m yolov5l yolov5x # models\n",
"do\n",
" python train.py --weights $x.pt --cfg $x.yaml --epochs 4 --img 320 --device 0 # train\n",
" for di in 0 cpu # inference devices\n",
" do\n",
" python detect.py --weights $x.pt --device $di # detect official\n",
" python detect.py --weights runs/exp0/weights/last.pt --device $di # detect custom\n",
" python test.py --weights $x.pt --device $di # test official\n",
" python test.py --weights runs/exp0/weights/last.pt --device $di # test custom\n",
" done\n",
" python models/yolo.py --cfg $x.yaml # inspect\n",
" python models/export.py --weights $x.pt --img 640 --batch 1 # export\n",
"done"
],
"execution_count": null,
"outputs": []
}
]