Object Detection Models

All of the YOLO models are object detection models. Object detection models are trained to look at an image and search for a subset of object classes. When found, these object classes are enclosed in a bounding box and their class is identified. Object detection models are typically trained and evaluated on the COCO dataset which contains a broad range of 80 object classes. From there, it is assumed that object detection models will generalize to new object detection tasks if they are exposed to new training data. Here is an example of me using YOLOv5 to detect helmet.

Install Dependencies

(Remember to choose GPU in Runtime if not already selected. Runtime --> Change Runtime Type --> Hardware accelerator --> GPU)

%cd /content/drive/MyDrive/Helment_Detection_Yolov5/yolov5/
!pip install -qr requirements.txt  # install dependencies (ignore errors)
import torch

from IPython.display import Image, clear_output  # to display images
from utils.google_utils import gdrive_download  # to download models/datasets

# clear_output()
print('Setup complete. Using torch %s %s' % (torch.__version__, torch.cuda.get_device_properties(0) if torch.cuda.is_available() else 'CPU'))
/content/drive/MyDrive/Helment_Detection_Yolov5/yolov5
     |████████████████████████████████| 645kB 22.4MB/s 
Setup complete. Using torch 1.8.1+cu101 _CudaDeviceProperties(name='Tesla T4', major=7, minor=5, total_memory=15109MB, multi_processor_count=40)

Mount Google Drive

We'll download our dataset from Roboflow. Use the "YOLOv5 PyTorch" export format. Note that the Ultralytics implementation calls for a YAML file defining where your training and test data is. The Roboflow export also writes this format for us.

from google.colab import drive
drive.mount('/content/drive')
Mounted at /content/drive
%cd /content/drive/MyDrive/Helment_Detection_Yolov5/
%cat data.yaml
/content/drive/MyDrive/Helment_Detection_Yolov5
train: ../train/images
val: ../valid/images

nc: 2
names: ['With Helmet', 'Without Helmet']

Define Model Configuration and Architecture

We will write a yaml script that defines the parameters for our model like the number of classes, anchors, and each layer.

You do not need to edit these cells, but you may.

import yaml
with open("/content/drive/MyDrive/Helment_Detection_Yolov5/data.yaml", 'r') as stream:
    num_classes = str(yaml.safe_load(stream)['nc'])

h

%cat /content/drive/MyDrive/Helment_Detection_Yolov5/yolov5/models/yolov5l.yaml
# parameters
nc: 80  # number of classes
depth_multiple: 1.0  # model depth multiple
width_multiple: 1.0  # layer channel multiple

# anchors
anchors:
  - [10,13, 16,30, 33,23]  # P3/8
  - [30,61, 62,45, 59,119]  # P4/16
  - [116,90, 156,198, 373,326]  # P5/32

# YOLOv5 backbone
backbone:
  # [from, number, module, args]
  [[-1, 1, Focus, [64, 3]],  # 0-P1/2
   [-1, 1, Conv, [128, 3, 2]],  # 1-P2/4
   [-1, 3, C3, [128]],
   [-1, 1, Conv, [256, 3, 2]],  # 3-P3/8
   [-1, 9, C3, [256]],
   [-1, 1, Conv, [512, 3, 2]],  # 5-P4/16
   [-1, 9, C3, [512]],
   [-1, 1, Conv, [1024, 3, 2]],  # 7-P5/32
   [-1, 1, SPP, [1024, [5, 9, 13]]],
   [-1, 3, C3, [1024, False]],  # 9
  ]

# YOLOv5 head
head:
  [[-1, 1, Conv, [512, 1, 1]],
   [-1, 1, nn.Upsample, [None, 2, 'nearest']],
   [[-1, 6], 1, Concat, [1]],  # cat backbone P4
   [-1, 3, C3, [512, False]],  # 13

   [-1, 1, Conv, [256, 1, 1]],
   [-1, 1, nn.Upsample, [None, 2, 'nearest']],
   [[-1, 4], 1, Concat, [1]],  # cat backbone P3
   [-1, 3, C3, [256, False]],  # 17 (P3/8-small)

   [-1, 1, Conv, [256, 3, 2]],
   [[-1, 14], 1, Concat, [1]],  # cat head P4
   [-1, 3, C3, [512, False]],  # 20 (P4/16-medium)

   [-1, 1, Conv, [512, 3, 2]],
   [[-1, 10], 1, Concat, [1]],  # cat head P5
   [-1, 3, C3, [1024, False]],  # 23 (P5/32-large)

   [[17, 20, 23], 1, Detect, [nc, anchors]],  # Detect(P3, P4, P5)
  ]

