{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "name": "advanced_logging_test.ipynb", "provenance": [], "authorship_tag": "ABX9TyPFy7j0vPOSgtY60fQfXjdq", "include_colab_link": true }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "accelerator": "GPU" }, "cells": [ { "cell_type": "markdown", "metadata": { "id": "view-in-github", "colab_type": "text" }, "source": [ "\"Open" ] }, { "cell_type": "markdown", "metadata": { "id": "-cMOOhIGFBJa", "colab_type": "text" }, "source": [ "# **Test Advanced Logging Branch Features**" ] }, { "cell_type": "code", "metadata": { "id": "YwXvkCXB9Yif", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 136 }, "outputId": "9a7ab9a3-c73d-4dae-ae35-237c9d84728f" }, "source": [ "!git clone -b advanced_logging https://github.com/alexstoken/yolov5.git" ], "execution_count": 1, "outputs": [ { "output_type": "stream", "text": [ "Cloning into 'yolov5'...\n", "remote: Enumerating objects: 53, done.\u001b[K\n", "remote: Counting objects: 100% (53/53), done.\u001b[K\n", "remote: Compressing objects: 100% (39/39), done.\u001b[K\n", "remote: Total 1223 (delta 28), reused 35 (delta 14), pack-reused 1170\u001b[K\n", "Receiving objects: 100% (1223/1223), 3.50 MiB | 3.20 MiB/s, done.\n", "Resolving deltas: 100% (811/811), done.\n" ], "name": "stdout" } ] }, { "cell_type": "code", "metadata": { "id": "pNJbzKWK9r3l", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 34 }, "outputId": "67d82040-b5af-48b5-fb93-4ed962e48680" }, "source": [ "!pip install -r yolov5/requirements.txt # install dependencies\n", "%cd yolov5\n", "\n", "import torch\n", "from IPython.display import Image, clear_output # to display images\n", "from utils.google_utils import gdrive_download # to download models/datasets\n", "\n", "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": 2, "outputs": [ { "output_type": "stream", "text": [ "Setup complete. Using torch 1.5.1+cu101 _CudaDeviceProperties(name='Tesla K80', major=3, minor=7, total_memory=11441MB, multi_processor_count=13)\n" ], "name": "stdout" } ] }, { "cell_type": "markdown", "metadata": { "id": "amtgnroz901E", "colab_type": "text" }, "source": [ "## Train" ] }, { "cell_type": "code", "metadata": { "id": "0NSb22om9ybq", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 34 }, "outputId": "ee202bce-ad59-4bba-fcd2-77a3dd98fd4a" }, "source": [ "# Download tutorial dataset coco128.yaml\n", "gdrive_download('1n_oKgR81BJtqk75b00eAjdv03qVCQn2f','coco128.zip') # tutorial dataset\n", "!mv ./coco128 ../ # move folder alongside /yolov5" ], "execution_count": 3, "outputs": [ { "output_type": "stream", "text": [ "Downloading https://drive.google.com/uc?export=download&id=1n_oKgR81BJtqk75b00eAjdv03qVCQn2f as coco128.zip... unzipping... Done (5.1s)\n" ], "name": "stdout" } ] }, { "cell_type": "markdown", "metadata": { "id": "71hxUTfvFJky", "colab_type": "text" }, "source": [ "**Verify Help Arg Works**" ] }, { "cell_type": "code", "metadata": { "id": "6SLw4hNi-C1L", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 544 }, "outputId": "e0ca506c-ddfb-4b86-d5e8-ca98729672b9" }, "source": [ "!python train.py --help" ], "execution_count": 4, "outputs": [ { "output_type": "stream", "text": [ "Apex recommended for faster mixed precision training: https://github.com/NVIDIA/apex\n", "usage: train.py [-h] [--cfg CFG] [--data DATA] [--hyp HYP] [--epochs EPOCHS]\n", " [--batch-size BATCH_SIZE] [--img-size IMG_SIZE [IMG_SIZE ...]]\n", " [--rect] [--resume [RESUME]] [--nosave] [--notest]\n", " [--noautoanchor] [--evolve] [--bucket BUCKET] [--cache-images]\n", " [--weights WEIGHTS] [--name NAME] [--device DEVICE]\n", " [--multi-scale] [--single-cls]\n", "\n", "optional arguments:\n", " -h, --help show this help message and exit\n", " --cfg CFG model cfg path[*.yaml]\n", " --data DATA data cfg path [*.yaml]\n", " --hyp HYP hyp cfg path [*.yaml].\n", " --epochs EPOCHS\n", " --batch-size BATCH_SIZE\n", " --img-size IMG_SIZE [IMG_SIZE ...]\n", " train,test sizes. Assumes square imgs.\n", " --rect rectangular training\n", " --resume [RESUME] resume training from given path/to/last.pt, or most\n", " recent run if blank.\n", " --nosave only save final checkpoint\n", " --notest only test final epoch\n", " --noautoanchor disable autoanchor check\n", " --evolve evolve hyperparameters\n", " --bucket BUCKET gsutil bucket\n", " --cache-images cache images for faster training\n", " --weights WEIGHTS initial weights path\n", " --name NAME renames results.txt to results_name.txt if supplied\n", " --device DEVICE cuda device, i.e. 0 or 0,1,2,3 or cpu\n", " --multi-scale vary img-size +/- 50%\n", " --single-cls train as single-class dataset\n" ], "name": "stdout" } ] }, { "cell_type": "markdown", "metadata": { "id": "ou1ochfx-VTr", "colab_type": "text" }, "source": [ "**Run with hyperparameters from yaml file**" ] }, { "cell_type": "code", "metadata": { "id": "wLHoZYbk-EqT", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 1000 }, "outputId": "63ed4676-22b8-4852-e663-5c3cfefe19df" }, "source": [ "!python train.py --img 320 --batch 32 --epochs 3 --data ./data/coco128.yaml --cfg ./models/yolov5s.yaml --weights yolov5s.pt --name tutorial --cache --hyp new_hyp.yaml" ], "execution_count": 9, "outputs": [ { "output_type": "stream", "text": [ "Apex recommended for faster mixed precision training: https://github.com/NVIDIA/apex\n", "Namespace(batch_size=32, bucket='', cache_images=True, cfg='./models/yolov5s.yaml', data='./data/coco128.yaml', device='', epochs=3, evolve=False, hyp='new_hyp.yaml', img_size=[320], multi_scale=False, name='tutorial', noautoanchor=False, nosave=False, notest=False, rect=False, resume=False, single_cls=False, weights='yolov5s.pt')\n", "Using CUDA device0 _CudaDeviceProperties(name='Tesla K80', total_memory=11441MB)\n", "\n", "2020-07-07 16:03:25.684542: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1\n", "Using FocalLoss(gamma=1)\n", "Beginning training with {'optimizer': 'adam', 'lr0': 0.001, 'momentum': 0.9, 'weight_decay': 0.000625, 'giou': 0.15, 'cls': 0.58, 'cls_pw': 1.0, 'obj': 1.0, 'obj_pw': 1.0, 'iou_t': 0.2, 'anchor_t': 10.0, 'fl_gamma': 1.0, 'hsv_h': 0.014, 'hsv_s': 0.68, 'hsv_v': 0.36, 'degrees': 20.0, 'translate': 0.0, 'scale': 0.5, 'shear': 0.0}\n", "\n", "\n", "Start Tensorboard with \"tensorboard --logdir=runs\", view at http://localhost:6006/\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 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: 62 .bias, 70 conv.weight, 59 other\n", "/usr/local/lib/python3.6/dist-packages/torch/optim/lr_scheduler.py:123: UserWarning: Detected call of `lr_scheduler.step()` before `optimizer.step()`. In PyTorch 1.1.0 and later, you should call them in the opposite order: `optimizer.step()` before `lr_scheduler.step()`. Failure to do this will result in PyTorch skipping the first value of the learning rate schedule. See more details at https://pytorch.org/docs/stable/optim.html#how-to-adjust-learning-rate\n", " \"https://pytorch.org/docs/stable/optim.html#how-to-adjust-learning-rate\", UserWarning)\n", "Caching labels ../coco128/labels/train2017 (126 found, 0 missing, 2 empty, 0 duplicate, for 128 images): 100% 128/128 [00:00<00:00, 6343.82it/s]\n", "Caching images (0.0GB): 100% 128/128 [00:00<00:00, 137.36it/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, 4530.37it/s]\n", "Caching images (0.0GB): 100% 128/128 [00:01<00:00, 124.18it/s]\n", "\n", "Analyzing anchors... Best Possible Recall (BPR) = 0.9968\n", "Image sizes 320 train, 320 test\n", "Using 2 dataloader workers\n", "Starting training for 3 epochs...\n", "\n", " Epoch gpu_mem GIoU obj cls total targets img_size\n", " 0/2 2.71G 0.2492 0.08469 0.01266 0.3466 469 320: 100% 4/4 [00:06<00:00, 1.56s/it]\n", " Class Images Targets P R mAP@.5 mAP@.5:.95: 100% 4/4 [00:21<00:00, 5.39s/it]\n", " all 128 929 0.0866 0.26 0.14 0.0587\n", "\n", " Epoch gpu_mem GIoU obj cls total targets img_size\n", " 1/2 2.67G 0.245 0.07209 0.01212 0.3292 424 320: 100% 4/4 [00:02<00:00, 1.69it/s]\n", " Class Images Targets P R mAP@.5 mAP@.5:.95: 0% 0/4 [00:00