Skip to content

Training

Farley Lai edited this page Apr 30, 2021 · 1 revision

YOLOv5 Training

Dependencies

  • apex for mixed precision training at O1

Hyperparameters

hyp = {'optimizer': 'SGD',  # ['adam', 'SGD', None] if none, default is SGD
       'lr0': 0.01,  # initial learning rate (SGD=1E-2, Adam=1E-3)
       'momentum': 0.937,  # SGD momentum/Adam beta1
       'weight_decay': 5e-4,  # optimizer weight decay
       'giou': 0.05,  # giou loss gain
       'cls': 0.58,  # cls loss gain
       'cls_pw': 1.0,  # cls BCELoss positive_weight
       'obj': 1.0,  # obj loss gain (*=img_size/320 if img_size != 320)
       'obj_pw': 1.0,  # obj BCELoss positive_weight
       'iou_t': 0.20,  # iou training threshold
       'anchor_t': 4.0,  # anchor-multiple threshold
       'fl_gamma': 0.0,  # focal loss gamma (efficientDet default is gamma=1.5)
       'hsv_h': 0.014,  # image HSV-Hue augmentation (fraction)
       'hsv_s': 0.68,  # image HSV-Saturation augmentation (fraction)
       'hsv_v': 0.36,  # image HSV-Value augmentation (fraction)
       'degrees': 0.0,  # image rotation (+/- deg)
       'translate': 0.0,  # image translation (+/- fraction)
       'scale': 0.5,  # image scale (+/- gain)
       'shear': 0.0}  # image shear (+/- deg)

Setup

  • Randomness
    torch.manual_seed(seed=1)
    cudnn.deterministic = False
    cudnn.benchmark = True
  • Rescaling to a multiple of stride default to 32
  • Nominal batch size: 64 with gradient accumulation if unequal
  • Cosine Learning Rate Decay
    lambda x: (((1 + math.cos(x * math.pi / epochs)) / 2) ** 1.0) * 0.9 + 0.1  # cosine
  • Distributed multi-GPU training by default

Annotations

Splits:

  • [train | val | test].txt: paths to images in the split

Images:

  • images/[train | val | test]2017/[imgid].jpg

Labels:

  • labels/[train | val | test]2017/[imgid].txt: normalized (cls, x1, y1, x2, y2)+

Cache:

  • '{path: [labels, shape]}'

Augmentations

  • HSV
  • rescaling
Clone this wiki locally