The Anatomy of an Object Detector

layers

layers

All object detectors take an image in for input and compress features down through a convolutional neural network backbone. In image classification, these backbones are the end of the network and prediction can be made off of them.

In object detection, multiple bounding boxes need to be drawn around images along with classification, so the feature layers of the convolutional backbone need to be mixed and held up in light of one another. The combination of backbone feature layers happens in the neck.

It is also useful to split object detectors into two categories: one-stage detectors and two stage detectors. Detection happens in the head.

Two-stage detectors decouple the task of object localization and classification for each bounding box.

One-stage detectors make the predictions for object localization and classification at the same time. YOLO is a one-stage detector, hence, You Only Look Once.</p> </div> </div> </div>

from IPython.core.magic import register_line_cell_magic

@register_line_cell_magic
def writetemplate(line, cell):
    with open(line, 'w') as f:
        f.write(cell.format(**globals()))
%%writetemplate /content/drive/MyDrive/Helment_Detection_Yolov5/yolov5/models/custom_yolov5l.yaml

# parameters
nc: {num_classes}  # number of classes
depth_multiple: 1.0  # model depth multiple
width_multiple: 1.0  # layer channel multiple

# anchors
anchors:
  - [10,13, 16,30, 33,23]  # P3/8
  - [30,61, 62,45, 59,119]  # P4/16
  - [116,90, 156,198, 373,326]  # P5/32

# YOLOv5 backbone
backbone:
  # [from, number, module, args]
  [[-1, 1, Focus, [64, 3]],  # 0-P1/2
   [-1, 1, Conv, [128, 3, 2]],  # 1-P2/4
   [-1, 3, C3, [128]],
   [-1, 1, Conv, [256, 3, 2]],  # 3-P3/8
   [-1, 9, C3, [256]],
   [-1, 1, Conv, [512, 3, 2]],  # 5-P4/16
   [-1, 9, C3, [512]],
   [-1, 1, Conv, [1024, 3, 2]],  # 7-P5/32
   [-1, 1, SPP, [1024, [5, 9, 13]]],
   [-1, 3, C3, [1024, False]],  # 9
  ]

# YOLOv5 head
head:
  [[-1, 1, Conv, [512, 1, 1]],
   [-1, 1, nn.Upsample, [None, 2, 'nearest']],
   [[-1, 6], 1, Concat, [1]],  # cat backbone P4
   [-1, 3, C3, [512, False]],  # 13

   [-1, 1, Conv, [256, 1, 1]],
   [-1, 1, nn.Upsample, [None, 2, 'nearest']],
   [[-1, 4], 1, Concat, [1]],  # cat backbone P3
   [-1, 3, C3, [256, False]],  # 17 (P3/8-small)

   [-1, 1, Conv, [256, 3, 2]],
   [[-1, 14], 1, Concat, [1]],  # cat head P4
   [-1, 3, C3, [512, False]],  # 20 (P4/16-medium)

   [-1, 1, Conv, [512, 3, 2]],
   [[-1, 10], 1, Concat, [1]],  # cat head P5
   [-1, 3, C3, [1024, False]],  # 23 (P5/32-large)

   [[17, 20, 23], 1, Detect, [nc, anchors]],  # Detect(P3, P4, P5)
  ]

The Detection Step

object

Train Helment Detector YOLOv5

Here, we are able to pass a number of arguments:

  • img: define input image size
  • batch: determine batch size
  • epochs: define the number of training epochs. (Note: often, 3000+ are common here!)
  • data: set the path to our yaml file
  • cfg: specify our model configuration
  • weights: specify a custom path to weights. (Note: you can download weights from the Ultralytics Google Drive folder)
  • name: result names
  • nosave: only save the final checkpoint
  • cache: cache images for faster training
# time its performance
%%time
%cd /content/drive/MyDrive/Helment_Detection_Yolov5/yolov5/
!python train.py --img 416 --batch 16 --epochs 100 --data '../data.yaml' --cfg ./models/custom_yolov5l.yaml --weights '' --name yolov5s_results  --cache
/content/drive/MyDrive/Helment_Detection_Yolov5/yolov5
remote: Enumerating objects: 61, done.
remote: Counting objects: 100% (57/57), done.
remote: Compressing objects: 100% (32/32), done.
remote: Total 61 (delta 31), reused 37 (delta 25), pack-reused 4
Unpacking objects: 100% (61/61), done.
From https://github.com/ultralytics/yolov5
   1849916..955eea8  master            -> origin/master
   c9c95fb..0824388  study_activations -> origin/study_activations
github: ⚠️ WARNING: code is out of date by 118 commits. Use 'git pull' to update or 'git clone https://github.com/ultralytics/yolov5' to download latest.
YOLOv5 v4.0-126-g886f1c0 torch 1.8.1+cu101 CUDA:0 (Tesla K80, 11441.1875MB)

Namespace(adam=False, batch_size=16, bucket='', cache_images=True, cfg='./models/custom_yolov5l.yaml', data='../data.yaml', device='', entity=None, epochs=100, evolve=False, exist_ok=False, global_rank=-1, hyp='data/hyp.scratch.yaml', image_weights=False, img_size=[416, 416], linear_lr=False, local_rank=-1, log_artifacts=False, log_imgs=16, multi_scale=False, name='yolov5s_results', noautoanchor=False, nosave=False, notest=False, project='runs/train', quad=False, rect=False, resume=False, save_dir='runs/train/yolov5s_results2', single_cls=False, sync_bn=False, total_batch_size=16, weights='', workers=8, world_size=1)
wandb: Install Weights & Biases for YOLOv5 logging with 'pip install wandb' (recommended)
Start Tensorboard with "tensorboard --logdir runs/train", view at http://localhost:6006/
2021-04-30 04:32:56.737730: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.11.0
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

                 from  n    params  module                                  arguments                     
  0                -1  1      7040  models.common.Focus                     [3, 64, 3]                    
  1                -1  1     73984  models.common.Conv                      [64, 128, 3, 2]               
  2                -1  1    156928  models.common.C3                        [128, 128, 3]                 
  3                -1  1    295424  models.common.Conv                      [128, 256, 3, 2]              
  4                -1  1   1611264  models.common.C3                        [256, 256, 9]                 
  5                -1  1   1180672  models.common.Conv                      [256, 512, 3, 2]              
  6                -1  1   6433792  models.common.C3                        [512, 512, 9]                 
  7                -1  1   4720640  models.common.Conv                      [512, 1024, 3, 2]             
  8                -1  1   2624512  models.common.SPP                       [1024, 1024, [5, 9, 13]]      
  9                -1  1   9971712  models.common.C3                        [1024, 1024, 3, False]        
 10                -1  1    525312  models.common.Conv                      [1024, 512, 1, 1]             
 11                -1  1         0  torch.nn.modules.upsampling.Upsample    [None, 2, 'nearest']          
 12           [-1, 6]  1         0  models.common.Concat                    [1]                           
 13                -1  1   2757632  models.common.C3                        [1024, 512, 3, False]         
 14                -1  1    131584  models.common.Conv                      [512, 256, 1, 1]              
 15                -1  1         0  torch.nn.modules.upsampling.Upsample    [None, 2, 'nearest']          
 16           [-1, 4]  1         0  models.common.Concat                    [1]                           
 17                -1  1    690688  models.common.C3                        [512, 256, 3, False]          
 18                -1  1    590336  models.common.Conv                      [256, 256, 3, 2]              
 19          [-1, 14]  1         0  models.common.Concat                    [1]                           
 20                -1  1   2495488  models.common.C3                        [512, 512, 3, False]          
 21                -1  1   2360320  models.common.Conv                      [512, 512, 3, 2]              
 22          [-1, 10]  1         0  models.common.Concat                    [1]                           
 23                -1  1   9971712  models.common.C3                        [1024, 1024, 3, False]        
 24      [17, 20, 23]  1     37695  models.yolo.Detect                      [2, [[10, 13, 16, 30, 33, 23], [30, 61, 62, 45, 59, 119], [116, 90, 156, 198, 373, 326]], [256, 512, 1024]]
Model Summary: 499 layers, 46636735 parameters, 46636735 gradients, 114.3 GFLOPS

Scaled weight_decay = 0.0005
Optimizer groups: 110 .bias, 110 conv.weight, 107 other
train: Scanning '../train/labels' for images and labels... 1320 found, 0 missing, 24 empty, 0 corrupted: 100% 1320/1320 [00:03<00:00, 376.62it/s]
train: New cache created: ../train/labels.cache
train: Caching images (0.7GB): 100% 1320/1320 [00:05<00:00, 261.41it/s]
val: Scanning '../valid/labels' for images and labels... 126 found, 0 missing, 0 empty, 0 corrupted: 100% 126/126 [00:00<00:00, 252.30it/s]
val: New cache created: ../valid/labels.cache
val: Caching images (0.1GB): 100% 126/126 [00:00<00:00, 230.62it/s]
Plotting labels... 

autoanchor: Analyzing anchors... anchors/target = 6.19, Best Possible Recall (BPR) = 1.0000
Image sizes 416 train, 416 test
Using 2 dataloader workers
Logging results to runs/train/yolov5s_results2
Starting training for 100 epochs...

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
      0/99     4.26G   0.09697   0.02842   0.02643    0.1518        32       416: 100% 83/83 [02:15<00:00,  1.64s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:14<00:00,  3.61s/it]
                 all         126         240     0.00177       0.279    0.000776    0.000123

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
      1/99     4.44G   0.09161   0.02987   0.02503    0.1465        20       416: 100% 83/83 [02:00<00:00,  1.45s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.12s/it]
                 all         126         240     0.00259        0.17    0.000594     8.9e-05

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
      2/99     4.44G   0.08948   0.03019   0.02386    0.1435        34       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.12s/it]
                 all         126         240     0.00136       0.213    0.000446     6.6e-05

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
      3/99     4.44G    0.0894   0.03097    0.0234    0.1438        25       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.12s/it]
                 all         126         240      0.0014       0.215    0.000488    7.06e-05

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
      4/99     4.44G    0.0893   0.02934    0.0238    0.1424        17       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.12s/it]
                 all         126         240     0.00785     0.00303     0.00046    6.84e-05

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
      5/99     4.44G   0.08878   0.03031   0.02349    0.1426        29       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.12s/it]
                 all         126         240      0.0085      0.0182     0.00104    0.000164

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
      6/99     4.44G   0.08824   0.03058   0.02332    0.1421        28       416: 100% 83/83 [01:57<00:00,  1.42s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.12s/it]
                 all         126         240      0.0161     0.00909     0.00139    0.000307

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
      7/99     4.44G   0.08661   0.03147   0.02371    0.1418        19       416: 100% 83/83 [01:57<00:00,  1.42s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.13s/it]
                 all         126         240      0.0112      0.0121     0.00213    0.000361

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
      8/99     4.44G   0.08436   0.03261   0.02315    0.1401        18       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:05<00:00,  1.26s/it]
                 all         126         240      0.0219      0.0424      0.0066     0.00141

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
      9/99     4.44G   0.07807    0.0301   0.02296    0.1311        16       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:07<00:00,  1.83s/it]
                 all         126         240      0.0988       0.101      0.0342     0.00713

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     10/99     4.44G   0.07444   0.02741   0.02231    0.1242        25       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:05<00:00,  1.27s/it]
                 all         126         240       0.102       0.118      0.0554      0.0134

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     11/99     4.44G   0.06966   0.02835   0.02108    0.1191        23       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.13s/it]
                 all         126         240       0.167       0.197       0.127       0.028

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     12/99     4.44G   0.06595   0.02687   0.01959    0.1124        15       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.17s/it]
                 all         126         240       0.137       0.258       0.124      0.0365

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     13/99     4.44G   0.06328   0.02514   0.01922    0.1076        32       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:06<00:00,  1.53s/it]
                 all         126         240       0.227       0.213        0.15      0.0547

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     14/99     4.44G   0.05947   0.02458   0.01807    0.1021        17       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.10s/it]
                 all         126         240       0.186       0.508       0.235      0.0707

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     15/99     4.44G   0.05721   0.02384   0.01636   0.09741        30       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.06s/it]
                 all         126         240       0.461       0.316       0.309       0.114

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     16/99     4.44G   0.05509   0.02422   0.01478   0.09408        16       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.06s/it]
                 all         126         240       0.411       0.413        0.31      0.0948

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     17/99     4.44G   0.05315   0.02356   0.01371   0.09042        41       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.06s/it]
                 all         126         240       0.404       0.428       0.343       0.135

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     18/99     4.44G   0.05281   0.02244   0.01317   0.08842        23       416: 100% 83/83 [01:59<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.07s/it]
                 all         126         240       0.363       0.349       0.289       0.107

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     19/99     4.44G   0.05009   0.02225   0.01232   0.08465        25       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.05s/it]
                 all         126         240       0.526       0.431       0.398       0.116

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     20/99     4.44G   0.04905   0.02106   0.01291   0.08302        19       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.05s/it]
                 all         126         240       0.538       0.516        0.43       0.176

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     21/99     4.44G   0.04894   0.02148   0.01124   0.08165        20       416: 100% 83/83 [01:59<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.04s/it]
                 all         126         240       0.527       0.462       0.447       0.166

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     22/99     4.44G   0.04723   0.02099   0.01069   0.07891        21       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.562         0.5       0.473       0.196

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     23/99     4.44G   0.04767   0.02068   0.01131   0.07966        36       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.14s/it]
                 all         126         240     0.00955       0.178      0.0011    0.000278

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     24/99     4.44G   0.04795   0.02099   0.01071   0.07964        35       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.437       0.518       0.421       0.141

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     25/99     4.44G   0.04608   0.02114  0.009783     0.077        21       416: 100% 83/83 [01:57<00:00,  1.42s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.569       0.551       0.501       0.209

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     26/99     4.44G   0.04454   0.02026  0.008806   0.07361        13       416: 100% 83/83 [01:57<00:00,  1.42s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.433       0.546       0.447       0.171

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     27/99     4.44G   0.04534   0.02042  0.009341    0.0751        20       416: 100% 83/83 [01:57<00:00,  1.42s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.04s/it]
                 all         126         240       0.656       0.517       0.505         0.2

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     28/99     4.44G   0.04466   0.01946  0.008201   0.07232        19       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.04s/it]
                 all         126         240       0.584       0.575       0.516        0.21

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     29/99     4.44G   0.04371   0.01889  0.007327   0.06993        39       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.585       0.616       0.583        0.23

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     30/99     4.44G   0.04287    0.0196   0.00685   0.06933        13       416: 100% 83/83 [01:57<00:00,  1.42s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.02s/it]
                 all         126         240       0.527       0.598       0.512       0.218

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     31/99     4.44G   0.04187   0.01821  0.007428   0.06751        22       416: 100% 83/83 [01:57<00:00,  1.42s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.02s/it]
                 all         126         240       0.595       0.566       0.532       0.237

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     32/99     4.44G   0.04209   0.01821  0.007386   0.06768        21       416: 100% 83/83 [01:57<00:00,  1.42s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.471       0.523       0.371       0.138

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     33/99     4.44G   0.04089    0.0181  0.006372   0.06536        16       416: 100% 83/83 [01:57<00:00,  1.42s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.04s/it]
                 all         126         240       0.661       0.521       0.536       0.228

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     34/99     4.44G   0.04211   0.01914  0.006914   0.06816        19       416: 100% 83/83 [01:57<00:00,  1.42s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.539       0.539       0.487       0.194

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     35/99     4.44G   0.04096   0.01867  0.006569    0.0662        19       416: 100% 83/83 [01:57<00:00,  1.42s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.644       0.504       0.509       0.208

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     36/99     4.44G     0.041   0.01861  0.006305   0.06591        18       416: 100% 83/83 [01:57<00:00,  1.42s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.554       0.562       0.517       0.223

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     37/99     4.44G    0.0409   0.01825  0.005963   0.06511        24       416: 100% 83/83 [01:58<00:00,  1.42s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.566        0.57       0.536       0.227

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     38/99     4.44G   0.03975   0.01876  0.006003   0.06451        10       416: 100% 83/83 [01:57<00:00,  1.42s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.02s/it]
                 all         126         240       0.614        0.59       0.555       0.231

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     39/99     4.44G   0.03928    0.0182   0.00552     0.063        37       416: 100% 83/83 [01:57<00:00,  1.42s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.02s/it]
                 all         126         240       0.686        0.53        0.57       0.221

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     40/99     4.44G   0.03948   0.01697  0.005399   0.06185        20       416: 100% 83/83 [01:57<00:00,  1.42s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.604        0.55       0.536       0.209

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     41/99     4.44G   0.03818   0.01732  0.004386   0.05988        26       416: 100% 83/83 [01:58<00:00,  1.42s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.572        0.63       0.575       0.236

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     42/99     4.44G   0.03826   0.01746  0.005158   0.06088        15       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.02s/it]
                 all         126         240        0.54       0.618       0.557        0.24

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     43/99     4.44G   0.03741   0.01685  0.004884   0.05914        25       416: 100% 83/83 [01:57<00:00,  1.42s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.548       0.557       0.519       0.229

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     44/99     4.44G   0.03721    0.0169  0.004807   0.05891        21       416: 100% 83/83 [01:57<00:00,  1.42s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.597       0.573        0.58       0.268

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     45/99     4.44G   0.03686   0.01648  0.004751   0.05809        27       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.02s/it]
                 all         126         240        0.63       0.607       0.616       0.264

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     46/99     4.44G    0.0373   0.01707  0.004799   0.05918        12       416: 100% 83/83 [01:57<00:00,  1.42s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.01s/it]
                 all         126         240       0.617       0.609       0.578        0.25

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     47/99     4.44G    0.0358   0.01641  0.003825   0.05604        35       416: 100% 83/83 [01:58<00:00,  1.42s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.536       0.614       0.526       0.218

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     48/99     4.44G   0.03578   0.01641  0.003722   0.05591        33       416: 100% 83/83 [01:57<00:00,  1.42s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.02s/it]
                 all         126         240       0.645       0.544       0.571        0.25

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     49/99     4.44G   0.03572   0.01627  0.004139   0.05613        23       416: 100% 83/83 [01:58<00:00,  1.42s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.539       0.622       0.569       0.255

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     50/99     4.44G    0.0346    0.0162  0.003541   0.05434        26       416: 100% 83/83 [01:58<00:00,  1.42s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.02s/it]
                 all         126         240       0.568       0.625       0.581       0.247

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     51/99     4.44G   0.03559   0.01588  0.003708   0.05518        14       416: 100% 83/83 [01:58<00:00,  1.42s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.614       0.602       0.578       0.229

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     52/99     4.44G   0.03397   0.01529  0.003692   0.05295        10       416: 100% 83/83 [01:57<00:00,  1.42s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.673        0.61       0.616       0.281

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     53/99     4.44G   0.03333   0.01531  0.003498   0.05214        16       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.638       0.606       0.611       0.276

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     54/99     4.44G   0.03375   0.01557  0.003505   0.05283        20       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.674        0.61       0.624       0.291

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     55/99     4.44G   0.03376   0.01552  0.003477   0.05276        28       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.608       0.587       0.555        0.24

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     56/99     4.44G   0.03314    0.0145  0.003712   0.05134        18       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.04s/it]
                 all         126         240       0.593       0.627        0.59       0.246

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     57/99     4.44G   0.03285    0.0153  0.003178   0.05133        28       416: 100% 83/83 [01:58<00:00,  1.42s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.02s/it]
                 all         126         240       0.616       0.603       0.598       0.266

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     58/99     4.44G   0.03249   0.01498  0.003033    0.0505        18       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240        0.62        0.62       0.593       0.264

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     59/99     4.44G    0.0318   0.01429  0.002914     0.049        21       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.577       0.656       0.571       0.251

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     60/99     4.44G   0.03215   0.01468  0.002896   0.04973        16       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240        0.57       0.641       0.565       0.262

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     61/99     4.44G   0.03266   0.01485  0.002792   0.05031        27       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.567       0.635        0.58       0.244

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     62/99     4.44G    0.0315   0.01464  0.002327   0.04846        22       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.589       0.573        0.57       0.259

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     63/99     4.44G   0.03142   0.01457  0.002556   0.04855        26       416: 100% 83/83 [01:59<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.718       0.536       0.597       0.275

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     64/99     4.44G   0.03094   0.01422  0.002988   0.04815        23       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.649       0.651       0.622       0.267

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     65/99     4.44G   0.03088   0.01405  0.002781   0.04771        24       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.611       0.634       0.599       0.258

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     66/99     4.44G   0.03033   0.01412  0.002732   0.04718        21       416: 100% 83/83 [01:59<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.709       0.549       0.565       0.246

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     67/99     4.44G   0.03021   0.01438  0.002187   0.04677        22       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.619       0.596       0.558       0.228

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     68/99     4.44G   0.02937   0.01381  0.002263   0.04545        23       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.588       0.639       0.592       0.262

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     69/99     4.44G   0.02973   0.01403   0.00233   0.04609        30       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240        0.68       0.611       0.601       0.268

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     70/99     4.44G   0.02883   0.01385  0.002633   0.04531        17       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.658       0.632       0.597       0.268

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     71/99     4.44G   0.02941    0.0133  0.002229   0.04495        12       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.721       0.555       0.601       0.266

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     72/99     4.44G   0.02934   0.01371   0.00248   0.04553        26       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.02s/it]
                 all         126         240       0.632       0.587        0.58       0.246

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     73/99     4.44G   0.02899   0.01349  0.002007   0.04448        15       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.646       0.568        0.59       0.261

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     74/99     4.44G   0.02832   0.01341  0.002194   0.04392        20       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.594       0.612       0.581       0.264

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     75/99     4.44G    0.0285    0.0134  0.002231   0.04413        23       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.619       0.622       0.588       0.255

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     76/99     4.44G   0.02858    0.0137  0.002069   0.04435        13       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.645       0.635       0.611       0.258

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     77/99     4.44G   0.02732   0.01295  0.002323   0.04259        21       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.623       0.602        0.58       0.252

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     78/99     4.44G   0.02745   0.01272  0.001845   0.04202        21       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.02s/it]
                 all         126         240        0.59       0.648        0.58       0.256

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     79/99     4.44G   0.02756   0.01276  0.002626   0.04294        22       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.02s/it]
                 all         126         240       0.604       0.621       0.609       0.266

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     80/99     4.44G   0.02747   0.01294  0.002191    0.0426        16       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.646       0.615         0.6       0.259

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     81/99     4.44G   0.02718   0.01288  0.002069   0.04213        17       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.645       0.636        0.61       0.256

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     82/99     4.44G   0.02662   0.01251  0.002086   0.04122        19       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.622       0.644       0.593       0.252

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     83/99     4.44G   0.02651   0.01305  0.002263   0.04182        27       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.743       0.566       0.607       0.284

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     84/99     4.44G   0.02664    0.0123  0.002308   0.04125        20       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.02s/it]
                 all         126         240       0.693       0.599       0.591       0.268

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     85/99     4.44G   0.02639   0.01309  0.001987   0.04147        30       416: 100% 83/83 [01:59<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.694       0.581       0.604        0.27

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     86/99     4.44G   0.02645   0.01254  0.002108    0.0411        17       416: 100% 83/83 [01:59<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.02s/it]
                 all         126         240       0.733       0.561       0.607       0.275

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     87/99     4.44G   0.02632   0.01244  0.001923   0.04068        21       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.04s/it]
                 all         126         240       0.622       0.615       0.587       0.266

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     88/99     4.44G    0.0259   0.01239  0.001953   0.04024        25       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.02s/it]
                 all         126         240       0.687       0.558       0.584       0.268

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     89/99     4.44G   0.02561   0.01237  0.001465   0.03944        26       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.666       0.583       0.595       0.258

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     90/99     4.44G   0.02565   0.01154  0.001819   0.03901        23       416: 100% 83/83 [01:59<00:00,  1.44s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.636       0.586       0.573       0.264

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     91/99     4.44G   0.02573   0.01259  0.002049   0.04037        33       416: 100% 83/83 [01:57<00:00,  1.42s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.02s/it]
                 all         126         240       0.598       0.654         0.6       0.275

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     92/99     4.44G   0.02565    0.0118  0.001828   0.03929        18       416: 100% 83/83 [01:57<00:00,  1.41s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.668       0.572        0.58       0.254

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     93/99     4.44G   0.02547   0.01187  0.001887   0.03923        19       416: 100% 83/83 [01:58<00:00,  1.42s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.02s/it]
                 all         126         240       0.601       0.615       0.588       0.253

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     94/99     4.44G   0.02589   0.01213  0.001698   0.03972        20       416: 100% 83/83 [01:57<00:00,  1.42s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.02s/it]
                 all         126         240       0.672       0.595       0.596       0.285

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     95/99     4.44G     0.025   0.01178  0.001609   0.03839        24       416: 100% 83/83 [01:57<00:00,  1.42s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.02s/it]
                 all         126         240       0.658       0.579       0.595       0.266

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     96/99     4.44G   0.02547   0.01245  0.001805   0.03972        16       416: 100% 83/83 [01:58<00:00,  1.42s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.04s/it]
                 all         126         240       0.637       0.626        0.61       0.272

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     97/99     4.44G    0.0247   0.01193  0.001771    0.0384        25       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240        0.64       0.578       0.591        0.27

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     98/99     4.44G   0.02499   0.01186   0.00169   0.03854        43       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:04<00:00,  1.03s/it]
                 all         126         240       0.688       0.545       0.587       0.266

     Epoch   gpu_mem       box       obj       cls     total   targets  img_size
     99/99     4.44G   0.02491    0.0112  0.001944   0.03805        17       416: 100% 83/83 [01:58<00:00,  1.43s/it]
               Class      Images     Targets           P           R      mAP@.5  mAP@.5:.95: 100% 4/4 [00:05<00:00,  1.27s/it]
                 all         126         240       0.594       0.637       0.593       0.264
         With Helmet         126         165       0.645       0.782       0.696        0.31
      Without Helmet         126          75       0.543       0.493       0.491       0.219
Optimizer stripped from runs/train/yolov5s_results2/weights/last.pt, 93.7MB
Optimizer stripped from runs/train/yolov5s_results2/weights/best.pt, 93.7MB
100 epochs completed in 3.499 hours.

CPU times: user 1min 1s, sys: 8.35 s, total: 1min 10s
Wall time: 3h 30min 55s

Evaluate Custom YOLOv5 Detector Performance

Training losses and performance metrics are saved to Tensorboard and also to a logfile defined above with the --name flag when we train. In our case, we named this yolov5s_results. (If given no name, it defaults to results.txt.) The results file is plotted as a png after training completes.

Note from Glenn: Partially completed results.txt files can be plotted with from utils.utils import plot_results; plot_results().

# Launch after you have started training
# logs save in the folder "runs"
#%load_ext tensorboard
#%tensorboard --logdir runs
from utils.plots import plot_results  # plot results.txt as results.png
Image(filename='/content/drive/MyDrive/Helment_Detection_Yolov5/yolov5/runs/train/yolov5s_results2/results.png', width=1000)  # view results.png
#Image(filename='/content/drive/MyDrive/Helment_Detection_Yolov5/yolov5/runs/train/yolov5s_results/results.png', width=1000)  # view results.png

Curious? Visualize Our Training Data with Labels

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 Glenn Jocher and first featured in YOLOv4.

print("GROUND TRUTH TRAINING DATA:")
Image(filename='/content/drive/MyDrive/Helment_Detection_Yolov5/yolov5/runs/train/yolov5s_results2/test_batch0_labels.jpg', width=900)
GROUND TRUTH TRAINING DATA:
print("GROUND TRUTH AUGMENTED TRAINING DATA:")
Image(filename='/content/drive/MyDrive/Helment_Detection_Yolov5/yolov5/runs/train/yolov5s_results2/train_batch0.jpg', width=900)
GROUND TRUTH AUGMENTED TRAINING DATA:

Run With Trained Weights

Run inference with a pretrained checkpoint on contents of test/images folder downloaded from Roboflow.

%cd /content/drive/MyDrive/Helment_Detection_Yolov5/yolov5/
%ls runs/
/content/drive/MyDrive/Helment_Detection_Yolov5/yolov5
detect/  train/
%ls runs/train/yolov5s_results2/weights
best.pt  last.pt
# use the best weights!
%cd /content/drive/MyDrive/Helment_Detection_Yolov5/yolov5/
!python detect.py --weights runs/train/yolov5s_results2/weights/last.pt --img 416 --conf 0.1 --source ../traffic
#!python detect.py --weights runs/train/yolov5s_results/weights/best.pt --img 416 --conf 0.4 --source 0
#!python detect.py --weights runs/train/yolov5s_results2/weights/best.pt --conf 0.1 --source ../race/Men1.mp4
/content/drive/MyDrive/Helment_Detection_Yolov5/yolov5
Namespace(agnostic_nms=False, augment=False, classes=None, conf_thres=0.1, device='', exist_ok=False, img_size=416, iou_thres=0.45, name='exp', project='runs/detect', save_conf=False, save_txt=False, source='../traffic', update=False, view_img=False, weights=['runs/train/yolov5s_results2/weights/last.pt'])
YOLOv5 v4.0-126-g886f1c0 torch 1.8.1+cu101 CUDA:0 (Tesla T4, 15109.75MB)

Fusing layers... 
Model Summary: 392 layers, 46605951 parameters, 0 gradients, 114.1 GFLOPS
image 1/5 /content/drive/My Drive/Helment_Detection_Yolov5/yolov5/../traffic/traffic-helment13.jpg: 256x416 3 Without Helmets, Done. (0.022s)
image 2/5 /content/drive/My Drive/Helment_Detection_Yolov5/yolov5/../traffic/traffic-helment14.jpg: 256x416 8 With Helmets, 1 Without Helmet, Done. (0.021s)
image 3/5 /content/drive/My Drive/Helment_Detection_Yolov5/yolov5/../traffic/traffic-helment15.jpg: 288x416 3 With Helmets, 5 Without Helmets, Done. (0.021s)
image 4/5 /content/drive/My Drive/Helment_Detection_Yolov5/yolov5/../traffic/traffic-helment31.jpg: 288x416 5 With Helmets, 5 Without Helmets, Done. (0.020s)
image 5/5 /content/drive/My Drive/Helment_Detection_Yolov5/yolov5/../traffic/traffic-helment33.jpg: 288x416 2 With Helmets, Done. (0.020s)
Results saved to runs/detect/exp11
Done. (1.829s)
#this looks much better with longer training above

import glob
from IPython.display import Image, display

for imageName in glob.glob('/content/drive/MyDrive/Helment_Detection_Yolov5/yolov5/runs/detect/exp11/*.jpg'): #assuming JPG
    display(Image(filename=imageName))
    print("\n")
Output hidden; open in https://colab.research.google.com to view.

Export Trained Weights for Future

Now that you have trained your custom detector, you can export the trained weights you have made here for inference on your device elsewhere

 
</div>