From 9c6cc8522341d3d561ee7812386c39800b8e980e Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 15 Dec 2020 22:48:27 -0800 Subject: [PATCH 001/176] Update C3 module --- data/hyp.scratch.yaml | 2 +- models/common.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/data/hyp.scratch.yaml b/data/hyp.scratch.yaml index 44f26b6658ae..d0babc0272de 100644 --- a/data/hyp.scratch.yaml +++ b/data/hyp.scratch.yaml @@ -13,7 +13,7 @@ warmup_bias_lr: 0.1 # warmup initial bias lr box: 0.05 # box loss gain cls: 0.5 # cls loss gain cls_pw: 1.0 # cls BCELoss positive_weight -obj: 1.0 # obj loss gain (scale with pixels) +obj: 0.5 # obj loss gain (scale with pixels) obj_pw: 1.0 # obj BCELoss positive_weight iou_t: 0.20 # IoU training threshold anchor_t: 4.0 # anchor-multiple threshold diff --git a/models/common.py b/models/common.py index c3b51a46f14a..81c33e463159 100644 --- a/models/common.py +++ b/models/common.py @@ -29,7 +29,7 @@ def __init__(self, c1, c2, k=1, s=1, p=None, g=1, act=True): # ch_in, ch_out, k super(Conv, self).__init__() self.conv = nn.Conv2d(c1, c2, k, s, autopad(k, p), groups=g, bias=False) self.bn = nn.BatchNorm2d(c2) - self.act = nn.Hardswish() if act is True else (act if isinstance(act, nn.Module) else nn.Identity()) + self.act = nn.SiLU() if act is True else (act if isinstance(act, nn.Module) else nn.Identity()) def forward(self, x): return self.act(self.bn(self.conv(x))) From b62f8911e16c500d524b8c5eb80f102835b478bb Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 15 Dec 2020 22:51:29 -0800 Subject: [PATCH 002/176] Update C3 module --- data/hyp.scratch_03cls.yaml | 33 +++++++++++++++++++++++++++++++++ data/hyp.scratch_08cls.yaml | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 data/hyp.scratch_03cls.yaml create mode 100644 data/hyp.scratch_08cls.yaml diff --git a/data/hyp.scratch_03cls.yaml b/data/hyp.scratch_03cls.yaml new file mode 100644 index 000000000000..8226046d19e8 --- /dev/null +++ b/data/hyp.scratch_03cls.yaml @@ -0,0 +1,33 @@ +# Hyperparameters for COCO training from scratch +# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 +# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials + + +lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) +lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) +momentum: 0.937 # SGD momentum/Adam beta1 +weight_decay: 0.0005 # optimizer weight decay 5e-4 +warmup_epochs: 3.0 # warmup epochs (fractions ok) +warmup_momentum: 0.8 # warmup initial momentum +warmup_bias_lr: 0.1 # warmup initial bias lr +box: 0.05 # box loss gain +cls: 0.3 # cls loss gain +cls_pw: 1.0 # cls BCELoss positive_weight +obj: 0.5 # obj loss gain (scale with pixels) +obj_pw: 1.0 # obj BCELoss positive_weight +iou_t: 0.20 # IoU training threshold +anchor_t: 4.0 # anchor-multiple threshold +# anchors: 3 # anchors per output layer (0 to ignore) +fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) +hsv_h: 0.015 # image HSV-Hue augmentation (fraction) +hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) +hsv_v: 0.4 # image HSV-Value augmentation (fraction) +degrees: 0.0 # image rotation (+/- deg) +translate: 0.1 # image translation (+/- fraction) +scale: 0.5 # image scale (+/- gain) +shear: 0.0 # image shear (+/- deg) +perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 +flipud: 0.0 # image flip up-down (probability) +fliplr: 0.5 # image flip left-right (probability) +mosaic: 1.0 # image mosaic (probability) +mixup: 0.0 # image mixup (probability) diff --git a/data/hyp.scratch_08cls.yaml b/data/hyp.scratch_08cls.yaml new file mode 100644 index 000000000000..091089b40d15 --- /dev/null +++ b/data/hyp.scratch_08cls.yaml @@ -0,0 +1,33 @@ +# Hyperparameters for COCO training from scratch +# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 +# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials + + +lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) +lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) +momentum: 0.937 # SGD momentum/Adam beta1 +weight_decay: 0.0005 # optimizer weight decay 5e-4 +warmup_epochs: 3.0 # warmup epochs (fractions ok) +warmup_momentum: 0.8 # warmup initial momentum +warmup_bias_lr: 0.1 # warmup initial bias lr +box: 0.05 # box loss gain +cls: 0.8 # cls loss gain +cls_pw: 1.0 # cls BCELoss positive_weight +obj: 0.5 # obj loss gain (scale with pixels) +obj_pw: 1.0 # obj BCELoss positive_weight +iou_t: 0.20 # IoU training threshold +anchor_t: 4.0 # anchor-multiple threshold +# anchors: 3 # anchors per output layer (0 to ignore) +fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) +hsv_h: 0.015 # image HSV-Hue augmentation (fraction) +hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) +hsv_v: 0.4 # image HSV-Value augmentation (fraction) +degrees: 0.0 # image rotation (+/- deg) +translate: 0.1 # image translation (+/- fraction) +scale: 0.5 # image scale (+/- gain) +shear: 0.0 # image shear (+/- deg) +perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 +flipud: 0.0 # image flip up-down (probability) +fliplr: 0.5 # image flip left-right (probability) +mosaic: 1.0 # image mosaic (probability) +mixup: 0.0 # image mixup (probability) From 81d4f2e270973ca9f1f909bc97314b55c14b3094 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 15 Dec 2020 22:53:09 -0800 Subject: [PATCH 003/176] Update C3 module --- data/coco.yaml | 3 +++ models/yolo.py | 2 +- models/yolov5l.yaml | 16 ++++++++-------- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/data/coco.yaml b/data/coco.yaml index 09f3a7890373..725843a7a5da 100644 --- a/data/coco.yaml +++ b/data/coco.yaml @@ -33,3 +33,6 @@ names: ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 't # d = yaml.load(f, Loader=yaml.FullLoader) # dict # for i, x in enumerate(d['names']): # print(i, x) + + +# python train.py --data coco.yaml --batch 24 --weights '' --cfg yolov5l.yaml --epochs 300 --project ../paper --name yolov5l3b --device 1 diff --git a/models/yolo.py b/models/yolo.py index 4ad44afe5367..ec50cea5ca70 100644 --- a/models/yolo.py +++ b/models/yolo.py @@ -262,7 +262,7 @@ def parse_model(d, ch): # model_dict, input_channels(3) if __name__ == '__main__': parser = argparse.ArgumentParser() - parser.add_argument('--cfg', type=str, default='yolov5s.yaml', help='model.yaml') + parser.add_argument('--cfg', type=str, default='yolov5l.yaml', help='model.yaml') parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu') opt = parser.parse_args() opt.cfg = check_file(opt.cfg) # check file diff --git a/models/yolov5l.yaml b/models/yolov5l.yaml index 13095541703f..71ebf86e5791 100644 --- a/models/yolov5l.yaml +++ b/models/yolov5l.yaml @@ -14,14 +14,14 @@ backbone: # [from, number, module, args] [[-1, 1, Focus, [64, 3]], # 0-P1/2 [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 - [-1, 3, BottleneckCSP, [128]], + [-1, 3, C3, [128]], [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 - [-1, 9, BottleneckCSP, [256]], + [-1, 9, C3, [256]], [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 - [-1, 9, BottleneckCSP, [512]], + [-1, 9, C3, [512]], [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 [-1, 1, SPP, [1024, [5, 9, 13]]], - [-1, 3, BottleneckCSP, [1024, False]], # 9 + [-1, 3, C3, [1024, False]], # 9 ] # YOLOv5 head @@ -29,20 +29,20 @@ head: [[-1, 1, Conv, [512, 1, 1]], [-1, 1, nn.Upsample, [None, 2, 'nearest']], [[-1, 6], 1, Concat, [1]], # cat backbone P4 - [-1, 3, BottleneckCSP, [512, False]], # 13 + [-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, BottleneckCSP, [256, False]], # 17 (P3/8-small) + [-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, BottleneckCSP, [512, False]], # 20 (P4/16-medium) + [-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, BottleneckCSP, [1024, False]], # 23 (P5/32-large) + [-1, 3, C3, [1024, False]], # 23 (P5/32-large) [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) ] From 51762f68619e4d384fc4a274196596cf0ff868c2 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 15 Dec 2020 23:59:57 -0800 Subject: [PATCH 004/176] Update C3 module --- data/coco.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/data/coco.yaml b/data/coco.yaml index 725843a7a5da..17cbdee53b7e 100644 --- a/data/coco.yaml +++ b/data/coco.yaml @@ -35,4 +35,5 @@ names: ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 't # print(i, x) -# python train.py --data coco.yaml --batch 24 --weights '' --cfg yolov5l.yaml --epochs 300 --project ../paper --name yolov5l3b --device 1 +# python train.py --data coco.yaml --batch 24 --weights '' --cfg yolov5l.yaml --epochs 300 --project ../paper --name yolov5lc3_03cls --hyp hyp.scratch_03cls.yaml --device 0 +# python train.py --data coco.yaml --batch 24 --weights '' --cfg yolov5l.yaml --epochs 300 --project ../paper --name yolov5lc3_08cls --hyp hyp.scratch_08cls.yaml --device 1 \ No newline at end of file From a6d84e1442cdcb8556bb8c120828fd4d62ff540e Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 16 Dec 2020 18:18:49 -0800 Subject: [PATCH 005/176] update --- data/hyp.scratch_03cls_06scale.yaml | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 data/hyp.scratch_03cls_06scale.yaml diff --git a/data/hyp.scratch_03cls_06scale.yaml b/data/hyp.scratch_03cls_06scale.yaml new file mode 100644 index 000000000000..1462e21bf137 --- /dev/null +++ b/data/hyp.scratch_03cls_06scale.yaml @@ -0,0 +1,33 @@ +# Hyperparameters for COCO training from scratch +# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 +# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials + + +lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) +lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) +momentum: 0.937 # SGD momentum/Adam beta1 +weight_decay: 0.0005 # optimizer weight decay 5e-4 +warmup_epochs: 3.0 # warmup epochs (fractions ok) +warmup_momentum: 0.8 # warmup initial momentum +warmup_bias_lr: 0.1 # warmup initial bias lr +box: 0.05 # box loss gain +cls: 0.3 # cls loss gain +cls_pw: 1.0 # cls BCELoss positive_weight +obj: 0.5 # obj loss gain (scale with pixels) +obj_pw: 1.0 # obj BCELoss positive_weight +iou_t: 0.20 # IoU training threshold +anchor_t: 4.0 # anchor-multiple threshold +# anchors: 3 # anchors per output layer (0 to ignore) +fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) +hsv_h: 0.015 # image HSV-Hue augmentation (fraction) +hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) +hsv_v: 0.4 # image HSV-Value augmentation (fraction) +degrees: 0.0 # image rotation (+/- deg) +translate: 0.1 # image translation (+/- fraction) +scale: 0.6 # image scale (+/- gain) +shear: 0.0 # image shear (+/- deg) +perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 +flipud: 0.0 # image flip up-down (probability) +fliplr: 0.5 # image flip left-right (probability) +mosaic: 1.0 # image mosaic (probability) +mixup: 0.0 # image mixup (probability) From 78380e60bd566e29dd27e475611d216265b2bac3 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 16 Dec 2020 19:54:56 -0800 Subject: [PATCH 006/176] update --- ...le.yaml => hyp.scratch_03cls_07scale.yaml} | 2 +- data/hyp.scratch_03cls_09scale.yaml | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) rename data/{hyp.scratch_03cls_06scale.yaml => hyp.scratch_03cls_07scale.yaml} (97%) create mode 100644 data/hyp.scratch_03cls_09scale.yaml diff --git a/data/hyp.scratch_03cls_06scale.yaml b/data/hyp.scratch_03cls_07scale.yaml similarity index 97% rename from data/hyp.scratch_03cls_06scale.yaml rename to data/hyp.scratch_03cls_07scale.yaml index 1462e21bf137..90026ebaec8a 100644 --- a/data/hyp.scratch_03cls_06scale.yaml +++ b/data/hyp.scratch_03cls_07scale.yaml @@ -24,7 +24,7 @@ hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) hsv_v: 0.4 # image HSV-Value augmentation (fraction) degrees: 0.0 # image rotation (+/- deg) translate: 0.1 # image translation (+/- fraction) -scale: 0.6 # image scale (+/- gain) +scale: 0.7 # image scale (+/- gain) shear: 0.0 # image shear (+/- deg) perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 flipud: 0.0 # image flip up-down (probability) diff --git a/data/hyp.scratch_03cls_09scale.yaml b/data/hyp.scratch_03cls_09scale.yaml new file mode 100644 index 000000000000..9078ac089247 --- /dev/null +++ b/data/hyp.scratch_03cls_09scale.yaml @@ -0,0 +1,33 @@ +# Hyperparameters for COCO training from scratch +# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 +# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials + + +lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) +lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) +momentum: 0.937 # SGD momentum/Adam beta1 +weight_decay: 0.0005 # optimizer weight decay 5e-4 +warmup_epochs: 3.0 # warmup epochs (fractions ok) +warmup_momentum: 0.8 # warmup initial momentum +warmup_bias_lr: 0.1 # warmup initial bias lr +box: 0.05 # box loss gain +cls: 0.3 # cls loss gain +cls_pw: 1.0 # cls BCELoss positive_weight +obj: 0.5 # obj loss gain (scale with pixels) +obj_pw: 1.0 # obj BCELoss positive_weight +iou_t: 0.20 # IoU training threshold +anchor_t: 4.0 # anchor-multiple threshold +# anchors: 3 # anchors per output layer (0 to ignore) +fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) +hsv_h: 0.015 # image HSV-Hue augmentation (fraction) +hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) +hsv_v: 0.4 # image HSV-Value augmentation (fraction) +degrees: 0.0 # image rotation (+/- deg) +translate: 0.1 # image translation (+/- fraction) +scale: 0.9 # image scale (+/- gain) +shear: 0.0 # image shear (+/- deg) +perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 +flipud: 0.0 # image flip up-down (probability) +fliplr: 0.5 # image flip left-right (probability) +mosaic: 1.0 # image mosaic (probability) +mixup: 0.0 # image mixup (probability) From b61827f4ff963dd887c606dbdb4dcf8bc295da6d Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Fri, 18 Dec 2020 14:14:25 -0800 Subject: [PATCH 007/176] update --- models/yolov5m.yaml | 16 ++++++++-------- models/yolov5s.yaml | 16 ++++++++-------- models/yolov5x.yaml | 16 ++++++++-------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/models/yolov5m.yaml b/models/yolov5m.yaml index eb50a713f2ff..3c749c916246 100644 --- a/models/yolov5m.yaml +++ b/models/yolov5m.yaml @@ -14,14 +14,14 @@ backbone: # [from, number, module, args] [[-1, 1, Focus, [64, 3]], # 0-P1/2 [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 - [-1, 3, BottleneckCSP, [128]], + [-1, 3, C3, [128]], [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 - [-1, 9, BottleneckCSP, [256]], + [-1, 9, C3, [256]], [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 - [-1, 9, BottleneckCSP, [512]], + [-1, 9, C3, [512]], [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 [-1, 1, SPP, [1024, [5, 9, 13]]], - [-1, 3, BottleneckCSP, [1024, False]], # 9 + [-1, 3, C3, [1024, False]], # 9 ] # YOLOv5 head @@ -29,20 +29,20 @@ head: [[-1, 1, Conv, [512, 1, 1]], [-1, 1, nn.Upsample, [None, 2, 'nearest']], [[-1, 6], 1, Concat, [1]], # cat backbone P4 - [-1, 3, BottleneckCSP, [512, False]], # 13 + [-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, BottleneckCSP, [256, False]], # 17 (P3/8-small) + [-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, BottleneckCSP, [512, False]], # 20 (P4/16-medium) + [-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, BottleneckCSP, [1024, False]], # 23 (P5/32-large) + [-1, 3, C3, [1024, False]], # 23 (P5/32-large) [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) ] diff --git a/models/yolov5s.yaml b/models/yolov5s.yaml index 2bec4529294e..aca669d60d8b 100644 --- a/models/yolov5s.yaml +++ b/models/yolov5s.yaml @@ -14,14 +14,14 @@ backbone: # [from, number, module, args] [[-1, 1, Focus, [64, 3]], # 0-P1/2 [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 - [-1, 3, BottleneckCSP, [128]], + [-1, 3, C3, [128]], [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 - [-1, 9, BottleneckCSP, [256]], + [-1, 9, C3, [256]], [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 - [-1, 9, BottleneckCSP, [512]], + [-1, 9, C3, [512]], [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 [-1, 1, SPP, [1024, [5, 9, 13]]], - [-1, 3, BottleneckCSP, [1024, False]], # 9 + [-1, 3, C3, [1024, False]], # 9 ] # YOLOv5 head @@ -29,20 +29,20 @@ head: [[-1, 1, Conv, [512, 1, 1]], [-1, 1, nn.Upsample, [None, 2, 'nearest']], [[-1, 6], 1, Concat, [1]], # cat backbone P4 - [-1, 3, BottleneckCSP, [512, False]], # 13 + [-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, BottleneckCSP, [256, False]], # 17 (P3/8-small) + [-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, BottleneckCSP, [512, False]], # 20 (P4/16-medium) + [-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, BottleneckCSP, [1024, False]], # 23 (P5/32-large) + [-1, 3, C3, [1024, False]], # 23 (P5/32-large) [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) ] diff --git a/models/yolov5x.yaml b/models/yolov5x.yaml index 9676402040ce..d3babdf7baf0 100644 --- a/models/yolov5x.yaml +++ b/models/yolov5x.yaml @@ -14,14 +14,14 @@ backbone: # [from, number, module, args] [[-1, 1, Focus, [64, 3]], # 0-P1/2 [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 - [-1, 3, BottleneckCSP, [128]], + [-1, 3, C3, [128]], [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 - [-1, 9, BottleneckCSP, [256]], + [-1, 9, C3, [256]], [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 - [-1, 9, BottleneckCSP, [512]], + [-1, 9, C3, [512]], [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 [-1, 1, SPP, [1024, [5, 9, 13]]], - [-1, 3, BottleneckCSP, [1024, False]], # 9 + [-1, 3, C3, [1024, False]], # 9 ] # YOLOv5 head @@ -29,20 +29,20 @@ head: [[-1, 1, Conv, [512, 1, 1]], [-1, 1, nn.Upsample, [None, 2, 'nearest']], [[-1, 6], 1, Concat, [1]], # cat backbone P4 - [-1, 3, BottleneckCSP, [512, False]], # 13 + [-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, BottleneckCSP, [256, False]], # 17 (P3/8-small) + [-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, BottleneckCSP, [512, False]], # 20 (P4/16-medium) + [-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, BottleneckCSP, [1024, False]], # 23 (P5/32-large) + [-1, 3, C3, [1024, False]], # 23 (P5/32-large) [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) ] From f79a47b23471a5be4707b15d5aef23e3487d11f5 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Fri, 18 Dec 2020 22:01:36 -0800 Subject: [PATCH 008/176] update --- data/hyp.scratch_01cls.yaml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 data/hyp.scratch_01cls.yaml diff --git a/data/hyp.scratch_01cls.yaml b/data/hyp.scratch_01cls.yaml new file mode 100644 index 000000000000..ec1b39d8b857 --- /dev/null +++ b/data/hyp.scratch_01cls.yaml @@ -0,0 +1,33 @@ +# Hyperparameters for COCO training from scratch +# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 +# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials + + +lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) +lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) +momentum: 0.937 # SGD momentum/Adam beta1 +weight_decay: 0.0005 # optimizer weight decay 5e-4 +warmup_epochs: 3.0 # warmup epochs (fractions ok) +warmup_momentum: 0.8 # warmup initial momentum +warmup_bias_lr: 0.1 # warmup initial bias lr +box: 0.05 # box loss gain +cls: 0.1 # cls loss gain +cls_pw: 1.0 # cls BCELoss positive_weight +obj: 0.5 # obj loss gain (scale with pixels) +obj_pw: 1.0 # obj BCELoss positive_weight +iou_t: 0.20 # IoU training threshold +anchor_t: 4.0 # anchor-multiple threshold +# anchors: 3 # anchors per output layer (0 to ignore) +fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) +hsv_h: 0.015 # image HSV-Hue augmentation (fraction) +hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) +hsv_v: 0.4 # image HSV-Value augmentation (fraction) +degrees: 0.0 # image rotation (+/- deg) +translate: 0.1 # image translation (+/- fraction) +scale: 0.5 # image scale (+/- gain) +shear: 0.0 # image shear (+/- deg) +perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 +flipud: 0.0 # image flip up-down (probability) +fliplr: 0.5 # image flip left-right (probability) +mosaic: 1.0 # image mosaic (probability) +mixup: 0.0 # image mixup (probability) From 7fad46e67ea39f7504324f200fddd5fb4cf58acb Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 20 Dec 2020 17:42:28 -0800 Subject: [PATCH 009/176] update --- models/yolov5l-p6.yaml | 56 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 models/yolov5l-p6.yaml diff --git a/models/yolov5l-p6.yaml b/models/yolov5l-p6.yaml new file mode 100644 index 000000000000..3728a118f090 --- /dev/null +++ b/models/yolov5l-p6.yaml @@ -0,0 +1,56 @@ +# parameters +nc: 80 # number of classes +depth_multiple: 1.0 # model depth multiple +width_multiple: 1.0 # layer channel multiple + +# anchors +anchors: 3 + +# 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, [ 768, 3, 2 ] ], # 7-P5/32 + [ -1, 3, C3, [ 768 ] ], + [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 + [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ], + [ -1, 3, C3, [ 1024, False ] ], # 11 + ] + +# YOLOv5 head +head: + [ [ -1, 1, Conv, [ 768, 1, 1 ] ], + [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], + [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 + [ -1, 3, C3, [ 768, False ] ], # 15 + + [ -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 ] ], # 19 + + [ -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 ] ], # 23 (P3/8-small) + + [ -1, 1, Conv, [ 256, 3, 2 ] ], + [ [ -1, 20 ], 1, Concat, [ 1 ] ], # cat head P4 + [ -1, 3, C3, [ 512, False ] ], # 26 (P4/16-medium) + + [ -1, 1, Conv, [ 512, 3, 2 ] ], + [ [ -1, 16 ], 1, Concat, [ 1 ] ], # cat head P5 + [ -1, 3, C3, [ 768, False ] ], # 29 (P5/32-large) + + [ -1, 1, Conv, [ 768, 3, 2 ] ], + [ [ -1, 12 ], 1, Concat, [ 1 ] ], # cat head P6 + [ -1, 3, C3, [ 1024, False ] ], # 32 (P5/64-xlarge) + + [ [ 23, 26, 29, 32 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) + ] From 84f2fec6d4e8d471cc6b4cd890cc00539c0f7e72 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 20 Dec 2020 20:12:51 -0800 Subject: [PATCH 010/176] update --- models/experimental.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/models/experimental.py b/models/experimental.py index 136e86d7f8e6..108e884ceae5 100644 --- a/models/experimental.py +++ b/models/experimental.py @@ -95,6 +95,34 @@ def forward(self, x): return x + self.act(self.bn(torch.cat([m(x) for m in self.m], 1))) +class Contract(nn.Module): + # Contract width-height into channels, i.e. x(1,64,80,80) to x(1,256,40,40) + def __init__(self, gain=2): + super().__init__() + self.gain = gain + + def forward(self, x): + N, C, H, W = x.size() # assert (H / s == 0) and (W / s == 0), 'Indivisible gain' + s = self.gain + x = x.view(N, C, H // s, s, W // s, s) # x(1,64,40,2,40,2) + x = x.permute(0, 3, 5, 1, 2, 4).contiguous() # x(1,2,2,64,40,40) + return x.view(N, C * s * s, H // s, W // s) # x(1,256,40,40) + + +class Expand(nn.Module): + # Expand channels into width-height, i.e. x(1,64,80,80) to x(1,16,160,160) + def __init__(self, gain=2): + super().__init__() + self.gain = gain + + def forward(self, x): + N, C, H, W = x.size() # assert C / s ** 2 == 0, 'Indivisible gain' + s = self.gain + x = x.view(N, s, s, C // s ** 2, H, W) # x(1,2,2,16,80,80) + x = x.permute(0, 3, 4, 1, 5, 2).contiguous() # x(1,16,80,2,80,2) + return x.view(N, C // s ** 2, H * s, W * s) # x(1,16,160,160) + + class Ensemble(nn.ModuleList): # Ensemble of models def __init__(self): From 9bb09fcc73cb0bff0019bd2843334037aec7dd97 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 20 Dec 2020 20:29:20 -0800 Subject: [PATCH 011/176] update --- models/common.py | 50 ++++++++++++++++++++++++++++++++++-------- models/experimental.py | 28 ----------------------- 2 files changed, 41 insertions(+), 37 deletions(-) diff --git a/models/common.py b/models/common.py index 81c33e463159..3b9464bd753c 100644 --- a/models/common.py +++ b/models/common.py @@ -99,14 +99,53 @@ def forward(self, x): return self.cv2(torch.cat([x] + [m(x) for m in self.m], 1)) +# class Focus(nn.Module): +# # Focus wh information into c-space +# def __init__(self, c1, c2, k=1, s=1, p=None, g=1, act=True): # ch_in, ch_out, kernel, stride, padding, groups +# super(Focus, self).__init__() +# self.conv = Conv(c1 * 4, c2, k, s, p, g, act) +# +# def forward(self, x): # x(b,c,w,h) -> y(b,4c,w/2,h/2) +# return self.conv(torch.cat([x[..., ::2, ::2], x[..., 1::2, ::2], x[..., ::2, 1::2], x[..., 1::2, 1::2]], 1)) + + class Focus(nn.Module): # Focus wh information into c-space def __init__(self, c1, c2, k=1, s=1, p=None, g=1, act=True): # ch_in, ch_out, kernel, stride, padding, groups super(Focus, self).__init__() self.conv = Conv(c1 * 4, c2, k, s, p, g, act) + self.contract = Contract(2) def forward(self, x): # x(b,c,w,h) -> y(b,4c,w/2,h/2) - return self.conv(torch.cat([x[..., ::2, ::2], x[..., 1::2, ::2], x[..., ::2, 1::2], x[..., 1::2, 1::2]], 1)) + return self.conv(self.contract(x)) + + +class Contract(nn.Module): + # Contract width-height into channels, i.e. x(1,64,80,80) to x(1,256,40,40) + def __init__(self, gain=2): + super().__init__() + self.gain = gain + + def forward(self, x): + N, C, H, W = x.size() # assert (H / s == 0) and (W / s == 0), 'Indivisible gain' + s = self.gain + x = x.view(N, C, H // s, s, W // s, s) # x(1,64,40,2,40,2) + x = x.permute(0, 3, 5, 1, 2, 4).contiguous() # x(1,2,2,64,40,40) + return x.view(N, C * s * s, H // s, W // s) # x(1,256,40,40) + + +class Expand(nn.Module): + # Expand channels into width-height, i.e. x(1,64,80,80) to x(1,16,160,160) + def __init__(self, gain=2): + super().__init__() + self.gain = gain + + def forward(self, x): + N, C, H, W = x.size() # assert C / s ** 2 == 0, 'Indivisible gain' + s = self.gain + x = x.view(N, s, s, C // s ** 2, H, W) # x(1,2,2,16,80,80) + x = x.permute(0, 3, 4, 1, 5, 2).contiguous() # x(1,16,80,2,80,2) + return x.view(N, C // s ** 2, H * s, W * s) # x(1,16,160,160) class Concat(nn.Module): @@ -245,20 +284,13 @@ def tolist(self): return x -class Flatten(nn.Module): - # Use after nn.AdaptiveAvgPool2d(1) to remove last 2 dimensions - @staticmethod - def forward(x): - return x.view(x.size(0), -1) - - class Classify(nn.Module): # Classification head, i.e. x(b,c1,20,20) to x(b,c2) def __init__(self, c1, c2, k=1, s=1, p=None, g=1): # ch_in, ch_out, kernel, stride, padding, groups super(Classify, self).__init__() self.aap = nn.AdaptiveAvgPool2d(1) # to x(b,c1,1,1) self.conv = nn.Conv2d(c1, c2, k, s, autopad(k, p), groups=g) # to x(b,c2,1,1) - self.flat = Flatten() + self.flat = nn.Flatten() def forward(self, x): z = torch.cat([self.aap(y) for y in (x if isinstance(x, list) else [x])], 1) # cat if list diff --git a/models/experimental.py b/models/experimental.py index 108e884ceae5..136e86d7f8e6 100644 --- a/models/experimental.py +++ b/models/experimental.py @@ -95,34 +95,6 @@ def forward(self, x): return x + self.act(self.bn(torch.cat([m(x) for m in self.m], 1))) -class Contract(nn.Module): - # Contract width-height into channels, i.e. x(1,64,80,80) to x(1,256,40,40) - def __init__(self, gain=2): - super().__init__() - self.gain = gain - - def forward(self, x): - N, C, H, W = x.size() # assert (H / s == 0) and (W / s == 0), 'Indivisible gain' - s = self.gain - x = x.view(N, C, H // s, s, W // s, s) # x(1,64,40,2,40,2) - x = x.permute(0, 3, 5, 1, 2, 4).contiguous() # x(1,2,2,64,40,40) - return x.view(N, C * s * s, H // s, W // s) # x(1,256,40,40) - - -class Expand(nn.Module): - # Expand channels into width-height, i.e. x(1,64,80,80) to x(1,16,160,160) - def __init__(self, gain=2): - super().__init__() - self.gain = gain - - def forward(self, x): - N, C, H, W = x.size() # assert C / s ** 2 == 0, 'Indivisible gain' - s = self.gain - x = x.view(N, s, s, C // s ** 2, H, W) # x(1,2,2,16,80,80) - x = x.permute(0, 3, 4, 1, 5, 2).contiguous() # x(1,16,80,2,80,2) - return x.view(N, C // s ** 2, H * s, W * s) # x(1,16,160,160) - - class Ensemble(nn.ModuleList): # Ensemble of models def __init__(self): From aa8ac51c4cb21e9f9f1956247d96e5fd989601af Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 20 Dec 2020 21:07:37 -0800 Subject: [PATCH 012/176] update --- models/yolov5l-p2.yaml | 57 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 models/yolov5l-p2.yaml diff --git a/models/yolov5l-p2.yaml b/models/yolov5l-p2.yaml new file mode 100644 index 000000000000..58eb27ea3d6d --- /dev/null +++ b/models/yolov5l-p2.yaml @@ -0,0 +1,57 @@ +# 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, [ 128, 1, 1 ] ], + [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], + [ [ -1, 2 ], 1, Concat, [ 1 ] ], # cat backbone P2 + [ -1, 3, C3, [ 128, False ] ], # 21 (P2/4-xsmall) + + [ -1, 1, Conv, [ 128, 3, 2 ] ], + [ [ -1, 18 ], 1, Concat, [ 1 ] ], # cat head P3 + [ -1, 3, C3, [ 256, False ] ], # 24 (P3/8-small) + + [ -1, 1, Conv, [ 256, 3, 2 ] ], + [ [ -1, 14 ], 1, Concat, [ 1 ] ], # cat head P4 + [ -1, 3, C3, [ 512, False ] ], # 27 (P4/16-medium) + + [ -1, 1, Conv, [ 512, 3, 2 ] ], + [ [ -1, 10 ], 1, Concat, [ 1 ] ], # cat head P5 + [ -1, 3, C3, [ 1024, False ] ], # 30 (P5/32-large) + + [ [ 24, 27, 30 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5) + ] From 1c8ce0483f391cc940d7ca536deb2614a24cabe0 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 20 Dec 2020 21:59:51 -0800 Subject: [PATCH 013/176] update --- models/yolov5l-p2.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/yolov5l-p2.yaml b/models/yolov5l-p2.yaml index 58eb27ea3d6d..1dd3cc1b3168 100644 --- a/models/yolov5l-p2.yaml +++ b/models/yolov5l-p2.yaml @@ -39,7 +39,7 @@ head: [ -1, 1, Conv, [ 128, 1, 1 ] ], [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], [ [ -1, 2 ], 1, Concat, [ 1 ] ], # cat backbone P2 - [ -1, 3, C3, [ 128, False ] ], # 21 (P2/4-xsmall) + [ -1, 1, C3, [ 128, False ] ], # 21 (P2/4-xsmall) [ -1, 1, Conv, [ 128, 3, 2 ] ], [ [ -1, 18 ], 1, Concat, [ 1 ] ], # cat head P3 From 5316dbac0ef5640a9bf0f9f01257e34b27ff4385 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 21 Dec 2020 16:34:58 -0800 Subject: [PATCH 014/176] updates --- models/yolo.py | 16 ++++++------- models/yolov5l-p2s.yaml | 50 +++++++++++++++++++++++++++++++++++++++++ models/yolov5l-p2t.yaml | 50 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+), 8 deletions(-) create mode 100644 models/yolov5l-p2s.yaml create mode 100644 models/yolov5l-p2t.yaml diff --git a/models/yolo.py b/models/yolo.py index ec50cea5ca70..ad08c7381472 100644 --- a/models/yolo.py +++ b/models/yolo.py @@ -4,14 +4,10 @@ from copy import deepcopy from pathlib import Path -import math -import torch -import torch.nn as nn - sys.path.append('./') # to run '$ python *.py' files in subdirectories logger = logging.getLogger(__name__) -from models.common import Conv, Bottleneck, SPP, DWConv, Focus, BottleneckCSP, C3, Concat, NMS, autoShape +from models.common import * from models.experimental import MixConv2d, CrossConv from utils.autoanchor import check_anchor_order from utils.general import make_divisible, check_file, set_logging @@ -241,13 +237,17 @@ def parse_model(d, ch): # model_dict, input_channels(3) elif m is nn.BatchNorm2d: args = [ch[f]] elif m is Concat: - c2 = sum([ch[-1 if x == -1 else x + 1] for x in f]) + c2 = sum([ch[x if x < 0 else x + 1] for x in f]) elif m is Detect: args.append([ch[x + 1] for x in f]) if isinstance(args[1], int): # number of anchors args[1] = [list(range(args[1] * 2))] * len(f) + elif m is Contract: + c2 = ch[f if f < 0 else f + 1] * args[0] ** 2 + elif m is Expand: + c2 = ch[f if f < 0 else f + 1] // args[0] ** 2 else: - c2 = ch[f] + c2 = ch[f if f < 0 else f + 1] m_ = nn.Sequential(*[m(*args) for _ in range(n)]) if n > 1 else m(*args) # module t = str(m)[8:-2].replace('__main__.', '') # module type @@ -262,7 +262,7 @@ def parse_model(d, ch): # model_dict, input_channels(3) if __name__ == '__main__': parser = argparse.ArgumentParser() - parser.add_argument('--cfg', type=str, default='yolov5l.yaml', help='model.yaml') + parser.add_argument('--cfg', type=str, default='yolov5l-p2t.yaml', help='model.yaml') parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu') opt = parser.parse_args() opt.cfg = check_file(opt.cfg) # check file diff --git a/models/yolov5l-p2s.yaml b/models/yolov5l-p2s.yaml new file mode 100644 index 000000000000..84a7050d6298 --- /dev/null +++ b/models/yolov5l-p2s.yaml @@ -0,0 +1,50 @@ +# 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' ] ], + [ 2, 1, Contract, [ 2 ] ], + [ [ -1, -2, 4 ], 1, Concat, [ 1 ] ], # cat backbone P2, P3 + [ -1, 3, C3, [ 256, False ] ], # 18 (P3/8-small) + + [ -1, 1, Conv, [ 256, 3, 2 ] ], + [ 10, 1, Expand, [ 2 ] ], + [ [ -1, -2, 14 ], 1, Concat, [ 1 ] ], # cat head P4 + [ -1, 3, C3, [ 512, False ] ], # 22 (P4/16-medium) + + [ -1, 1, Conv, [ 512, 3, 2 ] ], + [ [ -1, 10 ], 1, Concat, [ 1 ] ], # cat head P5 + [ -1, 3, C3, [ 1024, False ] ], # 25 (P5/32-large) + + [ [ 18, 22, 25 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5) + ] diff --git a/models/yolov5l-p2t.yaml b/models/yolov5l-p2t.yaml new file mode 100644 index 000000000000..2683e77c5745 --- /dev/null +++ b/models/yolov5l-p2t.yaml @@ -0,0 +1,50 @@ +# 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, Expand, [ 2 ] ], + [ [ -1, 6 ], 1, Concat, [ 1 ] ], # cat backbone P4 + [ -1, 3, C3, [ 512, False ] ], # 13 + + [ -1, 1, Conv, [ 256, 1, 1 ] ], + [ -1, 1, Expand, [ 2 ] ], + [ 2, 1, Contract, [ 2 ] ], + [ [ -1, -2, 4 ], 1, Concat, [ 1 ] ], # cat backbone P2, P3 + [ -1, 3, C3, [ 256, False ] ], # 18 (P3/8-small) + + [ -1, 1, Conv, [ 256, 3, 2 ] ], + [ 10, 1, Expand, [ 2 ] ], + [ [ -1, -2, 14 ], 1, Concat, [ 1 ] ], # cat head P4 + [ -1, 3, C3, [ 512, False ] ], # 22 (P4/16-medium) + + [ -1, 1, Conv, [ 512, 3, 2 ] ], + [ [ -1, 10 ], 1, Concat, [ 1 ] ], # cat head P5 + [ -1, 3, C3, [ 1024, False ] ], # 25 (P5/32-large) + + [ [ 18, 22, 25 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5) + ] From 163a7fa19a4fca4b9acd73c8f11c183740bc8a90 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 21 Dec 2020 17:08:46 -0800 Subject: [PATCH 015/176] updates --- data/hyp.scratch_07scale.yaml | 33 +++++++++++++++++++++++++++++++++ data/hyp.scratch_09scale.yaml | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 data/hyp.scratch_07scale.yaml create mode 100644 data/hyp.scratch_09scale.yaml diff --git a/data/hyp.scratch_07scale.yaml b/data/hyp.scratch_07scale.yaml new file mode 100644 index 000000000000..a2f285cdd6f5 --- /dev/null +++ b/data/hyp.scratch_07scale.yaml @@ -0,0 +1,33 @@ +# Hyperparameters for COCO training from scratch +# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 +# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials + + +lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) +lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) +momentum: 0.937 # SGD momentum/Adam beta1 +weight_decay: 0.0005 # optimizer weight decay 5e-4 +warmup_epochs: 3.0 # warmup epochs (fractions ok) +warmup_momentum: 0.8 # warmup initial momentum +warmup_bias_lr: 0.1 # warmup initial bias lr +box: 0.05 # box loss gain +cls: 0.5 # cls loss gain +cls_pw: 1.0 # cls BCELoss positive_weight +obj: 0.5 # obj loss gain (scale with pixels) +obj_pw: 1.0 # obj BCELoss positive_weight +iou_t: 0.20 # IoU training threshold +anchor_t: 4.0 # anchor-multiple threshold +# anchors: 3 # anchors per output layer (0 to ignore) +fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) +hsv_h: 0.015 # image HSV-Hue augmentation (fraction) +hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) +hsv_v: 0.4 # image HSV-Value augmentation (fraction) +degrees: 0.0 # image rotation (+/- deg) +translate: 0.1 # image translation (+/- fraction) +scale: 0.7 # image scale (+/- gain) +shear: 0.0 # image shear (+/- deg) +perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 +flipud: 0.0 # image flip up-down (probability) +fliplr: 0.5 # image flip left-right (probability) +mosaic: 1.0 # image mosaic (probability) +mixup: 0.0 # image mixup (probability) diff --git a/data/hyp.scratch_09scale.yaml b/data/hyp.scratch_09scale.yaml new file mode 100644 index 000000000000..d3a3e63101e4 --- /dev/null +++ b/data/hyp.scratch_09scale.yaml @@ -0,0 +1,33 @@ +# Hyperparameters for COCO training from scratch +# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 +# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials + + +lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) +lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) +momentum: 0.937 # SGD momentum/Adam beta1 +weight_decay: 0.0005 # optimizer weight decay 5e-4 +warmup_epochs: 3.0 # warmup epochs (fractions ok) +warmup_momentum: 0.8 # warmup initial momentum +warmup_bias_lr: 0.1 # warmup initial bias lr +box: 0.05 # box loss gain +cls: 0.5 # cls loss gain +cls_pw: 1.0 # cls BCELoss positive_weight +obj: 0.5 # obj loss gain (scale with pixels) +obj_pw: 1.0 # obj BCELoss positive_weight +iou_t: 0.20 # IoU training threshold +anchor_t: 4.0 # anchor-multiple threshold +# anchors: 3 # anchors per output layer (0 to ignore) +fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) +hsv_h: 0.015 # image HSV-Hue augmentation (fraction) +hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) +hsv_v: 0.4 # image HSV-Value augmentation (fraction) +degrees: 0.0 # image rotation (+/- deg) +translate: 0.1 # image translation (+/- fraction) +scale: 0.9 # image scale (+/- gain) +shear: 0.0 # image shear (+/- deg) +perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 +flipud: 0.0 # image flip up-down (probability) +fliplr: 0.5 # image flip left-right (probability) +mosaic: 1.0 # image mosaic (probability) +mixup: 0.0 # image mixup (probability) From 7007a51c5fd692bc0c751bfb89f7d59b97f999da Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 21 Dec 2020 23:33:06 -0800 Subject: [PATCH 016/176] updates --- data/hyp.scratch_09scale.yaml | 2 +- models/common.py | 24 ++++++++++++------------ models/yolov5l-p6.yaml | 4 ++-- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/data/hyp.scratch_09scale.yaml b/data/hyp.scratch_09scale.yaml index d3a3e63101e4..75e584586420 100644 --- a/data/hyp.scratch_09scale.yaml +++ b/data/hyp.scratch_09scale.yaml @@ -4,7 +4,7 @@ lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) -lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) +lrf: 0.1 # final OneCycleLR learning rate (lr0 * lrf) momentum: 0.937 # SGD momentum/Adam beta1 weight_decay: 0.0005 # optimizer weight decay 5e-4 warmup_epochs: 3.0 # warmup epochs (fractions ok) diff --git a/models/common.py b/models/common.py index 3b9464bd753c..1a51709bdb5a 100644 --- a/models/common.py +++ b/models/common.py @@ -99,25 +99,25 @@ def forward(self, x): return self.cv2(torch.cat([x] + [m(x) for m in self.m], 1)) -# class Focus(nn.Module): -# # Focus wh information into c-space -# def __init__(self, c1, c2, k=1, s=1, p=None, g=1, act=True): # ch_in, ch_out, kernel, stride, padding, groups -# super(Focus, self).__init__() -# self.conv = Conv(c1 * 4, c2, k, s, p, g, act) -# -# def forward(self, x): # x(b,c,w,h) -> y(b,4c,w/2,h/2) -# return self.conv(torch.cat([x[..., ::2, ::2], x[..., 1::2, ::2], x[..., ::2, 1::2], x[..., 1::2, 1::2]], 1)) - - class Focus(nn.Module): # Focus wh information into c-space def __init__(self, c1, c2, k=1, s=1, p=None, g=1, act=True): # ch_in, ch_out, kernel, stride, padding, groups super(Focus, self).__init__() self.conv = Conv(c1 * 4, c2, k, s, p, g, act) - self.contract = Contract(2) def forward(self, x): # x(b,c,w,h) -> y(b,4c,w/2,h/2) - return self.conv(self.contract(x)) + return self.conv(torch.cat([x[..., ::2, ::2], x[..., 1::2, ::2], x[..., ::2, 1::2], x[..., 1::2, 1::2]], 1)) + + +# class Focus(nn.Module): +# # Focus wh information into c-space +# def __init__(self, c1, c2, k=1, s=1, p=None, g=1, act=True): # ch_in, ch_out, kernel, stride, padding, groups +# super(Focus, self).__init__() +# self.conv = Conv(c1 * 4, c2, k, s, p, g, act) +# self.contract = Contract(2) +# +# def forward(self, x): # x(b,c,w,h) -> y(b,4c,w/2,h/2) +# return self.conv(self.contract(x)) class Contract(nn.Module): diff --git a/models/yolov5l-p6.yaml b/models/yolov5l-p6.yaml index 3728a118f090..9f9cb4565103 100644 --- a/models/yolov5l-p6.yaml +++ b/models/yolov5l-p6.yaml @@ -20,7 +20,7 @@ backbone: [ -1, 3, C3, [ 768 ] ], [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ], - [ -1, 3, C3, [ 1024, False ] ], # 11 + [ -1, 1, C3, [ 1024, False ] ], # 11 ] # YOLOv5 head @@ -50,7 +50,7 @@ head: [ -1, 1, Conv, [ 768, 3, 2 ] ], [ [ -1, 12 ], 1, Concat, [ 1 ] ], # cat head P6 - [ -1, 3, C3, [ 1024, False ] ], # 32 (P5/64-xlarge) + [ -1, 1, C3, [ 1024, False ] ], # 32 (P5/64-xlarge) [ [ 23, 26, 29, 32 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) ] From 7541a5c760716df6b7c73581f9fb1ac38e884888 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 21 Dec 2020 23:34:15 -0800 Subject: [PATCH 017/176] updates --- data/coco.yaml | 3 +- models/yolov5l.yaml | 5 +-- train.py | 2 +- utils/autoanchor.py | 1 + utils/datasets.py | 76 ++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 80 insertions(+), 7 deletions(-) diff --git a/data/coco.yaml b/data/coco.yaml index 17cbdee53b7e..c86c34c58d65 100644 --- a/data/coco.yaml +++ b/data/coco.yaml @@ -36,4 +36,5 @@ names: ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 't # python train.py --data coco.yaml --batch 24 --weights '' --cfg yolov5l.yaml --epochs 300 --project ../paper --name yolov5lc3_03cls --hyp hyp.scratch_03cls.yaml --device 0 -# python train.py --data coco.yaml --batch 24 --weights '' --cfg yolov5l.yaml --epochs 300 --project ../paper --name yolov5lc3_08cls --hyp hyp.scratch_08cls.yaml --device 1 \ No newline at end of file +# python train.py --data coco.yaml --batch 24 --weights '' --cfg yolov5l.yaml --epochs 300 --project ../paper --name yolov5lc3_08cls --hyp hyp.scratch_08cls.yaml --device 1 +# python train.py --data coco.yaml --batch 6 --img 1280 640 --epochs 75 --weights '' --cfg yolov5l.yaml --project ../paper --name yolov5l_1280 --hyp hyp.scratch_09scale.yaml --device 0 \ No newline at end of file diff --git a/models/yolov5l.yaml b/models/yolov5l.yaml index 71ebf86e5791..39f9cb5c0b02 100644 --- a/models/yolov5l.yaml +++ b/models/yolov5l.yaml @@ -4,10 +4,7 @@ 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 +anchors: 4 # YOLOv5 backbone backbone: diff --git a/train.py b/train.py index 8234025212b8..7f9977189994 100644 --- a/train.py +++ b/train.py @@ -101,7 +101,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): v.requires_grad = False # Optimizer - nbs = 64 # nominal batch size + nbs = 16 # nominal batch size accumulate = max(round(nbs / total_batch_size), 1) # accumulate loss before optimizing hyp['weight_decay'] *= total_batch_size * accumulate / nbs # scale weight_decay diff --git a/utils/autoanchor.py b/utils/autoanchor.py index 0c33dcbc3495..11f71ab538a6 100644 --- a/utils/autoanchor.py +++ b/utils/autoanchor.py @@ -110,6 +110,7 @@ def print_results(k): print('WARNING: Extremely small objects found. ' '%g of %g labels are < 3 pixels in width or height.' % (i, len(wh0))) wh = wh0[(wh0 >= 2.0).any(1)] # filter > 2 pixels + wh = wh * (np.random.rand(wh.shape[0], 1) * 0.9 + 0.1) # multiply by random scale 0-1 # Kmeans calculation print('Running kmeans for %g anchors on %g points...' % (n, len(wh))) diff --git a/utils/datasets.py b/utils/datasets.py index e2b139fa6371..06620afbb024 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -616,7 +616,7 @@ def augment_hsv(img, hgain=0.5, sgain=0.5, vgain=0.5): # img[:, :, i] = cv2.equalizeHist(img[:, :, i]) -def load_mosaic(self, index): +def load_mosaic4(self, index): # loads images in a mosaic labels4 = [] @@ -674,6 +674,80 @@ def load_mosaic(self, index): return img4, labels4 +def load_mosaic(self, index): + # loads images in a 9-mosaic + + labels9 = [] + s = self.img_size + indices = [index] + [self.indices[random.randint(0, self.n - 1)] for _ in range(8)] # 8 additional image indices + for i, index in enumerate(indices): + # Load image + img, _, (h, w) = load_image(self, index) + + # place img in img9 + if i == 0: # center + img9 = np.full((s * 3, s * 3, img.shape[2]), 114, dtype=np.uint8) # base image with 4 tiles + h0, w0 = h, w + c = s, s, s + w, s + h # xmin, ymin, xmax, ymax (base) coordinates + elif i == 1: # top + c = s, s - h, s + w, s + elif i == 2: # top right + c = s + wp, s - h, s + wp + w, s + elif i == 3: # right + c = s + w0, s, s + w0 + w, s + h + elif i == 4: # bottom right + c = s + w0, s + hp, s + w0 + w, s + hp + h + elif i == 5: # bottom + c = s + w0 - w, s + h0, s + w0, s + h0 + h + elif i == 6: # bottom left + c = s + w0 - wp - w, s + h0, s + w0 - wp, s + h0 + h + elif i == 7: # left + c = s - w, s + h0 - h, s, s + h0 + elif i == 8: # top left + c = s - w, s + h0 - hp - h, s, s + h0 - hp + + padx, pady = c[:2] + x1, y1, x2, y2 = [max(x, 0) for x in c] # allocate coords + + # Labels + x = self.labels[index] + labels = x.copy() + if x.size > 0: # Normalized xywh to pixel xyxy format + labels[:, 1] = w * (x[:, 1] - x[:, 3] / 2) + padx + labels[:, 2] = h * (x[:, 2] - x[:, 4] / 2) + pady + labels[:, 3] = w * (x[:, 1] + x[:, 3] / 2) + padx + labels[:, 4] = h * (x[:, 2] + x[:, 4] / 2) + pady + labels9.append(labels) + + # Image + img9[y1:y2, x1:x2] = img[y1 - pady:, x1 - padx:] # img9[ymin:ymax, xmin:xmax] + hp, wp = h, w # height, width previous + + # Offset + yc, xc = [int(random.uniform(0, s)) for x in self.mosaic_border] # mosaic center x, y + img9 = img9[yc:yc + 2 * s, xc:xc + 2 * s] + + # Concat/clip labels + if len(labels9): + labels9 = np.concatenate(labels9, 0) + labels9[:, [1, 3]] -= xc + labels9[:, [2, 4]] -= yc + + np.clip(labels9[:, 1:], 0, 2 * s, out=labels9[:, 1:]) # use with random_perspective + # img9, labels9 = replicate(img9, labels9) # replicate + + # Augment + img9, labels9 = random_perspective(img9, labels9, + degrees=self.hyp['degrees'], + translate=self.hyp['translate'], + scale=self.hyp['scale'], + shear=self.hyp['shear'], + perspective=self.hyp['perspective'], + border=self.mosaic_border) # border to remove + + return img9, labels9 + + def replicate(img, labels): # Replicate labels h, w = img.shape[:2] From b61145d06de9dda5f3e46cd55da1f7a5a32e8d14 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 22 Dec 2020 12:19:22 -0800 Subject: [PATCH 018/176] updates --- data/coco.yaml | 6 ++++++ models/yolov5l.yaml | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/data/coco.yaml b/data/coco.yaml index c86c34c58d65..8dfa36bb65a3 100644 --- a/data/coco.yaml +++ b/data/coco.yaml @@ -35,6 +35,12 @@ names: ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 't # print(i, x) +# python train.py --data coco.yaml --batch 24 --weights '' --cfg yolov5l.yaml --epochs 300 --project ../paper --name yolov5lc3_03cls --hyp hyp.scratch_03cls.yaml --device 0 +# python train.py --data coco.yaml --batch 24 --weights '' --cfg yolov5l.yaml --epochs 300 --project ../paper --name yolov5lc3_08cls --hyp hyp.scratch_08cls.yaml --device 1 +# python train.py --data coco.yaml --batch 6 --img 1280 640 --epochs 75 --weights '' --cfg yolov5l.yaml --project ../paper --name yolov5l_1280 --hyp hyp.scratch_09scale.yaml --device 0 +python train.py --data coco.yaml --batch 6 --img 1280 640 --epochs 75 --weights '' --cfg yolov5l-p6.yaml --project ../paper --name yolov5lp6_1280 --hyp hyp.scratch_09scale.yaml --device 1 + + # python train.py --data coco.yaml --batch 24 --weights '' --cfg yolov5l.yaml --epochs 300 --project ../paper --name yolov5lc3_03cls --hyp hyp.scratch_03cls.yaml --device 0 # python train.py --data coco.yaml --batch 24 --weights '' --cfg yolov5l.yaml --epochs 300 --project ../paper --name yolov5lc3_08cls --hyp hyp.scratch_08cls.yaml --device 1 # python train.py --data coco.yaml --batch 6 --img 1280 640 --epochs 75 --weights '' --cfg yolov5l.yaml --project ../paper --name yolov5l_1280 --hyp hyp.scratch_09scale.yaml --device 0 \ No newline at end of file diff --git a/models/yolov5l.yaml b/models/yolov5l.yaml index 39f9cb5c0b02..71ebf86e5791 100644 --- a/models/yolov5l.yaml +++ b/models/yolov5l.yaml @@ -4,7 +4,10 @@ depth_multiple: 1.0 # model depth multiple width_multiple: 1.0 # layer channel multiple # anchors -anchors: 4 +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 c3aaedecbc913653f3a766e6d79a5c0fe0cc70fd Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 22 Dec 2020 12:19:35 -0800 Subject: [PATCH 019/176] updates --- data/coco.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/coco.yaml b/data/coco.yaml index 8dfa36bb65a3..8049e450568d 100644 --- a/data/coco.yaml +++ b/data/coco.yaml @@ -38,7 +38,7 @@ names: ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 't # python train.py --data coco.yaml --batch 24 --weights '' --cfg yolov5l.yaml --epochs 300 --project ../paper --name yolov5lc3_03cls --hyp hyp.scratch_03cls.yaml --device 0 # python train.py --data coco.yaml --batch 24 --weights '' --cfg yolov5l.yaml --epochs 300 --project ../paper --name yolov5lc3_08cls --hyp hyp.scratch_08cls.yaml --device 1 # python train.py --data coco.yaml --batch 6 --img 1280 640 --epochs 75 --weights '' --cfg yolov5l.yaml --project ../paper --name yolov5l_1280 --hyp hyp.scratch_09scale.yaml --device 0 -python train.py --data coco.yaml --batch 6 --img 1280 640 --epochs 75 --weights '' --cfg yolov5l-p6.yaml --project ../paper --name yolov5lp6_1280 --hyp hyp.scratch_09scale.yaml --device 1 +# python train.py --data coco.yaml --batch 6 --img 1280 640 --epochs 75 --weights '' --cfg yolov5l-p6.yaml --project ../paper --name yolov5lp6_1280 --hyp hyp.scratch_09scale.yaml --device 1 # python train.py --data coco.yaml --batch 24 --weights '' --cfg yolov5l.yaml --epochs 300 --project ../paper --name yolov5lc3_03cls --hyp hyp.scratch_03cls.yaml --device 0 From 05632dce32a45f5cc5619faf826102b0d01164c8 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 22 Dec 2020 12:23:44 -0800 Subject: [PATCH 020/176] updates --- models/yolo.py | 2 +- train.py | 2 +- utils/autoanchor.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/models/yolo.py b/models/yolo.py index ad08c7381472..c60d02792881 100644 --- a/models/yolo.py +++ b/models/yolo.py @@ -262,7 +262,7 @@ def parse_model(d, ch): # model_dict, input_channels(3) if __name__ == '__main__': parser = argparse.ArgumentParser() - parser.add_argument('--cfg', type=str, default='yolov5l-p2t.yaml', help='model.yaml') + parser.add_argument('--cfg', type=str, default='yolov5s.yaml', help='model.yaml') parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu') opt = parser.parse_args() opt.cfg = check_file(opt.cfg) # check file diff --git a/train.py b/train.py index 7f9977189994..8234025212b8 100644 --- a/train.py +++ b/train.py @@ -101,7 +101,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): v.requires_grad = False # Optimizer - nbs = 16 # nominal batch size + nbs = 64 # nominal batch size accumulate = max(round(nbs / total_batch_size), 1) # accumulate loss before optimizing hyp['weight_decay'] *= total_batch_size * accumulate / nbs # scale weight_decay diff --git a/utils/autoanchor.py b/utils/autoanchor.py index 11f71ab538a6..badefc154138 100644 --- a/utils/autoanchor.py +++ b/utils/autoanchor.py @@ -110,7 +110,7 @@ def print_results(k): print('WARNING: Extremely small objects found. ' '%g of %g labels are < 3 pixels in width or height.' % (i, len(wh0))) wh = wh0[(wh0 >= 2.0).any(1)] # filter > 2 pixels - wh = wh * (np.random.rand(wh.shape[0], 1) * 0.9 + 0.1) # multiply by random scale 0-1 + # wh = wh * (np.random.rand(wh.shape[0], 1) * 0.9 + 0.1) # multiply by random scale 0-1 # Kmeans calculation print('Running kmeans for %g anchors on %g points...' % (n, len(wh))) From 0020026c54aa97a73a46a2db55cfc152abd4f0ff Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 22 Dec 2020 12:26:32 -0800 Subject: [PATCH 021/176] updates --- data/hyp.scratch.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/hyp.scratch.yaml b/data/hyp.scratch.yaml index d0babc0272de..b1bc1729c3f3 100644 --- a/data/hyp.scratch.yaml +++ b/data/hyp.scratch.yaml @@ -24,10 +24,10 @@ hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) hsv_v: 0.4 # image HSV-Value augmentation (fraction) degrees: 0.0 # image rotation (+/- deg) translate: 0.1 # image translation (+/- fraction) -scale: 0.5 # image scale (+/- gain) +scale: 0.9 # image scale (+/- gain) shear: 0.0 # image shear (+/- deg) perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 flipud: 0.0 # image flip up-down (probability) fliplr: 0.5 # image flip left-right (probability) mosaic: 1.0 # image mosaic (probability) -mixup: 0.0 # image mixup (probability) +mixup: 0.01 # image mixup (probability) From 834c5a9852d64c5aa3e2f3ca1dc60b2e1244d403 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 22 Dec 2020 12:35:27 -0800 Subject: [PATCH 022/176] updates --- utils/datasets.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/datasets.py b/utils/datasets.py index 06620afbb024..59c35b94b60a 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -616,7 +616,7 @@ def augment_hsv(img, hgain=0.5, sgain=0.5, vgain=0.5): # img[:, :, i] = cv2.equalizeHist(img[:, :, i]) -def load_mosaic4(self, index): +def load_mosaic(self, index): # loads images in a mosaic labels4 = [] @@ -674,7 +674,7 @@ def load_mosaic4(self, index): return img4, labels4 -def load_mosaic(self, index): +def load_mosaic9(self, index): # loads images in a 9-mosaic labels9 = [] From 07154cb5375d0c1b846bc427d0a826eeaef36c2b Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 22 Dec 2020 13:02:33 -0800 Subject: [PATCH 023/176] updates --- train.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/train.py b/train.py index 8234025212b8..169f1a44a7e6 100644 --- a/train.py +++ b/train.py @@ -131,7 +131,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): # plot_lr_scheduler(optimizer, scheduler, epochs) # Logging - if wandb and wandb.run is None: + if rank in [-1, 0] and wandb and wandb.run is None: opt.hyp = hyp # add hyperparameters wandb_run = wandb.init(config=opt, resume="allow", project='YOLOv5' if opt.project == 'runs/train' else Path(opt.project).stem, From 98e74f0bc18825aad876d3395395a9c2ade0caec Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 22 Dec 2020 17:10:57 -0800 Subject: [PATCH 024/176] update --- Dockerfile | 2 +- utils/google_utils.py | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index e09f5979552e..de5d20accdbf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Start FROM Nvidia PyTorch image https://ngc.nvidia.com/catalog/containers/nvidia:pytorch -FROM nvcr.io/nvidia/pytorch:20.10-py3 +FROM nvcr.io/nvidia/pytorch:20.12-py3 # Install linux packages RUN apt update && apt install -y screen diff --git a/utils/google_utils.py b/utils/google_utils.py index f97349d4594f..fcddd8b00dd3 100644 --- a/utils/google_utils.py +++ b/utils/google_utils.py @@ -53,10 +53,9 @@ def attempt_download(weights): return -def gdrive_download(id='1uH2BylpFxHKEGXKL6wJJlsgMU2YEjxuc', name='tmp.zip'): - # Downloads a file from Google Drive. from utils.google_utils import *; gdrive_download() +def gdrive_download(id='16TiPfZj7htmTyhntwcZyEEAejOUxuT6m', name='tmp.zip'): + # Downloads a file from Google Drive. from yolov5.utils.google_utils import *; gdrive_download() t = time.time() - print('Downloading https://drive.google.com/uc?export=download&id=%s as %s... ' % (id, name), end='') os.remove(name) if os.path.exists(name) else None # remove existing os.remove('cookie') if os.path.exists('cookie') else None From efb21cfc6eb9e171ee92ab23b4c41c087a3bf82c Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 22 Dec 2020 17:14:57 -0800 Subject: [PATCH 025/176] update --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index de5d20accdbf..24529d2b9415 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,12 +2,12 @@ FROM nvcr.io/nvidia/pytorch:20.12-py3 # Install linux packages -RUN apt update && apt install -y screen +RUN apt update && apt install -y screen libgl1-mesa-glx # Install python dependencies RUN pip install --upgrade pip -# COPY requirements.txt . -# RUN pip install -r requirements.txt +COPY requirements.txt . +RUN pip install -r requirements.txt RUN pip install gsutil # Create working directory From 201197b1a6297af0c3b0120ce79ba9885a1d6cac Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 22 Dec 2020 17:20:00 -0800 Subject: [PATCH 026/176] update --- models/yolo.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/yolo.py b/models/yolo.py index c60d02792881..7d11060d3ad9 100644 --- a/models/yolo.py +++ b/models/yolo.py @@ -144,8 +144,8 @@ def _initialize_biases(self, cf=None): # initialize biases into Detect(), cf is m = self.model[-1] # Detect() module for mi, s in zip(m.m, m.stride): # from b = mi.bias.view(m.na, -1) # conv.bias(255) to (3,85) - b[:, 4] += math.log(8 / (640 / s) ** 2) # obj (8 objects per 640 image) - b[:, 5:] += math.log(0.6 / (m.nc - 0.99)) if cf is None else torch.log(cf / cf.sum()) # cls + b.data[:, 4] += math.log(8 / (640 / s) ** 2) # obj (8 objects per 640 image) + b.data[:, 5:] += math.log(0.6 / (m.nc - 0.99)) if cf is None else torch.log(cf / cf.sum()) # cls mi.bias = torch.nn.Parameter(b.view(-1), requires_grad=True) def _print_biases(self): From 5ae91fec0b0176ff6bcdbc455cf380a0be50c410 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 22 Dec 2020 23:38:54 -0800 Subject: [PATCH 027/176] update --- data/hyp.scratch_0002decay.yaml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 data/hyp.scratch_0002decay.yaml diff --git a/data/hyp.scratch_0002decay.yaml b/data/hyp.scratch_0002decay.yaml new file mode 100644 index 000000000000..4fa5d92ea847 --- /dev/null +++ b/data/hyp.scratch_0002decay.yaml @@ -0,0 +1,33 @@ +# Hyperparameters for COCO training from scratch +# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 +# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials + + +lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) +lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) +momentum: 0.937 # SGD momentum/Adam beta1 +weight_decay: 0.0002 # optimizer weight decay 5e-4 +warmup_epochs: 3.0 # warmup epochs (fractions ok) +warmup_momentum: 0.8 # warmup initial momentum +warmup_bias_lr: 0.1 # warmup initial bias lr +box: 0.05 # box loss gain +cls: 0.5 # cls loss gain +cls_pw: 1.0 # cls BCELoss positive_weight +obj: 0.5 # obj loss gain (scale with pixels) +obj_pw: 1.0 # obj BCELoss positive_weight +iou_t: 0.20 # IoU training threshold +anchor_t: 4.0 # anchor-multiple threshold +# anchors: 3 # anchors per output layer (0 to ignore) +fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) +hsv_h: 0.015 # image HSV-Hue augmentation (fraction) +hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) +hsv_v: 0.4 # image HSV-Value augmentation (fraction) +degrees: 0.0 # image rotation (+/- deg) +translate: 0.1 # image translation (+/- fraction) +scale: 0.9 # image scale (+/- gain) +shear: 0.0 # image shear (+/- deg) +perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 +flipud: 0.0 # image flip up-down (probability) +fliplr: 0.5 # image flip left-right (probability) +mosaic: 1.0 # image mosaic (probability) +mixup: 0.01 # image mixup (probability) From 1809003a78c9189b0dd51105914edae507b5f9f9 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 23 Dec 2020 13:09:29 -0800 Subject: [PATCH 028/176] updates --- data/coco.yaml | 7 ++- data/hyp.scratch_0001decay.yaml | 33 +++++++++++ data/hyp.scratch_0003decay.yaml | 33 +++++++++++ data/hyp.scratch_0007decay.yaml | 33 +++++++++++ .../{yolov5l-p6.yaml => yolov5l-p6_11.yaml} | 0 models/yolov5l-p6_31.yaml | 56 +++++++++++++++++++ models/yolov5l-p6_33.yaml | 56 +++++++++++++++++++ 7 files changed, 216 insertions(+), 2 deletions(-) create mode 100644 data/hyp.scratch_0001decay.yaml create mode 100644 data/hyp.scratch_0003decay.yaml create mode 100644 data/hyp.scratch_0007decay.yaml rename models/{yolov5l-p6.yaml => yolov5l-p6_11.yaml} (100%) create mode 100644 models/yolov5l-p6_31.yaml create mode 100644 models/yolov5l-p6_33.yaml diff --git a/data/coco.yaml b/data/coco.yaml index 8049e450568d..a1fa58c77da8 100644 --- a/data/coco.yaml +++ b/data/coco.yaml @@ -38,9 +38,12 @@ names: ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 't # python train.py --data coco.yaml --batch 24 --weights '' --cfg yolov5l.yaml --epochs 300 --project ../paper --name yolov5lc3_03cls --hyp hyp.scratch_03cls.yaml --device 0 # python train.py --data coco.yaml --batch 24 --weights '' --cfg yolov5l.yaml --epochs 300 --project ../paper --name yolov5lc3_08cls --hyp hyp.scratch_08cls.yaml --device 1 # python train.py --data coco.yaml --batch 6 --img 1280 640 --epochs 75 --weights '' --cfg yolov5l.yaml --project ../paper --name yolov5l_1280 --hyp hyp.scratch_09scale.yaml --device 0 -# python train.py --data coco.yaml --batch 6 --img 1280 640 --epochs 75 --weights '' --cfg yolov5l-p6.yaml --project ../paper --name yolov5lp6_1280 --hyp hyp.scratch_09scale.yaml --device 1 +# python train.py --data coco.yaml --batch 6 --img 1280 640 --epochs 75 --weights '' --cfg yolov5l-p6_33.yaml --project ../paper --name yolov5lp6_1280 --hyp hyp.scratch_09scale.yaml --device 1 # python train.py --data coco.yaml --batch 24 --weights '' --cfg yolov5l.yaml --epochs 300 --project ../paper --name yolov5lc3_03cls --hyp hyp.scratch_03cls.yaml --device 0 # python train.py --data coco.yaml --batch 24 --weights '' --cfg yolov5l.yaml --epochs 300 --project ../paper --name yolov5lc3_08cls --hyp hyp.scratch_08cls.yaml --device 1 -# python train.py --data coco.yaml --batch 6 --img 1280 640 --epochs 75 --weights '' --cfg yolov5l.yaml --project ../paper --name yolov5l_1280 --hyp hyp.scratch_09scale.yaml --device 0 \ No newline at end of file +# python train.py --data coco.yaml --batch 6 --img 1280 640 --epochs 75 --weights '' --cfg yolov5l.yaml --project ../paper --name yolov5l_1280 --hyp hyp.scratch_09scale.yaml --device 0 + +# python train.py --data coco.yaml --batch 48 --weights '' --cfg yolov5m.yaml --epochs 300 --project ../v4 --name yolov5m --hyp hyp.scratch.yaml --device 0 +# python -m torch.distributed.launch --nproc_per_node 2 train.py --data coco.yaml --batch 16 --weights '' --cfg yolov5x.yaml --epochs 300 --project ../v4 --name yolov5x --hyp hyp.scratch.yaml \ No newline at end of file diff --git a/data/hyp.scratch_0001decay.yaml b/data/hyp.scratch_0001decay.yaml new file mode 100644 index 000000000000..6ccece241e88 --- /dev/null +++ b/data/hyp.scratch_0001decay.yaml @@ -0,0 +1,33 @@ +# Hyperparameters for COCO training from scratch +# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 +# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials + + +lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) +lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) +momentum: 0.937 # SGD momentum/Adam beta1 +weight_decay: 0.0001 # optimizer weight decay 5e-4 +warmup_epochs: 3.0 # warmup epochs (fractions ok) +warmup_momentum: 0.8 # warmup initial momentum +warmup_bias_lr: 0.1 # warmup initial bias lr +box: 0.05 # box loss gain +cls: 0.5 # cls loss gain +cls_pw: 1.0 # cls BCELoss positive_weight +obj: 0.5 # obj loss gain (scale with pixels) +obj_pw: 1.0 # obj BCELoss positive_weight +iou_t: 0.20 # IoU training threshold +anchor_t: 4.0 # anchor-multiple threshold +# anchors: 3 # anchors per output layer (0 to ignore) +fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) +hsv_h: 0.015 # image HSV-Hue augmentation (fraction) +hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) +hsv_v: 0.4 # image HSV-Value augmentation (fraction) +degrees: 0.0 # image rotation (+/- deg) +translate: 0.1 # image translation (+/- fraction) +scale: 0.9 # image scale (+/- gain) +shear: 0.0 # image shear (+/- deg) +perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 +flipud: 0.0 # image flip up-down (probability) +fliplr: 0.5 # image flip left-right (probability) +mosaic: 1.0 # image mosaic (probability) +mixup: 0.01 # image mixup (probability) diff --git a/data/hyp.scratch_0003decay.yaml b/data/hyp.scratch_0003decay.yaml new file mode 100644 index 000000000000..7b616904d31e --- /dev/null +++ b/data/hyp.scratch_0003decay.yaml @@ -0,0 +1,33 @@ +# Hyperparameters for COCO training from scratch +# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 +# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials + + +lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) +lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) +momentum: 0.937 # SGD momentum/Adam beta1 +weight_decay: 0.0003 # optimizer weight decay 5e-4 +warmup_epochs: 3.0 # warmup epochs (fractions ok) +warmup_momentum: 0.8 # warmup initial momentum +warmup_bias_lr: 0.1 # warmup initial bias lr +box: 0.05 # box loss gain +cls: 0.5 # cls loss gain +cls_pw: 1.0 # cls BCELoss positive_weight +obj: 0.5 # obj loss gain (scale with pixels) +obj_pw: 1.0 # obj BCELoss positive_weight +iou_t: 0.20 # IoU training threshold +anchor_t: 4.0 # anchor-multiple threshold +# anchors: 3 # anchors per output layer (0 to ignore) +fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) +hsv_h: 0.015 # image HSV-Hue augmentation (fraction) +hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) +hsv_v: 0.4 # image HSV-Value augmentation (fraction) +degrees: 0.0 # image rotation (+/- deg) +translate: 0.1 # image translation (+/- fraction) +scale: 0.9 # image scale (+/- gain) +shear: 0.0 # image shear (+/- deg) +perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 +flipud: 0.0 # image flip up-down (probability) +fliplr: 0.5 # image flip left-right (probability) +mosaic: 1.0 # image mosaic (probability) +mixup: 0.01 # image mixup (probability) diff --git a/data/hyp.scratch_0007decay.yaml b/data/hyp.scratch_0007decay.yaml new file mode 100644 index 000000000000..8557fecf1e6c --- /dev/null +++ b/data/hyp.scratch_0007decay.yaml @@ -0,0 +1,33 @@ +# Hyperparameters for COCO training from scratch +# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 +# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials + + +lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) +lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) +momentum: 0.937 # SGD momentum/Adam beta1 +weight_decay: 0.0007 # optimizer weight decay 5e-4 +warmup_epochs: 3.0 # warmup epochs (fractions ok) +warmup_momentum: 0.8 # warmup initial momentum +warmup_bias_lr: 0.1 # warmup initial bias lr +box: 0.05 # box loss gain +cls: 0.5 # cls loss gain +cls_pw: 1.0 # cls BCELoss positive_weight +obj: 0.5 # obj loss gain (scale with pixels) +obj_pw: 1.0 # obj BCELoss positive_weight +iou_t: 0.20 # IoU training threshold +anchor_t: 4.0 # anchor-multiple threshold +# anchors: 3 # anchors per output layer (0 to ignore) +fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) +hsv_h: 0.015 # image HSV-Hue augmentation (fraction) +hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) +hsv_v: 0.4 # image HSV-Value augmentation (fraction) +degrees: 0.0 # image rotation (+/- deg) +translate: 0.1 # image translation (+/- fraction) +scale: 0.9 # image scale (+/- gain) +shear: 0.0 # image shear (+/- deg) +perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 +flipud: 0.0 # image flip up-down (probability) +fliplr: 0.5 # image flip left-right (probability) +mosaic: 1.0 # image mosaic (probability) +mixup: 0.01 # image mixup (probability) diff --git a/models/yolov5l-p6.yaml b/models/yolov5l-p6_11.yaml similarity index 100% rename from models/yolov5l-p6.yaml rename to models/yolov5l-p6_11.yaml diff --git a/models/yolov5l-p6_31.yaml b/models/yolov5l-p6_31.yaml new file mode 100644 index 000000000000..9aa880c22f0e --- /dev/null +++ b/models/yolov5l-p6_31.yaml @@ -0,0 +1,56 @@ +# parameters +nc: 80 # number of classes +depth_multiple: 1.0 # model depth multiple +width_multiple: 1.0 # layer channel multiple + +# anchors +anchors: 3 + +# 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, [ 768, 3, 2 ] ], # 7-P5/32 + [ -1, 3, C3, [ 768 ] ], + [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 + [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ], + [ -1, 3, C3, [ 1024, False ] ], # 11 + ] + +# YOLOv5 head +head: + [ [ -1, 1, Conv, [ 768, 1, 1 ] ], + [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], + [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 + [ -1, 3, C3, [ 768, False ] ], # 15 + + [ -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 ] ], # 19 + + [ -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 ] ], # 23 (P3/8-small) + + [ -1, 1, Conv, [ 256, 3, 2 ] ], + [ [ -1, 20 ], 1, Concat, [ 1 ] ], # cat head P4 + [ -1, 3, C3, [ 512, False ] ], # 26 (P4/16-medium) + + [ -1, 1, Conv, [ 512, 3, 2 ] ], + [ [ -1, 16 ], 1, Concat, [ 1 ] ], # cat head P5 + [ -1, 3, C3, [ 768, False ] ], # 29 (P5/32-large) + + [ -1, 1, Conv, [ 768, 3, 2 ] ], + [ [ -1, 12 ], 1, Concat, [ 1 ] ], # cat head P6 + [ -1, 1, C3, [ 1024, False ] ], # 32 (P5/64-xlarge) + + [ [ 23, 26, 29, 32 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) + ] diff --git a/models/yolov5l-p6_33.yaml b/models/yolov5l-p6_33.yaml new file mode 100644 index 000000000000..3728a118f090 --- /dev/null +++ b/models/yolov5l-p6_33.yaml @@ -0,0 +1,56 @@ +# parameters +nc: 80 # number of classes +depth_multiple: 1.0 # model depth multiple +width_multiple: 1.0 # layer channel multiple + +# anchors +anchors: 3 + +# 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, [ 768, 3, 2 ] ], # 7-P5/32 + [ -1, 3, C3, [ 768 ] ], + [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 + [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ], + [ -1, 3, C3, [ 1024, False ] ], # 11 + ] + +# YOLOv5 head +head: + [ [ -1, 1, Conv, [ 768, 1, 1 ] ], + [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], + [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 + [ -1, 3, C3, [ 768, False ] ], # 15 + + [ -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 ] ], # 19 + + [ -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 ] ], # 23 (P3/8-small) + + [ -1, 1, Conv, [ 256, 3, 2 ] ], + [ [ -1, 20 ], 1, Concat, [ 1 ] ], # cat head P4 + [ -1, 3, C3, [ 512, False ] ], # 26 (P4/16-medium) + + [ -1, 1, Conv, [ 512, 3, 2 ] ], + [ [ -1, 16 ], 1, Concat, [ 1 ] ], # cat head P5 + [ -1, 3, C3, [ 768, False ] ], # 29 (P5/32-large) + + [ -1, 1, Conv, [ 768, 3, 2 ] ], + [ [ -1, 12 ], 1, Concat, [ 1 ] ], # cat head P6 + [ -1, 3, C3, [ 1024, False ] ], # 32 (P5/64-xlarge) + + [ [ 23, 26, 29, 32 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) + ] From 1f4c726e0342ae9e73549d00eee275d6e35d68ba Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 23 Dec 2020 13:18:38 -0800 Subject: [PATCH 029/176] updates --- data/hyp.scratch.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/hyp.scratch.yaml b/data/hyp.scratch.yaml index b1bc1729c3f3..6925446dbd8d 100644 --- a/data/hyp.scratch.yaml +++ b/data/hyp.scratch.yaml @@ -11,7 +11,7 @@ warmup_epochs: 3.0 # warmup epochs (fractions ok) warmup_momentum: 0.8 # warmup initial momentum warmup_bias_lr: 0.1 # warmup initial bias lr box: 0.05 # box loss gain -cls: 0.5 # cls loss gain +cls: 0.3 # cls loss gain cls_pw: 1.0 # cls BCELoss positive_weight obj: 0.5 # obj loss gain (scale with pixels) obj_pw: 1.0 # obj BCELoss positive_weight From c6db527ce7a9f3ae6644f680f65fb4b7103ae3e7 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 23 Dec 2020 14:00:28 -0800 Subject: [PATCH 030/176] updates --- data/hyp.scratch_0001decay.yaml | 2 +- data/hyp.scratch_0002decay.yaml | 2 +- data/hyp.scratch_0003decay.yaml | 2 +- data/hyp.scratch_0007decay.yaml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/data/hyp.scratch_0001decay.yaml b/data/hyp.scratch_0001decay.yaml index 6ccece241e88..baf748b9e048 100644 --- a/data/hyp.scratch_0001decay.yaml +++ b/data/hyp.scratch_0001decay.yaml @@ -11,7 +11,7 @@ warmup_epochs: 3.0 # warmup epochs (fractions ok) warmup_momentum: 0.8 # warmup initial momentum warmup_bias_lr: 0.1 # warmup initial bias lr box: 0.05 # box loss gain -cls: 0.5 # cls loss gain +cls: 0.3 # cls loss gain cls_pw: 1.0 # cls BCELoss positive_weight obj: 0.5 # obj loss gain (scale with pixels) obj_pw: 1.0 # obj BCELoss positive_weight diff --git a/data/hyp.scratch_0002decay.yaml b/data/hyp.scratch_0002decay.yaml index 4fa5d92ea847..abb7a43651ad 100644 --- a/data/hyp.scratch_0002decay.yaml +++ b/data/hyp.scratch_0002decay.yaml @@ -11,7 +11,7 @@ warmup_epochs: 3.0 # warmup epochs (fractions ok) warmup_momentum: 0.8 # warmup initial momentum warmup_bias_lr: 0.1 # warmup initial bias lr box: 0.05 # box loss gain -cls: 0.5 # cls loss gain +cls: 0.3 # cls loss gain cls_pw: 1.0 # cls BCELoss positive_weight obj: 0.5 # obj loss gain (scale with pixels) obj_pw: 1.0 # obj BCELoss positive_weight diff --git a/data/hyp.scratch_0003decay.yaml b/data/hyp.scratch_0003decay.yaml index 7b616904d31e..8079d8067d47 100644 --- a/data/hyp.scratch_0003decay.yaml +++ b/data/hyp.scratch_0003decay.yaml @@ -11,7 +11,7 @@ warmup_epochs: 3.0 # warmup epochs (fractions ok) warmup_momentum: 0.8 # warmup initial momentum warmup_bias_lr: 0.1 # warmup initial bias lr box: 0.05 # box loss gain -cls: 0.5 # cls loss gain +cls: 0.3 # cls loss gain cls_pw: 1.0 # cls BCELoss positive_weight obj: 0.5 # obj loss gain (scale with pixels) obj_pw: 1.0 # obj BCELoss positive_weight diff --git a/data/hyp.scratch_0007decay.yaml b/data/hyp.scratch_0007decay.yaml index 8557fecf1e6c..86fd7784f1ba 100644 --- a/data/hyp.scratch_0007decay.yaml +++ b/data/hyp.scratch_0007decay.yaml @@ -11,7 +11,7 @@ warmup_epochs: 3.0 # warmup epochs (fractions ok) warmup_momentum: 0.8 # warmup initial momentum warmup_bias_lr: 0.1 # warmup initial bias lr box: 0.05 # box loss gain -cls: 0.5 # cls loss gain +cls: 0.3 # cls loss gain cls_pw: 1.0 # cls BCELoss positive_weight obj: 0.5 # obj loss gain (scale with pixels) obj_pw: 1.0 # obj BCELoss positive_weight From 3cd90e568acec5112b42b727b9cfc1d80c8abf35 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 23 Dec 2020 16:24:16 -0800 Subject: [PATCH 031/176] updates --- data/hyp.scratch_20obj.yaml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 data/hyp.scratch_20obj.yaml diff --git a/data/hyp.scratch_20obj.yaml b/data/hyp.scratch_20obj.yaml new file mode 100644 index 000000000000..63baefad14e6 --- /dev/null +++ b/data/hyp.scratch_20obj.yaml @@ -0,0 +1,33 @@ +# Hyperparameters for COCO training from scratch +# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 +# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials + + +lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) +lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) +momentum: 0.937 # SGD momentum/Adam beta1 +weight_decay: 0.0001 # optimizer weight decay 5e-4 +warmup_epochs: 3.0 # warmup epochs (fractions ok) +warmup_momentum: 0.8 # warmup initial momentum +warmup_bias_lr: 0.1 # warmup initial bias lr +box: 0.05 # box loss gain +cls: 0.3 # cls loss gain +cls_pw: 1.0 # cls BCELoss positive_weight +obj: 2.0 # obj loss gain (scale with pixels) +obj_pw: 1.0 # obj BCELoss positive_weight +iou_t: 0.20 # IoU training threshold +anchor_t: 4.0 # anchor-multiple threshold +# anchors: 3 # anchors per output layer (0 to ignore) +fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) +hsv_h: 0.015 # image HSV-Hue augmentation (fraction) +hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) +hsv_v: 0.4 # image HSV-Value augmentation (fraction) +degrees: 0.0 # image rotation (+/- deg) +translate: 0.1 # image translation (+/- fraction) +scale: 0.9 # image scale (+/- gain) +shear: 0.0 # image shear (+/- deg) +perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 +flipud: 0.0 # image flip up-down (probability) +fliplr: 0.5 # image flip left-right (probability) +mosaic: 1.0 # image mosaic (probability) +mixup: 0.01 # image mixup (probability) From dfe78d5053a99be2e44f0f147a0a56bc91b8dc77 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Fri, 25 Dec 2020 12:20:19 -0800 Subject: [PATCH 032/176] update --- models/yolov5x-p6.yaml | 56 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 models/yolov5x-p6.yaml diff --git a/models/yolov5x-p6.yaml b/models/yolov5x-p6.yaml new file mode 100644 index 000000000000..eb4586bfbea9 --- /dev/null +++ b/models/yolov5x-p6.yaml @@ -0,0 +1,56 @@ +# parameters +nc: 80 # number of classes +depth_multiple: 1.33 # model depth multiple +width_multiple: 1.25 # layer channel multiple + +# anchors +anchors: 3 + +# 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, [ 768, 3, 2 ] ], # 7-P5/32 + [ -1, 3, C3, [ 768 ] ], + [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 + [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ], + [ -1, 3, C3, [ 1024, False ] ], # 11 + ] + +# YOLOv5 head +head: + [ [ -1, 1, Conv, [ 768, 1, 1 ] ], + [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], + [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 + [ -1, 3, C3, [ 768, False ] ], # 15 + + [ -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 ] ], # 19 + + [ -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 ] ], # 23 (P3/8-small) + + [ -1, 1, Conv, [ 256, 3, 2 ] ], + [ [ -1, 20 ], 1, Concat, [ 1 ] ], # cat head P4 + [ -1, 3, C3, [ 512, False ] ], # 26 (P4/16-medium) + + [ -1, 1, Conv, [ 512, 3, 2 ] ], + [ [ -1, 16 ], 1, Concat, [ 1 ] ], # cat head P5 + [ -1, 3, C3, [ 768, False ] ], # 29 (P5/32-large) + + [ -1, 1, Conv, [ 768, 3, 2 ] ], + [ [ -1, 12 ], 1, Concat, [ 1 ] ], # cat head P6 + [ -1, 3, C3, [ 1024, False ] ], # 32 (P5/64-xlarge) + + [ [ 23, 26, 29, 32 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) + ] From 873ba7313e3b223ebd90252f227488518c6d207e Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Fri, 25 Dec 2020 12:54:34 -0800 Subject: [PATCH 033/176] update --- data/hyp.scratch_15obj.yaml | 33 +++++++++++++++++++++++++++++++++ data/hyp.scratch_34obj.yaml | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 data/hyp.scratch_15obj.yaml create mode 100644 data/hyp.scratch_34obj.yaml diff --git a/data/hyp.scratch_15obj.yaml b/data/hyp.scratch_15obj.yaml new file mode 100644 index 000000000000..9d33e828fe48 --- /dev/null +++ b/data/hyp.scratch_15obj.yaml @@ -0,0 +1,33 @@ +# Hyperparameters for COCO training from scratch +# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 +# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials + + +lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) +lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) +momentum: 0.937 # SGD momentum/Adam beta1 +weight_decay: 0.0001 # optimizer weight decay 5e-4 +warmup_epochs: 3.0 # warmup epochs (fractions ok) +warmup_momentum: 0.8 # warmup initial momentum +warmup_bias_lr: 0.1 # warmup initial bias lr +box: 0.05 # box loss gain +cls: 0.3 # cls loss gain +cls_pw: 1.0 # cls BCELoss positive_weight +obj: 1.5 # obj loss gain (scale with pixels) +obj_pw: 1.0 # obj BCELoss positive_weight +iou_t: 0.20 # IoU training threshold +anchor_t: 4.0 # anchor-multiple threshold +# anchors: 3 # anchors per output layer (0 to ignore) +fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) +hsv_h: 0.015 # image HSV-Hue augmentation (fraction) +hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) +hsv_v: 0.4 # image HSV-Value augmentation (fraction) +degrees: 0.0 # image rotation (+/- deg) +translate: 0.1 # image translation (+/- fraction) +scale: 0.9 # image scale (+/- gain) +shear: 0.0 # image shear (+/- deg) +perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 +flipud: 0.0 # image flip up-down (probability) +fliplr: 0.5 # image flip left-right (probability) +mosaic: 1.0 # image mosaic (probability) +mixup: 0.01 # image mixup (probability) diff --git a/data/hyp.scratch_34obj.yaml b/data/hyp.scratch_34obj.yaml new file mode 100644 index 000000000000..93dbb093364e --- /dev/null +++ b/data/hyp.scratch_34obj.yaml @@ -0,0 +1,33 @@ +# Hyperparameters for COCO training from scratch +# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 +# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials + + +lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) +lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) +momentum: 0.937 # SGD momentum/Adam beta1 +weight_decay: 0.0001 # optimizer weight decay 5e-4 +warmup_epochs: 3.0 # warmup epochs (fractions ok) +warmup_momentum: 0.8 # warmup initial momentum +warmup_bias_lr: 0.1 # warmup initial bias lr +box: 0.05 # box loss gain +cls: 0.3 # cls loss gain +cls_pw: 1.0 # cls BCELoss positive_weight +obj: 3.4 # obj loss gain (scale with pixels) +obj_pw: 1.0 # obj BCELoss positive_weight +iou_t: 0.20 # IoU training threshold +anchor_t: 4.0 # anchor-multiple threshold +# anchors: 3 # anchors per output layer (0 to ignore) +fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) +hsv_h: 0.015 # image HSV-Hue augmentation (fraction) +hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) +hsv_v: 0.4 # image HSV-Value augmentation (fraction) +degrees: 0.0 # image rotation (+/- deg) +translate: 0.1 # image translation (+/- fraction) +scale: 0.9 # image scale (+/- gain) +shear: 0.0 # image shear (+/- deg) +perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 +flipud: 0.0 # image flip up-down (probability) +fliplr: 0.5 # image flip left-right (probability) +mosaic: 1.0 # image mosaic (probability) +mixup: 0.01 # image mixup (probability) From a864ea76495f7314f30351c252b61d12242d600d Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Fri, 25 Dec 2020 13:00:24 -0800 Subject: [PATCH 034/176] update --- data/coco.yaml | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/data/coco.yaml b/data/coco.yaml index a1fa58c77da8..cf5cdfea7ac1 100644 --- a/data/coco.yaml +++ b/data/coco.yaml @@ -18,15 +18,15 @@ test: ../coco/test-dev2017.txt # 20288 of 40670 images, submit to https://compe nc: 80 # class names -names: ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light', - 'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow', - 'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', - 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard', - 'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', - 'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', - 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone', - 'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear', - 'hair drier', 'toothbrush'] +names: [ 'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light', + 'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow', + 'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', + 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard', + 'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', + 'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', + 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone', + 'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear', + 'hair drier', 'toothbrush' ] # Print classes # with open('data/coco.yaml') as f: @@ -35,6 +35,15 @@ names: ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 't # print(i, x) +# python train.py --data coco.yaml --batch 24 --weights '' --cfg yolov5l.yaml --epochs 300 --project ../paper --name yolov5lc3_03cls --hyp hyp.scratch_03cls.yaml --device 0 +# python train.py --data coco.yaml --batch 24 --weights '' --cfg yolov5l.yaml --epochs 300 --project ../paper --name yolov5lc3_08cls --hyp hyp.scratch_08cls.yaml --device 1 +# python train.py --data coco.yaml --batch 6 --img 1280 640 --epochs 75 --weights '' --cfg yolov5l.yaml --project ../paper --name yolov5l_1280 --hyp hyp.scratch_09scale.yaml --device 0 +# python train.py --data coco.yaml --batch 6 --img 1280 640 --epochs 75 --weights '' --cfg yolov5l-p6_33.yaml --project ../paper --name yolov5lp6_1280 --hyp hyp.scratch_09scale.yaml --device 1 + +# python train.py --data coco.yaml --batch 24 --weights '' --cfg yolov5l-p6_33.yaml --epochs 300 --project ../v4 --name yolov5l-p6_640 --hyp hyp.scratch.yaml --log-artifacts --device 0 +# python -m torch.distributed.launch --nproc_per_node 4 train.py --data coco.yaml --batch 24 --weights '' yolov5l-p6_33.yaml --epochs 300 --project ../v4 --name yolov5l-p6_1280 --hyp hyp.scratch_15obj.yaml --img 1280 --log-artifacts +# python -m torch.distributed.launch --nproc_per_node 8 train.py --data coco.yaml --batch 20 --weights '' yolov5l-p6_33.yaml --epochs 300 --project ../v4 --name yolov5l-p6_1920 --hyp hyp.scratch_34obj.yaml --img 1920 --log-artifacts + # python train.py --data coco.yaml --batch 24 --weights '' --cfg yolov5l.yaml --epochs 300 --project ../paper --name yolov5lc3_03cls --hyp hyp.scratch_03cls.yaml --device 0 # python train.py --data coco.yaml --batch 24 --weights '' --cfg yolov5l.yaml --epochs 300 --project ../paper --name yolov5lc3_08cls --hyp hyp.scratch_08cls.yaml --device 1 # python train.py --data coco.yaml --batch 6 --img 1280 640 --epochs 75 --weights '' --cfg yolov5l.yaml --project ../paper --name yolov5l_1280 --hyp hyp.scratch_09scale.yaml --device 0 From 6c36cb28cfbcdfb9557b7a99000be1bb842df8ec Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Fri, 25 Dec 2020 14:41:17 -0800 Subject: [PATCH 035/176] update --- data/coco.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/data/coco.yaml b/data/coco.yaml index cf5cdfea7ac1..736c562b91a3 100644 --- a/data/coco.yaml +++ b/data/coco.yaml @@ -41,8 +41,10 @@ names: [ 'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', ' # python train.py --data coco.yaml --batch 6 --img 1280 640 --epochs 75 --weights '' --cfg yolov5l-p6_33.yaml --project ../paper --name yolov5lp6_1280 --hyp hyp.scratch_09scale.yaml --device 1 # python train.py --data coco.yaml --batch 24 --weights '' --cfg yolov5l-p6_33.yaml --epochs 300 --project ../v4 --name yolov5l-p6_640 --hyp hyp.scratch.yaml --log-artifacts --device 0 -# python -m torch.distributed.launch --nproc_per_node 4 train.py --data coco.yaml --batch 24 --weights '' yolov5l-p6_33.yaml --epochs 300 --project ../v4 --name yolov5l-p6_1280 --hyp hyp.scratch_15obj.yaml --img 1280 --log-artifacts -# python -m torch.distributed.launch --nproc_per_node 8 train.py --data coco.yaml --batch 20 --weights '' yolov5l-p6_33.yaml --epochs 300 --project ../v4 --name yolov5l-p6_1920 --hyp hyp.scratch_34obj.yaml --img 1920 --log-artifacts +# python -m torch.distributed.launch --nproc_per_node 4 train.py --data coco.yaml --batch 24 --weights '' --cfg yolov5l-p6_33.yaml --epochs 300 --project ../v4 --name yolov5l-p6_1280 --hyp hyp.scratch_15obj.yaml --img 1280 --log-artifacts + +# python -m torch.distributed.launch --nproc_per_node 2 train.py --data coco.yaml --batch 28 --weights '' --cfg yolov5x-p6.yaml --epochs 300 --project ../v4 --name yolov5x-p6_640 --hyp hyp.scratch.yaml --img 640 --log-artifacts +# python -m torch.distributed.launch --nproc_per_node 8 train.py --data coco.yaml --batch 28 --weights '' --cfg yolov5x-p6.yaml --epochs 300 --project ../v4 --name yolov5x-p6_1280 --hyp hyp.scratch_15obj.yaml --img 1280 --log-artifacts # python train.py --data coco.yaml --batch 24 --weights '' --cfg yolov5l.yaml --epochs 300 --project ../paper --name yolov5lc3_03cls --hyp hyp.scratch_03cls.yaml --device 0 # python train.py --data coco.yaml --batch 24 --weights '' --cfg yolov5l.yaml --epochs 300 --project ../paper --name yolov5lc3_08cls --hyp hyp.scratch_08cls.yaml --device 1 From 1f07c84d1410e8a3276696c7bc6a9b739bc81114 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Fri, 25 Dec 2020 15:03:11 -0800 Subject: [PATCH 036/176] update --- data/hyp.scratch_15obj.yaml | 2 +- data/hyp.scratch_20obj.yaml | 2 +- data/hyp.scratch_34obj.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/data/hyp.scratch_15obj.yaml b/data/hyp.scratch_15obj.yaml index 9d33e828fe48..1ed26cd46cf7 100644 --- a/data/hyp.scratch_15obj.yaml +++ b/data/hyp.scratch_15obj.yaml @@ -6,7 +6,7 @@ lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) momentum: 0.937 # SGD momentum/Adam beta1 -weight_decay: 0.0001 # optimizer weight decay 5e-4 +weight_decay: 0.0005 # optimizer weight decay 5e-4 warmup_epochs: 3.0 # warmup epochs (fractions ok) warmup_momentum: 0.8 # warmup initial momentum warmup_bias_lr: 0.1 # warmup initial bias lr diff --git a/data/hyp.scratch_20obj.yaml b/data/hyp.scratch_20obj.yaml index 63baefad14e6..a317564bb6e0 100644 --- a/data/hyp.scratch_20obj.yaml +++ b/data/hyp.scratch_20obj.yaml @@ -6,7 +6,7 @@ lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) momentum: 0.937 # SGD momentum/Adam beta1 -weight_decay: 0.0001 # optimizer weight decay 5e-4 +weight_decay: 0.0005 # optimizer weight decay 5e-4 warmup_epochs: 3.0 # warmup epochs (fractions ok) warmup_momentum: 0.8 # warmup initial momentum warmup_bias_lr: 0.1 # warmup initial bias lr diff --git a/data/hyp.scratch_34obj.yaml b/data/hyp.scratch_34obj.yaml index 93dbb093364e..8fa474d8f701 100644 --- a/data/hyp.scratch_34obj.yaml +++ b/data/hyp.scratch_34obj.yaml @@ -6,7 +6,7 @@ lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) momentum: 0.937 # SGD momentum/Adam beta1 -weight_decay: 0.0001 # optimizer weight decay 5e-4 +weight_decay: 0.0005 # optimizer weight decay 5e-4 warmup_epochs: 3.0 # warmup epochs (fractions ok) warmup_momentum: 0.8 # warmup initial momentum warmup_bias_lr: 0.1 # warmup initial bias lr From bfd92ee1142d4fa59558138cb4d53ac5a253e17f Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 26 Dec 2020 15:12:48 -0800 Subject: [PATCH 037/176] update --- models/yolov5l-p6-1280.yaml | 63 +++++++++++++++++++++++++++++++++++++ models/yolov5x-p6-1280.yaml | 62 ++++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 models/yolov5l-p6-1280.yaml create mode 100644 models/yolov5x-p6-1280.yaml diff --git a/models/yolov5l-p6-1280.yaml b/models/yolov5l-p6-1280.yaml new file mode 100644 index 000000000000..e50cce09a8c8 --- /dev/null +++ b/models/yolov5l-p6-1280.yaml @@ -0,0 +1,63 @@ +# parameters +nc: 80 # number of classes +depth_multiple: 1.0 # model depth multiple +width_multiple: 1.0 # layer channel multiple + +# anchors +anchors: + - [ 19,27, 44,40, 38,94 ] # P3/8 + - [ 96,68, 86,152, 180,137 ] # P4/16 + - [ 140,301, 303,264, 238,542 ] # P5/32 + - [ 436,615, 739,380, 925,792 ] # P6/64 +# normal n=12, img_size=1280, metric_all=0.281/0.714-mean/best, past_thr=0.468-mean: 19,27, 44,40, 38,94, 96,68, 86,152, 180,137, 140,301, 303,264, 238,542, 436,615, 739,380, 925,792 +# scale 0.9 n=12, img_size=1280, metric_all=0.267/0.705-mean/best, past_thr=0.467-mean: 6,9, 17,15, 16,36, 35,30, 33,61, 73,51, 60,118, 140,104, 126,225, 273,207, 262,398, 595,454 + + +# 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, [ 768, 3, 2 ] ], # 7-P5/32 + [ -1, 3, C3, [ 768 ] ], + [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 + [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ], + [ -1, 3, C3, [ 1024, False ] ], # 11 + ] + +# YOLOv5 head +head: + [ [ -1, 1, Conv, [ 768, 1, 1 ] ], + [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], + [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 + [ -1, 3, C3, [ 768, False ] ], # 15 + + [ -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 ] ], # 19 + + [ -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 ] ], # 23 (P3/8-small) + + [ -1, 1, Conv, [ 256, 3, 2 ] ], + [ [ -1, 20 ], 1, Concat, [ 1 ] ], # cat head P4 + [ -1, 3, C3, [ 512, False ] ], # 26 (P4/16-medium) + + [ -1, 1, Conv, [ 512, 3, 2 ] ], + [ [ -1, 16 ], 1, Concat, [ 1 ] ], # cat head P5 + [ -1, 3, C3, [ 768, False ] ], # 29 (P5/32-large) + + [ -1, 1, Conv, [ 768, 3, 2 ] ], + [ [ -1, 12 ], 1, Concat, [ 1 ] ], # cat head P6 + [ -1, 3, C3, [ 1024, False ] ], # 32 (P5/64-xlarge) + + [ [ 23, 26, 29, 32 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) + ] diff --git a/models/yolov5x-p6-1280.yaml b/models/yolov5x-p6-1280.yaml new file mode 100644 index 000000000000..6ba00577dbde --- /dev/null +++ b/models/yolov5x-p6-1280.yaml @@ -0,0 +1,62 @@ +# parameters +nc: 80 # number of classes +depth_multiple: 1.33 # model depth multiple +width_multiple: 1.25 # layer channel multiple + +# anchors +anchors: + - [ 19,27, 44,40, 38,94 ] # P3/8 + - [ 96,68, 86,152, 180,137 ] # P4/16 + - [ 140,301, 303,264, 238,542 ] # P5/32 + - [ 436,615, 739,380, 925,792 ] # P6/64 +# normal n=12, img_size=1280, metric_all=0.281/0.714-mean/best, past_thr=0.468-mean: 19,27, 44,40, 38,94, 96,68, 86,152, 180,137, 140,301, 303,264, 238,542, 436,615, 739,380, 925,792 +# scale 0.9 n=12, img_size=1280, metric_all=0.267/0.705-mean/best, past_thr=0.467-mean: 6,9, 17,15, 16,36, 35,30, 33,61, 73,51, 60,118, 140,104, 126,225, 273,207, 262,398, 595,454 + +# 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, [ 768, 3, 2 ] ], # 7-P5/32 + [ -1, 3, C3, [ 768 ] ], + [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 + [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ], + [ -1, 3, C3, [ 1024, False ] ], # 11 + ] + +# YOLOv5 head +head: + [ [ -1, 1, Conv, [ 768, 1, 1 ] ], + [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], + [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 + [ -1, 3, C3, [ 768, False ] ], # 15 + + [ -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 ] ], # 19 + + [ -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 ] ], # 23 (P3/8-small) + + [ -1, 1, Conv, [ 256, 3, 2 ] ], + [ [ -1, 20 ], 1, Concat, [ 1 ] ], # cat head P4 + [ -1, 3, C3, [ 512, False ] ], # 26 (P4/16-medium) + + [ -1, 1, Conv, [ 512, 3, 2 ] ], + [ [ -1, 16 ], 1, Concat, [ 1 ] ], # cat head P5 + [ -1, 3, C3, [ 768, False ] ], # 29 (P5/32-large) + + [ -1, 1, Conv, [ 768, 3, 2 ] ], + [ [ -1, 12 ], 1, Concat, [ 1 ] ], # cat head P6 + [ -1, 3, C3, [ 1024, False ] ], # 32 (P5/64-xlarge) + + [ [ 23, 26, 29, 32 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) + ] From ed3b0d325312a364344f5b40900a5217b7abfad4 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 27 Dec 2020 11:06:18 -0800 Subject: [PATCH 038/176] update --- train.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/train.py b/train.py index 169f1a44a7e6..9b7a86deb4bd 100644 --- a/train.py +++ b/train.py @@ -217,7 +217,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): hyp['cls'] *= nc / 80. # scale coco-tuned hyp['cls'] to current dataset model.nc = nc # attach number of classes to model model.hyp = hyp # attach hyperparameters to model - model.gr = 1.0 # iou loss ratio (obj_loss = 1.0 or iou) + model.gr = opt.gr # iou loss ratio (obj_loss = 1.0 or iou) model.class_weights = labels_to_class_weights(dataset.labels, nc).to(device) * nc # attach class weights model.names = names @@ -458,6 +458,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): parser.add_argument('--project', default='runs/train', help='save to project/name') parser.add_argument('--name', default='exp', help='save to project/name') parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment') + parser.add_argument('--gr', type=int, default=1.0, help='model.gr obj loss ratio') opt = parser.parse_args() # Set DDP variables From 4e53f3f8d05b1dd9e4f43a3ffb9fdf84dbd537ba Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 27 Dec 2020 11:15:11 -0800 Subject: [PATCH 039/176] update --- train.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/train.py b/train.py index 9b7a86deb4bd..3384f352ad1d 100644 --- a/train.py +++ b/train.py @@ -458,7 +458,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): parser.add_argument('--project', default='runs/train', help='save to project/name') parser.add_argument('--name', default='exp', help='save to project/name') parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment') - parser.add_argument('--gr', type=int, default=1.0, help='model.gr obj loss ratio') + parser.add_argument('--gr', default=1.0, help='model.gr obj loss ratio') opt = parser.parse_args() # Set DDP variables From 0a16ea43438a28030511f273402fc80fbc4a16ec Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 27 Dec 2020 11:16:57 -0800 Subject: [PATCH 040/176] update --- train.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/train.py b/train.py index 3384f352ad1d..638dbdaaf4d4 100644 --- a/train.py +++ b/train.py @@ -458,7 +458,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): parser.add_argument('--project', default='runs/train', help='save to project/name') parser.add_argument('--name', default='exp', help='save to project/name') parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment') - parser.add_argument('--gr', default=1.0, help='model.gr obj loss ratio') + parser.add_argument('--gr', type=float, default=1.0, help='model.gr obj loss ratio') opt = parser.parse_args() # Set DDP variables From 8868fca54ed796f2b7924f3ce03c374e12762bfc Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 27 Dec 2020 14:58:03 -0800 Subject: [PATCH 041/176] update --- data/hyp.scratch_05scale.yaml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 data/hyp.scratch_05scale.yaml diff --git a/data/hyp.scratch_05scale.yaml b/data/hyp.scratch_05scale.yaml new file mode 100644 index 000000000000..059bd5c61cb5 --- /dev/null +++ b/data/hyp.scratch_05scale.yaml @@ -0,0 +1,33 @@ +# Hyperparameters for COCO training from scratch +# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 +# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials + + +lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) +lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) +momentum: 0.937 # SGD momentum/Adam beta1 +weight_decay: 0.0005 # optimizer weight decay 5e-4 +warmup_epochs: 3.0 # warmup epochs (fractions ok) +warmup_momentum: 0.8 # warmup initial momentum +warmup_bias_lr: 0.1 # warmup initial bias lr +box: 0.05 # box loss gain +cls: 0.3 # cls loss gain +cls_pw: 1.0 # cls BCELoss positive_weight +obj: 0.5 # obj loss gain (scale with pixels) +obj_pw: 1.0 # obj BCELoss positive_weight +iou_t: 0.20 # IoU training threshold +anchor_t: 4.0 # anchor-multiple threshold +# anchors: 3 # anchors per output layer (0 to ignore) +fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) +hsv_h: 0.015 # image HSV-Hue augmentation (fraction) +hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) +hsv_v: 0.4 # image HSV-Value augmentation (fraction) +degrees: 0.0 # image rotation (+/- deg) +translate: 0.1 # image translation (+/- fraction) +scale: 0.5 # image scale (+/- gain) +shear: 0.0 # image shear (+/- deg) +perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 +flipud: 0.0 # image flip up-down (probability) +fliplr: 0.5 # image flip left-right (probability) +mosaic: 1.0 # image mosaic (probability) +mixup: 0.01 # image mixup (probability) From b5f0e723c8d5a36923caecdbe78f18fa18e10769 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 27 Dec 2020 18:21:34 -0800 Subject: [PATCH 042/176] update --- models/yolov5l-p7.yaml | 67 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 models/yolov5l-p7.yaml diff --git a/models/yolov5l-p7.yaml b/models/yolov5l-p7.yaml new file mode 100644 index 000000000000..676a5e7ca8b6 --- /dev/null +++ b/models/yolov5l-p7.yaml @@ -0,0 +1,67 @@ +# parameters +nc: 80 # number of classes +depth_multiple: 1.0 # model depth multiple +width_multiple: 1.0 # layer channel multiple + +# anchors +anchors: 3 + +# 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, [ 768, 3, 2 ] ], # 7-P5/32 + [ -1, 3, C3, [ 768 ] ], + [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 + [ -1, 3, C3, [ 1024 ] ], + [ -1, 1, Conv, [ 1280, 3, 2 ] ], # 11-P7/128 + [ -1, 1, SPP, [ 1280, [ 3, 5 ] ] ], + [ -1, 3, C3, [ 1280, False ] ], # 13 + ] + +# YOLOv5 head +head: + [ [ -1, 1, Conv, [ 1024, 1, 1 ] ], + [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], + [ [ -1, 10 ], 1, Concat, [ 1 ] ], # cat backbone P6 + [ -1, 3, C3, [ 1024, False ] ], # 17 + + [ -1, 1, Conv, [ 768, 1, 1 ] ], + [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], + [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 + [ -1, 3, C3, [ 768, False ] ], # 21 + + [ -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 ] ], # 25 + + [ -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 ] ], # 29 (P3/8-small) + + [ -1, 1, Conv, [ 256, 3, 2 ] ], + [ [ -1, 26 ], 1, Concat, [ 1 ] ], # cat head P4 + [ -1, 3, C3, [ 512, False ] ], # 32 (P4/16-medium) + + [ -1, 1, Conv, [ 512, 3, 2 ] ], + [ [ -1, 22 ], 1, Concat, [ 1 ] ], # cat head P5 + [ -1, 3, C3, [ 768, False ] ], # 35 (P5/32-large) + + [ -1, 1, Conv, [ 768, 3, 2 ] ], + [ [ -1, 18 ], 1, Concat, [ 1 ] ], # cat head P6 + [ -1, 3, C3, [ 1024, False ] ], # 38 (P6/64-xlarge) + + [ -1, 1, Conv, [ 1024, 3, 2 ] ], + [ [ -1, 14 ], 1, Concat, [ 1 ] ], # cat head P7 + [ -1, 3, C3, [ 1280, False ] ], # 41 (P7/128-xxlarge) + + [ [ 29, 32, 35, 38, 41 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) + ] From abb5a3e8d02e55ad80ebc9599cd3e83f786c7f25 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 27 Dec 2020 18:27:20 -0800 Subject: [PATCH 043/176] update --- models/yolov5l-p7-1280.yaml | 73 +++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 models/yolov5l-p7-1280.yaml diff --git a/models/yolov5l-p7-1280.yaml b/models/yolov5l-p7-1280.yaml new file mode 100644 index 000000000000..af12b2225e75 --- /dev/null +++ b/models/yolov5l-p7-1280.yaml @@ -0,0 +1,73 @@ +# parameters +nc: 80 # number of classes +depth_multiple: 1.0 # model depth multiple +width_multiple: 1.0 # layer channel multiple + +# anchors +anchors: + - [ 19,22, 54,36, 32,77 ] # P3/8 + - [ 70,83, 138,71, 75,173 ] # P4/16 + - [ 165,159, 148,334, 375,151 ] # P5/32 + - [ 334,317, 251,626, 499,474 ] # P6/64 + - [ 750,326, 534,814, 1079,818 ] # P7/128 + + +# 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, [ 768, 3, 2 ] ], # 7-P5/32 + [ -1, 3, C3, [ 768 ] ], + [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 + [ -1, 3, C3, [ 1024 ] ], + [ -1, 1, Conv, [ 1280, 3, 2 ] ], # 11-P7/128 + [ -1, 1, SPP, [ 1280, [ 3, 5 ] ] ], + [ -1, 3, C3, [ 1280, False ] ], # 13 + ] + +# YOLOv5 head +head: + [ [ -1, 1, Conv, [ 1024, 1, 1 ] ], + [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], + [ [ -1, 10 ], 1, Concat, [ 1 ] ], # cat backbone P6 + [ -1, 3, C3, [ 1024, False ] ], # 17 + + [ -1, 1, Conv, [ 768, 1, 1 ] ], + [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], + [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 + [ -1, 3, C3, [ 768, False ] ], # 21 + + [ -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 ] ], # 25 + + [ -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 ] ], # 29 (P3/8-small) + + [ -1, 1, Conv, [ 256, 3, 2 ] ], + [ [ -1, 26 ], 1, Concat, [ 1 ] ], # cat head P4 + [ -1, 3, C3, [ 512, False ] ], # 32 (P4/16-medium) + + [ -1, 1, Conv, [ 512, 3, 2 ] ], + [ [ -1, 22 ], 1, Concat, [ 1 ] ], # cat head P5 + [ -1, 3, C3, [ 768, False ] ], # 35 (P5/32-large) + + [ -1, 1, Conv, [ 768, 3, 2 ] ], + [ [ -1, 18 ], 1, Concat, [ 1 ] ], # cat head P6 + [ -1, 3, C3, [ 1024, False ] ], # 38 (P6/64-xlarge) + + [ -1, 1, Conv, [ 1024, 3, 2 ] ], + [ [ -1, 14 ], 1, Concat, [ 1 ] ], # cat head P7 + [ -1, 3, C3, [ 1280, False ] ], # 41 (P7/128-xxlarge) + + [ [ 29, 32, 35, 38, 41 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) + ] From d241ed9ed9a314c2f4ce5c7970b3cb353776e6af Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 27 Dec 2020 18:28:33 -0800 Subject: [PATCH 044/176] update --- models/yolo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/yolo.py b/models/yolo.py index 7d11060d3ad9..8440574aac75 100644 --- a/models/yolo.py +++ b/models/yolo.py @@ -84,7 +84,7 @@ def __init__(self, cfg='yolov5s.yaml', ch=3, nc=None): # model, input channels, # Build strides, anchors m = self.model[-1] # Detect() if isinstance(m, Detect): - s = 128 # 2x min stride + s = 256 # 2x min stride m.stride = torch.tensor([s / x.shape[-2] for x in self.forward(torch.zeros(1, ch, s, s))]) # forward m.anchors /= m.stride.view(-1, 1, 1) check_anchor_order(m) From 7a6e9533e6a18cf1e6caabf837bd6aab55432ffa Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 27 Dec 2020 18:36:48 -0800 Subject: [PATCH 045/176] update --- utils/loss.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/loss.py b/utils/loss.py index 2049516904ff..8fd256622923 100644 --- a/utils/loss.py +++ b/utils/loss.py @@ -106,7 +106,7 @@ def compute_loss(p, targets, model): # predictions, targets, model # Losses nt = 0 # number of targets no = len(p) # number of outputs - balance = [4.0, 1.0, 0.4] if no == 3 else [4.0, 1.0, 0.4, 0.1] # P3-5 or P3-6 + balance = [4.0, 1.0, 0.4, 0.1, 0.025] # P3-P7 for i, pi in enumerate(p): # layer index, layer predictions b, a, gj, gi = indices[i] # image, anchor, gridy, gridx tobj = torch.zeros_like(pi[..., 0], device=device) # target obj @@ -140,7 +140,7 @@ def compute_loss(p, targets, model): # predictions, targets, model s = 3 / no # output count scaling lbox *= h['box'] * s - lobj *= h['obj'] * s * (1.4 if no == 4 else 1.) + lobj *= h['obj'] # * s * (1.4 if no == 4 else 1.) lcls *= h['cls'] * s bs = tobj.shape[0] # batch size From 11228d0aac11ba0157ad77614f9cc18c7de29444 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 27 Dec 2020 18:44:04 -0800 Subject: [PATCH 046/176] update --- models/yolov5l-p7-1280.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/yolov5l-p7-1280.yaml b/models/yolov5l-p7-1280.yaml index af12b2225e75..ac81827c7889 100644 --- a/models/yolov5l-p7-1280.yaml +++ b/models/yolov5l-p7-1280.yaml @@ -19,11 +19,11 @@ backbone: [ -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, 6, C3, [ 256 ] ], [ -1, 1, Conv, [ 512, 3, 2 ] ], # 5-P4/16 [ -1, 9, C3, [ 512 ] ], [ -1, 1, Conv, [ 768, 3, 2 ] ], # 7-P5/32 - [ -1, 3, C3, [ 768 ] ], + [ -1, 6, C3, [ 768 ] ], [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 [ -1, 3, C3, [ 1024 ] ], [ -1, 1, Conv, [ 1280, 3, 2 ] ], # 11-P7/128 From 3a225f312179032eb582b04e7300378fc30a36ae Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 27 Dec 2020 18:55:13 -0800 Subject: [PATCH 047/176] update --- models/yolov5l-p7-1280.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/models/yolov5l-p7-1280.yaml b/models/yolov5l-p7-1280.yaml index ac81827c7889..517bc22a52b1 100644 --- a/models/yolov5l-p7-1280.yaml +++ b/models/yolov5l-p7-1280.yaml @@ -19,13 +19,13 @@ backbone: [ -1, 1, Conv, [ 128, 3, 2 ] ], # 1-P2/4 [ -1, 3, C3, [ 128 ] ], [ -1, 1, Conv, [ 256, 3, 2 ] ], # 3-P3/8 - [ -1, 6, C3, [ 256 ] ], + [ -1, 3, C3, [ 256 ] ], [ -1, 1, Conv, [ 512, 3, 2 ] ], # 5-P4/16 - [ -1, 9, C3, [ 512 ] ], + [ -1, 6, C3, [ 512 ] ], [ -1, 1, Conv, [ 768, 3, 2 ] ], # 7-P5/32 - [ -1, 6, C3, [ 768 ] ], + [ -1, 9, C3, [ 768 ] ], [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 - [ -1, 3, C3, [ 1024 ] ], + [ -1, 6, C3, [ 1024 ] ], [ -1, 1, Conv, [ 1280, 3, 2 ] ], # 11-P7/128 [ -1, 1, SPP, [ 1280, [ 3, 5 ] ] ], [ -1, 3, C3, [ 1280, False ] ], # 13 From 89f9965fb5ef1108836cba929fa6d8261491c0c7 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 27 Dec 2020 20:52:36 -0800 Subject: [PATCH 048/176] update --- utils/datasets.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/utils/datasets.py b/utils/datasets.py index 59c35b94b60a..b2aac0b74977 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -79,7 +79,7 @@ def create_dataloader(path, imgsz, batch_size, stride, opt, hyp=None, augment=Fa num_workers=nw, sampler=sampler, pin_memory=True, - collate_fn=LoadImagesAndLabels.collate_fn) + collate_fn=LoadImagesAndLabels.collate_fn4 if augment else LoadImagesAndLabels.collate_fn) return dataloader, dataset @@ -578,6 +578,13 @@ def collate_fn(batch): l[:, 0] = i # add target image index for build_targets() return torch.stack(img, 0), torch.cat(label, 0), path, shapes + @staticmethod + def collate_fn4(batch): + img, label, path, shapes = zip(*batch) # transposed + for i, l in enumerate(label): + l[:, 0] = i # add target image index for build_targets() + return torch.stack(img, 0), torch.cat(label, 0), path, shapes + # Ancillary functions -------------------------------------------------------------------------------------------------- def load_image(self, index): From 49abc1e08c9d05eba24228c01dcd6f298497e9c1 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 27 Dec 2020 21:22:11 -0800 Subject: [PATCH 049/176] update --- train.py | 3 ++- utils/datasets.py | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/train.py b/train.py index 638dbdaaf4d4..3757860e7705 100644 --- a/train.py +++ b/train.py @@ -187,7 +187,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): dataloader, dataset = create_dataloader(train_path, imgsz, batch_size, gs, opt, hyp=hyp, augment=True, cache=opt.cache_images, rect=opt.rect, rank=rank, world_size=opt.world_size, workers=opt.workers, - image_weights=opt.image_weights) + image_weights=opt.image_weights, quad=opt.quad) mlc = np.concatenate(dataset.labels, 0)[:, 0].max() # max label class nb = len(dataloader) # number of batches assert mlc < nc, 'Label class %g exceeds nc=%g in %s. Possible class labels are 0-%g' % (mlc, nc, opt.data, nc - 1) @@ -459,6 +459,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): parser.add_argument('--name', default='exp', help='save to project/name') parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment') parser.add_argument('--gr', type=float, default=1.0, help='model.gr obj loss ratio') + parser.add_argument('--quad', action='store_true', help='quad dataloader') opt = parser.parse_args() # Set DDP variables diff --git a/utils/datasets.py b/utils/datasets.py index b2aac0b74977..7c4584ea8eb5 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -55,7 +55,7 @@ def exif_size(img): def create_dataloader(path, imgsz, batch_size, stride, opt, hyp=None, augment=False, cache=False, pad=0.0, rect=False, - rank=-1, world_size=1, workers=8, image_weights=False): + rank=-1, world_size=1, workers=8, image_weights=False, quad=False): # Make sure only the first process in DDP process the dataset first, and the following others can use the cache with torch_distributed_zero_first(rank): dataset = LoadImagesAndLabels(path, imgsz, batch_size, @@ -79,7 +79,7 @@ def create_dataloader(path, imgsz, batch_size, stride, opt, hyp=None, augment=Fa num_workers=nw, sampler=sampler, pin_memory=True, - collate_fn=LoadImagesAndLabels.collate_fn4 if augment else LoadImagesAndLabels.collate_fn) + collate_fn=LoadImagesAndLabels.collate_fn4 if quad else LoadImagesAndLabels.collate_fn) return dataloader, dataset @@ -581,9 +581,21 @@ def collate_fn(batch): @staticmethod def collate_fn4(batch): img, label, path, shapes = zip(*batch) # transposed - for i, l in enumerate(label): + n = len(shapes) // 4 + img4, label4, path4, shapes4 = [], [], path[:n], shapes[:n] + + ho = torch.tensor([[0., 0, 0, 1, 0, 0]]) + wo = torch.tensor([[0., 0, 1, 0, 0, 0]]) + for i in range(n): # zidane torch.zeros(16,3,720,1280) # BCHW + i *= 4 + img4.append(torch.cat((torch.cat((img[i], img[i + 1]), 1), torch.cat((img[i + 2], img[i + 3]), 1)), 2)) + label4.append(torch.cat((label[i], label[i + 1] + ho, label[i + 2] + wo, label[i + 3] + ho + wo), 0)) + + for i, l in enumerate(label4): l[:, 0] = i # add target image index for build_targets() - return torch.stack(img, 0), torch.cat(label, 0), path, shapes + l[:, 2:] /= 2. + + return torch.stack(img4, 0), torch.cat(label4, 0), path4, shapes4 # Ancillary functions -------------------------------------------------------------------------------------------------- From 4f8f4459556d7779b7db346c6e066be55830aebb Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 27 Dec 2020 21:24:14 -0800 Subject: [PATCH 050/176] update --- train.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/train.py b/train.py index 3757860e7705..73db229055e4 100644 --- a/train.py +++ b/train.py @@ -290,6 +290,8 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): loss, loss_items = compute_loss(pred, targets.to(device), model) # loss scaled by batch_size if rank != -1: loss *= opt.world_size # gradient averaged between devices in DDP mode + if opt.quad: + loss *= 4. # Backward scaler.scale(loss).backward() From 2d5d00aa7572bbc2ca3e569f0cbde92bc3d5dc59 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 27 Dec 2020 21:43:56 -0800 Subject: [PATCH 051/176] update --- utils/datasets.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/utils/datasets.py b/utils/datasets.py index 7c4584ea8eb5..593e317b32c4 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -15,6 +15,7 @@ import cv2 import numpy as np import torch +import torch.nn.functional as F from PIL import Image, ExifTags from torch.utils.data import Dataset from tqdm import tqdm @@ -586,14 +587,21 @@ def collate_fn4(batch): ho = torch.tensor([[0., 0, 0, 1, 0, 0]]) wo = torch.tensor([[0., 0, 1, 0, 0, 0]]) + s = torch.tensor([[1, 1, .5, .5, .5, .5]]) # scale for i in range(n): # zidane torch.zeros(16,3,720,1280) # BCHW i *= 4 - img4.append(torch.cat((torch.cat((img[i], img[i + 1]), 1), torch.cat((img[i + 2], img[i + 3]), 1)), 2)) - label4.append(torch.cat((label[i], label[i + 1] + ho, label[i + 2] + wo, label[i + 3] + ho + wo), 0)) + if random.random() < 0.5: + im = F.interpolate(img[i].unsqueeze(0).float(), scale_factor=2., mode='bilinear', align_corners=False)[ + 0].type(img[i].type()) + l = label[i] + else: + im = torch.cat((torch.cat((img[i], img[i + 1]), 1), torch.cat((img[i + 2], img[i + 3]), 1)), 2) + l = torch.cat((label[i], label[i + 1] + ho, label[i + 2] + wo, label[i + 3] + ho + wo), 0) * s + img4.append(im) + label4.append(l) for i, l in enumerate(label4): l[:, 0] = i # add target image index for build_targets() - l[:, 2:] /= 2. return torch.stack(img4, 0), torch.cat(label4, 0), path4, shapes4 From d9e5535e66ed0fa94558f70997257a3222ba6c5e Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 27 Dec 2020 21:51:24 -0800 Subject: [PATCH 052/176] update --- .../{yolov5l-p6_33.yaml => yolov5l-p6.yaml} | 0 models/yolov5l-p6_11.yaml | 56 ------------------- models/yolov5l-p6_31.yaml | 56 ------------------- 3 files changed, 112 deletions(-) rename models/{yolov5l-p6_33.yaml => yolov5l-p6.yaml} (100%) delete mode 100644 models/yolov5l-p6_11.yaml delete mode 100644 models/yolov5l-p6_31.yaml diff --git a/models/yolov5l-p6_33.yaml b/models/yolov5l-p6.yaml similarity index 100% rename from models/yolov5l-p6_33.yaml rename to models/yolov5l-p6.yaml diff --git a/models/yolov5l-p6_11.yaml b/models/yolov5l-p6_11.yaml deleted file mode 100644 index 9f9cb4565103..000000000000 --- a/models/yolov5l-p6_11.yaml +++ /dev/null @@ -1,56 +0,0 @@ -# parameters -nc: 80 # number of classes -depth_multiple: 1.0 # model depth multiple -width_multiple: 1.0 # layer channel multiple - -# anchors -anchors: 3 - -# 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, [ 768, 3, 2 ] ], # 7-P5/32 - [ -1, 3, C3, [ 768 ] ], - [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 - [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ], - [ -1, 1, C3, [ 1024, False ] ], # 11 - ] - -# YOLOv5 head -head: - [ [ -1, 1, Conv, [ 768, 1, 1 ] ], - [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], - [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 - [ -1, 3, C3, [ 768, False ] ], # 15 - - [ -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 ] ], # 19 - - [ -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 ] ], # 23 (P3/8-small) - - [ -1, 1, Conv, [ 256, 3, 2 ] ], - [ [ -1, 20 ], 1, Concat, [ 1 ] ], # cat head P4 - [ -1, 3, C3, [ 512, False ] ], # 26 (P4/16-medium) - - [ -1, 1, Conv, [ 512, 3, 2 ] ], - [ [ -1, 16 ], 1, Concat, [ 1 ] ], # cat head P5 - [ -1, 3, C3, [ 768, False ] ], # 29 (P5/32-large) - - [ -1, 1, Conv, [ 768, 3, 2 ] ], - [ [ -1, 12 ], 1, Concat, [ 1 ] ], # cat head P6 - [ -1, 1, C3, [ 1024, False ] ], # 32 (P5/64-xlarge) - - [ [ 23, 26, 29, 32 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) - ] diff --git a/models/yolov5l-p6_31.yaml b/models/yolov5l-p6_31.yaml deleted file mode 100644 index 9aa880c22f0e..000000000000 --- a/models/yolov5l-p6_31.yaml +++ /dev/null @@ -1,56 +0,0 @@ -# parameters -nc: 80 # number of classes -depth_multiple: 1.0 # model depth multiple -width_multiple: 1.0 # layer channel multiple - -# anchors -anchors: 3 - -# 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, [ 768, 3, 2 ] ], # 7-P5/32 - [ -1, 3, C3, [ 768 ] ], - [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 - [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ], - [ -1, 3, C3, [ 1024, False ] ], # 11 - ] - -# YOLOv5 head -head: - [ [ -1, 1, Conv, [ 768, 1, 1 ] ], - [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], - [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 - [ -1, 3, C3, [ 768, False ] ], # 15 - - [ -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 ] ], # 19 - - [ -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 ] ], # 23 (P3/8-small) - - [ -1, 1, Conv, [ 256, 3, 2 ] ], - [ [ -1, 20 ], 1, Concat, [ 1 ] ], # cat head P4 - [ -1, 3, C3, [ 512, False ] ], # 26 (P4/16-medium) - - [ -1, 1, Conv, [ 512, 3, 2 ] ], - [ [ -1, 16 ], 1, Concat, [ 1 ] ], # cat head P5 - [ -1, 3, C3, [ 768, False ] ], # 29 (P5/32-large) - - [ -1, 1, Conv, [ 768, 3, 2 ] ], - [ [ -1, 12 ], 1, Concat, [ 1 ] ], # cat head P6 - [ -1, 1, C3, [ 1024, False ] ], # 32 (P5/64-xlarge) - - [ [ 23, 26, 29, 32 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) - ] From e48e07fc2d68063da67c4e0e3f5ef7ea09d581ed Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 27 Dec 2020 21:59:45 -0800 Subject: [PATCH 053/176] update --- models/{yolov5l-p6.yaml => yolov5l-p6-640.yaml} | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) rename models/{yolov5l-p6.yaml => yolov5l-p6-640.yaml} (91%) diff --git a/models/yolov5l-p6.yaml b/models/yolov5l-p6-640.yaml similarity index 91% rename from models/yolov5l-p6.yaml rename to models/yolov5l-p6-640.yaml index 3728a118f090..95661f66c8fd 100644 --- a/models/yolov5l-p6.yaml +++ b/models/yolov5l-p6-640.yaml @@ -4,7 +4,12 @@ depth_multiple: 1.0 # model depth multiple width_multiple: 1.0 # layer channel multiple # anchors -anchors: 3 +anchors: + - [ 9,11, 21,19, 17,41 ] # P3/8 + - [ 43,32, 39,70, 86,64 ] # P4/16 + - [ 65,131, 134,130, 120,265 ] # P5/32 + - [ 282,180, 247,354, 512,387 ] # P6/64 + # YOLOv5 backbone backbone: From e9b5e55585f7d3a52095660b8ae0320d5677bcea Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 27 Dec 2020 22:01:14 -0800 Subject: [PATCH 054/176] update --- train.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/train.py b/train.py index 73db229055e4..f12ca6b63c82 100644 --- a/train.py +++ b/train.py @@ -432,9 +432,9 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): if __name__ == '__main__': parser = argparse.ArgumentParser() - parser.add_argument('--weights', type=str, default='yolov5s.pt', help='initial weights path') - parser.add_argument('--cfg', type=str, default='', help='model.yaml path') - parser.add_argument('--data', type=str, default='data/coco128.yaml', help='data.yaml path') + parser.add_argument('--weights', type=str, default='', help='initial weights path') + parser.add_argument('--cfg', type=str, default='yolov5l-p6-640.yaml', help='model.yaml path') + parser.add_argument('--data', type=str, default='data/coco.yaml', help='data.yaml path') parser.add_argument('--hyp', type=str, default='data/hyp.scratch.yaml', help='hyperparameters path') parser.add_argument('--epochs', type=int, default=300) parser.add_argument('--batch-size', type=int, default=16, help='total batch size for all GPUs') From fff0174e01baa10d307a8a18737652882e4f3d12 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 27 Dec 2020 22:01:55 -0800 Subject: [PATCH 055/176] update --- data/hyp.scratch_10obj.yaml | 33 +++++++++++++++++++++++++++++++++ train.py | 6 +++--- 2 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 data/hyp.scratch_10obj.yaml diff --git a/data/hyp.scratch_10obj.yaml b/data/hyp.scratch_10obj.yaml new file mode 100644 index 000000000000..f5f81481ee2d --- /dev/null +++ b/data/hyp.scratch_10obj.yaml @@ -0,0 +1,33 @@ +# Hyperparameters for COCO training from scratch +# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 +# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials + + +lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) +lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) +momentum: 0.937 # SGD momentum/Adam beta1 +weight_decay: 0.0005 # optimizer weight decay 5e-4 +warmup_epochs: 3.0 # warmup epochs (fractions ok) +warmup_momentum: 0.8 # warmup initial momentum +warmup_bias_lr: 0.1 # warmup initial bias lr +box: 0.05 # box loss gain +cls: 0.3 # cls loss gain +cls_pw: 1.0 # cls BCELoss positive_weight +obj: 1.0 # obj loss gain (scale with pixels) +obj_pw: 1.0 # obj BCELoss positive_weight +iou_t: 0.20 # IoU training threshold +anchor_t: 4.0 # anchor-multiple threshold +# anchors: 3 # anchors per output layer (0 to ignore) +fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) +hsv_h: 0.015 # image HSV-Hue augmentation (fraction) +hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) +hsv_v: 0.4 # image HSV-Value augmentation (fraction) +degrees: 0.0 # image rotation (+/- deg) +translate: 0.1 # image translation (+/- fraction) +scale: 0.9 # image scale (+/- gain) +shear: 0.0 # image shear (+/- deg) +perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 +flipud: 0.0 # image flip up-down (probability) +fliplr: 0.5 # image flip left-right (probability) +mosaic: 1.0 # image mosaic (probability) +mixup: 0.01 # image mixup (probability) diff --git a/train.py b/train.py index f12ca6b63c82..73db229055e4 100644 --- a/train.py +++ b/train.py @@ -432,9 +432,9 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): if __name__ == '__main__': parser = argparse.ArgumentParser() - parser.add_argument('--weights', type=str, default='', help='initial weights path') - parser.add_argument('--cfg', type=str, default='yolov5l-p6-640.yaml', help='model.yaml path') - parser.add_argument('--data', type=str, default='data/coco.yaml', help='data.yaml path') + parser.add_argument('--weights', type=str, default='yolov5s.pt', help='initial weights path') + parser.add_argument('--cfg', type=str, default='', help='model.yaml path') + parser.add_argument('--data', type=str, default='data/coco128.yaml', help='data.yaml path') parser.add_argument('--hyp', type=str, default='data/hyp.scratch.yaml', help='hyperparameters path') parser.add_argument('--epochs', type=int, default=300) parser.add_argument('--batch-size', type=int, default=16, help='total batch size for all GPUs') From fb9c3c0f556c886264b2075e3b32dd30aa316478 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 28 Dec 2020 08:43:57 -0800 Subject: [PATCH 056/176] update --- utils/loss.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/loss.py b/utils/loss.py index 8fd256622923..2c8948da0a04 100644 --- a/utils/loss.py +++ b/utils/loss.py @@ -106,7 +106,7 @@ def compute_loss(p, targets, model): # predictions, targets, model # Losses nt = 0 # number of targets no = len(p) # number of outputs - balance = [4.0, 1.0, 0.4, 0.1, 0.025] # P3-P7 + balance = [4.0, 1.0, 0.3, 0.1, 0.03] # P3-P7 for i, pi in enumerate(p): # layer index, layer predictions b, a, gj, gi = indices[i] # image, anchor, gridy, gridx tobj = torch.zeros_like(pi[..., 0], device=device) # target obj From afef0ce7ecf4f72807a6850f9eae492285f00d5b Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 28 Dec 2020 18:56:01 -0800 Subject: [PATCH 057/176] update --- utils/google_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/google_utils.py b/utils/google_utils.py index fcddd8b00dd3..20a8a66462fc 100644 --- a/utils/google_utils.py +++ b/utils/google_utils.py @@ -21,7 +21,7 @@ def attempt_download(weights): file = Path(weights).name.lower() msg = weights + ' missing, try downloading from https://github.com/ultralytics/yolov5/releases/' - models = ['yolov5s.pt', 'yolov5m.pt', 'yolov5l.pt', 'yolov5x.pt'] # available models + models = ['yolov5s.pt', 'yolov5m.pt', 'yolov5l.pt', 'yolov5x.pt', 'yolov5s4.pt', 'yolov5m4.pt', 'yolov5l4.pt', 'yolov5x4.pt'] # available models redundant = False # offer second download option if file in models and not os.path.isfile(weights): From 4acc617244a1bb448dd2eaa9f57f1b3c69cc9780 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 29 Dec 2020 10:51:05 -0800 Subject: [PATCH 058/176] update --- test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.py b/test.py index b520eae98d00..b7b34038a069 100644 --- a/test.py +++ b/test.py @@ -320,7 +320,7 @@ def test(data, ) elif opt.task == 'study': # run over a range of settings and save/plot - for weights in ['yolov5s.pt', 'yolov5m.pt', 'yolov5l.pt', 'yolov5x.pt']: + for weights in ['yolov5s4.pt', 'yolov5m4.pt', 'yolov5l4.pt', 'yolov5x4.pt']: f = 'study_%s_%s.txt' % (Path(opt.data).stem, Path(weights).stem) # filename to save to x = list(range(320, 800, 64)) # x axis y = [] # y axis From 6c996dcccbfa67813aaa1bc168727666951ad624 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 29 Dec 2020 10:51:33 -0800 Subject: [PATCH 059/176] update --- utils/google_utils.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/utils/google_utils.py b/utils/google_utils.py index 20a8a66462fc..2220e28cd761 100644 --- a/utils/google_utils.py +++ b/utils/google_utils.py @@ -6,6 +6,7 @@ import time from pathlib import Path +import requests import torch @@ -21,21 +22,14 @@ def attempt_download(weights): file = Path(weights).name.lower() msg = weights + ' missing, try downloading from https://github.com/ultralytics/yolov5/releases/' - models = ['yolov5s.pt', 'yolov5m.pt', 'yolov5l.pt', 'yolov5x.pt', 'yolov5s4.pt', 'yolov5m4.pt', 'yolov5l4.pt', 'yolov5x4.pt'] # available models + models = ['yolov5s.pt', 'yolov5m.pt', 'yolov5l.pt', 'yolov5x.pt', 'yolov5s4.pt', 'yolov5m4.pt', 'yolov5l4.pt', + 'yolov5x4.pt'] # available models redundant = False # offer second download option if file in models and not os.path.isfile(weights): - # Google Drive - # d = {'yolov5s.pt': '1R5T6rIyy3lLwgFXNms8whc-387H0tMQO', - # 'yolov5m.pt': '1vobuEExpWQVpXExsJ2w-Mbf3HJjWkQJr', - # 'yolov5l.pt': '1hrlqD1Wdei7UT4OgT785BEk1JwnSvNEV', - # 'yolov5x.pt': '1mM8aZJlWTxOg7BZJvNUMrTnA2AbeCVzS'} - # r = gdrive_download(id=d[file], name=weights) if file in d else 1 - # if r == 0 and os.path.exists(weights) and os.path.getsize(weights) > 1E6: # check - # return - try: # GitHub - url = 'https://github.com/ultralytics/yolov5/releases/download/v3.1/' + file + tag = requests.get('https://api.github.com/repos/ultralytics/yolov5/releases/latest').json()['tag_name'] + url = f'https://github.com/ultralytics/yolov5/releases/download/{tag}/{file}' print('Downloading %s to %s...' % (url, weights)) torch.hub.download_url_to_file(url, weights) assert os.path.exists(weights) and os.path.getsize(weights) > 1E6 # check From 32759994f4eb823047049c6f793382f2a77e9e56 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 29 Dec 2020 15:06:29 -0800 Subject: [PATCH 060/176] update --- models/yolov5l-p6-1280.yaml | 1 - train.py | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/models/yolov5l-p6-1280.yaml b/models/yolov5l-p6-1280.yaml index e50cce09a8c8..49811e796947 100644 --- a/models/yolov5l-p6-1280.yaml +++ b/models/yolov5l-p6-1280.yaml @@ -12,7 +12,6 @@ anchors: # normal n=12, img_size=1280, metric_all=0.281/0.714-mean/best, past_thr=0.468-mean: 19,27, 44,40, 38,94, 96,68, 86,152, 180,137, 140,301, 303,264, 238,542, 436,615, 739,380, 925,792 # scale 0.9 n=12, img_size=1280, metric_all=0.267/0.705-mean/best, past_thr=0.467-mean: 6,9, 17,15, 16,36, 35,30, 33,61, 73,51, 60,118, 140,104, 126,225, 273,207, 262,398, 595,454 - # YOLOv5 backbone backbone: # [from, number, module, args] diff --git a/train.py b/train.py index 73db229055e4..173027b5dbda 100644 --- a/train.py +++ b/train.py @@ -104,6 +104,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): nbs = 64 # nominal batch size accumulate = max(round(nbs / total_batch_size), 1) # accumulate loss before optimizing hyp['weight_decay'] *= total_batch_size * accumulate / nbs # scale weight_decay + logger.info(f"Scaled weight_decay = {hyp['weight_decay']}") pg0, pg1, pg2 = [], [], [] # optimizer parameter groups for k, v in model.named_modules(): From d4a2880813248c884d85ca1cf156f89748fc768c Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 29 Dec 2020 17:42:29 -0800 Subject: [PATCH 061/176] update --- train.py | 1 + 1 file changed, 1 insertion(+) diff --git a/train.py b/train.py index 173027b5dbda..48eeb12e0996 100644 --- a/train.py +++ b/train.py @@ -492,6 +492,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): # DDP mode device = select_device(opt.device, batch_size=opt.batch_size) if opt.local_rank != -1: + os.environ['OMP_NUM_THREADS'] = 1 # avoid default twarning assert torch.cuda.device_count() > opt.local_rank torch.cuda.set_device(opt.local_rank) device = torch.device('cuda', opt.local_rank) From 52d4082ea53dba7c5555daf33c06c65de045ac52 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 29 Dec 2020 19:01:11 -0800 Subject: [PATCH 062/176] update --- train.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/train.py b/train.py index 48eeb12e0996..ef3518bced93 100644 --- a/train.py +++ b/train.py @@ -492,7 +492,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): # DDP mode device = select_device(opt.device, batch_size=opt.batch_size) if opt.local_rank != -1: - os.environ['OMP_NUM_THREADS'] = 1 # avoid default twarning + os.environ['OMP_NUM_THREADS'] = '1' # avoid default twarning assert torch.cuda.device_count() > opt.local_rank torch.cuda.set_device(opt.local_rank) device = torch.device('cuda', opt.local_rank) From 318b9cbe105c344dcb6ddd85a726556a38dc48b1 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 29 Dec 2020 19:02:40 -0800 Subject: [PATCH 063/176] update --- train.py | 1 - utils/torch_utils.py | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/train.py b/train.py index ef3518bced93..173027b5dbda 100644 --- a/train.py +++ b/train.py @@ -492,7 +492,6 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): # DDP mode device = select_device(opt.device, batch_size=opt.batch_size) if opt.local_rank != -1: - os.environ['OMP_NUM_THREADS'] = '1' # avoid default twarning assert torch.cuda.device_count() > opt.local_rank torch.cuda.set_device(opt.local_rank) device = torch.device('cuda', opt.local_rank) diff --git a/utils/torch_utils.py b/utils/torch_utils.py index 754b0870cd32..59a5c7be86ed 100644 --- a/utils/torch_utils.py +++ b/utils/torch_utils.py @@ -56,6 +56,7 @@ def select_device(device='', batch_size=None): ng = torch.cuda.device_count() if ng > 1 and batch_size: # check that batch_size is compatible with device_count assert batch_size % ng == 0, 'batch-size %g not multiple of GPU count %g' % (batch_size, ng) + os.environ['OMP_NUM_THREADS'] = '1' # avoid default twarning x = [torch.cuda.get_device_properties(i) for i in range(ng)] s = f'Using torch {torch.__version__} ' for i in range(0, ng): From 0737f83bddc811023546feb43c2586426eebe376 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 29 Dec 2020 19:04:16 -0800 Subject: [PATCH 064/176] update --- utils/torch_utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/utils/torch_utils.py b/utils/torch_utils.py index 59a5c7be86ed..754b0870cd32 100644 --- a/utils/torch_utils.py +++ b/utils/torch_utils.py @@ -56,7 +56,6 @@ def select_device(device='', batch_size=None): ng = torch.cuda.device_count() if ng > 1 and batch_size: # check that batch_size is compatible with device_count assert batch_size % ng == 0, 'batch-size %g not multiple of GPU count %g' % (batch_size, ng) - os.environ['OMP_NUM_THREADS'] = '1' # avoid default twarning x = [torch.cuda.get_device_properties(i) for i in range(ng)] s = f'Using torch {torch.__version__} ' for i in range(0, ng): From 67270cd93a090118891dc317c1ccaa88c0fe70f6 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 29 Dec 2020 20:14:28 -0800 Subject: [PATCH 065/176] update --- models/yolo.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/yolo.py b/models/yolo.py index 8440574aac75..f3f3c0f86160 100644 --- a/models/yolo.py +++ b/models/yolo.py @@ -100,8 +100,8 @@ def __init__(self, cfg='yolov5s.yaml', ch=3, nc=None): # model, input channels, def forward(self, x, augment=False, profile=False): if augment: img_size = x.shape[-2:] # height, width - s = [1, 0.83, 0.67] # scales - f = [None, 3, None] # flips (2-ud, 3-lr) + s = [1, 0.875, 0.75, 0.625] # scales + f = [None, 3, None, 3] # flips (2-ud, 3-lr) y = [] # outputs for si, fi in zip(s, f): xi = scale_img(x.flip(fi) if fi else x, si) From 4059db74829846f0325b4a42658d2d8e98ed5e8e Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 29 Dec 2020 20:50:23 -0800 Subject: [PATCH 066/176] update --- models/experimental.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/experimental.py b/models/experimental.py index 136e86d7f8e6..2dbbf7fa32f2 100644 --- a/models/experimental.py +++ b/models/experimental.py @@ -105,8 +105,8 @@ def forward(self, x, augment=False): for module in self: y.append(module(x, augment)[0]) # y = torch.stack(y).max(0)[0] # max ensemble - # y = torch.cat(y, 1) # nms ensemble - y = torch.stack(y).mean(0) # mean ensemble + # y = torch.stack(y).mean(0) # mean ensemble + y = torch.cat(y, 1) # nms ensemble return y, None # inference, train output From 821cce5ce42e0c4e23b5aacceab2e80abed4c9b1 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 29 Dec 2020 21:09:23 -0800 Subject: [PATCH 067/176] update --- utils/plots.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/plots.py b/utils/plots.py index 3a4dccdc34c5..9ac349e162d8 100644 --- a/utils/plots.py +++ b/utils/plots.py @@ -222,7 +222,7 @@ def plot_targets_txt(): # from utils.plots import *; plot_targets_txt() plt.savefig('targets.jpg', dpi=200) -def plot_study_txt(path='', x=None): # from utils.plots import *; plot_study_txt() +def plot_study_txt(path='study/', x=None): # from utils.plots import *; plot_study_txt() # Plot study.txt generated by test.py fig, ax = plt.subplots(2, 4, figsize=(10, 6), tight_layout=True) ax = ax.ravel() From 3c48bc0cf7b881b32157f40291b6d03363edc388 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 30 Dec 2020 12:51:13 -0800 Subject: [PATCH 068/176] update --- data/coco.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/data/coco.yaml b/data/coco.yaml index 736c562b91a3..abfd8feba123 100644 --- a/data/coco.yaml +++ b/data/coco.yaml @@ -35,6 +35,10 @@ names: [ 'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', ' # print(i, x) +# python -m torch.distributed.launch --nproc_per_node 2 train.py --batch-size 80 --data coco128.yaml --epochs 50 --weights yolov5s.pt +# python -m torch.distributed.launch --nproc_per_node 4 train.py --resume + + # python train.py --data coco.yaml --batch 24 --weights '' --cfg yolov5l.yaml --epochs 300 --project ../paper --name yolov5lc3_03cls --hyp hyp.scratch_03cls.yaml --device 0 # python train.py --data coco.yaml --batch 24 --weights '' --cfg yolov5l.yaml --epochs 300 --project ../paper --name yolov5lc3_08cls --hyp hyp.scratch_08cls.yaml --device 1 # python train.py --data coco.yaml --batch 6 --img 1280 640 --epochs 75 --weights '' --cfg yolov5l.yaml --project ../paper --name yolov5l_1280 --hyp hyp.scratch_09scale.yaml --device 0 From 5e69e1ff36ad24b6d671016a0186d1e716868412 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 30 Dec 2020 13:34:19 -0800 Subject: [PATCH 069/176] update --- train.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/train.py b/train.py index ba38c2af23b0..74833ee3be3e 100644 --- a/train.py +++ b/train.py @@ -466,7 +466,6 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): opt = parser.parse_args() # Set DDP variables - opt.total_batch_size = opt.batch_size opt.world_size = int(os.environ['WORLD_SIZE']) if 'WORLD_SIZE' in os.environ else 1 opt.global_rank = int(os.environ['RANK']) if 'RANK' in os.environ else -1 set_logging(opt.global_rank) @@ -477,10 +476,10 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): if opt.resume: # resume an interrupted run ckpt = opt.resume if isinstance(opt.resume, str) else get_latest_run() # specified or most recent path assert os.path.isfile(ckpt), 'ERROR: --resume checkpoint does not exist' - apriori = opt.global_rank, opt.local_rank + apriori = opt.global_rank, opt.local_rank, opt.batch_size with open(Path(ckpt).parent.parent / 'opt.yaml') as f: opt = argparse.Namespace(**yaml.load(f, Loader=yaml.FullLoader)) # replace - opt.cfg, opt.weights, opt.resume, opt.global_rank, opt.local_rank = '', ckpt, True, *apriori # reinstate + opt.cfg, opt.weights, opt.resume, opt.global_rank, opt.local_rank, opt.batch_size = '', ckpt, True, *apriori logger.info('Resuming training from %s' % ckpt) else: # opt.hyp = opt.hyp or ('hyp.finetune.yaml' if opt.weights else 'hyp.scratch.yaml') @@ -492,6 +491,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): # DDP mode device = select_device(opt.device, batch_size=opt.batch_size) + opt.total_batch_size = opt.batch_size if opt.local_rank != -1: assert torch.cuda.device_count() > opt.local_rank torch.cuda.set_device(opt.local_rank) From 9f7f70cf15166cc31879a828bc06f1402c144714 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 30 Dec 2020 14:54:59 -0800 Subject: [PATCH 070/176] update --- models/yolov5l-p2s.yaml | 50 ----------------------------------------- models/yolov5l-p2t.yaml | 50 ----------------------------------------- train.py | 4 +++- 3 files changed, 3 insertions(+), 101 deletions(-) delete mode 100644 models/yolov5l-p2s.yaml delete mode 100644 models/yolov5l-p2t.yaml diff --git a/models/yolov5l-p2s.yaml b/models/yolov5l-p2s.yaml deleted file mode 100644 index 84a7050d6298..000000000000 --- a/models/yolov5l-p2s.yaml +++ /dev/null @@ -1,50 +0,0 @@ -# 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' ] ], - [ 2, 1, Contract, [ 2 ] ], - [ [ -1, -2, 4 ], 1, Concat, [ 1 ] ], # cat backbone P2, P3 - [ -1, 3, C3, [ 256, False ] ], # 18 (P3/8-small) - - [ -1, 1, Conv, [ 256, 3, 2 ] ], - [ 10, 1, Expand, [ 2 ] ], - [ [ -1, -2, 14 ], 1, Concat, [ 1 ] ], # cat head P4 - [ -1, 3, C3, [ 512, False ] ], # 22 (P4/16-medium) - - [ -1, 1, Conv, [ 512, 3, 2 ] ], - [ [ -1, 10 ], 1, Concat, [ 1 ] ], # cat head P5 - [ -1, 3, C3, [ 1024, False ] ], # 25 (P5/32-large) - - [ [ 18, 22, 25 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5) - ] diff --git a/models/yolov5l-p2t.yaml b/models/yolov5l-p2t.yaml deleted file mode 100644 index 2683e77c5745..000000000000 --- a/models/yolov5l-p2t.yaml +++ /dev/null @@ -1,50 +0,0 @@ -# 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, Expand, [ 2 ] ], - [ [ -1, 6 ], 1, Concat, [ 1 ] ], # cat backbone P4 - [ -1, 3, C3, [ 512, False ] ], # 13 - - [ -1, 1, Conv, [ 256, 1, 1 ] ], - [ -1, 1, Expand, [ 2 ] ], - [ 2, 1, Contract, [ 2 ] ], - [ [ -1, -2, 4 ], 1, Concat, [ 1 ] ], # cat backbone P2, P3 - [ -1, 3, C3, [ 256, False ] ], # 18 (P3/8-small) - - [ -1, 1, Conv, [ 256, 3, 2 ] ], - [ 10, 1, Expand, [ 2 ] ], - [ [ -1, -2, 14 ], 1, Concat, [ 1 ] ], # cat head P4 - [ -1, 3, C3, [ 512, False ] ], # 22 (P4/16-medium) - - [ -1, 1, Conv, [ 512, 3, 2 ] ], - [ [ -1, 10 ], 1, Concat, [ 1 ] ], # cat head P5 - [ -1, 3, C3, [ 1024, False ] ], # 25 (P5/32-large) - - [ [ 18, 22, 25 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5) - ] diff --git a/train.py b/train.py index 74833ee3be3e..9ce24c4f7b07 100644 --- a/train.py +++ b/train.py @@ -166,6 +166,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): # Image sizes gs = int(max(model.stride)) # grid size (max stride) + nl = model.model[-1].nl # number of detection layers (used for scaling hyp['obj']) imgsz, imgsz_test = [check_img_size(x, gs) for x in opt.img_size] # verify imgsz are gs-multiples # DP mode @@ -215,7 +216,8 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): check_anchors(dataset, model=model, thr=hyp['anchor_t'], imgsz=imgsz) # Model parameters - hyp['cls'] *= nc / 80. # scale coco-tuned hyp['cls'] to current dataset + hyp['cls'] *= nc / 80. # scale hyp['cls'] to class count + hyp['obj'] *= imgsz ** 2 / 640. ** 2 * 3. / nl # scale hyp['obj'] to image size and output layers model.nc = nc # attach number of classes to model model.hyp = hyp # attach hyperparameters to model model.gr = opt.gr # iou loss ratio (obj_loss = 1.0 or iou) From fe838614276816630dc16df0bf2bee389c01b0b6 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 30 Dec 2020 15:08:18 -0800 Subject: [PATCH 071/176] update --- data/hyp.scratch_0001decay.yaml | 33 --------- data/hyp.scratch_0002decay.yaml | 33 --------- data/hyp.scratch_0003decay.yaml | 33 --------- data/hyp.scratch_0007decay.yaml | 33 --------- data/hyp.scratch_01cls.yaml | 33 --------- data/hyp.scratch_03cls.yaml | 33 --------- data/hyp.scratch_03cls_07scale.yaml | 33 --------- data/hyp.scratch_03cls_09scale.yaml | 33 --------- data/hyp.scratch_05scale.yaml | 33 --------- data/hyp.scratch_07scale.yaml | 33 --------- data/hyp.scratch_08cls.yaml | 33 --------- data/hyp.scratch_09scale.yaml | 33 --------- data/hyp.scratch_10obj.yaml | 33 --------- data/hyp.scratch_15obj.yaml | 33 --------- data/hyp.scratch_20obj.yaml | 33 --------- data/hyp.scratch_34obj.yaml | 33 --------- .../{yolov5l-p2.yaml => hub/yolov5-p2.yaml} | 5 +- models/hub/yolov5-p6.yaml | 56 ++++++++++++++++ models/hub/yolov5-p7.yaml | 67 +++++++++++++++++++ 19 files changed, 124 insertions(+), 532 deletions(-) delete mode 100644 data/hyp.scratch_0001decay.yaml delete mode 100644 data/hyp.scratch_0002decay.yaml delete mode 100644 data/hyp.scratch_0003decay.yaml delete mode 100644 data/hyp.scratch_0007decay.yaml delete mode 100644 data/hyp.scratch_01cls.yaml delete mode 100644 data/hyp.scratch_03cls.yaml delete mode 100644 data/hyp.scratch_03cls_07scale.yaml delete mode 100644 data/hyp.scratch_03cls_09scale.yaml delete mode 100644 data/hyp.scratch_05scale.yaml delete mode 100644 data/hyp.scratch_07scale.yaml delete mode 100644 data/hyp.scratch_08cls.yaml delete mode 100644 data/hyp.scratch_09scale.yaml delete mode 100644 data/hyp.scratch_10obj.yaml delete mode 100644 data/hyp.scratch_15obj.yaml delete mode 100644 data/hyp.scratch_20obj.yaml delete mode 100644 data/hyp.scratch_34obj.yaml rename models/{yolov5l-p2.yaml => hub/yolov5-p2.yaml} (93%) create mode 100644 models/hub/yolov5-p6.yaml create mode 100644 models/hub/yolov5-p7.yaml diff --git a/data/hyp.scratch_0001decay.yaml b/data/hyp.scratch_0001decay.yaml deleted file mode 100644 index baf748b9e048..000000000000 --- a/data/hyp.scratch_0001decay.yaml +++ /dev/null @@ -1,33 +0,0 @@ -# Hyperparameters for COCO training from scratch -# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 -# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials - - -lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) -lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) -momentum: 0.937 # SGD momentum/Adam beta1 -weight_decay: 0.0001 # optimizer weight decay 5e-4 -warmup_epochs: 3.0 # warmup epochs (fractions ok) -warmup_momentum: 0.8 # warmup initial momentum -warmup_bias_lr: 0.1 # warmup initial bias lr -box: 0.05 # box loss gain -cls: 0.3 # cls loss gain -cls_pw: 1.0 # cls BCELoss positive_weight -obj: 0.5 # obj loss gain (scale with pixels) -obj_pw: 1.0 # obj BCELoss positive_weight -iou_t: 0.20 # IoU training threshold -anchor_t: 4.0 # anchor-multiple threshold -# anchors: 3 # anchors per output layer (0 to ignore) -fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) -hsv_h: 0.015 # image HSV-Hue augmentation (fraction) -hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) -hsv_v: 0.4 # image HSV-Value augmentation (fraction) -degrees: 0.0 # image rotation (+/- deg) -translate: 0.1 # image translation (+/- fraction) -scale: 0.9 # image scale (+/- gain) -shear: 0.0 # image shear (+/- deg) -perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 -flipud: 0.0 # image flip up-down (probability) -fliplr: 0.5 # image flip left-right (probability) -mosaic: 1.0 # image mosaic (probability) -mixup: 0.01 # image mixup (probability) diff --git a/data/hyp.scratch_0002decay.yaml b/data/hyp.scratch_0002decay.yaml deleted file mode 100644 index abb7a43651ad..000000000000 --- a/data/hyp.scratch_0002decay.yaml +++ /dev/null @@ -1,33 +0,0 @@ -# Hyperparameters for COCO training from scratch -# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 -# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials - - -lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) -lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) -momentum: 0.937 # SGD momentum/Adam beta1 -weight_decay: 0.0002 # optimizer weight decay 5e-4 -warmup_epochs: 3.0 # warmup epochs (fractions ok) -warmup_momentum: 0.8 # warmup initial momentum -warmup_bias_lr: 0.1 # warmup initial bias lr -box: 0.05 # box loss gain -cls: 0.3 # cls loss gain -cls_pw: 1.0 # cls BCELoss positive_weight -obj: 0.5 # obj loss gain (scale with pixels) -obj_pw: 1.0 # obj BCELoss positive_weight -iou_t: 0.20 # IoU training threshold -anchor_t: 4.0 # anchor-multiple threshold -# anchors: 3 # anchors per output layer (0 to ignore) -fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) -hsv_h: 0.015 # image HSV-Hue augmentation (fraction) -hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) -hsv_v: 0.4 # image HSV-Value augmentation (fraction) -degrees: 0.0 # image rotation (+/- deg) -translate: 0.1 # image translation (+/- fraction) -scale: 0.9 # image scale (+/- gain) -shear: 0.0 # image shear (+/- deg) -perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 -flipud: 0.0 # image flip up-down (probability) -fliplr: 0.5 # image flip left-right (probability) -mosaic: 1.0 # image mosaic (probability) -mixup: 0.01 # image mixup (probability) diff --git a/data/hyp.scratch_0003decay.yaml b/data/hyp.scratch_0003decay.yaml deleted file mode 100644 index 8079d8067d47..000000000000 --- a/data/hyp.scratch_0003decay.yaml +++ /dev/null @@ -1,33 +0,0 @@ -# Hyperparameters for COCO training from scratch -# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 -# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials - - -lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) -lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) -momentum: 0.937 # SGD momentum/Adam beta1 -weight_decay: 0.0003 # optimizer weight decay 5e-4 -warmup_epochs: 3.0 # warmup epochs (fractions ok) -warmup_momentum: 0.8 # warmup initial momentum -warmup_bias_lr: 0.1 # warmup initial bias lr -box: 0.05 # box loss gain -cls: 0.3 # cls loss gain -cls_pw: 1.0 # cls BCELoss positive_weight -obj: 0.5 # obj loss gain (scale with pixels) -obj_pw: 1.0 # obj BCELoss positive_weight -iou_t: 0.20 # IoU training threshold -anchor_t: 4.0 # anchor-multiple threshold -# anchors: 3 # anchors per output layer (0 to ignore) -fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) -hsv_h: 0.015 # image HSV-Hue augmentation (fraction) -hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) -hsv_v: 0.4 # image HSV-Value augmentation (fraction) -degrees: 0.0 # image rotation (+/- deg) -translate: 0.1 # image translation (+/- fraction) -scale: 0.9 # image scale (+/- gain) -shear: 0.0 # image shear (+/- deg) -perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 -flipud: 0.0 # image flip up-down (probability) -fliplr: 0.5 # image flip left-right (probability) -mosaic: 1.0 # image mosaic (probability) -mixup: 0.01 # image mixup (probability) diff --git a/data/hyp.scratch_0007decay.yaml b/data/hyp.scratch_0007decay.yaml deleted file mode 100644 index 86fd7784f1ba..000000000000 --- a/data/hyp.scratch_0007decay.yaml +++ /dev/null @@ -1,33 +0,0 @@ -# Hyperparameters for COCO training from scratch -# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 -# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials - - -lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) -lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) -momentum: 0.937 # SGD momentum/Adam beta1 -weight_decay: 0.0007 # optimizer weight decay 5e-4 -warmup_epochs: 3.0 # warmup epochs (fractions ok) -warmup_momentum: 0.8 # warmup initial momentum -warmup_bias_lr: 0.1 # warmup initial bias lr -box: 0.05 # box loss gain -cls: 0.3 # cls loss gain -cls_pw: 1.0 # cls BCELoss positive_weight -obj: 0.5 # obj loss gain (scale with pixels) -obj_pw: 1.0 # obj BCELoss positive_weight -iou_t: 0.20 # IoU training threshold -anchor_t: 4.0 # anchor-multiple threshold -# anchors: 3 # anchors per output layer (0 to ignore) -fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) -hsv_h: 0.015 # image HSV-Hue augmentation (fraction) -hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) -hsv_v: 0.4 # image HSV-Value augmentation (fraction) -degrees: 0.0 # image rotation (+/- deg) -translate: 0.1 # image translation (+/- fraction) -scale: 0.9 # image scale (+/- gain) -shear: 0.0 # image shear (+/- deg) -perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 -flipud: 0.0 # image flip up-down (probability) -fliplr: 0.5 # image flip left-right (probability) -mosaic: 1.0 # image mosaic (probability) -mixup: 0.01 # image mixup (probability) diff --git a/data/hyp.scratch_01cls.yaml b/data/hyp.scratch_01cls.yaml deleted file mode 100644 index ec1b39d8b857..000000000000 --- a/data/hyp.scratch_01cls.yaml +++ /dev/null @@ -1,33 +0,0 @@ -# Hyperparameters for COCO training from scratch -# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 -# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials - - -lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) -lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) -momentum: 0.937 # SGD momentum/Adam beta1 -weight_decay: 0.0005 # optimizer weight decay 5e-4 -warmup_epochs: 3.0 # warmup epochs (fractions ok) -warmup_momentum: 0.8 # warmup initial momentum -warmup_bias_lr: 0.1 # warmup initial bias lr -box: 0.05 # box loss gain -cls: 0.1 # cls loss gain -cls_pw: 1.0 # cls BCELoss positive_weight -obj: 0.5 # obj loss gain (scale with pixels) -obj_pw: 1.0 # obj BCELoss positive_weight -iou_t: 0.20 # IoU training threshold -anchor_t: 4.0 # anchor-multiple threshold -# anchors: 3 # anchors per output layer (0 to ignore) -fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) -hsv_h: 0.015 # image HSV-Hue augmentation (fraction) -hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) -hsv_v: 0.4 # image HSV-Value augmentation (fraction) -degrees: 0.0 # image rotation (+/- deg) -translate: 0.1 # image translation (+/- fraction) -scale: 0.5 # image scale (+/- gain) -shear: 0.0 # image shear (+/- deg) -perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 -flipud: 0.0 # image flip up-down (probability) -fliplr: 0.5 # image flip left-right (probability) -mosaic: 1.0 # image mosaic (probability) -mixup: 0.0 # image mixup (probability) diff --git a/data/hyp.scratch_03cls.yaml b/data/hyp.scratch_03cls.yaml deleted file mode 100644 index 8226046d19e8..000000000000 --- a/data/hyp.scratch_03cls.yaml +++ /dev/null @@ -1,33 +0,0 @@ -# Hyperparameters for COCO training from scratch -# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 -# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials - - -lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) -lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) -momentum: 0.937 # SGD momentum/Adam beta1 -weight_decay: 0.0005 # optimizer weight decay 5e-4 -warmup_epochs: 3.0 # warmup epochs (fractions ok) -warmup_momentum: 0.8 # warmup initial momentum -warmup_bias_lr: 0.1 # warmup initial bias lr -box: 0.05 # box loss gain -cls: 0.3 # cls loss gain -cls_pw: 1.0 # cls BCELoss positive_weight -obj: 0.5 # obj loss gain (scale with pixels) -obj_pw: 1.0 # obj BCELoss positive_weight -iou_t: 0.20 # IoU training threshold -anchor_t: 4.0 # anchor-multiple threshold -# anchors: 3 # anchors per output layer (0 to ignore) -fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) -hsv_h: 0.015 # image HSV-Hue augmentation (fraction) -hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) -hsv_v: 0.4 # image HSV-Value augmentation (fraction) -degrees: 0.0 # image rotation (+/- deg) -translate: 0.1 # image translation (+/- fraction) -scale: 0.5 # image scale (+/- gain) -shear: 0.0 # image shear (+/- deg) -perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 -flipud: 0.0 # image flip up-down (probability) -fliplr: 0.5 # image flip left-right (probability) -mosaic: 1.0 # image mosaic (probability) -mixup: 0.0 # image mixup (probability) diff --git a/data/hyp.scratch_03cls_07scale.yaml b/data/hyp.scratch_03cls_07scale.yaml deleted file mode 100644 index 90026ebaec8a..000000000000 --- a/data/hyp.scratch_03cls_07scale.yaml +++ /dev/null @@ -1,33 +0,0 @@ -# Hyperparameters for COCO training from scratch -# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 -# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials - - -lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) -lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) -momentum: 0.937 # SGD momentum/Adam beta1 -weight_decay: 0.0005 # optimizer weight decay 5e-4 -warmup_epochs: 3.0 # warmup epochs (fractions ok) -warmup_momentum: 0.8 # warmup initial momentum -warmup_bias_lr: 0.1 # warmup initial bias lr -box: 0.05 # box loss gain -cls: 0.3 # cls loss gain -cls_pw: 1.0 # cls BCELoss positive_weight -obj: 0.5 # obj loss gain (scale with pixels) -obj_pw: 1.0 # obj BCELoss positive_weight -iou_t: 0.20 # IoU training threshold -anchor_t: 4.0 # anchor-multiple threshold -# anchors: 3 # anchors per output layer (0 to ignore) -fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) -hsv_h: 0.015 # image HSV-Hue augmentation (fraction) -hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) -hsv_v: 0.4 # image HSV-Value augmentation (fraction) -degrees: 0.0 # image rotation (+/- deg) -translate: 0.1 # image translation (+/- fraction) -scale: 0.7 # image scale (+/- gain) -shear: 0.0 # image shear (+/- deg) -perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 -flipud: 0.0 # image flip up-down (probability) -fliplr: 0.5 # image flip left-right (probability) -mosaic: 1.0 # image mosaic (probability) -mixup: 0.0 # image mixup (probability) diff --git a/data/hyp.scratch_03cls_09scale.yaml b/data/hyp.scratch_03cls_09scale.yaml deleted file mode 100644 index 9078ac089247..000000000000 --- a/data/hyp.scratch_03cls_09scale.yaml +++ /dev/null @@ -1,33 +0,0 @@ -# Hyperparameters for COCO training from scratch -# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 -# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials - - -lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) -lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) -momentum: 0.937 # SGD momentum/Adam beta1 -weight_decay: 0.0005 # optimizer weight decay 5e-4 -warmup_epochs: 3.0 # warmup epochs (fractions ok) -warmup_momentum: 0.8 # warmup initial momentum -warmup_bias_lr: 0.1 # warmup initial bias lr -box: 0.05 # box loss gain -cls: 0.3 # cls loss gain -cls_pw: 1.0 # cls BCELoss positive_weight -obj: 0.5 # obj loss gain (scale with pixels) -obj_pw: 1.0 # obj BCELoss positive_weight -iou_t: 0.20 # IoU training threshold -anchor_t: 4.0 # anchor-multiple threshold -# anchors: 3 # anchors per output layer (0 to ignore) -fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) -hsv_h: 0.015 # image HSV-Hue augmentation (fraction) -hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) -hsv_v: 0.4 # image HSV-Value augmentation (fraction) -degrees: 0.0 # image rotation (+/- deg) -translate: 0.1 # image translation (+/- fraction) -scale: 0.9 # image scale (+/- gain) -shear: 0.0 # image shear (+/- deg) -perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 -flipud: 0.0 # image flip up-down (probability) -fliplr: 0.5 # image flip left-right (probability) -mosaic: 1.0 # image mosaic (probability) -mixup: 0.0 # image mixup (probability) diff --git a/data/hyp.scratch_05scale.yaml b/data/hyp.scratch_05scale.yaml deleted file mode 100644 index 059bd5c61cb5..000000000000 --- a/data/hyp.scratch_05scale.yaml +++ /dev/null @@ -1,33 +0,0 @@ -# Hyperparameters for COCO training from scratch -# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 -# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials - - -lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) -lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) -momentum: 0.937 # SGD momentum/Adam beta1 -weight_decay: 0.0005 # optimizer weight decay 5e-4 -warmup_epochs: 3.0 # warmup epochs (fractions ok) -warmup_momentum: 0.8 # warmup initial momentum -warmup_bias_lr: 0.1 # warmup initial bias lr -box: 0.05 # box loss gain -cls: 0.3 # cls loss gain -cls_pw: 1.0 # cls BCELoss positive_weight -obj: 0.5 # obj loss gain (scale with pixels) -obj_pw: 1.0 # obj BCELoss positive_weight -iou_t: 0.20 # IoU training threshold -anchor_t: 4.0 # anchor-multiple threshold -# anchors: 3 # anchors per output layer (0 to ignore) -fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) -hsv_h: 0.015 # image HSV-Hue augmentation (fraction) -hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) -hsv_v: 0.4 # image HSV-Value augmentation (fraction) -degrees: 0.0 # image rotation (+/- deg) -translate: 0.1 # image translation (+/- fraction) -scale: 0.5 # image scale (+/- gain) -shear: 0.0 # image shear (+/- deg) -perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 -flipud: 0.0 # image flip up-down (probability) -fliplr: 0.5 # image flip left-right (probability) -mosaic: 1.0 # image mosaic (probability) -mixup: 0.01 # image mixup (probability) diff --git a/data/hyp.scratch_07scale.yaml b/data/hyp.scratch_07scale.yaml deleted file mode 100644 index a2f285cdd6f5..000000000000 --- a/data/hyp.scratch_07scale.yaml +++ /dev/null @@ -1,33 +0,0 @@ -# Hyperparameters for COCO training from scratch -# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 -# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials - - -lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) -lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) -momentum: 0.937 # SGD momentum/Adam beta1 -weight_decay: 0.0005 # optimizer weight decay 5e-4 -warmup_epochs: 3.0 # warmup epochs (fractions ok) -warmup_momentum: 0.8 # warmup initial momentum -warmup_bias_lr: 0.1 # warmup initial bias lr -box: 0.05 # box loss gain -cls: 0.5 # cls loss gain -cls_pw: 1.0 # cls BCELoss positive_weight -obj: 0.5 # obj loss gain (scale with pixels) -obj_pw: 1.0 # obj BCELoss positive_weight -iou_t: 0.20 # IoU training threshold -anchor_t: 4.0 # anchor-multiple threshold -# anchors: 3 # anchors per output layer (0 to ignore) -fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) -hsv_h: 0.015 # image HSV-Hue augmentation (fraction) -hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) -hsv_v: 0.4 # image HSV-Value augmentation (fraction) -degrees: 0.0 # image rotation (+/- deg) -translate: 0.1 # image translation (+/- fraction) -scale: 0.7 # image scale (+/- gain) -shear: 0.0 # image shear (+/- deg) -perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 -flipud: 0.0 # image flip up-down (probability) -fliplr: 0.5 # image flip left-right (probability) -mosaic: 1.0 # image mosaic (probability) -mixup: 0.0 # image mixup (probability) diff --git a/data/hyp.scratch_08cls.yaml b/data/hyp.scratch_08cls.yaml deleted file mode 100644 index 091089b40d15..000000000000 --- a/data/hyp.scratch_08cls.yaml +++ /dev/null @@ -1,33 +0,0 @@ -# Hyperparameters for COCO training from scratch -# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 -# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials - - -lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) -lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) -momentum: 0.937 # SGD momentum/Adam beta1 -weight_decay: 0.0005 # optimizer weight decay 5e-4 -warmup_epochs: 3.0 # warmup epochs (fractions ok) -warmup_momentum: 0.8 # warmup initial momentum -warmup_bias_lr: 0.1 # warmup initial bias lr -box: 0.05 # box loss gain -cls: 0.8 # cls loss gain -cls_pw: 1.0 # cls BCELoss positive_weight -obj: 0.5 # obj loss gain (scale with pixels) -obj_pw: 1.0 # obj BCELoss positive_weight -iou_t: 0.20 # IoU training threshold -anchor_t: 4.0 # anchor-multiple threshold -# anchors: 3 # anchors per output layer (0 to ignore) -fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) -hsv_h: 0.015 # image HSV-Hue augmentation (fraction) -hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) -hsv_v: 0.4 # image HSV-Value augmentation (fraction) -degrees: 0.0 # image rotation (+/- deg) -translate: 0.1 # image translation (+/- fraction) -scale: 0.5 # image scale (+/- gain) -shear: 0.0 # image shear (+/- deg) -perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 -flipud: 0.0 # image flip up-down (probability) -fliplr: 0.5 # image flip left-right (probability) -mosaic: 1.0 # image mosaic (probability) -mixup: 0.0 # image mixup (probability) diff --git a/data/hyp.scratch_09scale.yaml b/data/hyp.scratch_09scale.yaml deleted file mode 100644 index 75e584586420..000000000000 --- a/data/hyp.scratch_09scale.yaml +++ /dev/null @@ -1,33 +0,0 @@ -# Hyperparameters for COCO training from scratch -# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 -# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials - - -lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) -lrf: 0.1 # final OneCycleLR learning rate (lr0 * lrf) -momentum: 0.937 # SGD momentum/Adam beta1 -weight_decay: 0.0005 # optimizer weight decay 5e-4 -warmup_epochs: 3.0 # warmup epochs (fractions ok) -warmup_momentum: 0.8 # warmup initial momentum -warmup_bias_lr: 0.1 # warmup initial bias lr -box: 0.05 # box loss gain -cls: 0.5 # cls loss gain -cls_pw: 1.0 # cls BCELoss positive_weight -obj: 0.5 # obj loss gain (scale with pixels) -obj_pw: 1.0 # obj BCELoss positive_weight -iou_t: 0.20 # IoU training threshold -anchor_t: 4.0 # anchor-multiple threshold -# anchors: 3 # anchors per output layer (0 to ignore) -fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) -hsv_h: 0.015 # image HSV-Hue augmentation (fraction) -hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) -hsv_v: 0.4 # image HSV-Value augmentation (fraction) -degrees: 0.0 # image rotation (+/- deg) -translate: 0.1 # image translation (+/- fraction) -scale: 0.9 # image scale (+/- gain) -shear: 0.0 # image shear (+/- deg) -perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 -flipud: 0.0 # image flip up-down (probability) -fliplr: 0.5 # image flip left-right (probability) -mosaic: 1.0 # image mosaic (probability) -mixup: 0.0 # image mixup (probability) diff --git a/data/hyp.scratch_10obj.yaml b/data/hyp.scratch_10obj.yaml deleted file mode 100644 index f5f81481ee2d..000000000000 --- a/data/hyp.scratch_10obj.yaml +++ /dev/null @@ -1,33 +0,0 @@ -# Hyperparameters for COCO training from scratch -# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 -# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials - - -lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) -lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) -momentum: 0.937 # SGD momentum/Adam beta1 -weight_decay: 0.0005 # optimizer weight decay 5e-4 -warmup_epochs: 3.0 # warmup epochs (fractions ok) -warmup_momentum: 0.8 # warmup initial momentum -warmup_bias_lr: 0.1 # warmup initial bias lr -box: 0.05 # box loss gain -cls: 0.3 # cls loss gain -cls_pw: 1.0 # cls BCELoss positive_weight -obj: 1.0 # obj loss gain (scale with pixels) -obj_pw: 1.0 # obj BCELoss positive_weight -iou_t: 0.20 # IoU training threshold -anchor_t: 4.0 # anchor-multiple threshold -# anchors: 3 # anchors per output layer (0 to ignore) -fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) -hsv_h: 0.015 # image HSV-Hue augmentation (fraction) -hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) -hsv_v: 0.4 # image HSV-Value augmentation (fraction) -degrees: 0.0 # image rotation (+/- deg) -translate: 0.1 # image translation (+/- fraction) -scale: 0.9 # image scale (+/- gain) -shear: 0.0 # image shear (+/- deg) -perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 -flipud: 0.0 # image flip up-down (probability) -fliplr: 0.5 # image flip left-right (probability) -mosaic: 1.0 # image mosaic (probability) -mixup: 0.01 # image mixup (probability) diff --git a/data/hyp.scratch_15obj.yaml b/data/hyp.scratch_15obj.yaml deleted file mode 100644 index 1ed26cd46cf7..000000000000 --- a/data/hyp.scratch_15obj.yaml +++ /dev/null @@ -1,33 +0,0 @@ -# Hyperparameters for COCO training from scratch -# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 -# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials - - -lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) -lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) -momentum: 0.937 # SGD momentum/Adam beta1 -weight_decay: 0.0005 # optimizer weight decay 5e-4 -warmup_epochs: 3.0 # warmup epochs (fractions ok) -warmup_momentum: 0.8 # warmup initial momentum -warmup_bias_lr: 0.1 # warmup initial bias lr -box: 0.05 # box loss gain -cls: 0.3 # cls loss gain -cls_pw: 1.0 # cls BCELoss positive_weight -obj: 1.5 # obj loss gain (scale with pixels) -obj_pw: 1.0 # obj BCELoss positive_weight -iou_t: 0.20 # IoU training threshold -anchor_t: 4.0 # anchor-multiple threshold -# anchors: 3 # anchors per output layer (0 to ignore) -fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) -hsv_h: 0.015 # image HSV-Hue augmentation (fraction) -hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) -hsv_v: 0.4 # image HSV-Value augmentation (fraction) -degrees: 0.0 # image rotation (+/- deg) -translate: 0.1 # image translation (+/- fraction) -scale: 0.9 # image scale (+/- gain) -shear: 0.0 # image shear (+/- deg) -perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 -flipud: 0.0 # image flip up-down (probability) -fliplr: 0.5 # image flip left-right (probability) -mosaic: 1.0 # image mosaic (probability) -mixup: 0.01 # image mixup (probability) diff --git a/data/hyp.scratch_20obj.yaml b/data/hyp.scratch_20obj.yaml deleted file mode 100644 index a317564bb6e0..000000000000 --- a/data/hyp.scratch_20obj.yaml +++ /dev/null @@ -1,33 +0,0 @@ -# Hyperparameters for COCO training from scratch -# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 -# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials - - -lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) -lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) -momentum: 0.937 # SGD momentum/Adam beta1 -weight_decay: 0.0005 # optimizer weight decay 5e-4 -warmup_epochs: 3.0 # warmup epochs (fractions ok) -warmup_momentum: 0.8 # warmup initial momentum -warmup_bias_lr: 0.1 # warmup initial bias lr -box: 0.05 # box loss gain -cls: 0.3 # cls loss gain -cls_pw: 1.0 # cls BCELoss positive_weight -obj: 2.0 # obj loss gain (scale with pixels) -obj_pw: 1.0 # obj BCELoss positive_weight -iou_t: 0.20 # IoU training threshold -anchor_t: 4.0 # anchor-multiple threshold -# anchors: 3 # anchors per output layer (0 to ignore) -fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) -hsv_h: 0.015 # image HSV-Hue augmentation (fraction) -hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) -hsv_v: 0.4 # image HSV-Value augmentation (fraction) -degrees: 0.0 # image rotation (+/- deg) -translate: 0.1 # image translation (+/- fraction) -scale: 0.9 # image scale (+/- gain) -shear: 0.0 # image shear (+/- deg) -perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 -flipud: 0.0 # image flip up-down (probability) -fliplr: 0.5 # image flip left-right (probability) -mosaic: 1.0 # image mosaic (probability) -mixup: 0.01 # image mixup (probability) diff --git a/data/hyp.scratch_34obj.yaml b/data/hyp.scratch_34obj.yaml deleted file mode 100644 index 8fa474d8f701..000000000000 --- a/data/hyp.scratch_34obj.yaml +++ /dev/null @@ -1,33 +0,0 @@ -# Hyperparameters for COCO training from scratch -# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 -# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials - - -lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) -lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) -momentum: 0.937 # SGD momentum/Adam beta1 -weight_decay: 0.0005 # optimizer weight decay 5e-4 -warmup_epochs: 3.0 # warmup epochs (fractions ok) -warmup_momentum: 0.8 # warmup initial momentum -warmup_bias_lr: 0.1 # warmup initial bias lr -box: 0.05 # box loss gain -cls: 0.3 # cls loss gain -cls_pw: 1.0 # cls BCELoss positive_weight -obj: 3.4 # obj loss gain (scale with pixels) -obj_pw: 1.0 # obj BCELoss positive_weight -iou_t: 0.20 # IoU training threshold -anchor_t: 4.0 # anchor-multiple threshold -# anchors: 3 # anchors per output layer (0 to ignore) -fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) -hsv_h: 0.015 # image HSV-Hue augmentation (fraction) -hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) -hsv_v: 0.4 # image HSV-Value augmentation (fraction) -degrees: 0.0 # image rotation (+/- deg) -translate: 0.1 # image translation (+/- fraction) -scale: 0.9 # image scale (+/- gain) -shear: 0.0 # image shear (+/- deg) -perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 -flipud: 0.0 # image flip up-down (probability) -fliplr: 0.5 # image flip left-right (probability) -mosaic: 1.0 # image mosaic (probability) -mixup: 0.01 # image mixup (probability) diff --git a/models/yolov5l-p2.yaml b/models/hub/yolov5-p2.yaml similarity index 93% rename from models/yolov5l-p2.yaml rename to models/hub/yolov5-p2.yaml index 1dd3cc1b3168..0633a90fd065 100644 --- a/models/yolov5l-p2.yaml +++ b/models/hub/yolov5-p2.yaml @@ -4,10 +4,7 @@ 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 +anchors: 3 # YOLOv5 backbone backbone: diff --git a/models/hub/yolov5-p6.yaml b/models/hub/yolov5-p6.yaml new file mode 100644 index 000000000000..3728a118f090 --- /dev/null +++ b/models/hub/yolov5-p6.yaml @@ -0,0 +1,56 @@ +# parameters +nc: 80 # number of classes +depth_multiple: 1.0 # model depth multiple +width_multiple: 1.0 # layer channel multiple + +# anchors +anchors: 3 + +# 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, [ 768, 3, 2 ] ], # 7-P5/32 + [ -1, 3, C3, [ 768 ] ], + [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 + [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ], + [ -1, 3, C3, [ 1024, False ] ], # 11 + ] + +# YOLOv5 head +head: + [ [ -1, 1, Conv, [ 768, 1, 1 ] ], + [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], + [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 + [ -1, 3, C3, [ 768, False ] ], # 15 + + [ -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 ] ], # 19 + + [ -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 ] ], # 23 (P3/8-small) + + [ -1, 1, Conv, [ 256, 3, 2 ] ], + [ [ -1, 20 ], 1, Concat, [ 1 ] ], # cat head P4 + [ -1, 3, C3, [ 512, False ] ], # 26 (P4/16-medium) + + [ -1, 1, Conv, [ 512, 3, 2 ] ], + [ [ -1, 16 ], 1, Concat, [ 1 ] ], # cat head P5 + [ -1, 3, C3, [ 768, False ] ], # 29 (P5/32-large) + + [ -1, 1, Conv, [ 768, 3, 2 ] ], + [ [ -1, 12 ], 1, Concat, [ 1 ] ], # cat head P6 + [ -1, 3, C3, [ 1024, False ] ], # 32 (P5/64-xlarge) + + [ [ 23, 26, 29, 32 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) + ] diff --git a/models/hub/yolov5-p7.yaml b/models/hub/yolov5-p7.yaml new file mode 100644 index 000000000000..ca8f8492ce0e --- /dev/null +++ b/models/hub/yolov5-p7.yaml @@ -0,0 +1,67 @@ +# parameters +nc: 80 # number of classes +depth_multiple: 1.0 # model depth multiple +width_multiple: 1.0 # layer channel multiple + +# anchors +anchors: 3 + +# 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, [ 768, 3, 2 ] ], # 7-P5/32 + [ -1, 3, C3, [ 768 ] ], + [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 + [ -1, 3, C3, [ 1024 ] ], + [ -1, 1, Conv, [ 1280, 3, 2 ] ], # 11-P7/128 + [ -1, 1, SPP, [ 1280, [ 3, 5 ] ] ], + [ -1, 3, C3, [ 1280, False ] ], # 13 + ] + +# YOLOv5 head +head: + [ [ -1, 1, Conv, [ 1024, 1, 1 ] ], + [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], + [ [ -1, 10 ], 1, Concat, [ 1 ] ], # cat backbone P6 + [ -1, 3, C3, [ 1024, False ] ], # 17 + + [ -1, 1, Conv, [ 768, 1, 1 ] ], + [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], + [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 + [ -1, 3, C3, [ 768, False ] ], # 21 + + [ -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 ] ], # 25 + + [ -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 ] ], # 29 (P3/8-small) + + [ -1, 1, Conv, [ 256, 3, 2 ] ], + [ [ -1, 26 ], 1, Concat, [ 1 ] ], # cat head P4 + [ -1, 3, C3, [ 512, False ] ], # 32 (P4/16-medium) + + [ -1, 1, Conv, [ 512, 3, 2 ] ], + [ [ -1, 22 ], 1, Concat, [ 1 ] ], # cat head P5 + [ -1, 3, C3, [ 768, False ] ], # 35 (P5/32-large) + + [ -1, 1, Conv, [ 768, 3, 2 ] ], + [ [ -1, 18 ], 1, Concat, [ 1 ] ], # cat head P6 + [ -1, 3, C3, [ 1024, False ] ], # 38 (P6/64-xlarge) + + [ -1, 1, Conv, [ 1024, 3, 2 ] ], + [ [ -1, 14 ], 1, Concat, [ 1 ] ], # cat head P7 + [ -1, 3, C3, [ 1280, False ] ], # 41 (P7/128-xxlarge) + + [ [ 29, 32, 35, 38, 41 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6, P7) + ] From 914cef659e623e3134eef3c463346aab7ad004f6 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 30 Dec 2020 15:11:39 -0800 Subject: [PATCH 072/176] update datasets --- data/coco.yaml | 29 ----------------------------- data/coco128.yaml | 18 +++++++++--------- data/voc.yaml | 4 ++-- 3 files changed, 11 insertions(+), 40 deletions(-) diff --git a/data/coco.yaml b/data/coco.yaml index abfd8feba123..b9da2bf5919b 100644 --- a/data/coco.yaml +++ b/data/coco.yaml @@ -33,32 +33,3 @@ names: [ 'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', ' # d = yaml.load(f, Loader=yaml.FullLoader) # dict # for i, x in enumerate(d['names']): # print(i, x) - - -# python -m torch.distributed.launch --nproc_per_node 2 train.py --batch-size 80 --data coco128.yaml --epochs 50 --weights yolov5s.pt -# python -m torch.distributed.launch --nproc_per_node 4 train.py --resume - - -# python train.py --data coco.yaml --batch 24 --weights '' --cfg yolov5l.yaml --epochs 300 --project ../paper --name yolov5lc3_03cls --hyp hyp.scratch_03cls.yaml --device 0 -# python train.py --data coco.yaml --batch 24 --weights '' --cfg yolov5l.yaml --epochs 300 --project ../paper --name yolov5lc3_08cls --hyp hyp.scratch_08cls.yaml --device 1 -# python train.py --data coco.yaml --batch 6 --img 1280 640 --epochs 75 --weights '' --cfg yolov5l.yaml --project ../paper --name yolov5l_1280 --hyp hyp.scratch_09scale.yaml --device 0 -# python train.py --data coco.yaml --batch 6 --img 1280 640 --epochs 75 --weights '' --cfg yolov5l-p6_33.yaml --project ../paper --name yolov5lp6_1280 --hyp hyp.scratch_09scale.yaml --device 1 - -# python train.py --data coco.yaml --batch 24 --weights '' --cfg yolov5l-p6_33.yaml --epochs 300 --project ../v4 --name yolov5l-p6_640 --hyp hyp.scratch.yaml --log-artifacts --device 0 -# python -m torch.distributed.launch --nproc_per_node 4 train.py --data coco.yaml --batch 24 --weights '' --cfg yolov5l-p6_33.yaml --epochs 300 --project ../v4 --name yolov5l-p6_1280 --hyp hyp.scratch_15obj.yaml --img 1280 --log-artifacts - -# python -m torch.distributed.launch --nproc_per_node 2 train.py --data coco.yaml --batch 28 --weights '' --cfg yolov5x-p6.yaml --epochs 300 --project ../v4 --name yolov5x-p6_640 --hyp hyp.scratch.yaml --img 640 --log-artifacts -# python -m torch.distributed.launch --nproc_per_node 8 train.py --data coco.yaml --batch 28 --weights '' --cfg yolov5x-p6.yaml --epochs 300 --project ../v4 --name yolov5x-p6_1280 --hyp hyp.scratch_15obj.yaml --img 1280 --log-artifacts - -# python train.py --data coco.yaml --batch 24 --weights '' --cfg yolov5l.yaml --epochs 300 --project ../paper --name yolov5lc3_03cls --hyp hyp.scratch_03cls.yaml --device 0 -# python train.py --data coco.yaml --batch 24 --weights '' --cfg yolov5l.yaml --epochs 300 --project ../paper --name yolov5lc3_08cls --hyp hyp.scratch_08cls.yaml --device 1 -# python train.py --data coco.yaml --batch 6 --img 1280 640 --epochs 75 --weights '' --cfg yolov5l.yaml --project ../paper --name yolov5l_1280 --hyp hyp.scratch_09scale.yaml --device 0 -# python train.py --data coco.yaml --batch 6 --img 1280 640 --epochs 75 --weights '' --cfg yolov5l-p6_33.yaml --project ../paper --name yolov5lp6_1280 --hyp hyp.scratch_09scale.yaml --device 1 - - -# python train.py --data coco.yaml --batch 24 --weights '' --cfg yolov5l.yaml --epochs 300 --project ../paper --name yolov5lc3_03cls --hyp hyp.scratch_03cls.yaml --device 0 -# python train.py --data coco.yaml --batch 24 --weights '' --cfg yolov5l.yaml --epochs 300 --project ../paper --name yolov5lc3_08cls --hyp hyp.scratch_08cls.yaml --device 1 -# python train.py --data coco.yaml --batch 6 --img 1280 640 --epochs 75 --weights '' --cfg yolov5l.yaml --project ../paper --name yolov5l_1280 --hyp hyp.scratch_09scale.yaml --device 0 - -# python train.py --data coco.yaml --batch 48 --weights '' --cfg yolov5m.yaml --epochs 300 --project ../v4 --name yolov5m --hyp hyp.scratch.yaml --device 0 -# python -m torch.distributed.launch --nproc_per_node 2 train.py --data coco.yaml --batch 16 --weights '' --cfg yolov5x.yaml --epochs 300 --project ../v4 --name yolov5x --hyp hyp.scratch.yaml \ No newline at end of file diff --git a/data/coco128.yaml b/data/coco128.yaml index 12e1d799718d..c41bccf2b8d5 100644 --- a/data/coco128.yaml +++ b/data/coco128.yaml @@ -17,12 +17,12 @@ val: ../coco128/images/train2017/ # 128 images nc: 80 # class names -names: ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light', - 'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow', - 'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', - 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard', - 'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', - 'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', - 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone', - 'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear', - 'hair drier', 'toothbrush'] +names: [ 'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light', + 'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow', + 'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', + 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard', + 'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', + 'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', + 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone', + 'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear', + 'hair drier', 'toothbrush' ] diff --git a/data/voc.yaml b/data/voc.yaml index b93f6a0e5717..851a9e0b060c 100644 --- a/data/voc.yaml +++ b/data/voc.yaml @@ -17,5 +17,5 @@ val: ../VOC/images/val/ # 4952 images nc: 20 # class names -names: ['aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 'dog', - 'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor'] +names: [ 'aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 'dog', + 'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor' ] From ef511898efee05a1e7709688dbca22a40426736f Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 30 Dec 2020 15:13:39 -0800 Subject: [PATCH 073/176] update --- models/common.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/models/common.py b/models/common.py index d876dd5d70db..a25707fdd387 100644 --- a/models/common.py +++ b/models/common.py @@ -105,20 +105,11 @@ class Focus(nn.Module): def __init__(self, c1, c2, k=1, s=1, p=None, g=1, act=True): # ch_in, ch_out, kernel, stride, padding, groups super(Focus, self).__init__() self.conv = Conv(c1 * 4, c2, k, s, p, g, act) + # self.contract = Contract(gain=2) def forward(self, x): # x(b,c,w,h) -> y(b,4c,w/2,h/2) return self.conv(torch.cat([x[..., ::2, ::2], x[..., 1::2, ::2], x[..., ::2, 1::2], x[..., 1::2, 1::2]], 1)) - - -# class Focus(nn.Module): -# # Focus wh information into c-space -# def __init__(self, c1, c2, k=1, s=1, p=None, g=1, act=True): # ch_in, ch_out, kernel, stride, padding, groups -# super(Focus, self).__init__() -# self.conv = Conv(c1 * 4, c2, k, s, p, g, act) -# self.contract = Contract(2) -# -# def forward(self, x): # x(b,c,w,h) -> y(b,4c,w/2,h/2) -# return self.conv(self.contract(x)) + # return self.conv(self.contract(x)) class Contract(nn.Module): From 5a29bc3b6acc6b50c43443f08359b9109fb3e239 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 30 Dec 2020 15:18:36 -0800 Subject: [PATCH 074/176] update --- train.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/train.py b/train.py index 9ce24c4f7b07..07fe1da101c9 100644 --- a/train.py +++ b/train.py @@ -220,7 +220,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): hyp['obj'] *= imgsz ** 2 / 640. ** 2 * 3. / nl # scale hyp['obj'] to image size and output layers model.nc = nc # attach number of classes to model model.hyp = hyp # attach hyperparameters to model - model.gr = opt.gr # iou loss ratio (obj_loss = 1.0 or iou) + model.gr = 1.0 # iou loss ratio (obj_loss = 1.0 or iou) model.class_weights = labels_to_class_weights(dataset.labels, nc).to(device) * nc # attach class weights model.names = names @@ -463,7 +463,6 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): parser.add_argument('--project', default='runs/train', help='save to project/name') parser.add_argument('--name', default='exp', help='save to project/name') parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment') - parser.add_argument('--gr', type=float, default=1.0, help='model.gr obj loss ratio') parser.add_argument('--quad', action='store_true', help='quad dataloader') opt = parser.parse_args() From ad671cc8ea01113094a858b7b9e7981995883c37 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 30 Dec 2020 16:00:44 -0800 Subject: [PATCH 075/176] update --- models/hub/anchors.yaml | 58 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 models/hub/anchors.yaml diff --git a/models/hub/anchors.yaml b/models/hub/anchors.yaml new file mode 100644 index 000000000000..a07a4dc72387 --- /dev/null +++ b/models/hub/anchors.yaml @@ -0,0 +1,58 @@ +# Default YOLOv5 anchors for COCO data + + +# P5 ------------------------------------------------------------------------------------------------------------------- +# P5-640: +anchors_p5_640: + - [ 10,13, 16,30, 33,23 ] # P3/8 + - [ 30,61, 62,45, 59,119 ] # P4/16 + - [ 116,90, 156,198, 373,326 ] # P5/32 + + +# P6 ------------------------------------------------------------------------------------------------------------------- +# P6-640: thr=0.25: 0.9964 BPR, 5.54 anchors past thr, n=12, img_size=640, metric_all=0.281/0.716-mean/best, past_thr=0.469-mean: 9,11, 21,19, 17,41, 43,32, 39,70, 86,64, 65,131, 134,130, 120,265, 282,180, 247,354, 512,387 +anchors_p6_640: + - [ 9,11, 21,19, 17,41 ] # P3/8 + - [ 43,32, 39,70, 86,64 ] # P4/16 + - [ 65,131, 134,130, 120,265 ] # P5/32 + - [ 282,180, 247,354, 512,387 ] # P6/64 + +# P6-1280: thr=0.25: 0.9950 BPR, 5.55 anchors past thr, n=12, img_size=1280, metric_all=0.281/0.714-mean/best, past_thr=0.468-mean: 19,27, 44,40, 38,94, 96,68, 86,152, 180,137, 140,301, 303,264, 238,542, 436,615, 739,380, 925,792 +anchors_p6_1280: + - [ 19,27, 44,40, 38,94 ] # P3/8 + - [ 96,68, 86,152, 180,137 ] # P4/16 + - [ 140,301, 303,264, 238,542 ] # P5/32 + - [ 436,615, 739,380, 925,792 ] # P6/64 + +# P6-1920: thr=0.25: 0.9950 BPR, 5.55 anchors past thr, n=12, img_size=1920, metric_all=0.281/0.714-mean/best, past_thr=0.468-mean: 28,41, 67,59, 57,141, 144,103, 129,227, 270,205, 209,452, 455,396, 358,812, 653,922, 1109,570, 1387,1187 +anchors_p6_1920: + - [ 28,41, 67,59, 57,141 ] # P3/8 + - [ 144,103, 129,227, 270,205 ] # P4/16 + - [ 209,452, 455,396, 358,812 ] # P5/32 + - [ 653,922, 1109,570, 1387,1187 ] # P6/64 + + +# P7 ------------------------------------------------------------------------------------------------------------------- +# P7-640: thr=0.25: 0.9962 BPR, 6.76 anchors past thr, n=15, img_size=640, metric_all=0.275/0.733-mean/best, past_thr=0.466-mean: 11,11, 13,30, 29,20, 30,46, 61,38, 39,92, 78,80, 146,66, 79,163, 149,150, 321,143, 157,303, 257,402, 359,290, 524,372 +anchors_p7_640: + - [ 11,11, 13,30, 29,20 ] # P3/8 + - [ 30,46, 61,38, 39,92 ] # P4/16 + - [ 78,80, 146,66, 79,163 ] # P5/32 + - [ 149,150, 321,143, 157,303 ] # P6/64 + - [ 257,402, 359,290, 524,372 ] # P7/128 + +# P7-1280: thr=0.25: 0.9968 BPR, 6.71 anchors past thr, n=15, img_size=1280, metric_all=0.273/0.732-mean/best, past_thr=0.463-mean: 19,22, 54,36, 32,77, 70,83, 138,71, 75,173, 165,159, 148,334, 375,151, 334,317, 251,626, 499,474, 750,326, 534,814, 1079,818 +anchors_p7_1280: + - [ 19,22, 54,36, 32,77 ] # P3/8 + - [ 70,83, 138,71, 75,173 ] # P4/16 + - [ 165,159, 148,334, 375,151 ] # P5/32 + - [ 334,317, 251,626, 499,474 ] # P6/64 + - [ 750,326, 534,814, 1079,818 ] # P7/128 + +# P7-1920: thr=0.25: 0.9968 BPR, 6.71 anchors past thr, n=15, img_size=1920, metric_all=0.273/0.732-mean/best, past_thr=0.463-mean: 29,34, 81,55, 47,115, 105,124, 207,107, 113,259, 247,238, 222,500, 563,227, 501,476, 376,939, 749,711, 1126,489, 801,1222, 1618,1227 +anchors_p7_1920: + - [ 29,34, 81,55, 47,115 ] # P3/8 + - [ 105,124, 207,107, 113,259 ] # P4/16 + - [ 247,238, 222,500, 563,227 ] # P5/32 + - [ 501,476, 376,939, 749,711 ] # P6/64 + - [ 1126,489, 801,1222, 1618,1227 ] # P7/128 From 66b85538f8ff454eb8eeee6293ea1a5cd8166742 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 30 Dec 2020 16:14:59 -0800 Subject: [PATCH 076/176] update attempt_downlaod() --- utils/google_utils.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/utils/google_utils.py b/utils/google_utils.py index 2220e28cd761..a747249f27f1 100644 --- a/utils/google_utils.py +++ b/utils/google_utils.py @@ -22,13 +22,13 @@ def attempt_download(weights): file = Path(weights).name.lower() msg = weights + ' missing, try downloading from https://github.com/ultralytics/yolov5/releases/' - models = ['yolov5s.pt', 'yolov5m.pt', 'yolov5l.pt', 'yolov5x.pt', 'yolov5s4.pt', 'yolov5m4.pt', 'yolov5l4.pt', - 'yolov5x4.pt'] # available models - redundant = False # offer second download option + response = requests.get('https://api.github.com/repos/ultralytics/yolov5/releases/latest').json() # github api + assets = [x['name'] for x in response['assets']] # release assets + redundant = False # second download option - if file in models and not os.path.isfile(weights): + if file in assets and not os.path.isfile(weights): try: # GitHub - tag = requests.get('https://api.github.com/repos/ultralytics/yolov5/releases/latest').json()['tag_name'] + tag = response['tag_name'] # 'v1.0' url = f'https://github.com/ultralytics/yolov5/releases/download/{tag}/{file}' print('Downloading %s to %s...' % (url, weights)) torch.hub.download_url_to_file(url, weights) From ac010e10cb7be9f811219906acf18e2cb1460fa4 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 30 Dec 2020 16:20:02 -0800 Subject: [PATCH 077/176] merge --- models/yolo.py | 1 + 1 file changed, 1 insertion(+) diff --git a/models/yolo.py b/models/yolo.py index f3f3c0f86160..eb21fe135492 100644 --- a/models/yolo.py +++ b/models/yolo.py @@ -74,6 +74,7 @@ def __init__(self, cfg='yolov5s.yaml', ch=3, nc=None): # model, input channels, self.yaml = yaml.load(f, Loader=yaml.FullLoader) # model dict # Define model + ch = self.yaml['ch'] = self.yaml.get('ch', ch) # input channels if nc and nc != self.yaml['nc']: logger.info('Overriding model.yaml nc=%g with nc=%g' % (self.yaml['nc'], nc)) self.yaml['nc'] = nc # override yaml value From f316064dc15418f8ec850700c8892c9c7b75d0df Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 30 Dec 2020 16:21:18 -0800 Subject: [PATCH 078/176] merge --- models/yolo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/yolo.py b/models/yolo.py index eb21fe135492..0d0aba9f9927 100644 --- a/models/yolo.py +++ b/models/yolo.py @@ -78,7 +78,7 @@ def __init__(self, cfg='yolov5s.yaml', ch=3, nc=None): # model, input channels, if nc and nc != self.yaml['nc']: logger.info('Overriding model.yaml nc=%g with nc=%g' % (self.yaml['nc'], nc)) self.yaml['nc'] = nc # override yaml value - self.model, self.save = parse_model(deepcopy(self.yaml), ch=[ch]) # model, savelist, ch_out + self.model, self.save = parse_model(deepcopy(self.yaml), ch=[ch]) # model, savelist self.names = [str(i) for i in range(self.yaml['nc'])] # default names # print([x.shape for x in self.forward(torch.zeros(1, ch, 64, 64))]) From 75a5bc004ab7f23ae4baec4b2d99911629238620 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 31 Dec 2020 09:13:02 -0800 Subject: [PATCH 079/176] update --- models/yolov5l-p6-1920.yaml | 60 ++++++++++++++++++++++++++++++ models/yolov5l-p7-1920.yaml | 73 +++++++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 models/yolov5l-p6-1920.yaml create mode 100644 models/yolov5l-p7-1920.yaml diff --git a/models/yolov5l-p6-1920.yaml b/models/yolov5l-p6-1920.yaml new file mode 100644 index 000000000000..6350ef9b17b5 --- /dev/null +++ b/models/yolov5l-p6-1920.yaml @@ -0,0 +1,60 @@ +# parameters +nc: 80 # number of classes +depth_multiple: 1.0 # model depth multiple +width_multiple: 1.0 # layer channel multiple + +# anchors +anchors: + - [ 28,41, 67,59, 57,141 ] # P3/8 + - [ 144,103, 129,227, 270,205 ] # P4/16 + - [ 209,452, 455,396, 358,812 ] # P5/32 + - [ 653,922, 1109,570, 1387,1187 ] # P6/64 + +# 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, [ 768, 3, 2 ] ], # 7-P5/32 + [ -1, 3, C3, [ 768 ] ], + [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 + [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ], + [ -1, 3, C3, [ 1024, False ] ], # 11 + ] + +# YOLOv5 head +head: + [ [ -1, 1, Conv, [ 768, 1, 1 ] ], + [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], + [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 + [ -1, 3, C3, [ 768, False ] ], # 15 + + [ -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 ] ], # 19 + + [ -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 ] ], # 23 (P3/8-small) + + [ -1, 1, Conv, [ 256, 3, 2 ] ], + [ [ -1, 20 ], 1, Concat, [ 1 ] ], # cat head P4 + [ -1, 3, C3, [ 512, False ] ], # 26 (P4/16-medium) + + [ -1, 1, Conv, [ 512, 3, 2 ] ], + [ [ -1, 16 ], 1, Concat, [ 1 ] ], # cat head P5 + [ -1, 3, C3, [ 768, False ] ], # 29 (P5/32-large) + + [ -1, 1, Conv, [ 768, 3, 2 ] ], + [ [ -1, 12 ], 1, Concat, [ 1 ] ], # cat head P6 + [ -1, 3, C3, [ 1024, False ] ], # 32 (P5/64-xlarge) + + [ [ 23, 26, 29, 32 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) + ] diff --git a/models/yolov5l-p7-1920.yaml b/models/yolov5l-p7-1920.yaml new file mode 100644 index 000000000000..479c91b42bcb --- /dev/null +++ b/models/yolov5l-p7-1920.yaml @@ -0,0 +1,73 @@ +# parameters +nc: 80 # number of classes +depth_multiple: 1.0 # model depth multiple +width_multiple: 1.0 # layer channel multiple + +# anchors +anchors: + - [ 29,34, 81,55, 47,115 ] # P3/8 + - [ 105,124, 207,107, 113,259 ] # P4/16 + - [ 247,238, 222,500, 563,227 ] # P5/32 + - [ 501,476, 376,939, 749,711 ] # P6/64 + - [ 1126,489, 801,1222, 1618,1227 ] # P7/128 + + +# 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, 3, C3, [ 256 ] ], + [ -1, 1, Conv, [ 512, 3, 2 ] ], # 5-P4/16 + [ -1, 6, C3, [ 512 ] ], + [ -1, 1, Conv, [ 768, 3, 2 ] ], # 7-P5/32 + [ -1, 9, C3, [ 768 ] ], + [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 + [ -1, 6, C3, [ 1024 ] ], + [ -1, 1, Conv, [ 1280, 3, 2 ] ], # 11-P7/128 + [ -1, 1, SPP, [ 1280, [ 3, 5 ] ] ], + [ -1, 3, C3, [ 1280, False ] ], # 13 + ] + +# YOLOv5 head +head: + [ [ -1, 1, Conv, [ 1024, 1, 1 ] ], + [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], + [ [ -1, 10 ], 1, Concat, [ 1 ] ], # cat backbone P6 + [ -1, 3, C3, [ 1024, False ] ], # 17 + + [ -1, 1, Conv, [ 768, 1, 1 ] ], + [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], + [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 + [ -1, 3, C3, [ 768, False ] ], # 21 + + [ -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 ] ], # 25 + + [ -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 ] ], # 29 (P3/8-small) + + [ -1, 1, Conv, [ 256, 3, 2 ] ], + [ [ -1, 26 ], 1, Concat, [ 1 ] ], # cat head P4 + [ -1, 3, C3, [ 512, False ] ], # 32 (P4/16-medium) + + [ -1, 1, Conv, [ 512, 3, 2 ] ], + [ [ -1, 22 ], 1, Concat, [ 1 ] ], # cat head P5 + [ -1, 3, C3, [ 768, False ] ], # 35 (P5/32-large) + + [ -1, 1, Conv, [ 768, 3, 2 ] ], + [ [ -1, 18 ], 1, Concat, [ 1 ] ], # cat head P6 + [ -1, 3, C3, [ 1024, False ] ], # 38 (P6/64-xlarge) + + [ -1, 1, Conv, [ 1024, 3, 2 ] ], + [ [ -1, 14 ], 1, Concat, [ 1 ] ], # cat head P7 + [ -1, 3, C3, [ 1280, False ] ], # 41 (P7/128-xxlarge) + + [ [ 29, 32, 35, 38, 41 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) + ] From f29df1ef8339aad3abd6ca79e5c59932b97f9abb Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 31 Dec 2020 10:12:23 -0800 Subject: [PATCH 080/176] update --- models/yolov5x-p6-1920.yaml | 60 +++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 models/yolov5x-p6-1920.yaml diff --git a/models/yolov5x-p6-1920.yaml b/models/yolov5x-p6-1920.yaml new file mode 100644 index 000000000000..a9b39c24b565 --- /dev/null +++ b/models/yolov5x-p6-1920.yaml @@ -0,0 +1,60 @@ +# parameters +nc: 80 # number of classes +depth_multiple: 1.33 # model depth multiple +width_multiple: 1.25 # layer channel multiple + +# anchors +anchors: + - [ 28,41, 67,59, 57,141 ] # P3/8 + - [ 144,103, 129,227, 270,205 ] # P4/16 + - [ 209,452, 455,396, 358,812 ] # P5/32 + - [ 653,922, 1109,570, 1387,1187 ] # P6/64 + - + # 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, [ 768, 3, 2 ] ], # 7-P5/32 + [ -1, 3, C3, [ 768 ] ], + [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 + [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ], + [ -1, 3, C3, [ 1024, False ] ], # 11 + ] + +# YOLOv5 head +head: + [ [ -1, 1, Conv, [ 768, 1, 1 ] ], + [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], + [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 + [ -1, 3, C3, [ 768, False ] ], # 15 + + [ -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 ] ], # 19 + + [ -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 ] ], # 23 (P3/8-small) + + [ -1, 1, Conv, [ 256, 3, 2 ] ], + [ [ -1, 20 ], 1, Concat, [ 1 ] ], # cat head P4 + [ -1, 3, C3, [ 512, False ] ], # 26 (P4/16-medium) + + [ -1, 1, Conv, [ 512, 3, 2 ] ], + [ [ -1, 16 ], 1, Concat, [ 1 ] ], # cat head P5 + [ -1, 3, C3, [ 768, False ] ], # 29 (P5/32-large) + + [ -1, 1, Conv, [ 768, 3, 2 ] ], + [ [ -1, 12 ], 1, Concat, [ 1 ] ], # cat head P6 + [ -1, 3, C3, [ 1024, False ] ], # 32 (P5/64-xlarge) + + [ [ 23, 26, 29, 32 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) + ] From 815134710c1ff4f90652b5761a0c993834f12931 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 31 Dec 2020 10:13:47 -0800 Subject: [PATCH 081/176] update --- models/yolov5x-p6-1920.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/models/yolov5x-p6-1920.yaml b/models/yolov5x-p6-1920.yaml index a9b39c24b565..af7d9599c050 100644 --- a/models/yolov5x-p6-1920.yaml +++ b/models/yolov5x-p6-1920.yaml @@ -9,7 +9,8 @@ anchors: - [ 144,103, 129,227, 270,205 ] # P4/16 - [ 209,452, 455,396, 358,812 ] # P5/32 - [ 653,922, 1109,570, 1387,1187 ] # P6/64 - - + + # YOLOv5 backbone backbone: # [from, number, module, args] From ddf749c3cd39843ee5b4babb37659c7d384ad360 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 31 Dec 2020 10:15:54 -0800 Subject: [PATCH 082/176] update --- models/yolov5x-p7-1920.yaml | 73 +++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 models/yolov5x-p7-1920.yaml diff --git a/models/yolov5x-p7-1920.yaml b/models/yolov5x-p7-1920.yaml new file mode 100644 index 000000000000..84e04d694f57 --- /dev/null +++ b/models/yolov5x-p7-1920.yaml @@ -0,0 +1,73 @@ +# parameters +nc: 80 # number of classes +depth_multiple: 1.33 # model depth multiple +width_multiple: 1.25 # layer channel multiple + +# anchors +anchors: + - [ 29,34, 81,55, 47,115 ] # P3/8 + - [ 105,124, 207,107, 113,259 ] # P4/16 + - [ 247,238, 222,500, 563,227 ] # P5/32 + - [ 501,476, 376,939, 749,711 ] # P6/64 + - [ 1126,489, 801,1222, 1618,1227 ] # P7/128 + + +# 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, 3, C3, [ 256 ] ], + [ -1, 1, Conv, [ 512, 3, 2 ] ], # 5-P4/16 + [ -1, 6, C3, [ 512 ] ], + [ -1, 1, Conv, [ 768, 3, 2 ] ], # 7-P5/32 + [ -1, 9, C3, [ 768 ] ], + [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 + [ -1, 6, C3, [ 1024 ] ], + [ -1, 1, Conv, [ 1280, 3, 2 ] ], # 11-P7/128 + [ -1, 1, SPP, [ 1280, [ 3, 5 ] ] ], + [ -1, 3, C3, [ 1280, False ] ], # 13 + ] + +# YOLOv5 head +head: + [ [ -1, 1, Conv, [ 1024, 1, 1 ] ], + [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], + [ [ -1, 10 ], 1, Concat, [ 1 ] ], # cat backbone P6 + [ -1, 3, C3, [ 1024, False ] ], # 17 + + [ -1, 1, Conv, [ 768, 1, 1 ] ], + [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], + [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 + [ -1, 3, C3, [ 768, False ] ], # 21 + + [ -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 ] ], # 25 + + [ -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 ] ], # 29 (P3/8-small) + + [ -1, 1, Conv, [ 256, 3, 2 ] ], + [ [ -1, 26 ], 1, Concat, [ 1 ] ], # cat head P4 + [ -1, 3, C3, [ 512, False ] ], # 32 (P4/16-medium) + + [ -1, 1, Conv, [ 512, 3, 2 ] ], + [ [ -1, 22 ], 1, Concat, [ 1 ] ], # cat head P5 + [ -1, 3, C3, [ 768, False ] ], # 35 (P5/32-large) + + [ -1, 1, Conv, [ 768, 3, 2 ] ], + [ [ -1, 18 ], 1, Concat, [ 1 ] ], # cat head P6 + [ -1, 3, C3, [ 1024, False ] ], # 38 (P6/64-xlarge) + + [ -1, 1, Conv, [ 1024, 3, 2 ] ], + [ [ -1, 14 ], 1, Concat, [ 1 ] ], # cat head P7 + [ -1, 3, C3, [ 1280, False ] ], # 41 (P7/128-xxlarge) + + [ [ 29, 32, 35, 38, 41 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) + ] From cc680042a53cc9267c5f12eee9213874c3df01e3 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 31 Dec 2020 10:25:23 -0800 Subject: [PATCH 083/176] update --- models/yolov5x-p7-1280.yaml | 73 +++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 models/yolov5x-p7-1280.yaml diff --git a/models/yolov5x-p7-1280.yaml b/models/yolov5x-p7-1280.yaml new file mode 100644 index 000000000000..b269f86a81b2 --- /dev/null +++ b/models/yolov5x-p7-1280.yaml @@ -0,0 +1,73 @@ +# parameters +nc: 80 # number of classes +depth_multiple: 1.33 # model depth multiple +width_multiple: 1.25 # layer channel multiple + +# anchors +anchors: + - [ 19,22, 54,36, 32,77 ] # P3/8 + - [ 70,83, 138,71, 75,173 ] # P4/16 + - [ 165,159, 148,334, 375,151 ] # P5/32 + - [ 334,317, 251,626, 499,474 ] # P6/64 + - [ 750,326, 534,814, 1079,818 ] # P7/128 + + +# 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, 3, C3, [ 256 ] ], + [ -1, 1, Conv, [ 512, 3, 2 ] ], # 5-P4/16 + [ -1, 6, C3, [ 512 ] ], + [ -1, 1, Conv, [ 768, 3, 2 ] ], # 7-P5/32 + [ -1, 9, C3, [ 768 ] ], + [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 + [ -1, 6, C3, [ 1024 ] ], + [ -1, 1, Conv, [ 1280, 3, 2 ] ], # 11-P7/128 + [ -1, 1, SPP, [ 1280, [ 3, 5 ] ] ], + [ -1, 3, C3, [ 1280, False ] ], # 13 + ] + +# YOLOv5 head +head: + [ [ -1, 1, Conv, [ 1024, 1, 1 ] ], + [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], + [ [ -1, 10 ], 1, Concat, [ 1 ] ], # cat backbone P6 + [ -1, 3, C3, [ 1024, False ] ], # 17 + + [ -1, 1, Conv, [ 768, 1, 1 ] ], + [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], + [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 + [ -1, 3, C3, [ 768, False ] ], # 21 + + [ -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 ] ], # 25 + + [ -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 ] ], # 29 (P3/8-small) + + [ -1, 1, Conv, [ 256, 3, 2 ] ], + [ [ -1, 26 ], 1, Concat, [ 1 ] ], # cat head P4 + [ -1, 3, C3, [ 512, False ] ], # 32 (P4/16-medium) + + [ -1, 1, Conv, [ 512, 3, 2 ] ], + [ [ -1, 22 ], 1, Concat, [ 1 ] ], # cat head P5 + [ -1, 3, C3, [ 768, False ] ], # 35 (P5/32-large) + + [ -1, 1, Conv, [ 768, 3, 2 ] ], + [ [ -1, 18 ], 1, Concat, [ 1 ] ], # cat head P6 + [ -1, 3, C3, [ 1024, False ] ], # 38 (P6/64-xlarge) + + [ -1, 1, Conv, [ 1024, 3, 2 ] ], + [ [ -1, 14 ], 1, Concat, [ 1 ] ], # cat head P7 + [ -1, 3, C3, [ 1280, False ] ], # 41 (P7/128-xxlarge) + + [ [ 29, 32, 35, 38, 41 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) + ] From fee9d79513afc1b97a81006035aec14c27e55d5d Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 31 Dec 2020 13:15:13 -0800 Subject: [PATCH 084/176] update --- models/{yolov5l-p6-1280.yaml => yolov5l6-1280.yaml} | 2 -- models/{yolov5l-p6-1920.yaml => yolov5l6-1920.yaml} | 0 models/{yolov5l-p6-640.yaml => yolov5l6-640.yaml} | 1 - models/{yolov5l-p7-1280.yaml => yolov5l7-1280.yaml} | 1 - models/{yolov5l-p7-1920.yaml => yolov5l7-1920.yaml} | 1 - models/{yolov5l-p7.yaml => yolov5l7-640.yaml} | 7 ++++++- models/{yolov5x-p6-1280.yaml => yolov5x6-1280.yaml} | 2 -- models/{yolov5x-p6-1920.yaml => yolov5x6-1920.yaml} | 3 +-- models/{yolov5x-p6.yaml => yolov5x6-640.yaml} | 6 +++++- models/{yolov5x-p7-1280.yaml => yolov5x7-1280.yaml} | 1 - models/{yolov5x-p7-1920.yaml => yolov5x7-1920.yaml} | 1 - 11 files changed, 12 insertions(+), 13 deletions(-) rename models/{yolov5l-p6-1280.yaml => yolov5l6-1280.yaml} (83%) rename models/{yolov5l-p6-1920.yaml => yolov5l6-1920.yaml} (100%) rename models/{yolov5l-p6-640.yaml => yolov5l6-640.yaml} (99%) rename models/{yolov5l-p7-1280.yaml => yolov5l7-1280.yaml} (99%) rename models/{yolov5l-p7-1920.yaml => yolov5l7-1920.yaml} (99%) rename models/{yolov5l-p7.yaml => yolov5l7-640.yaml} (91%) rename models/{yolov5x-p6-1280.yaml => yolov5x6-1280.yaml} (83%) rename models/{yolov5x-p6-1920.yaml => yolov5x6-1920.yaml} (98%) rename models/{yolov5x-p6.yaml => yolov5x6-640.yaml} (91%) rename models/{yolov5x-p7-1280.yaml => yolov5x7-1280.yaml} (99%) rename models/{yolov5x-p7-1920.yaml => yolov5x7-1920.yaml} (99%) diff --git a/models/yolov5l-p6-1280.yaml b/models/yolov5l6-1280.yaml similarity index 83% rename from models/yolov5l-p6-1280.yaml rename to models/yolov5l6-1280.yaml index 49811e796947..e0699d413c9f 100644 --- a/models/yolov5l-p6-1280.yaml +++ b/models/yolov5l6-1280.yaml @@ -9,8 +9,6 @@ anchors: - [ 96,68, 86,152, 180,137 ] # P4/16 - [ 140,301, 303,264, 238,542 ] # P5/32 - [ 436,615, 739,380, 925,792 ] # P6/64 -# normal n=12, img_size=1280, metric_all=0.281/0.714-mean/best, past_thr=0.468-mean: 19,27, 44,40, 38,94, 96,68, 86,152, 180,137, 140,301, 303,264, 238,542, 436,615, 739,380, 925,792 -# scale 0.9 n=12, img_size=1280, metric_all=0.267/0.705-mean/best, past_thr=0.467-mean: 6,9, 17,15, 16,36, 35,30, 33,61, 73,51, 60,118, 140,104, 126,225, 273,207, 262,398, 595,454 # YOLOv5 backbone backbone: diff --git a/models/yolov5l-p6-1920.yaml b/models/yolov5l6-1920.yaml similarity index 100% rename from models/yolov5l-p6-1920.yaml rename to models/yolov5l6-1920.yaml diff --git a/models/yolov5l-p6-640.yaml b/models/yolov5l6-640.yaml similarity index 99% rename from models/yolov5l-p6-640.yaml rename to models/yolov5l6-640.yaml index 95661f66c8fd..1db7f3caec58 100644 --- a/models/yolov5l-p6-640.yaml +++ b/models/yolov5l6-640.yaml @@ -10,7 +10,6 @@ anchors: - [ 65,131, 134,130, 120,265 ] # P5/32 - [ 282,180, 247,354, 512,387 ] # P6/64 - # YOLOv5 backbone backbone: # [from, number, module, args] diff --git a/models/yolov5l-p7-1280.yaml b/models/yolov5l7-1280.yaml similarity index 99% rename from models/yolov5l-p7-1280.yaml rename to models/yolov5l7-1280.yaml index 517bc22a52b1..6ca0f693d572 100644 --- a/models/yolov5l-p7-1280.yaml +++ b/models/yolov5l7-1280.yaml @@ -11,7 +11,6 @@ anchors: - [ 334,317, 251,626, 499,474 ] # P6/64 - [ 750,326, 534,814, 1079,818 ] # P7/128 - # YOLOv5 backbone backbone: # [from, number, module, args] diff --git a/models/yolov5l-p7-1920.yaml b/models/yolov5l7-1920.yaml similarity index 99% rename from models/yolov5l-p7-1920.yaml rename to models/yolov5l7-1920.yaml index 479c91b42bcb..6225f1073143 100644 --- a/models/yolov5l-p7-1920.yaml +++ b/models/yolov5l7-1920.yaml @@ -11,7 +11,6 @@ anchors: - [ 501,476, 376,939, 749,711 ] # P6/64 - [ 1126,489, 801,1222, 1618,1227 ] # P7/128 - # YOLOv5 backbone backbone: # [from, number, module, args] diff --git a/models/yolov5l-p7.yaml b/models/yolov5l7-640.yaml similarity index 91% rename from models/yolov5l-p7.yaml rename to models/yolov5l7-640.yaml index 676a5e7ca8b6..19982c367ef1 100644 --- a/models/yolov5l-p7.yaml +++ b/models/yolov5l7-640.yaml @@ -4,7 +4,12 @@ depth_multiple: 1.0 # model depth multiple width_multiple: 1.0 # layer channel multiple # anchors -anchors: 3 +anchors: + - [ 11,11, 13,30, 29,20 ] # P3/8 + - [ 30,46, 61,38, 39,92 ] # P4/16 + - [ 78,80, 146,66, 79,163 ] # P5/32 + - [ 149,150, 321,143, 157,303 ] # P6/64 + - [ 257,402, 359,290, 524,372 ] # P7/128 # YOLOv5 backbone backbone: diff --git a/models/yolov5x-p6-1280.yaml b/models/yolov5x6-1280.yaml similarity index 83% rename from models/yolov5x-p6-1280.yaml rename to models/yolov5x6-1280.yaml index 6ba00577dbde..eda764406e93 100644 --- a/models/yolov5x-p6-1280.yaml +++ b/models/yolov5x6-1280.yaml @@ -9,8 +9,6 @@ anchors: - [ 96,68, 86,152, 180,137 ] # P4/16 - [ 140,301, 303,264, 238,542 ] # P5/32 - [ 436,615, 739,380, 925,792 ] # P6/64 -# normal n=12, img_size=1280, metric_all=0.281/0.714-mean/best, past_thr=0.468-mean: 19,27, 44,40, 38,94, 96,68, 86,152, 180,137, 140,301, 303,264, 238,542, 436,615, 739,380, 925,792 -# scale 0.9 n=12, img_size=1280, metric_all=0.267/0.705-mean/best, past_thr=0.467-mean: 6,9, 17,15, 16,36, 35,30, 33,61, 73,51, 60,118, 140,104, 126,225, 273,207, 262,398, 595,454 # YOLOv5 backbone backbone: diff --git a/models/yolov5x-p6-1920.yaml b/models/yolov5x6-1920.yaml similarity index 98% rename from models/yolov5x-p6-1920.yaml rename to models/yolov5x6-1920.yaml index af7d9599c050..cbc12312d533 100644 --- a/models/yolov5x-p6-1920.yaml +++ b/models/yolov5x6-1920.yaml @@ -10,8 +10,7 @@ anchors: - [ 209,452, 455,396, 358,812 ] # P5/32 - [ 653,922, 1109,570, 1387,1187 ] # P6/64 - - # YOLOv5 backbone +# YOLOv5 backbone backbone: # [from, number, module, args] [ [ -1, 1, Focus, [ 64, 3 ] ], # 0-P1/2 diff --git a/models/yolov5x-p6.yaml b/models/yolov5x6-640.yaml similarity index 91% rename from models/yolov5x-p6.yaml rename to models/yolov5x6-640.yaml index eb4586bfbea9..be0bc4bdcd3a 100644 --- a/models/yolov5x-p6.yaml +++ b/models/yolov5x6-640.yaml @@ -4,7 +4,11 @@ depth_multiple: 1.33 # model depth multiple width_multiple: 1.25 # layer channel multiple # anchors -anchors: 3 +anchors: + - [ 9,11, 21,19, 17,41 ] # P3/8 + - [ 43,32, 39,70, 86,64 ] # P4/16 + - [ 65,131, 134,130, 120,265 ] # P5/32 + - [ 282,180, 247,354, 512,387 ] # P6/64 # YOLOv5 backbone backbone: diff --git a/models/yolov5x-p7-1280.yaml b/models/yolov5x7-1280.yaml similarity index 99% rename from models/yolov5x-p7-1280.yaml rename to models/yolov5x7-1280.yaml index b269f86a81b2..e3e7cc3e4fa9 100644 --- a/models/yolov5x-p7-1280.yaml +++ b/models/yolov5x7-1280.yaml @@ -11,7 +11,6 @@ anchors: - [ 334,317, 251,626, 499,474 ] # P6/64 - [ 750,326, 534,814, 1079,818 ] # P7/128 - # YOLOv5 backbone backbone: # [from, number, module, args] diff --git a/models/yolov5x-p7-1920.yaml b/models/yolov5x7-1920.yaml similarity index 99% rename from models/yolov5x-p7-1920.yaml rename to models/yolov5x7-1920.yaml index 84e04d694f57..dafefb09039b 100644 --- a/models/yolov5x-p7-1920.yaml +++ b/models/yolov5x7-1920.yaml @@ -11,7 +11,6 @@ anchors: - [ 501,476, 376,939, 749,711 ] # P6/64 - [ 1126,489, 801,1222, 1618,1227 ] # P7/128 - # YOLOv5 backbone backbone: # [from, number, module, args] From 7609b2388b52a6c1487a57c4a02171785eb7fa75 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 31 Dec 2020 13:15:30 -0800 Subject: [PATCH 085/176] update --- models/yolov5x7-640.yaml | 72 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 models/yolov5x7-640.yaml diff --git a/models/yolov5x7-640.yaml b/models/yolov5x7-640.yaml new file mode 100644 index 000000000000..dedc15dab704 --- /dev/null +++ b/models/yolov5x7-640.yaml @@ -0,0 +1,72 @@ +# parameters +nc: 80 # number of classes +depth_multiple: 1.33 # model depth multiple +width_multiple: 1.25 # layer channel multiple + +# anchors +anchors: + - [ 11,11, 13,30, 29,20 ] # P3/8 + - [ 30,46, 61,38, 39,92 ] # P4/16 + - [ 78,80, 146,66, 79,163 ] # P5/32 + - [ 149,150, 321,143, 157,303 ] # P6/64 + - [ 257,402, 359,290, 524,372 ] # P7/128 + +# 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, 3, C3, [ 256 ] ], + [ -1, 1, Conv, [ 512, 3, 2 ] ], # 5-P4/16 + [ -1, 6, C3, [ 512 ] ], + [ -1, 1, Conv, [ 768, 3, 2 ] ], # 7-P5/32 + [ -1, 9, C3, [ 768 ] ], + [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 + [ -1, 6, C3, [ 1024 ] ], + [ -1, 1, Conv, [ 1280, 3, 2 ] ], # 11-P7/128 + [ -1, 1, SPP, [ 1280, [ 3, 5 ] ] ], + [ -1, 3, C3, [ 1280, False ] ], # 13 + ] + +# YOLOv5 head +head: + [ [ -1, 1, Conv, [ 1024, 1, 1 ] ], + [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], + [ [ -1, 10 ], 1, Concat, [ 1 ] ], # cat backbone P6 + [ -1, 3, C3, [ 1024, False ] ], # 17 + + [ -1, 1, Conv, [ 768, 1, 1 ] ], + [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], + [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 + [ -1, 3, C3, [ 768, False ] ], # 21 + + [ -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 ] ], # 25 + + [ -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 ] ], # 29 (P3/8-small) + + [ -1, 1, Conv, [ 256, 3, 2 ] ], + [ [ -1, 26 ], 1, Concat, [ 1 ] ], # cat head P4 + [ -1, 3, C3, [ 512, False ] ], # 32 (P4/16-medium) + + [ -1, 1, Conv, [ 512, 3, 2 ] ], + [ [ -1, 22 ], 1, Concat, [ 1 ] ], # cat head P5 + [ -1, 3, C3, [ 768, False ] ], # 35 (P5/32-large) + + [ -1, 1, Conv, [ 768, 3, 2 ] ], + [ [ -1, 18 ], 1, Concat, [ 1 ] ], # cat head P6 + [ -1, 3, C3, [ 1024, False ] ], # 38 (P6/64-xlarge) + + [ -1, 1, Conv, [ 1024, 3, 2 ] ], + [ [ -1, 14 ], 1, Concat, [ 1 ] ], # cat head P7 + [ -1, 3, C3, [ 1280, False ] ], # 41 (P7/128-xxlarge) + + [ [ 29, 32, 35, 38, 41 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) + ] From a487d5fcbc6c3527b74ece7eef683daf86b403a9 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 31 Dec 2020 13:16:48 -0800 Subject: [PATCH 086/176] update --- models/{ => hub/experimental}/yolov5l6-1280.yaml | 0 models/{ => hub/experimental}/yolov5l6-1920.yaml | 0 models/{ => hub/experimental}/yolov5l6-640.yaml | 0 models/{ => hub/experimental}/yolov5l7-1280.yaml | 0 models/{ => hub/experimental}/yolov5l7-1920.yaml | 0 models/{ => hub/experimental}/yolov5l7-640.yaml | 0 models/{ => hub/experimental}/yolov5x6-1280.yaml | 0 models/{ => hub/experimental}/yolov5x6-1920.yaml | 0 models/{ => hub/experimental}/yolov5x6-640.yaml | 0 models/{ => hub/experimental}/yolov5x7-1280.yaml | 0 models/{ => hub/experimental}/yolov5x7-1920.yaml | 0 models/{ => hub/experimental}/yolov5x7-640.yaml | 0 12 files changed, 0 insertions(+), 0 deletions(-) rename models/{ => hub/experimental}/yolov5l6-1280.yaml (100%) rename models/{ => hub/experimental}/yolov5l6-1920.yaml (100%) rename models/{ => hub/experimental}/yolov5l6-640.yaml (100%) rename models/{ => hub/experimental}/yolov5l7-1280.yaml (100%) rename models/{ => hub/experimental}/yolov5l7-1920.yaml (100%) rename models/{ => hub/experimental}/yolov5l7-640.yaml (100%) rename models/{ => hub/experimental}/yolov5x6-1280.yaml (100%) rename models/{ => hub/experimental}/yolov5x6-1920.yaml (100%) rename models/{ => hub/experimental}/yolov5x6-640.yaml (100%) rename models/{ => hub/experimental}/yolov5x7-1280.yaml (100%) rename models/{ => hub/experimental}/yolov5x7-1920.yaml (100%) rename models/{ => hub/experimental}/yolov5x7-640.yaml (100%) diff --git a/models/yolov5l6-1280.yaml b/models/hub/experimental/yolov5l6-1280.yaml similarity index 100% rename from models/yolov5l6-1280.yaml rename to models/hub/experimental/yolov5l6-1280.yaml diff --git a/models/yolov5l6-1920.yaml b/models/hub/experimental/yolov5l6-1920.yaml similarity index 100% rename from models/yolov5l6-1920.yaml rename to models/hub/experimental/yolov5l6-1920.yaml diff --git a/models/yolov5l6-640.yaml b/models/hub/experimental/yolov5l6-640.yaml similarity index 100% rename from models/yolov5l6-640.yaml rename to models/hub/experimental/yolov5l6-640.yaml diff --git a/models/yolov5l7-1280.yaml b/models/hub/experimental/yolov5l7-1280.yaml similarity index 100% rename from models/yolov5l7-1280.yaml rename to models/hub/experimental/yolov5l7-1280.yaml diff --git a/models/yolov5l7-1920.yaml b/models/hub/experimental/yolov5l7-1920.yaml similarity index 100% rename from models/yolov5l7-1920.yaml rename to models/hub/experimental/yolov5l7-1920.yaml diff --git a/models/yolov5l7-640.yaml b/models/hub/experimental/yolov5l7-640.yaml similarity index 100% rename from models/yolov5l7-640.yaml rename to models/hub/experimental/yolov5l7-640.yaml diff --git a/models/yolov5x6-1280.yaml b/models/hub/experimental/yolov5x6-1280.yaml similarity index 100% rename from models/yolov5x6-1280.yaml rename to models/hub/experimental/yolov5x6-1280.yaml diff --git a/models/yolov5x6-1920.yaml b/models/hub/experimental/yolov5x6-1920.yaml similarity index 100% rename from models/yolov5x6-1920.yaml rename to models/hub/experimental/yolov5x6-1920.yaml diff --git a/models/yolov5x6-640.yaml b/models/hub/experimental/yolov5x6-640.yaml similarity index 100% rename from models/yolov5x6-640.yaml rename to models/hub/experimental/yolov5x6-640.yaml diff --git a/models/yolov5x7-1280.yaml b/models/hub/experimental/yolov5x7-1280.yaml similarity index 100% rename from models/yolov5x7-1280.yaml rename to models/hub/experimental/yolov5x7-1280.yaml diff --git a/models/yolov5x7-1920.yaml b/models/hub/experimental/yolov5x7-1920.yaml similarity index 100% rename from models/yolov5x7-1920.yaml rename to models/hub/experimental/yolov5x7-1920.yaml diff --git a/models/yolov5x7-640.yaml b/models/hub/experimental/yolov5x7-640.yaml similarity index 100% rename from models/yolov5x7-640.yaml rename to models/hub/experimental/yolov5x7-640.yaml From 8807a5619c9fa5f78fba3a902352a39c924bbf08 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 31 Dec 2020 13:59:31 -0800 Subject: [PATCH 087/176] update --- README.md | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index f3d1ba3445e6..31bbc9eb6d9e 100755 --- a/README.md +++ b/README.md @@ -18,14 +18,18 @@ This repository represents Ultralytics open-source research into future object d ## Pretrained Checkpoints -| Model | APval | APtest | AP50 | SpeedGPU | FPSGPU || params | GFLOPS | -|---------- |------ |------ |------ | -------- | ------| ------ |------ | :------: | -| [YOLOv5s](https://github.com/ultralytics/yolov5/releases) | 37.0 | 37.0 | 56.2 | **2.4ms** | **416** || 7.5M | 17.5 -| [YOLOv5m](https://github.com/ultralytics/yolov5/releases) | 44.3 | 44.3 | 63.2 | 3.4ms | 294 || 21.8M | 52.3 -| [YOLOv5l](https://github.com/ultralytics/yolov5/releases) | 47.7 | 47.7 | 66.5 | 4.4ms | 227 || 47.8M | 117.2 -| [YOLOv5x](https://github.com/ultralytics/yolov5/releases) | **49.2** | **49.2** | **67.7** | 6.9ms | 145 || 89.0M | 221.5 -| | | | | | || | -| [YOLOv5x](https://github.com/ultralytics/yolov5/releases) + TTA|**50.8**| **50.8** | **68.9** | 25.5ms | 39 || 89.0M | 801.0 +| Model | size | APval | APtest | AP50 | SpeedV100 | FPSV100 || params | GFLOPS | +|---------- |------ |------ |------ |------ | -------- | ------| ------ |------ | :------: | +| [YOLOv5s](https://github.com/ultralytics/yolov5/releases) |640 |36.8 |36.8 |55.6 |**2.2ms** |**455** ||7.3M |17.0 +| [YOLOv5m](https://github.com/ultralytics/yolov5/releases) |640 |44.5 |44.5 |63.1 |2.9ms |345 ||21.4M |51.3 +| [YOLOv5l](https://github.com/ultralytics/yolov5/releases) |640 |48.1 |48.1 |66.4 |3.8ms |264 ||47.0M |115.4 +| [YOLOv5x](https://github.com/ultralytics/yolov5/releases) |640 |**50.1** |**50.1** |**68.7** |6.0ms |167 ||87.7M |218.8 +| | | | | | | || | +| [YOLOv5x](https://github.com/ultralytics/yolov5/releases) + TTA |832 |**51.9** |**51.9** |**69.6** |24.9ms |40 ||87.7M |1005.3 + + ** APtest denotes COCO [test-dev2017](http://cocodataset.org/#upload) server results, all other AP results denote val2017 accuracy. ** All AP numbers are for single-model single-scale without ensemble or TTA. **Reproduce mAP** by `python test.py --data coco.yaml --img 640 --conf 0.001 --iou 0.65` From d9605746a804b9f71d5d938d3b7d0d58754e62e8 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 31 Dec 2020 15:38:28 -0800 Subject: [PATCH 088/176] update --- test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.py b/test.py index b7b34038a069..ce8c593d0384 100644 --- a/test.py +++ b/test.py @@ -320,7 +320,7 @@ def test(data, ) elif opt.task == 'study': # run over a range of settings and save/plot - for weights in ['yolov5s4.pt', 'yolov5m4.pt', 'yolov5l4.pt', 'yolov5x4.pt']: + for weights in ['yolov5x4.pt']: f = 'study_%s_%s.txt' % (Path(opt.data).stem, Path(weights).stem) # filename to save to x = list(range(320, 800, 64)) # x axis y = [] # y axis From 884149b4ff0d122b1536411a637e0440900d1473 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Fri, 1 Jan 2021 13:07:42 -0800 Subject: [PATCH 089/176] parameterize eps --- utils/datasets.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/datasets.py b/utils/datasets.py index 593e317b32c4..ec9b57a3541b 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -912,12 +912,12 @@ def random_perspective(img, targets=(), degrees=10, translate=.1, scale=.1, shea return img, targets -def box_candidates(box1, box2, wh_thr=2, ar_thr=20, area_thr=0.1): # box1(4,n), box2(4,n) +def box_candidates(box1, box2, wh_thr=2, ar_thr=20, area_thr=0.1, eps=1e-16): # box1(4,n), box2(4,n) # Compute candidate boxes: box1 before augment, box2 after augment, wh_thr (pixels), aspect_ratio_thr, area_ratio w1, h1 = box1[2] - box1[0], box1[3] - box1[1] w2, h2 = box2[2] - box2[0], box2[3] - box2[1] - ar = np.maximum(w2 / (h2 + 1e-16), h2 / (w2 + 1e-16)) # aspect ratio - return (w2 > wh_thr) & (h2 > wh_thr) & (w2 * h2 / (w1 * h1 + 1e-16) > area_thr) & (ar < ar_thr) # candidates + ar = np.maximum(w2 / (h2 + eps), h2 / (w2 + eps)) # aspect ratio + return (w2 > wh_thr) & (h2 > wh_thr) & (w2 * h2 / (w1 * h1 + eps) > area_thr) & (ar < ar_thr) # candidates def cutout(image, labels): From a19e111dddc06122506ea42450482e7f089a1005 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Fri, 1 Jan 2021 21:46:14 -0800 Subject: [PATCH 090/176] comments --- utils/google_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/google_utils.py b/utils/google_utils.py index a747249f27f1..242270c1b033 100644 --- a/utils/google_utils.py +++ b/utils/google_utils.py @@ -23,12 +23,12 @@ def attempt_download(weights): msg = weights + ' missing, try downloading from https://github.com/ultralytics/yolov5/releases/' response = requests.get('https://api.github.com/repos/ultralytics/yolov5/releases/latest').json() # github api - assets = [x['name'] for x in response['assets']] # release assets + assets = [x['name'] for x in response['assets']] # release assets, i.e. ['yolov5s.pt', 'yolov5m.pt', ...] redundant = False # second download option if file in assets and not os.path.isfile(weights): try: # GitHub - tag = response['tag_name'] # 'v1.0' + tag = response['tag_name'] # i.e. 'v1.0' url = f'https://github.com/ultralytics/yolov5/releases/download/{tag}/{file}' print('Downloading %s to %s...' % (url, weights)) torch.hub.download_url_to_file(url, weights) From 5fee648cc42737aa18797692011982e1cdd65828 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Fri, 1 Jan 2021 22:16:28 -0800 Subject: [PATCH 091/176] gs-multiple --- README.md | 12 ++++++------ models/yolo.py | 2 +- train.py | 2 +- utils/torch_utils.py | 5 ++--- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 31bbc9eb6d9e..a0522c7d87be 100755 --- a/README.md +++ b/README.md @@ -4,16 +4,15 @@ ![CI CPU testing](https://github.com/ultralytics/yolov5/workflows/CI%20CPU%20testing/badge.svg) -This repository represents Ultralytics open-source research into future object detection methods, and incorporates our lessons learned and best practices evolved over training thousands of models on custom client datasets with our previous YOLO repository https://github.com/ultralytics/yolov3. **All code and models are under active development, and are subject to modification or deletion without notice.** Use at your own risk. +This repository represents Ultralytics open-source research into future object detection methods, and incorporates anonymized lessons learned and best practices evolved over thousands of hours of training and evolution on custom client datasets. **All code and models are under active development, and are subject to modification or deletion without notice.** Use at your own risk. ** GPU Speed measures end-to-end time per image averaged over 5000 COCO val2017 images using a V100 GPU with batch size 32, and includes image preprocessing, PyTorch FP16 inference, postprocessing and NMS. EfficientDet data from [google/automl](https://github.com/google/automl) at batch size 8. +- **January 2, 2021**: [v4.0 release](https://github.com/ultralytics/yolov5/releases/tag/v4.0): nn.SiLU() activations, [Weights & Biases](https://wandb.ai/) logging, [PyTorch Hub](https://pytorch.org/hub/ultralytics_yolov5/) integration. - **August 13, 2020**: [v3.0 release](https://github.com/ultralytics/yolov5/releases/tag/v3.0): nn.Hardswish() activations, data autodownload, native AMP. - **July 23, 2020**: [v2.0 release](https://github.com/ultralytics/yolov5/releases/tag/v2.0): improved model definition, training and mAP. - **June 22, 2020**: [PANet](https://arxiv.org/abs/1803.01534) updates: new heads, reduced parameters, improved speed and mAP [364fcfd](https://github.com/ultralytics/yolov5/commit/364fcfd7dba53f46edd4f04c037a039c0a287972). - **June 19, 2020**: [FP16](https://pytorch.org/docs/stable/nn.html#torch.nn.Module.half) as new default for smaller checkpoints and faster inference [d4c6674](https://github.com/ultralytics/yolov5/commit/d4c6674c98e19df4c40e33a777610a18d1961145). -- **June 9, 2020**: [CSP](https://github.com/WongKinYiu/CrossStagePartialNetworks) updates: improved speed, size, and accuracy (credit to @WongKinYiu for CSP). -- **May 27, 2020**: Public release. YOLOv5 models are SOTA among all known YOLO implementations. ## Pretrained Checkpoints @@ -37,6 +36,7 @@ This repository represents Ultralytics open-source research into future object d ** All checkpoints are trained to 300 epochs with default settings and hyperparameters (no autoaugmentation). ** Test Time Augmentation ([TTA](https://github.com/ultralytics/yolov5/issues/303)) runs at 3 image sizes. **Reproduce TTA** by `python test.py --data coco.yaml --img 832 --iou 0.65 --augment` + ## Requirements Python 3.8 or later with all [requirements.txt](https://github.com/ultralytics/yolov5/blob/master/requirements.txt) dependencies installed, including `torch>=1.7`. To install run: @@ -110,7 +110,7 @@ import torch from PIL import Image # Model -model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True) # for PIL/cv2/np inputs and NMS +model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True) # Images img1 = Image.open('zidane.jpg') @@ -118,13 +118,13 @@ img2 = Image.open('bus.jpg') imgs = [img1, img2] # batched list of images # Inference -prediction = model(imgs, size=640) # includes NMS +result = model(imgs) ``` ## Training -Download [COCO](https://github.com/ultralytics/yolov5/blob/master/data/scripts/get_coco.sh) and run command below. Training times for YOLOv5s/m/l/x are 2/4/6/8 days on a single V100 (multi-GPU times faster). Use the largest `--batch-size` your GPU allows (batch sizes shown for 16 GB devices). +Run commands below to reproduce results on [COCO](https://github.com/ultralytics/yolov5/blob/master/data/scripts/get_coco.sh) dataset (dataset auto-downloads on first use). Training times for YOLOv5s/m/l/x are 2/4/6/8 days on a single V100 (multi-GPU times faster). Use the largest `--batch-size` your GPU allows (batch sizes shown for 16 GB devices). ```bash $ python train.py --data coco.yaml --cfg yolov5s.yaml --weights '' --batch-size 64 yolov5m 40 diff --git a/models/yolo.py b/models/yolo.py index 0d0aba9f9927..3001eb042a9d 100644 --- a/models/yolo.py +++ b/models/yolo.py @@ -105,7 +105,7 @@ def forward(self, x, augment=False, profile=False): f = [None, 3, None, 3] # flips (2-ud, 3-lr) y = [] # outputs for si, fi in zip(s, f): - xi = scale_img(x.flip(fi) if fi else x, si) + xi = scale_img(x.flip(fi) if fi else x, si, gs=int(self.stride.max())) yi = self.forward_once(xi)[0] # forward # cv2.imwrite('img%g.jpg' % s, 255 * xi[0].numpy().transpose((1, 2, 0))[:, :, ::-1]) # save yi[..., :4] /= si # de-scale diff --git a/train.py b/train.py index 07fe1da101c9..99a28476dc27 100644 --- a/train.py +++ b/train.py @@ -165,7 +165,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): del ckpt, state_dict # Image sizes - gs = int(max(model.stride)) # grid size (max stride) + gs = int(model.stride.max()) # grid size (max stride) nl = model.model[-1].nl # number of detection layers (used for scaling hyp['obj']) imgsz, imgsz_test = [check_img_size(x, gs) for x in opt.img_size] # verify imgsz are gs-multiples diff --git a/utils/torch_utils.py b/utils/torch_utils.py index 4aea9ba10fb5..d2fd9a4f1db1 100644 --- a/utils/torch_utils.py +++ b/utils/torch_utils.py @@ -226,8 +226,8 @@ def load_classifier(name='resnet101', n=2): return model -def scale_img(img, ratio=1.0, same_shape=False): # img(16,3,256,416), r=ratio - # scales img(bs,3,y,x) by ratio +def scale_img(img, ratio=1.0, same_shape=False, gs=32): # img(16,3,256,416) + # scales img(bs,3,y,x) by ratio constrained to gs-multiple if ratio == 1.0: return img else: @@ -235,7 +235,6 @@ def scale_img(img, ratio=1.0, same_shape=False): # img(16,3,256,416), r=ratio s = (int(h * ratio), int(w * ratio)) # new size img = F.interpolate(img, size=s, mode='bilinear', align_corners=False) # resize if not same_shape: # pad/crop img - gs = 32 # (pixels) grid size h, w = [math.ceil(x * ratio / gs) * gs for x in (h, w)] return F.pad(img, [0, w - s[1], 0, h - s[0]], value=0.447) # value = imagenet mean From bc9ab3ab54bdfc78d3b61f3d99f502805a108d58 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 2 Jan 2021 12:18:32 -0800 Subject: [PATCH 092/176] update --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a0522c7d87be..de360d0d7aad 100755 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ This repository represents Ultralytics open-source research into future object d ** APtest denotes COCO [test-dev2017](http://cocodataset.org/#upload) server results, all other AP results denote val2017 accuracy. From e3b4eb7b6aa4b1d7ab72659f8499ad3cb6381d38 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 2 Jan 2021 15:56:39 -0800 Subject: [PATCH 093/176] max_nms implemented --- utils/general.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/utils/general.py b/utils/general.py index 12249059c8fc..378fb1687fed 100755 --- a/utils/general.py +++ b/utils/general.py @@ -276,6 +276,7 @@ def non_max_suppression(prediction, conf_thres=0.25, iou_thres=0.45, classes=Non # Settings min_wh, max_wh = 2, 4096 # (pixels) minimum and maximum box width and height max_det = 300 # maximum number of detections per image + max_nms = 30000 # maximum number of boxes into torchvision.ops.nms() time_limit = 10.0 # seconds to quit after redundant = True # require redundant detections multi_label = nc > 1 # multiple labels per box (adds 0.5ms/img) @@ -323,13 +324,12 @@ def non_max_suppression(prediction, conf_thres=0.25, iou_thres=0.45, classes=Non # if not torch.isfinite(x).all(): # x = x[torch.isfinite(x).all(1)] - # If none remain process next image + # Check shape n = x.shape[0] # number of boxes - if not n: + if not n: # no boxes continue - - # Sort by confidence - # x = x[x[:, 4].argsort(descending=True)] + elif n > max_nms: # excess boxes + x = x[x[:, 4].argsort(descending=True)[:max_nms]] # sort by confidence # Batched NMS c = x[:, 5:6] * (0 if agnostic else max_wh) # classes @@ -347,6 +347,7 @@ def non_max_suppression(prediction, conf_thres=0.25, iou_thres=0.45, classes=Non output[xi] = x[i] if (time.time() - t) > time_limit: + print(f'WARNING: NMS time limit {time_limit}s exceeded') break # time limit exceeded return output From 8e9127d6b5bac5f2b1d0e6ed9435650949f35f8b Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 4 Jan 2021 15:44:54 -0800 Subject: [PATCH 094/176] Create one_cycle() function --- train.py | 6 +++--- utils/general.py | 5 +++++ utils/plots.py | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/train.py b/train.py index 14d7ac8fc027..d0f3bdcc1ab1 100644 --- a/train.py +++ b/train.py @@ -28,7 +28,7 @@ from utils.datasets import create_dataloader from utils.general import labels_to_class_weights, increment_path, labels_to_image_weights, init_seeds, \ fitness, strip_optimizer, get_latest_run, check_dataset, check_file, check_git_status, check_img_size, \ - print_mutation, set_logging + print_mutation, set_logging, one_cycle from utils.google_utils import attempt_download from utils.loss import compute_loss from utils.plots import plot_images, plot_labels, plot_results, plot_evolution @@ -126,12 +126,12 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): # Scheduler https://arxiv.org/pdf/1812.01187.pdf # https://pytorch.org/docs/stable/_modules/torch/optim/lr_scheduler.html#OneCycleLR - lf = lambda x: ((1 + math.cos(x * math.pi / epochs)) / 2) * (1 - hyp['lrf']) + hyp['lrf'] # cosine + lf = one_cycle(1, hyp['lrf'], epochs) # cosine 1->hyp['lrf'] scheduler = lr_scheduler.LambdaLR(optimizer, lr_lambda=lf) # plot_lr_scheduler(optimizer, scheduler, epochs) # Logging - if wandb and wandb.run is None: + if rank in [-1, 0] and wandb and wandb.run is None: opt.hyp = hyp # add hyperparameters wandb_run = wandb.init(config=opt, resume="allow", project='YOLOv5' if opt.project == 'runs/train' else Path(opt.project).stem, diff --git a/utils/general.py b/utils/general.py index 12249059c8fc..fceefb0a4a97 100755 --- a/utils/general.py +++ b/utils/general.py @@ -102,6 +102,11 @@ def clean_str(s): return re.sub(pattern="[|@#!¡·$€%&()=?¿^*;:,¨´><+]", repl="_", string=s) +def one_cycle(y1=0.0, y2=1.0, steps=100): + # lambda function for sinusoidal ramp from y1 to y2 + return lambda x: ((1 - math.cos(x * math.pi / steps)) / 2) * (y2 - y1) + y1 + + def labels_to_class_weights(labels, nc=80): # Get class weights (inverse frequency) from training labels if labels[0] is None: # no labels loaded diff --git a/utils/plots.py b/utils/plots.py index 3a4dccdc34c5..6b4e30147b77 100644 --- a/utils/plots.py +++ b/utils/plots.py @@ -190,6 +190,7 @@ def plot_lr_scheduler(optimizer, scheduler, epochs=300, save_dir=''): plt.xlim(0, epochs) plt.ylim(0) plt.savefig(Path(save_dir) / 'LR.png', dpi=200) + plt.close() def plot_test_txt(): # from utils.plots import *; plot_test() From 18671c8ba991db078565f7e9d2649bde54c2a810 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 4 Jan 2021 16:17:05 -0800 Subject: [PATCH 095/176] update --- detect.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/detect.py b/detect.py index 45dbdb7fa9ba..802b99fd761d 100644 --- a/detect.py +++ b/detect.py @@ -117,8 +117,6 @@ def detect(save_img=False): # Stream results if view_img: cv2.imshow(str(p), im0) - if cv2.waitKey(1) == ord('q'): # q to quit - raise StopIteration # Save results (image with detections) if save_img: From 693d4e71f80a3868cec560ffd3ed770f4f517feb Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 4 Jan 2021 16:22:22 -0800 Subject: [PATCH 096/176] update --- README.md | 2 +- test.py | 2 +- train.py | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ede808ca28d6..9fd1003bbefb 100755 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ This repository represents Ultralytics open-source research into future object d ** GPU Speed measures end-to-end time per image averaged over 5000 COCO val2017 images using a V100 GPU with batch size 32, and includes image preprocessing, PyTorch FP16 inference, postprocessing and NMS. EfficientDet data from [google/automl](https://github.com/google/automl) at batch size 8. -- **January 2, 2021**: [v4.0 release](https://github.com/ultralytics/yolov5/releases/tag/v4.0): nn.SiLU() activations, [Weights & Biases](https://wandb.ai/) logging, [PyTorch Hub](https://pytorch.org/hub/ultralytics_yolov5/) integration. +- **January 5, 2021**: [v4.0 release](https://github.com/ultralytics/yolov5/releases/tag/v4.0): nn.SiLU() activations, [Weights & Biases](https://wandb.ai/) logging, [PyTorch Hub](https://pytorch.org/hub/ultralytics_yolov5/) integration. - **August 13, 2020**: [v3.0 release](https://github.com/ultralytics/yolov5/releases/tag/v3.0): nn.Hardswish() activations, data autodownload, native AMP. - **July 23, 2020**: [v2.0 release](https://github.com/ultralytics/yolov5/releases/tag/v2.0): improved model definition, training and mAP. - **June 22, 2020**: [PANet](https://arxiv.org/abs/1803.01534) updates: new heads, reduced parameters, improved speed and mAP [364fcfd](https://github.com/ultralytics/yolov5/commit/364fcfd7dba53f46edd4f04c037a039c0a287972). diff --git a/test.py b/test.py index ce8c593d0384..b520eae98d00 100644 --- a/test.py +++ b/test.py @@ -320,7 +320,7 @@ def test(data, ) elif opt.task == 'study': # run over a range of settings and save/plot - for weights in ['yolov5x4.pt']: + for weights in ['yolov5s.pt', 'yolov5m.pt', 'yolov5l.pt', 'yolov5x.pt']: f = 'study_%s_%s.txt' % (Path(opt.data).stem, Path(weights).stem) # filename to save to x = list(range(320, 800, 64)) # x axis y = [] # y axis diff --git a/train.py b/train.py index dd56625b4fd5..4d06d26e13b3 100644 --- a/train.py +++ b/train.py @@ -467,6 +467,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): opt = parser.parse_args() # Set DDP variables + opt.total_batch_size = opt.batch_size opt.world_size = int(os.environ['WORLD_SIZE']) if 'WORLD_SIZE' in os.environ else 1 opt.global_rank = int(os.environ['RANK']) if 'RANK' in os.environ else -1 set_logging(opt.global_rank) @@ -477,10 +478,10 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): if opt.resume: # resume an interrupted run ckpt = opt.resume if isinstance(opt.resume, str) else get_latest_run() # specified or most recent path assert os.path.isfile(ckpt), 'ERROR: --resume checkpoint does not exist' - apriori = opt.global_rank, opt.local_rank, opt.batch_size + apriori = opt.global_rank, opt.local_rank with open(Path(ckpt).parent.parent / 'opt.yaml') as f: opt = argparse.Namespace(**yaml.load(f, Loader=yaml.FullLoader)) # replace - opt.cfg, opt.weights, opt.resume, opt.global_rank, opt.local_rank, opt.batch_size = '', ckpt, True, *apriori + opt.cfg, opt.weights, opt.resume, opt.global_rank, opt.local_rank = '', ckpt, True, *apriori # reinstate logger.info('Resuming training from %s' % ckpt) else: # opt.hyp = opt.hyp or ('hyp.finetune.yaml' if opt.weights else 'hyp.scratch.yaml') From 2a87b2bedc592579846e6f77c9309a46b1d612eb Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 4 Jan 2021 16:24:32 -0800 Subject: [PATCH 097/176] update --- train.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/train.py b/train.py index 4d06d26e13b3..d61ca4b3ac2a 100644 --- a/train.py +++ b/train.py @@ -467,7 +467,6 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): opt = parser.parse_args() # Set DDP variables - opt.total_batch_size = opt.batch_size opt.world_size = int(os.environ['WORLD_SIZE']) if 'WORLD_SIZE' in os.environ else 1 opt.global_rank = int(os.environ['RANK']) if 'RANK' in os.environ else -1 set_logging(opt.global_rank) @@ -492,8 +491,8 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): opt.save_dir = increment_path(Path(opt.project) / opt.name, exist_ok=opt.exist_ok | opt.evolve) # increment run # DDP mode - device = select_device(opt.device, batch_size=opt.batch_size) opt.total_batch_size = opt.batch_size + device = select_device(opt.device, batch_size=opt.batch_size) if opt.local_rank != -1: assert torch.cuda.device_count() > opt.local_rank torch.cuda.set_device(opt.local_rank) From 2c0af2f8648a8a84abd5c36406953542afc1672e Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 4 Jan 2021 17:40:03 -0800 Subject: [PATCH 098/176] update --- models/hub/experimental/yolov5l7-1280.yaml | 8 ++++---- models/hub/experimental/yolov5l7-1920.yaml | 8 ++++---- models/hub/experimental/yolov5x7-1280.yaml | 8 ++++---- models/hub/experimental/yolov5x7-1920.yaml | 8 ++++---- models/hub/experimental/yolov5x7-640.yaml | 8 ++++---- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/models/hub/experimental/yolov5l7-1280.yaml b/models/hub/experimental/yolov5l7-1280.yaml index 6ca0f693d572..5571a98fd542 100644 --- a/models/hub/experimental/yolov5l7-1280.yaml +++ b/models/hub/experimental/yolov5l7-1280.yaml @@ -18,13 +18,13 @@ backbone: [ -1, 1, Conv, [ 128, 3, 2 ] ], # 1-P2/4 [ -1, 3, C3, [ 128 ] ], [ -1, 1, Conv, [ 256, 3, 2 ] ], # 3-P3/8 - [ -1, 3, C3, [ 256 ] ], + [ -1, 9, C3, [ 256 ] ], [ -1, 1, Conv, [ 512, 3, 2 ] ], # 5-P4/16 - [ -1, 6, C3, [ 512 ] ], + [ -1, 9, C3, [ 512 ] ], [ -1, 1, Conv, [ 768, 3, 2 ] ], # 7-P5/32 - [ -1, 9, C3, [ 768 ] ], + [ -1, 3, C3, [ 768 ] ], [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 - [ -1, 6, C3, [ 1024 ] ], + [ -1, 3, C3, [ 1024 ] ], [ -1, 1, Conv, [ 1280, 3, 2 ] ], # 11-P7/128 [ -1, 1, SPP, [ 1280, [ 3, 5 ] ] ], [ -1, 3, C3, [ 1280, False ] ], # 13 diff --git a/models/hub/experimental/yolov5l7-1920.yaml b/models/hub/experimental/yolov5l7-1920.yaml index 6225f1073143..574359cf799f 100644 --- a/models/hub/experimental/yolov5l7-1920.yaml +++ b/models/hub/experimental/yolov5l7-1920.yaml @@ -18,13 +18,13 @@ backbone: [ -1, 1, Conv, [ 128, 3, 2 ] ], # 1-P2/4 [ -1, 3, C3, [ 128 ] ], [ -1, 1, Conv, [ 256, 3, 2 ] ], # 3-P3/8 - [ -1, 3, C3, [ 256 ] ], + [ -1, 9, C3, [ 256 ] ], [ -1, 1, Conv, [ 512, 3, 2 ] ], # 5-P4/16 - [ -1, 6, C3, [ 512 ] ], + [ -1, 9, C3, [ 512 ] ], [ -1, 1, Conv, [ 768, 3, 2 ] ], # 7-P5/32 - [ -1, 9, C3, [ 768 ] ], + [ -1, 3, C3, [ 768 ] ], [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 - [ -1, 6, C3, [ 1024 ] ], + [ -1, 3, C3, [ 1024 ] ], [ -1, 1, Conv, [ 1280, 3, 2 ] ], # 11-P7/128 [ -1, 1, SPP, [ 1280, [ 3, 5 ] ] ], [ -1, 3, C3, [ 1280, False ] ], # 13 diff --git a/models/hub/experimental/yolov5x7-1280.yaml b/models/hub/experimental/yolov5x7-1280.yaml index e3e7cc3e4fa9..6189f5f85c34 100644 --- a/models/hub/experimental/yolov5x7-1280.yaml +++ b/models/hub/experimental/yolov5x7-1280.yaml @@ -18,13 +18,13 @@ backbone: [ -1, 1, Conv, [ 128, 3, 2 ] ], # 1-P2/4 [ -1, 3, C3, [ 128 ] ], [ -1, 1, Conv, [ 256, 3, 2 ] ], # 3-P3/8 - [ -1, 3, C3, [ 256 ] ], + [ -1, 9, C3, [ 256 ] ], [ -1, 1, Conv, [ 512, 3, 2 ] ], # 5-P4/16 - [ -1, 6, C3, [ 512 ] ], + [ -1, 9, C3, [ 512 ] ], [ -1, 1, Conv, [ 768, 3, 2 ] ], # 7-P5/32 - [ -1, 9, C3, [ 768 ] ], + [ -1, 3, C3, [ 768 ] ], [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 - [ -1, 6, C3, [ 1024 ] ], + [ -1, 3, C3, [ 1024 ] ], [ -1, 1, Conv, [ 1280, 3, 2 ] ], # 11-P7/128 [ -1, 1, SPP, [ 1280, [ 3, 5 ] ] ], [ -1, 3, C3, [ 1280, False ] ], # 13 diff --git a/models/hub/experimental/yolov5x7-1920.yaml b/models/hub/experimental/yolov5x7-1920.yaml index dafefb09039b..ba6a79a5e7ea 100644 --- a/models/hub/experimental/yolov5x7-1920.yaml +++ b/models/hub/experimental/yolov5x7-1920.yaml @@ -18,13 +18,13 @@ backbone: [ -1, 1, Conv, [ 128, 3, 2 ] ], # 1-P2/4 [ -1, 3, C3, [ 128 ] ], [ -1, 1, Conv, [ 256, 3, 2 ] ], # 3-P3/8 - [ -1, 3, C3, [ 256 ] ], + [ -1, 9, C3, [ 256 ] ], [ -1, 1, Conv, [ 512, 3, 2 ] ], # 5-P4/16 - [ -1, 6, C3, [ 512 ] ], + [ -1, 9, C3, [ 512 ] ], [ -1, 1, Conv, [ 768, 3, 2 ] ], # 7-P5/32 - [ -1, 9, C3, [ 768 ] ], + [ -1, 3, C3, [ 768 ] ], [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 - [ -1, 6, C3, [ 1024 ] ], + [ -1, 3, C3, [ 1024 ] ], [ -1, 1, Conv, [ 1280, 3, 2 ] ], # 11-P7/128 [ -1, 1, SPP, [ 1280, [ 3, 5 ] ] ], [ -1, 3, C3, [ 1280, False ] ], # 13 diff --git a/models/hub/experimental/yolov5x7-640.yaml b/models/hub/experimental/yolov5x7-640.yaml index dedc15dab704..a89f9f4867f9 100644 --- a/models/hub/experimental/yolov5x7-640.yaml +++ b/models/hub/experimental/yolov5x7-640.yaml @@ -18,13 +18,13 @@ backbone: [ -1, 1, Conv, [ 128, 3, 2 ] ], # 1-P2/4 [ -1, 3, C3, [ 128 ] ], [ -1, 1, Conv, [ 256, 3, 2 ] ], # 3-P3/8 - [ -1, 3, C3, [ 256 ] ], + [ -1, 9, C3, [ 256 ] ], [ -1, 1, Conv, [ 512, 3, 2 ] ], # 5-P4/16 - [ -1, 6, C3, [ 512 ] ], + [ -1, 9, C3, [ 512 ] ], [ -1, 1, Conv, [ 768, 3, 2 ] ], # 7-P5/32 - [ -1, 9, C3, [ 768 ] ], + [ -1, 3, C3, [ 768 ] ], [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 - [ -1, 6, C3, [ 1024 ] ], + [ -1, 3, C3, [ 1024 ] ], [ -1, 1, Conv, [ 1280, 3, 2 ] ], # 11-P7/128 [ -1, 1, SPP, [ 1280, [ 3, 5 ] ] ], [ -1, 3, C3, [ 1280, False ] ], # 13 From 8bee44d6670035cf21c3c7f020d9196cfb1d7e7b Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 6 Jan 2021 01:39:23 -0800 Subject: [PATCH 099/176] update --- .../hub/experimental/yolov5l6-1280-36666.yaml | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 models/hub/experimental/yolov5l6-1280-36666.yaml diff --git a/models/hub/experimental/yolov5l6-1280-36666.yaml b/models/hub/experimental/yolov5l6-1280-36666.yaml new file mode 100644 index 000000000000..6ecb76381fc7 --- /dev/null +++ b/models/hub/experimental/yolov5l6-1280-36666.yaml @@ -0,0 +1,60 @@ +# parameters +nc: 80 # number of classes +depth_multiple: 1.0 # model depth multiple +width_multiple: 1.0 # layer channel multiple + +# anchors +anchors: + - [ 19,27, 44,40, 38,94 ] # P3/8 + - [ 96,68, 86,152, 180,137 ] # P4/16 + - [ 140,301, 303,264, 238,542 ] # P5/32 + - [ 436,615, 739,380, 925,792 ] # P6/64 + +# 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, 6, C3, [ 256 ] ], + [ -1, 1, Conv, [ 512, 3, 2 ] ], # 5-P4/16 + [ -1, 6, C3, [ 512 ] ], + [ -1, 1, Conv, [ 768, 3, 2 ] ], # 7-P5/32 + [ -1, 6, C3, [ 768 ] ], + [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 + [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ], + [ -1, 6, C3, [ 1024, False ] ], # 11 + ] + +# YOLOv5 head +head: + [ [ -1, 1, Conv, [ 768, 1, 1 ] ], + [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], + [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 + [ -1, 3, C3, [ 768, False ] ], # 15 + + [ -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 ] ], # 19 + + [ -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 ] ], # 23 (P3/8-small) + + [ -1, 1, Conv, [ 256, 3, 2 ] ], + [ [ -1, 20 ], 1, Concat, [ 1 ] ], # cat head P4 + [ -1, 3, C3, [ 512, False ] ], # 26 (P4/16-medium) + + [ -1, 1, Conv, [ 512, 3, 2 ] ], + [ [ -1, 16 ], 1, Concat, [ 1 ] ], # cat head P5 + [ -1, 3, C3, [ 768, False ] ], # 29 (P5/32-large) + + [ -1, 1, Conv, [ 768, 3, 2 ] ], + [ [ -1, 12 ], 1, Concat, [ 1 ] ], # cat head P6 + [ -1, 3, C3, [ 1024, False ] ], # 32 (P5/64-xlarge) + + [ [ 23, 26, 29, 32 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) + ] From 4c476c43e7dd94548149f3954f9e462e3c7d5c05 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 6 Jan 2021 01:49:05 -0800 Subject: [PATCH 100/176] update --- data/hyp.lrf01.yaml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 data/hyp.lrf01.yaml diff --git a/data/hyp.lrf01.yaml b/data/hyp.lrf01.yaml new file mode 100644 index 000000000000..23e53eb8a9d3 --- /dev/null +++ b/data/hyp.lrf01.yaml @@ -0,0 +1,33 @@ +# Hyperparameters for COCO training from scratch +# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 +# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials + + +lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) +lrf: 0.1 # final OneCycleLR learning rate (lr0 * lrf) +momentum: 0.937 # SGD momentum/Adam beta1 +weight_decay: 0.0005 # optimizer weight decay 5e-4 +warmup_epochs: 3.0 # warmup epochs (fractions ok) +warmup_momentum: 0.8 # warmup initial momentum +warmup_bias_lr: 0.1 # warmup initial bias lr +box: 0.05 # box loss gain +cls: 0.3 # cls loss gain +cls_pw: 1.0 # cls BCELoss positive_weight +obj: 0.5 # obj loss gain (scale with pixels) +obj_pw: 1.0 # obj BCELoss positive_weight +iou_t: 0.20 # IoU training threshold +anchor_t: 4.0 # anchor-multiple threshold +# anchors: 3 # anchors per output layer (0 to ignore) +fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) +hsv_h: 0.015 # image HSV-Hue augmentation (fraction) +hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) +hsv_v: 0.4 # image HSV-Value augmentation (fraction) +degrees: 0.0 # image rotation (+/- deg) +translate: 0.1 # image translation (+/- fraction) +scale: 0.9 # image scale (+/- gain) +shear: 0.0 # image shear (+/- deg) +perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 +flipud: 0.0 # image flip up-down (probability) +fliplr: 0.5 # image flip left-right (probability) +mosaic: 1.0 # image mosaic (probability) +mixup: 0.01 # image mixup (probability) From 804bcc9790c366d1fcc3f52af588c293885398d4 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Fri, 8 Jan 2021 09:02:15 -0800 Subject: [PATCH 101/176] update --- test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.py b/test.py index 9c8d3b28bb03..41313ede3912 100644 --- a/test.py +++ b/test.py @@ -321,7 +321,7 @@ def test(data, ) elif opt.task == 'study': # run over a range of settings and save/plot - for weights in ['yolov5s.pt', 'yolov5m.pt', 'yolov5l.pt', 'yolov5x.pt']: + for weights in opt.weights: # ['yolov5s.pt', 'yolov5m.pt', 'yolov5l.pt', 'yolov5x.pt']: f = 'study_%s_%s.txt' % (Path(opt.data).stem, Path(weights).stem) # filename to save to x = list(range(320, 800, 64)) # x axis y = [] # y axis From f89b5dd5b41d4a713212debc241e4c077ffef8ae Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Fri, 8 Jan 2021 09:07:58 -0800 Subject: [PATCH 102/176] update --- test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.py b/test.py index 41313ede3912..ee919ac90716 100644 --- a/test.py +++ b/test.py @@ -323,7 +323,7 @@ def test(data, elif opt.task == 'study': # run over a range of settings and save/plot for weights in opt.weights: # ['yolov5s.pt', 'yolov5m.pt', 'yolov5l.pt', 'yolov5x.pt']: f = 'study_%s_%s.txt' % (Path(opt.data).stem, Path(weights).stem) # filename to save to - x = list(range(320, 800, 64)) # x axis + x = list(range(320, 1344, 64)) # x axis y = [] # y axis for i in x: # img-size print('\nRunning %s point %s...' % (f, i)) From 195f52a3392debd1e8fef5cf7ee7d7764bffadf2 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Fri, 8 Jan 2021 20:19:21 -0800 Subject: [PATCH 103/176] update --- utils/datasets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/datasets.py b/utils/datasets.py index 9001832aadec..9f9d6ad27f5c 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -846,7 +846,7 @@ def random_perspective(img, targets=(), degrees=10, translate=.1, scale=.1, shea R = np.eye(3) a = random.uniform(-degrees, degrees) # a += random.choice([-180, -90, 0, 90]) # add 90deg rotations to small rotations - s = random.uniform(1 - scale, 1 + scale) + s = random.uniform(1 - scale, 4) # s = random.uniform(1 - scale, 1 + scale) # s = 2 ** random.uniform(-scale, scale) R[:2] = cv2.getRotationMatrix2D(angle=a, center=(0, 0), scale=s) From e6fa5692eb8663b4cbc593760a078de0a655c419 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Fri, 8 Jan 2021 20:26:05 -0800 Subject: [PATCH 104/176] update --- utils/datasets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/datasets.py b/utils/datasets.py index 9f9d6ad27f5c..f9d9ab8d3e22 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -846,7 +846,7 @@ def random_perspective(img, targets=(), degrees=10, translate=.1, scale=.1, shea R = np.eye(3) a = random.uniform(-degrees, degrees) # a += random.choice([-180, -90, 0, 90]) # add 90deg rotations to small rotations - s = random.uniform(1 - scale, 4) # s = random.uniform(1 - scale, 1 + scale) + s = random.uniform(1 - scale, 3) # s = random.uniform(1 - scale, 1 + scale) # s = 2 ** random.uniform(-scale, scale) R[:2] = cv2.getRotationMatrix2D(angle=a, center=(0, 0), scale=s) From c28b137c80406bfd1dc75961bce6cec0400c0aba Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Fri, 8 Jan 2021 20:39:08 -0800 Subject: [PATCH 105/176] update --- utils/datasets.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/datasets.py b/utils/datasets.py index f9d9ab8d3e22..24d0625e52dd 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -590,7 +590,7 @@ def collate_fn4(batch): s = torch.tensor([[1, 1, .5, .5, .5, .5]]) # scale for i in range(n): # zidane torch.zeros(16,3,720,1280) # BCHW i *= 4 - if random.random() < 0.5: + if random.random() < 0.0: im = F.interpolate(img[i].unsqueeze(0).float(), scale_factor=2., mode='bilinear', align_corners=False)[ 0].type(img[i].type()) l = label[i] @@ -846,7 +846,7 @@ def random_perspective(img, targets=(), degrees=10, translate=.1, scale=.1, shea R = np.eye(3) a = random.uniform(-degrees, degrees) # a += random.choice([-180, -90, 0, 90]) # add 90deg rotations to small rotations - s = random.uniform(1 - scale, 3) # s = random.uniform(1 - scale, 1 + scale) + s = random.uniform(1 - scale, 2) # s = random.uniform(1 - scale, 1 + scale) # s = 2 ** random.uniform(-scale, scale) R[:2] = cv2.getRotationMatrix2D(angle=a, center=(0, 0), scale=s) From 37ae230c329f5ca65b83903683132f1b5559de8d Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Fri, 8 Jan 2021 20:47:24 -0800 Subject: [PATCH 106/176] update --- utils/datasets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/datasets.py b/utils/datasets.py index 24d0625e52dd..0562f0098bcf 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -590,7 +590,7 @@ def collate_fn4(batch): s = torch.tensor([[1, 1, .5, .5, .5, .5]]) # scale for i in range(n): # zidane torch.zeros(16,3,720,1280) # BCHW i *= 4 - if random.random() < 0.0: + if random.random() < 0.2: im = F.interpolate(img[i].unsqueeze(0).float(), scale_factor=2., mode='bilinear', align_corners=False)[ 0].type(img[i].type()) l = label[i] From 852708469709513246d1f76f3db5834fc135e59a Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Fri, 8 Jan 2021 22:02:12 -0800 Subject: [PATCH 107/176] update --- utils/plots.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/plots.py b/utils/plots.py index c883ea24f253..5b68090c403c 100644 --- a/utils/plots.py +++ b/utils/plots.py @@ -231,9 +231,9 @@ def plot_study_txt(path='study/', x=None): # from utils.plots import *; plot_st fig2, ax2 = plt.subplots(1, 1, figsize=(8, 4), tight_layout=True) for f in [Path(path) / f'study_coco_{x}.txt' for x in ['yolov5s', 'yolov5m', 'yolov5l', 'yolov5x']]: y = np.loadtxt(f, dtype=np.float32, usecols=[0, 1, 2, 3, 7, 8, 9], ndmin=2).T - x = np.arange(y.shape[1]) if x is None else np.array(x) + x = np.arange(y.shape[1]) s = ['P', 'R', 'mAP@.5', 'mAP@.5:.95', 't_inference (ms/img)', 't_NMS (ms/img)', 't_total (ms/img)'] - for i in range(7): + for i in range(y.shape[0]): ax[i].plot(x, y[i], '.-', linewidth=2, markersize=8) ax[i].set_title(s[i]) @@ -247,7 +247,7 @@ def plot_study_txt(path='study/', x=None): # from utils.plots import *; plot_st ax2.grid() ax2.set_xlim(0, 30) ax2.set_ylim(29, 51) - ax2.set_yticks(np.arange(30, 55, 5)) + ax2.set_yticks(np.arange(30, 60, 5)) ax2.set_xlabel('GPU Speed (ms/img)') ax2.set_ylabel('COCO AP val') ax2.legend(loc='lower right') From bb79ac899c79b7bb7380c32b4a5ec285522b23f6 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 9 Jan 2021 17:14:18 -0800 Subject: [PATCH 108/176] update --- utils/loss.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utils/loss.py b/utils/loss.py index 18636861a648..c59d94bd8c1d 100644 --- a/utils/loss.py +++ b/utils/loss.py @@ -105,7 +105,8 @@ def compute_loss(p, targets, model): # predictions, targets, model # Losses nt = 0 # number of targets - balance = [4.0, 1.0, 0.3, 0.1, 0.03] # P3-P7 + no = len(p) # number of outputs + balance = {3: [3.67, 1.0, 0.43], 4: [3.78, 1.0, 0.39, 0.22], 5: [3.88, 1.0, 0.37, 0.17, 0.10]}[no] # P3-P7 for i, pi in enumerate(p): # layer index, layer predictions b, a, gj, gi = indices[i] # image, anchor, gridy, gridx tobj = torch.zeros_like(pi[..., 0], device=device) # target obj From 0026841f815449e1877b36a14d3728b096e7b55a Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 9 Jan 2021 17:29:39 -0800 Subject: [PATCH 109/176] update --- utils/datasets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/datasets.py b/utils/datasets.py index 0562f0098bcf..6a7d7bfdc9e7 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -846,7 +846,7 @@ def random_perspective(img, targets=(), degrees=10, translate=.1, scale=.1, shea R = np.eye(3) a = random.uniform(-degrees, degrees) # a += random.choice([-180, -90, 0, 90]) # add 90deg rotations to small rotations - s = random.uniform(1 - scale, 2) # s = random.uniform(1 - scale, 1 + scale) + s = random.uniform(1 - scale, 1 + scale) # s = random.uniform(1 - scale, 1 + scale) # s = 2 ** random.uniform(-scale, scale) R[:2] = cv2.getRotationMatrix2D(angle=a, center=(0, 0), scale=s) From 6f5edca6354547865a16fb4aa3e87c508cb44c5c Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 9 Jan 2021 17:37:47 -0800 Subject: [PATCH 110/176] update --- utils/datasets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/datasets.py b/utils/datasets.py index 6a7d7bfdc9e7..88927f4fc81f 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -590,7 +590,7 @@ def collate_fn4(batch): s = torch.tensor([[1, 1, .5, .5, .5, .5]]) # scale for i in range(n): # zidane torch.zeros(16,3,720,1280) # BCHW i *= 4 - if random.random() < 0.2: + if random.random() < 0.0: im = F.interpolate(img[i].unsqueeze(0).float(), scale_factor=2., mode='bilinear', align_corners=False)[ 0].type(img[i].type()) l = label[i] From 6b04c8e8b800ce12b9827e402aa8e66407e9425e Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 9 Jan 2021 17:39:21 -0800 Subject: [PATCH 111/176] update --- utils/datasets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/datasets.py b/utils/datasets.py index 88927f4fc81f..10da61cff7ec 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -590,7 +590,7 @@ def collate_fn4(batch): s = torch.tensor([[1, 1, .5, .5, .5, .5]]) # scale for i in range(n): # zidane torch.zeros(16,3,720,1280) # BCHW i *= 4 - if random.random() < 0.0: + if random.random() < 0.1: im = F.interpolate(img[i].unsqueeze(0).float(), scale_factor=2., mode='bilinear', align_corners=False)[ 0].type(img[i].type()) l = label[i] From d13046536016006fe7f8a877eab4f83ac84f79fd Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 9 Jan 2021 17:49:45 -0800 Subject: [PATCH 112/176] update --- utils/datasets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/datasets.py b/utils/datasets.py index 10da61cff7ec..8d9f4f8de569 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -846,7 +846,7 @@ def random_perspective(img, targets=(), degrees=10, translate=.1, scale=.1, shea R = np.eye(3) a = random.uniform(-degrees, degrees) # a += random.choice([-180, -90, 0, 90]) # add 90deg rotations to small rotations - s = random.uniform(1 - scale, 1 + scale) # s = random.uniform(1 - scale, 1 + scale) + s = random.uniform(1 - scale, 2.3) # s = random.uniform(1 - scale, 1 + scale) # s = 2 ** random.uniform(-scale, scale) R[:2] = cv2.getRotationMatrix2D(angle=a, center=(0, 0), scale=s) From 0e44515c21ee44162afbb1f52d9994801bc470c8 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 10 Jan 2021 18:04:48 -0800 Subject: [PATCH 113/176] GitHub API rate limit fix --- utils/datasets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/datasets.py b/utils/datasets.py index 8d9f4f8de569..10da61cff7ec 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -846,7 +846,7 @@ def random_perspective(img, targets=(), degrees=10, translate=.1, scale=.1, shea R = np.eye(3) a = random.uniform(-degrees, degrees) # a += random.choice([-180, -90, 0, 90]) # add 90deg rotations to small rotations - s = random.uniform(1 - scale, 2.3) # s = random.uniform(1 - scale, 1 + scale) + s = random.uniform(1 - scale, 1 + scale) # s = random.uniform(1 - scale, 1 + scale) # s = 2 ** random.uniform(-scale, scale) R[:2] = cv2.getRotationMatrix2D(angle=a, center=(0, 0), scale=s) From 1178b3e877dcea9aae2c1af7211346dbf1fb73b9 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 12 Jan 2021 14:33:04 -0800 Subject: [PATCH 114/176] update --- models/hub/experimental/yolov5l2-640-3.yaml | 57 ++++++++++++++++++++ models/hub/experimental/yolov5l2-640-4.yaml | 58 +++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 models/hub/experimental/yolov5l2-640-3.yaml create mode 100644 models/hub/experimental/yolov5l2-640-4.yaml diff --git a/models/hub/experimental/yolov5l2-640-3.yaml b/models/hub/experimental/yolov5l2-640-3.yaml new file mode 100644 index 000000000000..1dd3cc1b3168 --- /dev/null +++ b/models/hub/experimental/yolov5l2-640-3.yaml @@ -0,0 +1,57 @@ +# 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, [ 128, 1, 1 ] ], + [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], + [ [ -1, 2 ], 1, Concat, [ 1 ] ], # cat backbone P2 + [ -1, 1, C3, [ 128, False ] ], # 21 (P2/4-xsmall) + + [ -1, 1, Conv, [ 128, 3, 2 ] ], + [ [ -1, 18 ], 1, Concat, [ 1 ] ], # cat head P3 + [ -1, 3, C3, [ 256, False ] ], # 24 (P3/8-small) + + [ -1, 1, Conv, [ 256, 3, 2 ] ], + [ [ -1, 14 ], 1, Concat, [ 1 ] ], # cat head P4 + [ -1, 3, C3, [ 512, False ] ], # 27 (P4/16-medium) + + [ -1, 1, Conv, [ 512, 3, 2 ] ], + [ [ -1, 10 ], 1, Concat, [ 1 ] ], # cat head P5 + [ -1, 3, C3, [ 1024, False ] ], # 30 (P5/32-large) + + [ [ 24, 27, 30 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5) + ] diff --git a/models/hub/experimental/yolov5l2-640-4.yaml b/models/hub/experimental/yolov5l2-640-4.yaml new file mode 100644 index 000000000000..ec0559d469a2 --- /dev/null +++ b/models/hub/experimental/yolov5l2-640-4.yaml @@ -0,0 +1,58 @@ +# parameters +nc: 80 # number of classes +depth_multiple: 1.0 # model depth multiple +width_multiple: 1.0 # layer channel multiple + +# anchors +anchors: + - [ 9,11, 21,19, 17,41 ] # P3/8 + - [ 43,32, 39,70, 86,64 ] # P4/16 + - [ 65,131, 134,130, 120,265 ] # P5/32 + - [ 282,180, 247,354, 512,387 ] # P6/64 + +# 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, [ 128, 1, 1 ] ], + [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], + [ [ -1, 2 ], 1, Concat, [ 1 ] ], # cat backbone P2 + [ -1, 1, C3, [ 128, False ] ], # 21 (P2/4-xsmall) + + [ -1, 1, Conv, [ 128, 3, 2 ] ], + [ [ -1, 18 ], 1, Concat, [ 1 ] ], # cat head P3 + [ -1, 3, C3, [ 256, False ] ], # 24 (P3/8-small) + + [ -1, 1, Conv, [ 256, 3, 2 ] ], + [ [ -1, 14 ], 1, Concat, [ 1 ] ], # cat head P4 + [ -1, 3, C3, [ 512, False ] ], # 27 (P4/16-medium) + + [ -1, 1, Conv, [ 512, 3, 2 ] ], + [ [ -1, 10 ], 1, Concat, [ 1 ] ], # cat head P5 + [ -1, 3, C3, [ 1024, False ] ], # 30 (P5/32-large) + + [ [ 21, 24, 27, 30 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5) + ] From 2c5930122436594884418936a0f031f6c30d20ac Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 13 Jan 2021 11:53:19 -0800 Subject: [PATCH 115/176] ComputeLoss --- train.py | 4 +- utils/loss.py | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+), 1 deletion(-) diff --git a/train.py b/train.py index 459c81c6130d..1d42017a50cb 100644 --- a/train.py +++ b/train.py @@ -29,7 +29,7 @@ fitness, strip_optimizer, get_latest_run, check_dataset, check_file, check_git_status, check_img_size, \ check_requirements, print_mutation, set_logging, one_cycle, colorstr from utils.google_utils import attempt_download -from utils.loss import compute_loss +from utils.loss import compute_loss, ComputeLoss from utils.plots import plot_images, plot_labels, plot_results, plot_evolution from utils.torch_utils import ModelEMA, select_device, intersect_dicts, torch_distributed_zero_first @@ -227,6 +227,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): results = (0, 0, 0, 0, 0, 0, 0) # P, R, mAP@.5, mAP@.5-.95, val_loss(box, obj, cls) scheduler.last_epoch = start_epoch - 1 # do not move scaler = amp.GradScaler(enabled=cuda) + compute_loss2 = ComputeLoss(model) logger.info(f'Image sizes {imgsz} train, {imgsz_test} test\n' f'Using {dataloader.num_workers} dataloader workers\n' f'Logging results to {save_dir}\n' @@ -287,6 +288,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): with amp.autocast(enabled=cuda): pred = model(imgs) # forward loss, loss_items = compute_loss(pred, targets.to(device), model) # loss scaled by batch_size + loss2, loss_items2 = compute_loss2(pred, targets.to(device)) # loss scaled by batch_size if rank != -1: loss *= opt.world_size # gradient averaged between devices in DDP mode if opt.quad: diff --git a/utils/loss.py b/utils/loss.py index c59d94bd8c1d..65831a984349 100644 --- a/utils/loss.py +++ b/utils/loss.py @@ -85,6 +85,133 @@ def forward(self, pred, true): return loss +class ComputeLoss: + # Compute losses + def __init__(self, model): + super(ComputeLoss, self).__init__() + device = next(model.parameters()).device # get model device + h = model.hyp # hyperparameters + + # Define criteria + BCEcls = nn.BCEWithLogitsLoss(pos_weight=torch.tensor([h['cls_pw']], device=device)) + BCEobj = nn.BCEWithLogitsLoss(pos_weight=torch.tensor([h['obj_pw']], device=device)) + + # Class label smoothing https://arxiv.org/pdf/1902.04103.pdf eqn 3 + self.cp, self.cn = smooth_BCE(eps=0.0) + + # Focal loss + g = h['fl_gamma'] # focal loss gamma + if g > 0: + BCEcls, BCEobj = FocalLoss(BCEcls, g), FocalLoss(BCEobj, g) + + det = model.module.model[-1] if is_parallel(model) else model.model[-1] # Detect() module + self.balance = {3: [3.67, 1.0, 0.43], 4: [3.78, 1.0, 0.39, 0.22], 5: [3.88, 1.0, 0.37, 0.17, 0.10]}[det.nl] + self.BCEcls, self.BCEobj = BCEcls, BCEobj + for k in 'na', 'nc', 'nl', 'anchors': + setattr(self, k, getattr(det, k)) + self.gr = model.gr + self.hyp = h + + def __call__(self, p, targets): # predictions, targets, model + device = targets.device + lcls, lbox, lobj = torch.zeros(1, device=device), torch.zeros(1, device=device), torch.zeros(1, device=device) + tcls, tbox, indices, anchors = self.build_targets(p, targets) # targets + + # Losses + for i, pi in enumerate(p): # layer index, layer predictions + b, a, gj, gi = indices[i] # image, anchor, gridy, gridx + tobj = torch.zeros_like(pi[..., 0], device=device) # target obj + + n = b.shape[0] # number of targets + if n: + ps = pi[b, a, gj, gi] # prediction subset corresponding to targets + + # Regression + pxy = ps[:, :2].sigmoid() * 2. - 0.5 + pwh = (ps[:, 2:4].sigmoid() * 2) ** 2 * anchors[i] + pbox = torch.cat((pxy, pwh), 1) # predicted box + iou = bbox_iou(pbox.T, tbox[i], x1y1x2y2=False, CIoU=True) # iou(prediction, target) + lbox += (1.0 - iou).mean() # iou loss + + # Objectness + tobj[b, a, gj, gi] = (1.0 - self.gr) + self.gr * iou.detach().clamp(0).type(tobj.dtype) # iou ratio + + # Classification + if self.nc > 1: # cls loss (only if multiple classes) + t = torch.full_like(ps[:, 5:], self.cn, device=device) # targets + t[range(n), tcls[i]] = self.cp + lcls += self.BCEcls(ps[:, 5:], t) # BCE + + # Append targets to text file + # with open('targets.txt', 'a') as file: + # [file.write('%11.5g ' * 4 % tuple(x) + '\n') for x in torch.cat((txy[i], twh[i]), 1)] + + lobj += self.BCEobj(pi[..., 4], tobj) * self.balance[i] # obj loss + + lbox *= self.hyp['box'] + lobj *= self.hyp['obj'] + lcls *= self.hyp['cls'] + bs = tobj.shape[0] # batch size + + loss = lbox + lobj + lcls + return loss * bs, torch.cat((lbox, lobj, lcls, loss)).detach() + + def build_targets(self, p, targets): + # Build targets for compute_loss(), input targets(image,class,x,y,w,h) + na, nt = self.na, targets.shape[0] # number of anchors, targets + tcls, tbox, indices, anch = [], [], [], [] + gain = torch.ones(7, device=targets.device) # normalized to gridspace gain + ai = torch.arange(na, device=targets.device).float().view(na, 1).repeat(1, nt) # same as .repeat_interleave(nt) + targets = torch.cat((targets.repeat(na, 1, 1), ai[:, :, None]), 2) # append anchor indices + + g = 0.5 # bias + off = torch.tensor([[0, 0], + [1, 0], [0, 1], [-1, 0], [0, -1], # j,k,l,m + # [1, 1], [1, -1], [-1, 1], [-1, -1], # jk,jm,lk,lm + ], device=targets.device).float() * g # offsets + + for i in range(self.nl): + anchors = self.anchors[i] + gain[2:6] = torch.tensor(p[i].shape)[[3, 2, 3, 2]] # xyxy gain + + # Match targets to anchors + t = targets * gain + if nt: + # Matches + r = t[:, :, 4:6] / anchors[:, None] # wh ratio + j = torch.max(r, 1. / r).max(2)[0] < self.hyp['anchor_t'] # compare + # j = wh_iou(anchors, t[:, 4:6]) > model.hyp['iou_t'] # iou(3,n)=wh_iou(anchors(3,2), gwh(n,2)) + t = t[j] # filter + + # Offsets + gxy = t[:, 2:4] # grid xy + gxi = gain[[2, 3]] - gxy # inverse + j, k = ((gxy % 1. < g) & (gxy > 1.)).T + l, m = ((gxi % 1. < g) & (gxi > 1.)).T + j = torch.stack((torch.ones_like(j), j, k, l, m)) + t = t.repeat((5, 1, 1))[j] + offsets = (torch.zeros_like(gxy)[None] + off[:, None])[j] + else: + t = targets[0] + offsets = 0 + + # Define + b, c = t[:, :2].long().T # image, class + gxy = t[:, 2:4] # grid xy + gwh = t[:, 4:6] # grid wh + gij = (gxy - offsets).long() + gi, gj = gij.T # grid xy indices + + # Append + a = t[:, 6].long() # anchor indices + indices.append((b, a, gj.clamp_(0, gain[3] - 1), gi.clamp_(0, gain[2] - 1))) # image, anchor, grid indices + tbox.append(torch.cat((gxy - gij, gwh), 1)) # box + anch.append(anchors[a]) # anchors + tcls.append(c) # class + + return tcls, tbox, indices, anch + + def compute_loss(p, targets, model): # predictions, targets, model device = targets.device lcls, lbox, lobj = torch.zeros(1, device=device), torch.zeros(1, device=device), torch.zeros(1, device=device) From 9bea325d20a71820f07132287724056fd8c67249 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 13 Jan 2021 12:12:11 -0800 Subject: [PATCH 116/176] ComputeLoss --- train.py | 5 +++-- utils/loss.py | 12 +++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/train.py b/train.py index 1d42017a50cb..9454f7ba30c1 100644 --- a/train.py +++ b/train.py @@ -287,8 +287,9 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): # Forward with amp.autocast(enabled=cuda): pred = model(imgs) # forward - loss, loss_items = compute_loss(pred, targets.to(device), model) # loss scaled by batch_size - loss2, loss_items2 = compute_loss2(pred, targets.to(device)) # loss scaled by batch_size + # loss, loss_items = compute_loss(pred, targets.to(device), model) # loss scaled by batch_size + loss, loss_items = compute_loss2(pred, targets.to(device)) # loss scaled by batch_size + print(compute_loss2.balance) if rank != -1: loss *= opt.world_size # gradient averaged between devices in DDP mode if opt.quad: diff --git a/utils/loss.py b/utils/loss.py index 65831a984349..09dbdeb58079 100644 --- a/utils/loss.py +++ b/utils/loss.py @@ -87,7 +87,7 @@ def forward(self, pred, true): class ComputeLoss: # Compute losses - def __init__(self, model): + def __init__(self, model, autobalance=True): super(ComputeLoss, self).__init__() device = next(model.parameters()).device # get model device h = model.hyp # hyperparameters @@ -106,11 +106,9 @@ def __init__(self, model): det = model.module.model[-1] if is_parallel(model) else model.model[-1] # Detect() module self.balance = {3: [3.67, 1.0, 0.43], 4: [3.78, 1.0, 0.39, 0.22], 5: [3.88, 1.0, 0.37, 0.17, 0.10]}[det.nl] - self.BCEcls, self.BCEobj = BCEcls, BCEobj + self.BCEcls, self.BCEobj, self.gr, self.hyp, self.autobalance = BCEcls, BCEobj, model.gr, h, autobalance for k in 'na', 'nc', 'nl', 'anchors': setattr(self, k, getattr(det, k)) - self.gr = model.gr - self.hyp = h def __call__(self, p, targets): # predictions, targets, model device = targets.device @@ -146,8 +144,12 @@ def __call__(self, p, targets): # predictions, targets, model # with open('targets.txt', 'a') as file: # [file.write('%11.5g ' * 4 % tuple(x) + '\n') for x in torch.cat((txy[i], twh[i]), 1)] - lobj += self.BCEobj(pi[..., 4], tobj) * self.balance[i] # obj loss + obji = self.BCEobj(pi[..., 4], tobj) + self.balance[i] = self.balance[i] * 0.99 + obji.detach().item().cpu() * 0.01 + lobj += obji * self.balance[i] # obj loss + + self.balance = [x/self.balance[1] for x in self.balance] lbox *= self.hyp['box'] lobj *= self.hyp['obj'] lcls *= self.hyp['cls'] From b241471908f3600d4098e874877c159a31de4290 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 13 Jan 2021 12:25:44 -0800 Subject: [PATCH 117/176] ComputeLoss --- utils/loss.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/utils/loss.py b/utils/loss.py index 09dbdeb58079..b22aa91366fc 100644 --- a/utils/loss.py +++ b/utils/loss.py @@ -105,7 +105,8 @@ def __init__(self, model, autobalance=True): BCEcls, BCEobj = FocalLoss(BCEcls, g), FocalLoss(BCEobj, g) det = model.module.model[-1] if is_parallel(model) else model.model[-1] # Detect() module - self.balance = {3: [3.67, 1.0, 0.43], 4: [3.78, 1.0, 0.39, 0.22], 5: [3.88, 1.0, 0.37, 0.17, 0.10]}[det.nl] + # self.balance = {3: [3.67, 1.0, 0.43], 4: [3.78, 1.0, 0.39, 0.22], 5: [3.88, 1.0, 0.37, 0.17, 0.10]}[det.nl] + self.balance = [1.0] * det.nl self.BCEcls, self.BCEobj, self.gr, self.hyp, self.autobalance = BCEcls, BCEobj, model.gr, h, autobalance for k in 'na', 'nc', 'nl', 'anchors': setattr(self, k, getattr(det, k)) @@ -145,11 +146,11 @@ def __call__(self, p, targets): # predictions, targets, model # [file.write('%11.5g ' * 4 % tuple(x) + '\n') for x in torch.cat((txy[i], twh[i]), 1)] obji = self.BCEobj(pi[..., 4], tobj) - self.balance[i] = self.balance[i] * 0.99 + obji.detach().item().cpu() * 0.01 + self.balance[i] = self.balance[i] * 0.99 + 1. / obji.detach().item() * 0.01 lobj += obji * self.balance[i] # obj loss - self.balance = [x/self.balance[1] for x in self.balance] + self.balance = [x / self.balance[1] for x in self.balance] lbox *= self.hyp['box'] lobj *= self.hyp['obj'] lcls *= self.hyp['cls'] From a37ba340a8758d469b54abb61ae909308ea1fd65 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 13 Jan 2021 12:29:31 -0800 Subject: [PATCH 118/176] ComputeLoss --- utils/loss.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/loss.py b/utils/loss.py index b22aa91366fc..23d3e885b9ee 100644 --- a/utils/loss.py +++ b/utils/loss.py @@ -146,7 +146,7 @@ def __call__(self, p, targets): # predictions, targets, model # [file.write('%11.5g ' * 4 % tuple(x) + '\n') for x in torch.cat((txy[i], twh[i]), 1)] obji = self.BCEobj(pi[..., 4], tobj) - self.balance[i] = self.balance[i] * 0.99 + 1. / obji.detach().item() * 0.01 + self.balance[i] = self.balance[i] * 0.999 + 0.001 / obji.detach().item() lobj += obji * self.balance[i] # obj loss From 18b785364a7c270de678b218a99ba949b19e1f0b Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 13 Jan 2021 12:43:32 -0800 Subject: [PATCH 119/176] ComputeLoss --- utils/loss.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/loss.py b/utils/loss.py index 23d3e885b9ee..55b2d9863d79 100644 --- a/utils/loss.py +++ b/utils/loss.py @@ -146,7 +146,7 @@ def __call__(self, p, targets): # predictions, targets, model # [file.write('%11.5g ' * 4 % tuple(x) + '\n') for x in torch.cat((txy[i], twh[i]), 1)] obji = self.BCEobj(pi[..., 4], tobj) - self.balance[i] = self.balance[i] * 0.999 + 0.001 / obji.detach().item() + self.balance[i] = self.balance[i] * 0.9999 + 0.0001 / obji.detach().item() lobj += obji * self.balance[i] # obj loss From 2faf5537239f70cbf525a13d8134dcb9ac85a76b Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 13 Jan 2021 15:13:06 -0800 Subject: [PATCH 120/176] ComputeLoss --- train.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/train.py b/train.py index 9454f7ba30c1..0a74f384a7c4 100644 --- a/train.py +++ b/train.py @@ -29,7 +29,7 @@ fitness, strip_optimizer, get_latest_run, check_dataset, check_file, check_git_status, check_img_size, \ check_requirements, print_mutation, set_logging, one_cycle, colorstr from utils.google_utils import attempt_download -from utils.loss import compute_loss, ComputeLoss +from utils.loss import ComputeLoss from utils.plots import plot_images, plot_labels, plot_results, plot_evolution from utils.torch_utils import ModelEMA, select_device, intersect_dicts, torch_distributed_zero_first @@ -289,7 +289,6 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): pred = model(imgs) # forward # loss, loss_items = compute_loss(pred, targets.to(device), model) # loss scaled by batch_size loss, loss_items = compute_loss2(pred, targets.to(device)) # loss scaled by batch_size - print(compute_loss2.balance) if rank != -1: loss *= opt.world_size # gradient averaged between devices in DDP mode if opt.quad: @@ -310,8 +309,8 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): if rank in [-1, 0]: mloss = (mloss * i + loss_items) / (i + 1) # update mean losses mem = '%.3gG' % (torch.cuda.memory_reserved() / 1E9 if torch.cuda.is_available() else 0) # (GB) - s = ('%10s' * 2 + '%10.4g' * 6) % ( - '%g/%g' % (epoch, epochs - 1), mem, *mloss, targets.shape[0], imgs.shape[-1]) + s = ('%10s' * 2 + '%10.4g' * 9) % ( + '%g/%g' % (epoch, epochs - 1), mem, *mloss, targets.shape[0], imgs.shape[-1], *compute_loss2.balance) pbar.set_description(s) # Plot From 6d26e7fa7d7cdeb2034639488658a4c87edb487c Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 13 Jan 2021 15:28:12 -0800 Subject: [PATCH 121/176] ComputeLoss --- train.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/train.py b/train.py index 0a74f384a7c4..3f9f0b01e825 100644 --- a/train.py +++ b/train.py @@ -309,9 +309,8 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): if rank in [-1, 0]: mloss = (mloss * i + loss_items) / (i + 1) # update mean losses mem = '%.3gG' % (torch.cuda.memory_reserved() / 1E9 if torch.cuda.is_available() else 0) # (GB) - s = ('%10s' * 2 + '%10.4g' * 9) % ( - '%g/%g' % (epoch, epochs - 1), mem, *mloss, targets.shape[0], imgs.shape[-1], *compute_loss2.balance) - pbar.set_description(s) + s = '%g/%g' % (epoch, epochs - 1), mem, *mloss, targets.shape[0], imgs.shape[-1], *compute_loss2.balance + pbar.set_description(('%10s' * 2 + '%10.4g' * (len(s)-2)) % s) # Plot if plots and ni < 3: From 9a67af2dc90f7f33b7b928ee1ab51b12678ff13e Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 13 Jan 2021 15:34:14 -0800 Subject: [PATCH 122/176] ComputeLoss --- train.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/train.py b/train.py index 3f9f0b01e825..ad69c5a4ef22 100644 --- a/train.py +++ b/train.py @@ -309,8 +309,9 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): if rank in [-1, 0]: mloss = (mloss * i + loss_items) / (i + 1) # update mean losses mem = '%.3gG' % (torch.cuda.memory_reserved() / 1E9 if torch.cuda.is_available() else 0) # (GB) - s = '%g/%g' % (epoch, epochs - 1), mem, *mloss, targets.shape[0], imgs.shape[-1], *compute_loss2.balance - pbar.set_description(('%10s' * 2 + '%10.4g' * (len(s)-2)) % s) + s = f'{epoch}/{epochs - 1}', mem, *mloss, targets.shape[0], imgs.shape[-1], *compute_loss2.balance + s = ('%10s' * 2 + '%10.4g' * (len(s) - 2)) % s + pbar.set_description(s) # Plot if plots and ni < 3: @@ -432,13 +433,13 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): if __name__ == '__main__': parser = argparse.ArgumentParser() - parser.add_argument('--weights', type=str, default='yolov5s.pt', help='initial weights path') - parser.add_argument('--cfg', type=str, default='', help='model.yaml path') + parser.add_argument('--weights', type=str, default='', help='initial weights path') + parser.add_argument('--cfg', type=str, default='yolov5l2-640-4.yaml', help='model.yaml path') parser.add_argument('--data', type=str, default='data/coco128.yaml', help='data.yaml path') parser.add_argument('--hyp', type=str, default='data/hyp.scratch.yaml', help='hyperparameters path') parser.add_argument('--epochs', type=int, default=300) - parser.add_argument('--batch-size', type=int, default=16, help='total batch size for all GPUs') - parser.add_argument('--img-size', nargs='+', type=int, default=[640, 640], help='[train, test] image sizes') + parser.add_argument('--batch-size', type=int, default=2, help='total batch size for all GPUs') + parser.add_argument('--img-size', nargs='+', type=int, default=[320, 320], help='[train, test] image sizes') parser.add_argument('--rect', action='store_true', help='rectangular training') parser.add_argument('--resume', nargs='?', const=True, default=False, help='resume most recent training') parser.add_argument('--nosave', action='store_true', help='only save final checkpoint') From e2ab588fb1a83edf54aa94f3f4792d0d81bb9786 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 13 Jan 2021 15:34:49 -0800 Subject: [PATCH 123/176] ComputeLoss --- train.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/train.py b/train.py index ad69c5a4ef22..65993102d93d 100644 --- a/train.py +++ b/train.py @@ -433,13 +433,13 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): if __name__ == '__main__': parser = argparse.ArgumentParser() - parser.add_argument('--weights', type=str, default='', help='initial weights path') - parser.add_argument('--cfg', type=str, default='yolov5l2-640-4.yaml', help='model.yaml path') + parser.add_argument('--weights', type=str, default='yolov5s.pt', help='initial weights path') + parser.add_argument('--cfg', type=str, default='', help='model.yaml path') parser.add_argument('--data', type=str, default='data/coco128.yaml', help='data.yaml path') parser.add_argument('--hyp', type=str, default='data/hyp.scratch.yaml', help='hyperparameters path') parser.add_argument('--epochs', type=int, default=300) parser.add_argument('--batch-size', type=int, default=2, help='total batch size for all GPUs') - parser.add_argument('--img-size', nargs='+', type=int, default=[320, 320], help='[train, test] image sizes') + parser.add_argument('--img-size', nargs='+', type=int, default=[640, 640], help='[train, test] image sizes') parser.add_argument('--rect', action='store_true', help='rectangular training') parser.add_argument('--resume', nargs='?', const=True, default=False, help='resume most recent training') parser.add_argument('--nosave', action='store_true', help='only save final checkpoint') From e22c68e6e0ea9b88ba0655ad02b5830533cf81f7 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 13 Jan 2021 15:35:21 -0800 Subject: [PATCH 124/176] ComputeLoss --- train.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/train.py b/train.py index 65993102d93d..c64174c2fe0b 100644 --- a/train.py +++ b/train.py @@ -438,7 +438,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): parser.add_argument('--data', type=str, default='data/coco128.yaml', help='data.yaml path') parser.add_argument('--hyp', type=str, default='data/hyp.scratch.yaml', help='hyperparameters path') parser.add_argument('--epochs', type=int, default=300) - parser.add_argument('--batch-size', type=int, default=2, help='total batch size for all GPUs') + parser.add_argument('--batch-size', type=int, default=16, help='total batch size for all GPUs') parser.add_argument('--img-size', nargs='+', type=int, default=[640, 640], help='[train, test] image sizes') parser.add_argument('--rect', action='store_true', help='rectangular training') parser.add_argument('--resume', nargs='?', const=True, default=False, help='resume most recent training') From 1e6896a42fde4f5eabdd3e6327ec55a1e8669e32 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 13 Jan 2021 16:19:19 -0800 Subject: [PATCH 125/176] ComputeLoss --- utils/loss.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utils/loss.py b/utils/loss.py index 55b2d9863d79..3e9bc18269b6 100644 --- a/utils/loss.py +++ b/utils/loss.py @@ -107,6 +107,7 @@ def __init__(self, model, autobalance=True): det = model.module.model[-1] if is_parallel(model) else model.model[-1] # Detect() module # self.balance = {3: [3.67, 1.0, 0.43], 4: [3.78, 1.0, 0.39, 0.22], 5: [3.88, 1.0, 0.37, 0.17, 0.10]}[det.nl] self.balance = [1.0] * det.nl + self.ssi = (det.stride == 16).nonzero().item() # stride 16 index self.BCEcls, self.BCEobj, self.gr, self.hyp, self.autobalance = BCEcls, BCEobj, model.gr, h, autobalance for k in 'na', 'nc', 'nl', 'anchors': setattr(self, k, getattr(det, k)) @@ -150,7 +151,7 @@ def __call__(self, p, targets): # predictions, targets, model lobj += obji * self.balance[i] # obj loss - self.balance = [x / self.balance[1] for x in self.balance] + self.balance = [x / self.balance[self.ssi] for x in self.balance] lbox *= self.hyp['box'] lobj *= self.hyp['obj'] lcls *= self.hyp['cls'] From 86e86248914aa71d2134d0b0640888ff49d055b3 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 14 Jan 2021 20:03:39 -0800 Subject: [PATCH 126/176] astuple --- utils/loss.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/loss.py b/utils/loss.py index 3e9bc18269b6..02d5e3e4b9cd 100644 --- a/utils/loss.py +++ b/utils/loss.py @@ -107,7 +107,7 @@ def __init__(self, model, autobalance=True): det = model.module.model[-1] if is_parallel(model) else model.model[-1] # Detect() module # self.balance = {3: [3.67, 1.0, 0.43], 4: [3.78, 1.0, 0.39, 0.22], 5: [3.88, 1.0, 0.37, 0.17, 0.10]}[det.nl] self.balance = [1.0] * det.nl - self.ssi = (det.stride == 16).nonzero().item() # stride 16 index + self.ssi = (det.stride == 16).nonzero(as_tuple=False).item() # stride 16 index self.BCEcls, self.BCEobj, self.gr, self.hyp, self.autobalance = BCEcls, BCEobj, model.gr, h, autobalance for k in 'na', 'nc', 'nl', 'anchors': setattr(self, k, getattr(det, k)) From c9bd7d1d64d6134e44637b83a4e88dfb8d04264e Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 14 Jan 2021 20:40:55 -0800 Subject: [PATCH 127/176] epochs --- train.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/train.py b/train.py index fcf76b92393e..b3f961fbbffb 100644 --- a/train.py +++ b/train.py @@ -363,7 +363,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): if tb_writer: tb_writer.add_scalar(tag, x, epoch) # tensorboard if wandb: - wandb.log({tag: x}) # W&B + wandb.log({tag: x, 'epoch': epoch}) # W&B # Update best mAP fi = fitness(np.array(results).reshape(1, -1)) # weighted combination of [P, R, mAP@.5, mAP@.5-.95] From 0f5dfc8d7a0130b81f7d821313f29c09da4a22a2 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 14 Jan 2021 21:11:47 -0800 Subject: [PATCH 128/176] update --- train.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/train.py b/train.py index b3f961fbbffb..fcf76b92393e 100644 --- a/train.py +++ b/train.py @@ -363,7 +363,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): if tb_writer: tb_writer.add_scalar(tag, x, epoch) # tensorboard if wandb: - wandb.log({tag: x, 'epoch': epoch}) # W&B + wandb.log({tag: x}) # W&B # Update best mAP fi = fitness(np.array(results).reshape(1, -1)) # weighted combination of [P, R, mAP@.5, mAP@.5-.95] From 640b7bcbed25e5ca987babac50a166b89b6955df Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 14 Jan 2021 21:56:02 -0800 Subject: [PATCH 129/176] update --- utils/loss.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/loss.py b/utils/loss.py index 02d5e3e4b9cd..a0f6720816c3 100644 --- a/utils/loss.py +++ b/utils/loss.py @@ -146,8 +146,8 @@ def __call__(self, p, targets): # predictions, targets, model # with open('targets.txt', 'a') as file: # [file.write('%11.5g ' * 4 % tuple(x) + '\n') for x in torch.cat((txy[i], twh[i]), 1)] - obji = self.BCEobj(pi[..., 4], tobj) - self.balance[i] = self.balance[i] * 0.9999 + 0.0001 / obji.detach().item() + obji = self.BCEobj(pi[..., 4], tobj) + self.balance[i] = self.balance[i] * 0.9999 + 0.0001 / obji.detach().item() lobj += obji * self.balance[i] # obj loss From a1e27e6b827ed5d03f5bc03c5dd8bbae7fe7cc49 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Fri, 15 Jan 2021 13:14:51 -0800 Subject: [PATCH 130/176] ComputeLoss() --- train.py | 7 ++- utils/loss.py | 119 -------------------------------------------------- 2 files changed, 3 insertions(+), 123 deletions(-) diff --git a/train.py b/train.py index cb8ca601d600..ccc91fd9784c 100644 --- a/train.py +++ b/train.py @@ -227,7 +227,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): results = (0, 0, 0, 0, 0, 0, 0) # P, R, mAP@.5, mAP@.5-.95, val_loss(box, obj, cls) scheduler.last_epoch = start_epoch - 1 # do not move scaler = amp.GradScaler(enabled=cuda) - compute_loss2 = ComputeLoss(model) + compute_loss = ComputeLoss(model) # init loss class logger.info(f'Image sizes {imgsz} train, {imgsz_test} test\n' f'Using {dataloader.num_workers} dataloader workers\n' f'Logging results to {save_dir}\n' @@ -287,8 +287,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): # Forward with amp.autocast(enabled=cuda): pred = model(imgs) # forward - # loss, loss_items = compute_loss(pred, targets.to(device), model) # loss scaled by batch_size - loss, loss_items = compute_loss2(pred, targets.to(device)) # loss scaled by batch_size + loss, loss_items = compute_loss(pred, targets.to(device)) # loss scaled by batch_size if rank != -1: loss *= opt.world_size # gradient averaged between devices in DDP mode if opt.quad: @@ -309,7 +308,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): if rank in [-1, 0]: mloss = (mloss * i + loss_items) / (i + 1) # update mean losses mem = '%.3gG' % (torch.cuda.memory_reserved() / 1E9 if torch.cuda.is_available() else 0) # (GB) - s = f'{epoch}/{epochs - 1}', mem, *mloss, targets.shape[0], imgs.shape[-1], *compute_loss2.balance + s = f'{epoch}/{epochs - 1}', mem, *mloss, targets.shape[0], imgs.shape[-1], *compute_loss.balance s = ('%10s' * 2 + '%10.4g' * (len(s) - 2)) % s pbar.set_description(s) diff --git a/utils/loss.py b/utils/loss.py index a0f6720816c3..95c9e52840fb 100644 --- a/utils/loss.py +++ b/utils/loss.py @@ -214,122 +214,3 @@ def build_targets(self, p, targets): tcls.append(c) # class return tcls, tbox, indices, anch - - -def compute_loss(p, targets, model): # predictions, targets, model - device = targets.device - lcls, lbox, lobj = torch.zeros(1, device=device), torch.zeros(1, device=device), torch.zeros(1, device=device) - tcls, tbox, indices, anchors = build_targets(p, targets, model) # targets - h = model.hyp # hyperparameters - - # Define criteria - BCEcls = nn.BCEWithLogitsLoss(pos_weight=torch.tensor([h['cls_pw']], device=device)) # weight=model.class_weights) - BCEobj = nn.BCEWithLogitsLoss(pos_weight=torch.tensor([h['obj_pw']], device=device)) - - # Class label smoothing https://arxiv.org/pdf/1902.04103.pdf eqn 3 - cp, cn = smooth_BCE(eps=0.0) - - # Focal loss - g = h['fl_gamma'] # focal loss gamma - if g > 0: - BCEcls, BCEobj = FocalLoss(BCEcls, g), FocalLoss(BCEobj, g) - - # Losses - nt = 0 # number of targets - no = len(p) # number of outputs - balance = {3: [3.67, 1.0, 0.43], 4: [3.78, 1.0, 0.39, 0.22], 5: [3.88, 1.0, 0.37, 0.17, 0.10]}[no] # P3-P7 - for i, pi in enumerate(p): # layer index, layer predictions - b, a, gj, gi = indices[i] # image, anchor, gridy, gridx - tobj = torch.zeros_like(pi[..., 0], device=device) # target obj - - n = b.shape[0] # number of targets - if n: - nt += n # cumulative targets - ps = pi[b, a, gj, gi] # prediction subset corresponding to targets - - # Regression - pxy = ps[:, :2].sigmoid() * 2. - 0.5 - pwh = (ps[:, 2:4].sigmoid() * 2) ** 2 * anchors[i] - pbox = torch.cat((pxy, pwh), 1) # predicted box - iou = bbox_iou(pbox.T, tbox[i], x1y1x2y2=False, CIoU=True) # iou(prediction, target) - lbox += (1.0 - iou).mean() # iou loss - - # Objectness - tobj[b, a, gj, gi] = (1.0 - model.gr) + model.gr * iou.detach().clamp(0).type(tobj.dtype) # iou ratio - - # Classification - if model.nc > 1: # cls loss (only if multiple classes) - t = torch.full_like(ps[:, 5:], cn, device=device) # targets - t[range(n), tcls[i]] = cp - lcls += BCEcls(ps[:, 5:], t) # BCE - - # Append targets to text file - # with open('targets.txt', 'a') as file: - # [file.write('%11.5g ' * 4 % tuple(x) + '\n') for x in torch.cat((txy[i], twh[i]), 1)] - - lobj += BCEobj(pi[..., 4], tobj) * balance[i] # obj loss - - lbox *= h['box'] - lobj *= h['obj'] - lcls *= h['cls'] - bs = tobj.shape[0] # batch size - - loss = lbox + lobj + lcls - return loss * bs, torch.cat((lbox, lobj, lcls, loss)).detach() - - -def build_targets(p, targets, model): - # Build targets for compute_loss(), input targets(image,class,x,y,w,h) - det = model.module.model[-1] if is_parallel(model) else model.model[-1] # Detect() module - na, nt = det.na, targets.shape[0] # number of anchors, targets - tcls, tbox, indices, anch = [], [], [], [] - gain = torch.ones(7, device=targets.device) # normalized to gridspace gain - ai = torch.arange(na, device=targets.device).float().view(na, 1).repeat(1, nt) # same as .repeat_interleave(nt) - targets = torch.cat((targets.repeat(na, 1, 1), ai[:, :, None]), 2) # append anchor indices - - g = 0.5 # bias - off = torch.tensor([[0, 0], - [1, 0], [0, 1], [-1, 0], [0, -1], # j,k,l,m - # [1, 1], [1, -1], [-1, 1], [-1, -1], # jk,jm,lk,lm - ], device=targets.device).float() * g # offsets - - for i in range(det.nl): - anchors = det.anchors[i] - gain[2:6] = torch.tensor(p[i].shape)[[3, 2, 3, 2]] # xyxy gain - - # Match targets to anchors - t = targets * gain - if nt: - # Matches - r = t[:, :, 4:6] / anchors[:, None] # wh ratio - j = torch.max(r, 1. / r).max(2)[0] < model.hyp['anchor_t'] # compare - # j = wh_iou(anchors, t[:, 4:6]) > model.hyp['iou_t'] # iou(3,n)=wh_iou(anchors(3,2), gwh(n,2)) - t = t[j] # filter - - # Offsets - gxy = t[:, 2:4] # grid xy - gxi = gain[[2, 3]] - gxy # inverse - j, k = ((gxy % 1. < g) & (gxy > 1.)).T - l, m = ((gxi % 1. < g) & (gxi > 1.)).T - j = torch.stack((torch.ones_like(j), j, k, l, m)) - t = t.repeat((5, 1, 1))[j] - offsets = (torch.zeros_like(gxy)[None] + off[:, None])[j] - else: - t = targets[0] - offsets = 0 - - # Define - b, c = t[:, :2].long().T # image, class - gxy = t[:, 2:4] # grid xy - gwh = t[:, 4:6] # grid wh - gij = (gxy - offsets).long() - gi, gj = gij.T # grid xy indices - - # Append - a = t[:, 6].long() # anchor indices - indices.append((b, a, gj.clamp_(0, gain[3] - 1), gi.clamp_(0, gain[2] - 1))) # image, anchor, grid indices - tbox.append(torch.cat((gxy - gij, gwh), 1)) # box - anch.append(anchors[a]) # anchors - tcls.append(c) # class - - return tcls, tbox, indices, anch From 20f64f46106aa877aaaa7019de643c6cf4fe11b7 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Fri, 15 Jan 2021 14:56:53 -0800 Subject: [PATCH 131/176] update --- test.py | 4 ++-- train.py | 13 +++++++++---- utils/loss.py | 12 ++++++------ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/test.py b/test.py index e6b1f023e49a..300a6e53e8c9 100644 --- a/test.py +++ b/test.py @@ -95,7 +95,7 @@ def test(data, coco91class = coco80_to_coco91_class() s = ('%20s' + '%12s' * 6) % ('Class', 'Images', 'Targets', 'P', 'R', 'mAP@.5', 'mAP@.5:.95') p, r, f1, mp, mr, map50, map, t0, t1 = 0., 0., 0., 0., 0., 0., 0., 0., 0. - loss = torch.zeros(3, device=device) + loss = torch.zeros(12, device=device) jdict, stats, ap, ap_class, wandb_images = [], [], [], [], [] for batch_i, (img, targets, paths, shapes) in enumerate(tqdm(dataloader, desc=s)): img = img.to(device, non_blocking=True) @@ -112,7 +112,7 @@ def test(data, # Compute loss if compute_loss: - loss += compute_loss([x.float() for x in train_out], targets)[1][:3] # box, obj, cls + loss += compute_loss([x.float() for x in train_out], targets)[1][:-1] # box, obj, cls # Run NMS targets[:, 2:] *= torch.Tensor([width, height, width, height]).to(device) # to pixels diff --git a/train.py b/train.py index fe0e19cfef66..331cac5af06f 100644 --- a/train.py +++ b/train.py @@ -253,7 +253,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): # b = int(random.uniform(0.25 * imgsz, 0.75 * imgsz + gs) // gs * gs) # dataset.mosaic_border = [b - imgsz, -b] # height, width borders - mloss = torch.zeros(4, device=device) # mean losses + mloss = torch.zeros(13, device=device) # mean losses if rank != -1: dataloader.sampler.set_epoch(epoch) pbar = enumerate(dataloader) @@ -350,14 +350,19 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): # Write with open(results_file, 'a') as f: - f.write(s + '%10.4g' * 7 % results + '\n') # P, R, mAP@.5, mAP@.5-.95, val_loss(box, obj, cls) + f.write( + s + '%10.4g' * len(results) % results + '\n') # P, R, mAP@.5, mAP@.5-.95, val_loss(box, obj, cls) if len(opt.name) and opt.bucket: os.system('gsutil cp %s gs://%s/results/results%s.txt' % (results_file, opt.bucket, opt.name)) # Log - tags = ['train/box_loss', 'train/obj_loss', 'train/cls_loss', # train loss + tags = ['train/box_loss3', 'train/box_loss4', 'train/box_loss5', 'train/box_loss6', # train loss + 'train/obj_loss3', 'train/obj_loss4', 'train/obj_loss5', 'train/obj_loss6', # train loss + 'train/cls_loss3', 'train/cls_loss4', 'train/cls_loss5', 'train/cls_loss6', # train loss 'metrics/precision', 'metrics/recall', 'metrics/mAP_0.5', 'metrics/mAP_0.5:0.95', - 'val/box_loss', 'val/obj_loss', 'val/cls_loss', # val loss + 'val/box_loss3', 'val/box_loss4', 'val/box_loss5', 'val/box_loss6', # train loss + 'val/obj_loss3', 'val/obj_loss4', 'val/obj_loss5', 'val/obj_loss6', # train loss + 'val/cls_loss3', 'val/cls_loss4', 'val/cls_loss5', 'val/cls_loss6', # train loss 'x/lr0', 'x/lr1', 'x/lr2'] # params for x, tag in zip(list(mloss[:-1]) + list(results) + lr, tags): if tb_writer: diff --git a/utils/loss.py b/utils/loss.py index 889ddf7295da..e170d97f4ed9 100644 --- a/utils/loss.py +++ b/utils/loss.py @@ -114,7 +114,7 @@ def __init__(self, model, autobalance=False): def __call__(self, p, targets): # predictions, targets, model device = targets.device - lcls, lbox, lobj = torch.zeros(1, device=device), torch.zeros(1, device=device), torch.zeros(1, device=device) + lcls, lbox, lobj = torch.zeros(self.nl, device=device), torch.zeros(self.nl, device=device), torch.zeros(self.nl, device=device) tcls, tbox, indices, anchors = self.build_targets(p, targets) # targets # Losses @@ -131,7 +131,7 @@ def __call__(self, p, targets): # predictions, targets, model pwh = (ps[:, 2:4].sigmoid() * 2) ** 2 * anchors[i] pbox = torch.cat((pxy, pwh), 1) # predicted box iou = bbox_iou(pbox.T, tbox[i], x1y1x2y2=False, CIoU=True) # iou(prediction, target) - lbox += (1.0 - iou).mean() # iou loss + lbox[i] = (1.0 - iou).mean() # iou loss # Objectness tobj[b, a, gj, gi] = (1.0 - self.gr) + self.gr * iou.detach().clamp(0).type(tobj.dtype) # iou ratio @@ -140,14 +140,14 @@ def __call__(self, p, targets): # predictions, targets, model if self.nc > 1: # cls loss (only if multiple classes) t = torch.full_like(ps[:, 5:], self.cn, device=device) # targets t[range(n), tcls[i]] = self.cp - lcls += self.BCEcls(ps[:, 5:], t) # BCE + lcls[i] = self.BCEcls(ps[:, 5:], t) # BCE # Append targets to text file # with open('targets.txt', 'a') as file: # [file.write('%11.5g ' * 4 % tuple(x) + '\n') for x in torch.cat((txy[i], twh[i]), 1)] obji = self.BCEobj(pi[..., 4], tobj) - lobj += obji * self.balance[i] # obj loss + lobj[i] = obji * self.balance[i] # obj loss if self.autobalance: self.balance[i] = self.balance[i] * 0.9999 + 0.0001 / obji.detach().item() @@ -158,8 +158,8 @@ def __call__(self, p, targets): # predictions, targets, model lcls *= self.hyp['cls'] bs = tobj.shape[0] # batch size - loss = lbox + lobj + lcls - return loss * bs, torch.cat((lbox, lobj, lcls, loss)).detach() + loss = (lbox + lobj + lcls).sum() + return loss * bs, torch.cat((lbox, lobj, lcls, loss[None])).detach() def build_targets(self, p, targets): # Build targets for compute_loss(), input targets(image,class,x,y,w,h) From 270aab4ff928dd91476c7bd12e4ffd91437528eb Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Fri, 15 Jan 2021 15:12:10 -0800 Subject: [PATCH 132/176] update --- train.py | 3 ++- utils/loss.py | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/train.py b/train.py index 331cac5af06f..deb449601136 100644 --- a/train.py +++ b/train.py @@ -227,7 +227,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): results = (0, 0, 0, 0, 0, 0, 0) # P, R, mAP@.5, mAP@.5-.95, val_loss(box, obj, cls) scheduler.last_epoch = start_epoch - 1 # do not move scaler = amp.GradScaler(enabled=cuda) - compute_loss = ComputeLoss(model) # init loss class + compute_loss = ComputeLoss(model, autobalance=opt.autobalance) # init loss class logger.info(f'Image sizes {imgsz} train, {imgsz_test} test\n' f'Using {dataloader.num_workers} dataloader workers\n' f'Logging results to {save_dir}\n' @@ -468,6 +468,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): parser.add_argument('--name', default='exp', help='save to project/name') parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment') parser.add_argument('--quad', action='store_true', help='quad dataloader') + parser.add_argument('--autobalance', action='store_true', help='autobalance') opt = parser.parse_args() # Set DDP variables diff --git a/utils/loss.py b/utils/loss.py index e170d97f4ed9..e7ef2ead33cf 100644 --- a/utils/loss.py +++ b/utils/loss.py @@ -105,7 +105,8 @@ def __init__(self, model, autobalance=False): BCEcls, BCEobj = FocalLoss(BCEcls, g), FocalLoss(BCEobj, g) det = model.module.model[-1] if is_parallel(model) else model.model[-1] # Detect() module - self.balance = {3: [3.67, 1.0, 0.43], 4: [3.78, 1.0, 0.39, 0.22], 5: [3.88, 1.0, 0.37, 0.17, 0.10]}[det.nl] + # self.balance = {3: [3.67, 1.0, 0.43], 4: [3.78, 1.0, 0.39, 0.22], 5: [3.88, 1.0, 0.37, 0.17, 0.10]}[det.nl] + self.balance = {3: [3.67, 1.0, 0.43], 4: [4.0, 1.0, 0.4, 0.1], 5: [3.88, 1.0, 0.37, 0.17, 0.10]}[det.nl] # self.balance = [1.0] * det.nl self.ssi = (det.stride == 16).nonzero(as_tuple=False).item() # stride 16 index self.BCEcls, self.BCEobj, self.gr, self.hyp, self.autobalance = BCEcls, BCEobj, model.gr, h, autobalance @@ -114,7 +115,8 @@ def __init__(self, model, autobalance=False): def __call__(self, p, targets): # predictions, targets, model device = targets.device - lcls, lbox, lobj = torch.zeros(self.nl, device=device), torch.zeros(self.nl, device=device), torch.zeros(self.nl, device=device) + lcls, lbox, lobj = torch.zeros(self.nl, device=device), torch.zeros(self.nl, device=device), torch.zeros( + self.nl, device=device) tcls, tbox, indices, anchors = self.build_targets(p, targets) # targets # Losses @@ -154,7 +156,7 @@ def __call__(self, p, targets): # predictions, targets, model if self.autobalance: self.balance = [x / self.balance[self.ssi] for x in self.balance] lbox *= self.hyp['box'] - lobj *= self.hyp['obj'] + lobj *= self.hyp['obj'] * 1.4 lcls *= self.hyp['cls'] bs = tobj.shape[0] # batch size From 0704da574d6d1d016dbef6b8b3f9f17877917926 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 16 Jan 2021 00:44:39 -0800 Subject: [PATCH 133/176] update --- utils/loss.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/utils/loss.py b/utils/loss.py index 889ddf7295da..9373da16ea92 100644 --- a/utils/loss.py +++ b/utils/loss.py @@ -105,7 +105,8 @@ def __init__(self, model, autobalance=False): BCEcls, BCEobj = FocalLoss(BCEcls, g), FocalLoss(BCEobj, g) det = model.module.model[-1] if is_parallel(model) else model.model[-1] # Detect() module - self.balance = {3: [3.67, 1.0, 0.43], 4: [3.78, 1.0, 0.39, 0.22], 5: [3.88, 1.0, 0.37, 0.17, 0.10]}[det.nl] + self.balance = {3: [3.67, 1.0, 0.43], 4: [4.00, 1.0, 0.4, 0.10], 5: [3.88, 1.0, 0.37, 0.17, 0.10]}[det.nl] + # self.balance = {3: [3.67, 1.0, 0.43], 4: [3.78, 1.0, 0.39, 0.22], 5: [3.88, 1.0, 0.37, 0.17, 0.10]}[det.nl] # self.balance = [1.0] * det.nl self.ssi = (det.stride == 16).nonzero(as_tuple=False).item() # stride 16 index self.BCEcls, self.BCEobj, self.gr, self.hyp, self.autobalance = BCEcls, BCEobj, model.gr, h, autobalance @@ -154,7 +155,7 @@ def __call__(self, p, targets): # predictions, targets, model if self.autobalance: self.balance = [x / self.balance[self.ssi] for x in self.balance] lbox *= self.hyp['box'] - lobj *= self.hyp['obj'] + lobj *= self.hyp['obj'] * 1.4 lcls *= self.hyp['cls'] bs = tobj.shape[0] # batch size From 8d94cf9ec22ba6c4d75593d0dd2d2240cbcab4a0 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 16 Jan 2021 01:37:04 -0800 Subject: [PATCH 134/176] update --- data/hyp.scratch.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/hyp.scratch.yaml b/data/hyp.scratch.yaml index 6925446dbd8d..458179446ce9 100644 --- a/data/hyp.scratch.yaml +++ b/data/hyp.scratch.yaml @@ -4,7 +4,7 @@ lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) -lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) +lrf: 0.15 # final OneCycleLR learning rate (lr0 * lrf) momentum: 0.937 # SGD momentum/Adam beta1 weight_decay: 0.0005 # optimizer weight decay 5e-4 warmup_epochs: 3.0 # warmup epochs (fractions ok) @@ -24,7 +24,7 @@ hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) hsv_v: 0.4 # image HSV-Value augmentation (fraction) degrees: 0.0 # image rotation (+/- deg) translate: 0.1 # image translation (+/- fraction) -scale: 0.9 # image scale (+/- gain) +scale: 0.95 # image scale (+/- gain) shear: 0.0 # image shear (+/- deg) perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 flipud: 0.0 # image flip up-down (probability) From fb768e6fb406b46c8fccf67c373392960dd8dd38 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 16 Jan 2021 02:16:30 -0800 Subject: [PATCH 135/176] update --- utils/general.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/general.py b/utils/general.py index 3247b66da0ce..b71570628d5e 100755 --- a/utils/general.py +++ b/utils/general.py @@ -24,7 +24,7 @@ torch.set_printoptions(linewidth=320, precision=5, profile='long') np.set_printoptions(linewidth=320, formatter={'float_kind': '{:11.5g}'.format}) # format short g, %precision=5 cv2.setNumThreads(0) # prevent OpenCV from multithreading (incompatible with PyTorch DataLoader) -os.environ['NUMEXPR_MAX_THREADS'] = str(min(os.cpu_count(), 8)) # NumExpr max threads +os.environ['NUMEXPR_MAX_THREADS'] = str(min(os.cpu_count(), 16)) # NumExpr max threads def set_logging(rank=-1): From d0c901b46f8391e32cca54b59679accb097676a4 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 16 Jan 2021 02:17:15 -0800 Subject: [PATCH 136/176] update --- utils/general.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/general.py b/utils/general.py index b71570628d5e..3247b66da0ce 100755 --- a/utils/general.py +++ b/utils/general.py @@ -24,7 +24,7 @@ torch.set_printoptions(linewidth=320, precision=5, profile='long') np.set_printoptions(linewidth=320, formatter={'float_kind': '{:11.5g}'.format}) # format short g, %precision=5 cv2.setNumThreads(0) # prevent OpenCV from multithreading (incompatible with PyTorch DataLoader) -os.environ['NUMEXPR_MAX_THREADS'] = str(min(os.cpu_count(), 16)) # NumExpr max threads +os.environ['NUMEXPR_MAX_THREADS'] = str(min(os.cpu_count(), 8)) # NumExpr max threads def set_logging(rank=-1): From 342ad43db62557041ead800340e19aa40ef7c183 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 16 Jan 2021 02:21:02 -0800 Subject: [PATCH 137/176] update --- test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.py b/test.py index e6b1f023e49a..9f871d72e4d1 100644 --- a/test.py +++ b/test.py @@ -324,7 +324,7 @@ def test(data, elif opt.task == 'study': # run over a range of settings and save/plot for weights in opt.weights: # ['yolov5s.pt', 'yolov5m.pt', 'yolov5l.pt', 'yolov5x.pt']: f = 'study_%s_%s.txt' % (Path(opt.data).stem, Path(weights).stem) # filename to save to - x = list(range(320, 1344, 64)) # x axis + x = list(range(256, 1408, 128)) # x axis y = [] # y axis for i in x: # img-size print('\nRunning %s point %s...' % (f, i)) From 7846e414e94caf3badace0dbf5ba0ad09bec49ff Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 16 Jan 2021 02:30:46 -0800 Subject: [PATCH 138/176] update --- utils/loss.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/loss.py b/utils/loss.py index 9373da16ea92..96b26aa8eb45 100644 --- a/utils/loss.py +++ b/utils/loss.py @@ -155,7 +155,7 @@ def __call__(self, p, targets): # predictions, targets, model if self.autobalance: self.balance = [x / self.balance[self.ssi] for x in self.balance] lbox *= self.hyp['box'] - lobj *= self.hyp['obj'] * 1.4 + lobj *= self.hyp['obj'] * 1.4 * 3 / 4 lcls *= self.hyp['cls'] bs = tobj.shape[0] # batch size From e02d1a88348d15a66e5f6d8072b2d6d6e245854b Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 16 Jan 2021 13:25:03 -0800 Subject: [PATCH 139/176] update --- models/common.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/models/common.py b/models/common.py index 3bfdb3c7dc14..7b19a2820be1 100644 --- a/models/common.py +++ b/models/common.py @@ -109,7 +109,8 @@ def __init__(self, c1, c2, k=1, s=1, p=None, g=1, act=True): # ch_in, ch_out, k # self.contract = Contract(gain=2) def forward(self, x): # x(b,c,w,h) -> y(b,4c,w/2,h/2) - return self.conv(torch.cat([x[..., ::2, ::2], x[..., 1::2, ::2], x[..., ::2, 1::2], x[..., 1::2, 1::2]], 1)) + x = torch.cat([x[..., ::2, ::2], x[..., 1::2, ::2], x[..., ::2, 1::2], x[..., 1::2, 1::2]], 1) + return self.conv(x) # return self.conv(self.contract(x)) From 8c38674c36de8453e1851bf12a30ff62c68fb981 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 16 Jan 2021 14:46:08 -0800 Subject: [PATCH 140/176] update --- train.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/train.py b/train.py index fe0e19cfef66..c4f43e427cdf 100644 --- a/train.py +++ b/train.py @@ -338,7 +338,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): final_epoch = epoch + 1 == epochs if not opt.notest or final_epoch: # Calculate mAP results, maps, times = test.test(opt.data, - batch_size=total_batch_size, + batch_size=batch_size * 2, imgsz=imgsz_test, model=ema.ema, single_cls=opt.single_cls, From 51a2b7924f2f34c07f5b26e40187d888c3f1152e Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 16 Jan 2021 14:48:47 -0800 Subject: [PATCH 141/176] update --- train.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/train.py b/train.py index c4f43e427cdf..d7aeab862bf9 100644 --- a/train.py +++ b/train.py @@ -190,7 +190,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): # Process 0 if rank in [-1, 0]: ema.updates = start_epoch * nb // accumulate # set EMA updates - testloader = create_dataloader(test_path, imgsz_test, total_batch_size, gs, opt, # testloader + testloader = create_dataloader(test_path, imgsz_test, batch_size * 2, gs, opt, # testloader hyp=hyp, cache=opt.cache_images and not opt.notest, rect=True, rank=-1, world_size=opt.world_size, workers=opt.workers, pad=0.5, prefix=colorstr('val: '))[0] From 125cacfa3425ab2d7e66c26996a17d44166da25c Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 17 Jan 2021 20:06:16 -0800 Subject: [PATCH 142/176] merge --- models/hub/experimental/yolov5l26-1280.yaml | 69 +++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 models/hub/experimental/yolov5l26-1280.yaml diff --git a/models/hub/experimental/yolov5l26-1280.yaml b/models/hub/experimental/yolov5l26-1280.yaml new file mode 100644 index 000000000000..07f72b6e37e3 --- /dev/null +++ b/models/hub/experimental/yolov5l26-1280.yaml @@ -0,0 +1,69 @@ +# parameters +nc: 80 # number of classes +depth_multiple: 1.0 # model depth multiple +width_multiple: 1.0 # layer channel multiple + +# anchors +anchors: + - [ 19,27, 44,40, 38,94 ] # P3/8 + - [ 96,68, 86,152, 180,137 ] # P4/16 + - [ 140,301, 303,264, 238,542 ] # P5/32 + - [ 436,615, 739,380, 925,792 ] # P6/64 + +# 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, [ 768, 3, 2 ] ], # 7-P5/32 + [ -1, 3, C3, [ 768 ] ], + [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 + [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ], + [ -1, 3, C3, [ 1024, False ] ], # 11 + ] + +# YOLOv5 head +head: + [ [ -1, 1, Conv, [ 768, 1, 1 ] ], + [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], + [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 + [ -1, 3, C3, [ 768, False ] ], # 15 + + [ -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 ] ], # 19 + + [ -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 ] ], # 23 + + [ -1, 1, Conv, [ 128, 1, 1 ] ], + [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], + [ [ -1, 2 ], 1, Concat, [ 1 ] ], # cat backbone P2 + [ -1, 1, C3, [ 128, False ] ], # 27 (P2/4-xsmall) + + [ -1, 1, Conv, [ 128, 3, 2 ] ], + [ [ -1, 24 ], 1, Concat, [ 1 ] ], # cat head P3 + [ -1, 3, C3, [ 256, False ] ], # 30 (P3/8-small) + + [ -1, 1, Conv, [ 256, 3, 2 ] ], + [ [ -1, 20 ], 1, Concat, [ 1 ] ], # cat head P4 + [ -1, 3, C3, [ 512, False ] ], # 33 (P4/16-medium) + + [ -1, 1, Conv, [ 512, 3, 2 ] ], + [ [ -1, 16 ], 1, Concat, [ 1 ] ], # cat head P5 + [ -1, 3, C3, [ 768, False ] ], # 36 (P5/32-large) + + [ -1, 1, Conv, [ 768, 3, 2 ] ], + [ [ -1, 12 ], 1, Concat, [ 1 ] ], # cat head P6 + [ -1, 3, C3, [ 1024, False ] ], # 39 (P5/64-xlarge) + + [ [ 30, 33, 36, 39 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) + ] From 73c0f7a6a13d3bbc76aa0b43a9dde4700522c521 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 21 Jan 2021 12:15:08 -0800 Subject: [PATCH 143/176] merge --- data/hyp.scratch.yaml | 2 +- utils/loss.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/data/hyp.scratch.yaml b/data/hyp.scratch.yaml index 6925446dbd8d..51d2fda3d51b 100644 --- a/data/hyp.scratch.yaml +++ b/data/hyp.scratch.yaml @@ -13,7 +13,7 @@ warmup_bias_lr: 0.1 # warmup initial bias lr box: 0.05 # box loss gain cls: 0.3 # cls loss gain cls_pw: 1.0 # cls BCELoss positive_weight -obj: 0.5 # obj loss gain (scale with pixels) +obj: 0.7 # obj loss gain (scale with pixels) obj_pw: 1.0 # obj BCELoss positive_weight iou_t: 0.20 # IoU training threshold anchor_t: 4.0 # anchor-multiple threshold diff --git a/utils/loss.py b/utils/loss.py index 1f46ce92a5c6..1505575ede09 100644 --- a/utils/loss.py +++ b/utils/loss.py @@ -156,7 +156,7 @@ def __call__(self, p, targets): # predictions, targets, model if self.autobalance: self.balance = [x / self.balance[self.ssi] for x in self.balance] lbox *= self.hyp['box'] - lobj *= self.hyp['obj'] * 1.4 + lobj *= self.hyp['obj'] lcls *= self.hyp['cls'] bs = tobj.shape[0] # batch size From 5b3597dcdbd9fb991d50560d973883ede5580f70 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 21 Jan 2021 13:06:44 -0800 Subject: [PATCH 144/176] merge --- data/hyp.lrf001.yaml | 33 +++++++++++++++++++++++++++++++++ data/hyp.lrf01.yaml | 2 +- train.py | 6 +++++- 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 data/hyp.lrf001.yaml diff --git a/data/hyp.lrf001.yaml b/data/hyp.lrf001.yaml new file mode 100644 index 000000000000..53635e299276 --- /dev/null +++ b/data/hyp.lrf001.yaml @@ -0,0 +1,33 @@ +# Hyperparameters for COCO training from scratch +# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 +# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials + + +lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) +lrf: 0.01 # final OneCycleLR learning rate (lr0 * lrf) +momentum: 0.937 # SGD momentum/Adam beta1 +weight_decay: 0.0005 # optimizer weight decay 5e-4 +warmup_epochs: 3.0 # warmup epochs (fractions ok) +warmup_momentum: 0.8 # warmup initial momentum +warmup_bias_lr: 0.1 # warmup initial bias lr +box: 0.05 # box loss gain +cls: 0.3 # cls loss gain +cls_pw: 1.0 # cls BCELoss positive_weight +obj: 0.7 # obj loss gain (scale with pixels) +obj_pw: 1.0 # obj BCELoss positive_weight +iou_t: 0.20 # IoU training threshold +anchor_t: 4.0 # anchor-multiple threshold +# anchors: 3 # anchors per output layer (0 to ignore) +fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) +hsv_h: 0.015 # image HSV-Hue augmentation (fraction) +hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) +hsv_v: 0.4 # image HSV-Value augmentation (fraction) +degrees: 0.0 # image rotation (+/- deg) +translate: 0.1 # image translation (+/- fraction) +scale: 0.9 # image scale (+/- gain) +shear: 0.0 # image shear (+/- deg) +perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 +flipud: 0.0 # image flip up-down (probability) +fliplr: 0.5 # image flip left-right (probability) +mosaic: 1.0 # image mosaic (probability) +mixup: 0.01 # image mixup (probability) diff --git a/data/hyp.lrf01.yaml b/data/hyp.lrf01.yaml index 23e53eb8a9d3..bbb05f725975 100644 --- a/data/hyp.lrf01.yaml +++ b/data/hyp.lrf01.yaml @@ -13,7 +13,7 @@ warmup_bias_lr: 0.1 # warmup initial bias lr box: 0.05 # box loss gain cls: 0.3 # cls loss gain cls_pw: 1.0 # cls BCELoss positive_weight -obj: 0.5 # obj loss gain (scale with pixels) +obj: 0.7 # obj loss gain (scale with pixels) obj_pw: 1.0 # obj BCELoss positive_weight iou_t: 0.20 # IoU training threshold anchor_t: 4.0 # anchor-multiple threshold diff --git a/train.py b/train.py index 1e82a670e2c3..abc793996382 100644 --- a/train.py +++ b/train.py @@ -120,7 +120,10 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): # Scheduler https://arxiv.org/pdf/1812.01187.pdf # https://pytorch.org/docs/stable/_modules/torch/optim/lr_scheduler.html#OneCycleLR - lf = one_cycle(1, hyp['lrf'], epochs) # cosine 1->hyp['lrf'] + if opt.linear_lr: + lf = lambda x: (1 - x / (epochs - 1)) * (1.0 - hyp['lrf']) + hyp['lrf'] # linear + else: + lf = one_cycle(1, hyp['lrf'], epochs) # cosine 1->hyp['lrf'] scheduler = lr_scheduler.LambdaLR(optimizer, lr_lambda=lf) # plot_lr_scheduler(optimizer, scheduler, epochs) @@ -469,6 +472,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment') parser.add_argument('--quad', action='store_true', help='quad dataloader') parser.add_argument('--autobalance', action='store_true', help='autobalance') + parser.add_argument('--linear-lr', action='store_true', help='linear LR') opt = parser.parse_args() # Set DDP variables From f18175b92b326d94e6754381b22af48b50c5b0d1 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 21 Jan 2021 13:36:03 -0800 Subject: [PATCH 145/176] merge --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 7ff38c449453..3264c15b03d8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -45,7 +45,8 @@ COPY . /usr/src/app # sudo docker container exec -it ba65811811ab bash # Bash into stopped container -# sudo docker commit 092b16b25c5b usr/resume && sudo docker run -it --gpus all --ipc=host -v "$(pwd)"/coco:/usr/src/coco --entrypoint=sh usr/resume +# id=ac7b8bea8d6d && sudo docker start $id && sudo docker exec -it $id bash +# sudo docker commit $id usr/resume && sudo docker run -it --gpus all --ipc=host -v "$(pwd)"/coco:/usr/src/coco --entrypoint=sh usr/resume # Send weights to GCP # python -c "from utils.general import *; strip_optimizer('runs/train/exp0_*/weights/best.pt', 'tmp.pt')" && gsutil cp tmp.pt gs://*.pt From a18654a6f0c96996394d0791f5906aef9a776572 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 26 Jan 2021 21:44:09 -0800 Subject: [PATCH 146/176] update --- data/hyp.lrf001.yaml | 33 --------------------------------- data/hyp.lrf01.yaml | 6 +++--- utils/loss.py | 3 ++- 3 files changed, 5 insertions(+), 37 deletions(-) delete mode 100644 data/hyp.lrf001.yaml diff --git a/data/hyp.lrf001.yaml b/data/hyp.lrf001.yaml deleted file mode 100644 index 53635e299276..000000000000 --- a/data/hyp.lrf001.yaml +++ /dev/null @@ -1,33 +0,0 @@ -# Hyperparameters for COCO training from scratch -# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 -# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials - - -lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) -lrf: 0.01 # final OneCycleLR learning rate (lr0 * lrf) -momentum: 0.937 # SGD momentum/Adam beta1 -weight_decay: 0.0005 # optimizer weight decay 5e-4 -warmup_epochs: 3.0 # warmup epochs (fractions ok) -warmup_momentum: 0.8 # warmup initial momentum -warmup_bias_lr: 0.1 # warmup initial bias lr -box: 0.05 # box loss gain -cls: 0.3 # cls loss gain -cls_pw: 1.0 # cls BCELoss positive_weight -obj: 0.7 # obj loss gain (scale with pixels) -obj_pw: 1.0 # obj BCELoss positive_weight -iou_t: 0.20 # IoU training threshold -anchor_t: 4.0 # anchor-multiple threshold -# anchors: 3 # anchors per output layer (0 to ignore) -fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) -hsv_h: 0.015 # image HSV-Hue augmentation (fraction) -hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) -hsv_v: 0.4 # image HSV-Value augmentation (fraction) -degrees: 0.0 # image rotation (+/- deg) -translate: 0.1 # image translation (+/- fraction) -scale: 0.9 # image scale (+/- gain) -shear: 0.0 # image shear (+/- deg) -perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 -flipud: 0.0 # image flip up-down (probability) -fliplr: 0.5 # image flip left-right (probability) -mosaic: 1.0 # image mosaic (probability) -mixup: 0.01 # image mixup (probability) diff --git a/data/hyp.lrf01.yaml b/data/hyp.lrf01.yaml index bbb05f725975..4c619fede914 100644 --- a/data/hyp.lrf01.yaml +++ b/data/hyp.lrf01.yaml @@ -4,7 +4,7 @@ lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) -lrf: 0.1 # final OneCycleLR learning rate (lr0 * lrf) +lrf: 0.10 # final OneCycleLR learning rate (lr0 * lrf) momentum: 0.937 # SGD momentum/Adam beta1 weight_decay: 0.0005 # optimizer weight decay 5e-4 warmup_epochs: 3.0 # warmup epochs (fractions ok) @@ -13,7 +13,7 @@ warmup_bias_lr: 0.1 # warmup initial bias lr box: 0.05 # box loss gain cls: 0.3 # cls loss gain cls_pw: 1.0 # cls BCELoss positive_weight -obj: 0.7 # obj loss gain (scale with pixels) +obj: 0.52 # obj loss gain (scale with pixels) obj_pw: 1.0 # obj BCELoss positive_weight iou_t: 0.20 # IoU training threshold anchor_t: 4.0 # anchor-multiple threshold @@ -24,7 +24,7 @@ hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) hsv_v: 0.4 # image HSV-Value augmentation (fraction) degrees: 0.0 # image rotation (+/- deg) translate: 0.1 # image translation (+/- fraction) -scale: 0.9 # image scale (+/- gain) +scale: 0.95 # image scale (+/- gain) shear: 0.0 # image shear (+/- deg) perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 flipud: 0.0 # image flip up-down (probability) diff --git a/utils/loss.py b/utils/loss.py index 1505575ede09..1c451b09232b 100644 --- a/utils/loss.py +++ b/utils/loss.py @@ -106,7 +106,8 @@ def __init__(self, model, autobalance=False): det = model.module.model[-1] if is_parallel(model) else model.model[-1] # Detect() module # self.balance = {3: [3.67, 1.0, 0.43], 4: [3.78, 1.0, 0.39, 0.22], 5: [3.88, 1.0, 0.37, 0.17, 0.10]}[det.nl] - self.balance = {3: [3.67, 1.0, 0.43], 4: [4.0, 1.0, 0.25, 0.06], 5: [3.88, 1.0, 0.37, 0.17, 0.10]}[det.nl] + # self.balance = {3: [3.67, 1.0, 0.43], 4: [4.0, 1.0, 0.25, 0.06], 5: [3.88, 1.0, 0.37, 0.17, 0.10]}[det.nl] + self.balance = {3: [3.67, 1.0, 0.43], 4: [4.0, 1.0, 0.4, 0.1], 5: [3.88, 1.0, 0.37, 0.17, 0.10]}[det.nl] # self.balance = [1.0] * det.nl self.ssi = (det.stride == 16).nonzero(as_tuple=False).item() # stride 16 index self.BCEcls, self.BCEobj, self.gr, self.hyp, self.autobalance = BCEcls, BCEobj, model.gr, h, autobalance From 7c2bffb11b6a08f05f7c5692378a489b31578149 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 26 Jan 2021 21:55:15 -0800 Subject: [PATCH 147/176] update --- utils/loss.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/loss.py b/utils/loss.py index 1c451b09232b..e5063867dfcd 100644 --- a/utils/loss.py +++ b/utils/loss.py @@ -106,8 +106,8 @@ def __init__(self, model, autobalance=False): det = model.module.model[-1] if is_parallel(model) else model.model[-1] # Detect() module # self.balance = {3: [3.67, 1.0, 0.43], 4: [3.78, 1.0, 0.39, 0.22], 5: [3.88, 1.0, 0.37, 0.17, 0.10]}[det.nl] - # self.balance = {3: [3.67, 1.0, 0.43], 4: [4.0, 1.0, 0.25, 0.06], 5: [3.88, 1.0, 0.37, 0.17, 0.10]}[det.nl] - self.balance = {3: [3.67, 1.0, 0.43], 4: [4.0, 1.0, 0.4, 0.1], 5: [3.88, 1.0, 0.37, 0.17, 0.10]}[det.nl] + self.balance = {3: [3.67, 1.0, 0.43], 4: [4.0, 1.0, 0.25, 0.06], 5: [3.88, 1.0, 0.37, 0.17, 0.10]}[det.nl] + # self.balance = {3: [3.67, 1.0, 0.43], 4: [4.0, 1.0, 0.4, 0.1], 5: [3.88, 1.0, 0.37, 0.17, 0.10]}[det.nl] # self.balance = [1.0] * det.nl self.ssi = (det.stride == 16).nonzero(as_tuple=False).item() # stride 16 index self.BCEcls, self.BCEobj, self.gr, self.hyp, self.autobalance = BCEcls, BCEobj, model.gr, h, autobalance From 2b058ee694e28083f33542ae20f5b1d809439f84 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 27 Jan 2021 22:24:24 -0800 Subject: [PATCH 148/176] update --- models/hub/experimental/yolov5m6-1280.yaml | 60 ++++++++++++++++++++++ models/hub/experimental/yolov5s6-1280.yaml | 60 ++++++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 models/hub/experimental/yolov5m6-1280.yaml create mode 100644 models/hub/experimental/yolov5s6-1280.yaml diff --git a/models/hub/experimental/yolov5m6-1280.yaml b/models/hub/experimental/yolov5m6-1280.yaml new file mode 100644 index 000000000000..71ff2ca89936 --- /dev/null +++ b/models/hub/experimental/yolov5m6-1280.yaml @@ -0,0 +1,60 @@ +# parameters +nc: 80 # number of classes +depth_multiple: .67 # model depth multiple +width_multiple: .75 # layer channel multiple + +# anchors +anchors: + - [ 19,27, 44,40, 38,94 ] # P3/8 + - [ 96,68, 86,152, 180,137 ] # P4/16 + - [ 140,301, 303,264, 238,542 ] # P5/32 + - [ 436,615, 739,380, 925,792 ] # P6/64 + +# 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, [ 768, 3, 2 ] ], # 7-P5/32 + [ -1, 3, C3, [ 768 ] ], + [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 + [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ], + [ -1, 3, C3, [ 1024, False ] ], # 11 + ] + +# YOLOv5 head +head: + [ [ -1, 1, Conv, [ 768, 1, 1 ] ], + [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], + [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 + [ -1, 3, C3, [ 768, False ] ], # 15 + + [ -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 ] ], # 19 + + [ -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 ] ], # 23 (P3/8-small) + + [ -1, 1, Conv, [ 256, 3, 2 ] ], + [ [ -1, 20 ], 1, Concat, [ 1 ] ], # cat head P4 + [ -1, 3, C3, [ 512, False ] ], # 26 (P4/16-medium) + + [ -1, 1, Conv, [ 512, 3, 2 ] ], + [ [ -1, 16 ], 1, Concat, [ 1 ] ], # cat head P5 + [ -1, 3, C3, [ 768, False ] ], # 29 (P5/32-large) + + [ -1, 1, Conv, [ 768, 3, 2 ] ], + [ [ -1, 12 ], 1, Concat, [ 1 ] ], # cat head P6 + [ -1, 3, C3, [ 1024, False ] ], # 32 (P5/64-xlarge) + + [ [ 23, 26, 29, 32 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) + ] diff --git a/models/hub/experimental/yolov5s6-1280.yaml b/models/hub/experimental/yolov5s6-1280.yaml new file mode 100644 index 000000000000..876cd764515b --- /dev/null +++ b/models/hub/experimental/yolov5s6-1280.yaml @@ -0,0 +1,60 @@ +# parameters +nc: 80 # number of classes +depth_multiple: .33 # model depth multiple +width_multiple: .50 # layer channel multiple + +# anchors +anchors: + - [ 19,27, 44,40, 38,94 ] # P3/8 + - [ 96,68, 86,152, 180,137 ] # P4/16 + - [ 140,301, 303,264, 238,542 ] # P5/32 + - [ 436,615, 739,380, 925,792 ] # P6/64 + +# 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, [ 768, 3, 2 ] ], # 7-P5/32 + [ -1, 3, C3, [ 768 ] ], + [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 + [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ], + [ -1, 3, C3, [ 1024, False ] ], # 11 + ] + +# YOLOv5 head +head: + [ [ -1, 1, Conv, [ 768, 1, 1 ] ], + [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], + [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 + [ -1, 3, C3, [ 768, False ] ], # 15 + + [ -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 ] ], # 19 + + [ -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 ] ], # 23 (P3/8-small) + + [ -1, 1, Conv, [ 256, 3, 2 ] ], + [ [ -1, 20 ], 1, Concat, [ 1 ] ], # cat head P4 + [ -1, 3, C3, [ 512, False ] ], # 26 (P4/16-medium) + + [ -1, 1, Conv, [ 512, 3, 2 ] ], + [ [ -1, 16 ], 1, Concat, [ 1 ] ], # cat head P5 + [ -1, 3, C3, [ 768, False ] ], # 29 (P5/32-large) + + [ -1, 1, Conv, [ 768, 3, 2 ] ], + [ [ -1, 12 ], 1, Concat, [ 1 ] ], # cat head P6 + [ -1, 3, C3, [ 1024, False ] ], # 32 (P5/64-xlarge) + + [ [ 23, 26, 29, 32 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) + ] From 699e1f95e4d805f03d5fcbe8506f5fa9d3d6af9a Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 27 Jan 2021 22:25:53 -0800 Subject: [PATCH 149/176] update --- utils/loss.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/loss.py b/utils/loss.py index e5063867dfcd..1c451b09232b 100644 --- a/utils/loss.py +++ b/utils/loss.py @@ -106,8 +106,8 @@ def __init__(self, model, autobalance=False): det = model.module.model[-1] if is_parallel(model) else model.model[-1] # Detect() module # self.balance = {3: [3.67, 1.0, 0.43], 4: [3.78, 1.0, 0.39, 0.22], 5: [3.88, 1.0, 0.37, 0.17, 0.10]}[det.nl] - self.balance = {3: [3.67, 1.0, 0.43], 4: [4.0, 1.0, 0.25, 0.06], 5: [3.88, 1.0, 0.37, 0.17, 0.10]}[det.nl] - # self.balance = {3: [3.67, 1.0, 0.43], 4: [4.0, 1.0, 0.4, 0.1], 5: [3.88, 1.0, 0.37, 0.17, 0.10]}[det.nl] + # self.balance = {3: [3.67, 1.0, 0.43], 4: [4.0, 1.0, 0.25, 0.06], 5: [3.88, 1.0, 0.37, 0.17, 0.10]}[det.nl] + self.balance = {3: [3.67, 1.0, 0.43], 4: [4.0, 1.0, 0.4, 0.1], 5: [3.88, 1.0, 0.37, 0.17, 0.10]}[det.nl] # self.balance = [1.0] * det.nl self.ssi = (det.stride == 16).nonzero(as_tuple=False).item() # stride 16 index self.BCEcls, self.BCEobj, self.gr, self.hyp, self.autobalance = BCEcls, BCEobj, model.gr, h, autobalance From 8a9b864e5873ecad2a3397ff866d95f7a62b595e Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 28 Jan 2021 17:27:40 -0800 Subject: [PATCH 150/176] commit=tag == tags[-1] --- train.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/train.py b/train.py index b491af03daea..8d86a15fc2ea 100644 --- a/train.py +++ b/train.py @@ -372,7 +372,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): if tb_writer: tb_writer.add_scalar(tag, x, epoch) # tensorboard if wandb: - wandb.log({tag: x}, step=epoch) # W&B + wandb.log({tag: x}, step=epoch, commit=tag == tags[-1]) # W&B # Update best mAP fi = fitness(np.array(results).reshape(1, -1)) # weighted combination of [P, R, mAP@.5, mAP@.5-.95] From 8e9b73b93887b5fcbc443e9a8765ea4dbeccf6c6 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 1 Feb 2021 13:54:38 -0800 Subject: [PATCH 151/176] Update cudnn.benchmark --- test.py | 1 + train.py | 1 + 2 files changed, 2 insertions(+) diff --git a/test.py b/test.py index 738764f15601..2182d6a0acca 100644 --- a/test.py +++ b/test.py @@ -40,6 +40,7 @@ def test(data, # Initialize/load model and set device training = model is not None if training: # called by train.py + torch.backends.cudnn.benchmark = False device = next(model.parameters()).device # get model device else: # called directly diff --git a/train.py b/train.py index 4ec97ae71e16..9ad46d37171c 100644 --- a/train.py +++ b/train.py @@ -234,6 +234,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): f'Starting training for {epochs} epochs...') for epoch in range(start_epoch, epochs): # epoch ------------------------------------------------------------------ model.train() + torch.backends.cudnn.benchmark = True # Update image weights (optional) if opt.image_weights: From 1b2733c6d22d9a69c31f369fe9c88cfb9851e775 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 1 Feb 2021 14:40:37 -0800 Subject: [PATCH 152/176] update --- utils/loss.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/loss.py b/utils/loss.py index 1c451b09232b..182883373b5b 100644 --- a/utils/loss.py +++ b/utils/loss.py @@ -107,7 +107,7 @@ def __init__(self, model, autobalance=False): det = model.module.model[-1] if is_parallel(model) else model.model[-1] # Detect() module # self.balance = {3: [3.67, 1.0, 0.43], 4: [3.78, 1.0, 0.39, 0.22], 5: [3.88, 1.0, 0.37, 0.17, 0.10]}[det.nl] # self.balance = {3: [3.67, 1.0, 0.43], 4: [4.0, 1.0, 0.25, 0.06], 5: [3.88, 1.0, 0.37, 0.17, 0.10]}[det.nl] - self.balance = {3: [3.67, 1.0, 0.43], 4: [4.0, 1.0, 0.4, 0.1], 5: [3.88, 1.0, 0.37, 0.17, 0.10]}[det.nl] + self.balance = {3: [3.67, 1.0, 0.43], 4: [4.0, 1.0, 0.25, 0.06], 5: [3.88, 1.0, 0.37, 0.17, 0.10]}[det.nl] # self.balance = [1.0] * det.nl self.ssi = (det.stride == 16).nonzero(as_tuple=False).item() # stride 16 index self.BCEcls, self.BCEobj, self.gr, self.hyp, self.autobalance = BCEcls, BCEobj, model.gr, h, autobalance From 8820fd317776d300076b7c54c9d1e3306bea1541 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 1 Feb 2021 14:48:00 -0800 Subject: [PATCH 153/176] update --- utils/loss.py | 1 - 1 file changed, 1 deletion(-) diff --git a/utils/loss.py b/utils/loss.py index 182883373b5b..1505575ede09 100644 --- a/utils/loss.py +++ b/utils/loss.py @@ -106,7 +106,6 @@ def __init__(self, model, autobalance=False): det = model.module.model[-1] if is_parallel(model) else model.model[-1] # Detect() module # self.balance = {3: [3.67, 1.0, 0.43], 4: [3.78, 1.0, 0.39, 0.22], 5: [3.88, 1.0, 0.37, 0.17, 0.10]}[det.nl] - # self.balance = {3: [3.67, 1.0, 0.43], 4: [4.0, 1.0, 0.25, 0.06], 5: [3.88, 1.0, 0.37, 0.17, 0.10]}[det.nl] self.balance = {3: [3.67, 1.0, 0.43], 4: [4.0, 1.0, 0.25, 0.06], 5: [3.88, 1.0, 0.37, 0.17, 0.10]}[det.nl] # self.balance = [1.0] * det.nl self.ssi = (det.stride == 16).nonzero(as_tuple=False).item() # stride 16 index From daba287e8021b6b9c3497a80218856fab15b1c86 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 4 Feb 2021 17:32:32 -0800 Subject: [PATCH 154/176] update --- data/hyp.scratch.box.yaml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 data/hyp.scratch.box.yaml diff --git a/data/hyp.scratch.box.yaml b/data/hyp.scratch.box.yaml new file mode 100644 index 000000000000..ee31a79d8211 --- /dev/null +++ b/data/hyp.scratch.box.yaml @@ -0,0 +1,33 @@ +# Hyperparameters for COCO training from scratch +# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 +# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials + + +lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) +lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) +momentum: 0.937 # SGD momentum/Adam beta1 +weight_decay: 0.0005 # optimizer weight decay 5e-4 +warmup_epochs: 3.0 # warmup epochs (fractions ok) +warmup_momentum: 0.8 # warmup initial momentum +warmup_bias_lr: 0.1 # warmup initial bias lr +box: 0.05 # box loss gain +cls: 0.0 # cls loss gain +cls_pw: 1.0 # cls BCELoss positive_weight +obj: 0.0 # obj loss gain (scale with pixels) +obj_pw: 1.0 # obj BCELoss positive_weight +iou_t: 0.20 # IoU training threshold +anchor_t: 4.0 # anchor-multiple threshold +# anchors: 3 # anchors per output layer (0 to ignore) +fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) +hsv_h: 0.015 # image HSV-Hue augmentation (fraction) +hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) +hsv_v: 0.4 # image HSV-Value augmentation (fraction) +degrees: 0.0 # image rotation (+/- deg) +translate: 0.1 # image translation (+/- fraction) +scale: 0.9 # image scale (+/- gain) +shear: 0.0 # image shear (+/- deg) +perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 +flipud: 0.0 # image flip up-down (probability) +fliplr: 0.5 # image flip left-right (probability) +mosaic: 1.0 # image mosaic (probability) +mixup: 0.01 # image mixup (probability) From a7fc41e0854b9664641efb209e8cde6e36a936a4 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 4 Feb 2021 21:42:44 -0800 Subject: [PATCH 155/176] updates --- .../hub/experimental/yolov5l6-3only-640.yaml | 45 +++++++++++++++ .../hub/experimental/yolov5l6-4only-640.yaml | 49 ++++++++++++++++ .../hub/experimental/yolov5l6-5only-640.yaml | 53 +++++++++++++++++ .../hub/experimental/yolov5l6-6only-640.yaml | 57 +++++++++++++++++++ 4 files changed, 204 insertions(+) create mode 100644 models/hub/experimental/yolov5l6-3only-640.yaml create mode 100644 models/hub/experimental/yolov5l6-4only-640.yaml create mode 100644 models/hub/experimental/yolov5l6-5only-640.yaml create mode 100644 models/hub/experimental/yolov5l6-6only-640.yaml diff --git a/models/hub/experimental/yolov5l6-3only-640.yaml b/models/hub/experimental/yolov5l6-3only-640.yaml new file mode 100644 index 000000000000..e8c2db1365d5 --- /dev/null +++ b/models/hub/experimental/yolov5l6-3only-640.yaml @@ -0,0 +1,45 @@ +# parameters +nc: 80 # number of classes +depth_multiple: 1.0 # model depth multiple +width_multiple: 1.0 # layer channel multiple + +# anchors +anchors: + - [ 9,11, 21,19, 17,41 ] # P3/8 + +# 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, [ 768, 3, 2 ] ], # 7-P5/32 + [ -1, 3, C3, [ 768 ] ], + [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 + [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ], + [ -1, 3, C3, [ 1024, False ] ], # 11 + ] + +# YOLOv5 head +head: + [ [ -1, 1, Conv, [ 768, 1, 1 ] ], + [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], + [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 + [ -1, 3, C3, [ 768, False ] ], # 15 + + [ -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 ] ], # 19 + + [ -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 ] ], # 23 (P3/8-small) + + [ [ 23 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) + ] diff --git a/models/hub/experimental/yolov5l6-4only-640.yaml b/models/hub/experimental/yolov5l6-4only-640.yaml new file mode 100644 index 000000000000..997f1351bb62 --- /dev/null +++ b/models/hub/experimental/yolov5l6-4only-640.yaml @@ -0,0 +1,49 @@ +# parameters +nc: 80 # number of classes +depth_multiple: 1.0 # model depth multiple +width_multiple: 1.0 # layer channel multiple + +# anchors +anchors: + - [ 43,32, 39,70, 86,64 ] # P4/16 + +# 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, [ 768, 3, 2 ] ], # 7-P5/32 + [ -1, 3, C3, [ 768 ] ], + [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 + [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ], + [ -1, 3, C3, [ 1024, False ] ], # 11 + ] + +# YOLOv5 head +head: + [ [ -1, 1, Conv, [ 768, 1, 1 ] ], + [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], + [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 + [ -1, 3, C3, [ 768, False ] ], # 15 + + [ -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 ] ], # 19 + + [ -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 ] ], # 23 (P3/8-small) + + [ -1, 1, Conv, [ 256, 3, 2 ] ], + [ [ -1, 20 ], 1, Concat, [ 1 ] ], # cat head P4 + [ -1, 3, C3, [ 512, False ] ], # 26 (P4/16-medium) + + [ [ 26 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) + ] diff --git a/models/hub/experimental/yolov5l6-5only-640.yaml b/models/hub/experimental/yolov5l6-5only-640.yaml new file mode 100644 index 000000000000..db4dc33d9b3a --- /dev/null +++ b/models/hub/experimental/yolov5l6-5only-640.yaml @@ -0,0 +1,53 @@ +# parameters +nc: 80 # number of classes +depth_multiple: 1.0 # model depth multiple +width_multiple: 1.0 # layer channel multiple + +# anchors +anchors: + - [ 65,131, 134,130, 120,265 ] # 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, [ 768, 3, 2 ] ], # 7-P5/32 + [ -1, 3, C3, [ 768 ] ], + [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 + [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ], + [ -1, 3, C3, [ 1024, False ] ], # 11 + ] + +# YOLOv5 head +head: + [ [ -1, 1, Conv, [ 768, 1, 1 ] ], + [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], + [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 + [ -1, 3, C3, [ 768, False ] ], # 15 + + [ -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 ] ], # 19 + + [ -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 ] ], # 23 (P3/8-small) + + [ -1, 1, Conv, [ 256, 3, 2 ] ], + [ [ -1, 20 ], 1, Concat, [ 1 ] ], # cat head P4 + [ -1, 3, C3, [ 512, False ] ], # 26 (P4/16-medium) + + [ -1, 1, Conv, [ 512, 3, 2 ] ], + [ [ -1, 16 ], 1, Concat, [ 1 ] ], # cat head P5 + [ -1, 3, C3, [ 768, False ] ], # 29 (P5/32-large) + + [ [ 29 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) + ] diff --git a/models/hub/experimental/yolov5l6-6only-640.yaml b/models/hub/experimental/yolov5l6-6only-640.yaml new file mode 100644 index 000000000000..d77a1449ea08 --- /dev/null +++ b/models/hub/experimental/yolov5l6-6only-640.yaml @@ -0,0 +1,57 @@ +# parameters +nc: 80 # number of classes +depth_multiple: 1.0 # model depth multiple +width_multiple: 1.0 # layer channel multiple + +# anchors +anchors: + - [ 282,180, 247,354, 512,387 ] # P6/64 + +# 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, [ 768, 3, 2 ] ], # 7-P5/32 + [ -1, 3, C3, [ 768 ] ], + [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 + [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ], + [ -1, 3, C3, [ 1024, False ] ], # 11 + ] + +# YOLOv5 head +head: + [ [ -1, 1, Conv, [ 768, 1, 1 ] ], + [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], + [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 + [ -1, 3, C3, [ 768, False ] ], # 15 + + [ -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 ] ], # 19 + + [ -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 ] ], # 23 (P3/8-small) + + [ -1, 1, Conv, [ 256, 3, 2 ] ], + [ [ -1, 20 ], 1, Concat, [ 1 ] ], # cat head P4 + [ -1, 3, C3, [ 512, False ] ], # 26 (P4/16-medium) + + [ -1, 1, Conv, [ 512, 3, 2 ] ], + [ [ -1, 16 ], 1, Concat, [ 1 ] ], # cat head P5 + [ -1, 3, C3, [ 768, False ] ], # 29 (P5/32-large) + + [ -1, 1, Conv, [ 768, 3, 2 ] ], + [ [ -1, 12 ], 1, Concat, [ 1 ] ], # cat head P6 + [ -1, 3, C3, [ 1024, False ] ], # 32 (P5/64-xlarge) + + [ [ 32 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) + ] From c5c1c402e7f255cf3c3b5f340250b7b11c0dfee3 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 6 Feb 2021 09:56:15 -0800 Subject: [PATCH 156/176] updates --- models/hub/experimental/yolov5l7-1280.yaml | 2 +- models/hub/experimental/yolov5l7-1920.yaml | 2 +- models/hub/experimental/yolov5l7-640.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/models/hub/experimental/yolov5l7-1280.yaml b/models/hub/experimental/yolov5l7-1280.yaml index 5571a98fd542..1e430c520059 100644 --- a/models/hub/experimental/yolov5l7-1280.yaml +++ b/models/hub/experimental/yolov5l7-1280.yaml @@ -26,7 +26,7 @@ backbone: [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 [ -1, 3, C3, [ 1024 ] ], [ -1, 1, Conv, [ 1280, 3, 2 ] ], # 11-P7/128 - [ -1, 1, SPP, [ 1280, [ 3, 5 ] ] ], + [ -1, 1, SPP, [ 1280, [ 3, 5, 7 ] ] ], [ -1, 3, C3, [ 1280, False ] ], # 13 ] diff --git a/models/hub/experimental/yolov5l7-1920.yaml b/models/hub/experimental/yolov5l7-1920.yaml index 574359cf799f..15c7a93bfd3b 100644 --- a/models/hub/experimental/yolov5l7-1920.yaml +++ b/models/hub/experimental/yolov5l7-1920.yaml @@ -26,7 +26,7 @@ backbone: [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 [ -1, 3, C3, [ 1024 ] ], [ -1, 1, Conv, [ 1280, 3, 2 ] ], # 11-P7/128 - [ -1, 1, SPP, [ 1280, [ 3, 5 ] ] ], + [ -1, 1, SPP, [ 1280, [ 3, 5, 7 ] ] ], [ -1, 3, C3, [ 1280, False ] ], # 13 ] diff --git a/models/hub/experimental/yolov5l7-640.yaml b/models/hub/experimental/yolov5l7-640.yaml index 19982c367ef1..78d896afbdec 100644 --- a/models/hub/experimental/yolov5l7-640.yaml +++ b/models/hub/experimental/yolov5l7-640.yaml @@ -26,7 +26,7 @@ backbone: [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 [ -1, 3, C3, [ 1024 ] ], [ -1, 1, Conv, [ 1280, 3, 2 ] ], # 11-P7/128 - [ -1, 1, SPP, [ 1280, [ 3, 5 ] ] ], + [ -1, 1, SPP, [ 1280, [ 3, 5, 7 ] ] ], [ -1, 3, C3, [ 1280, False ] ], # 13 ] From b5514570250ada6ddbf232dc95f805bd01ad8f7d Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 8 Feb 2021 22:33:43 -0800 Subject: [PATCH 157/176] updates --- utils/datasets.py | 101 +++++++++++++++++++++++++++------------------- utils/general.py | 36 ++++++++++++++++- 2 files changed, 95 insertions(+), 42 deletions(-) diff --git a/utils/datasets.py b/utils/datasets.py index 7a8f073608cb..513367e13a55 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -20,7 +20,8 @@ from torch.utils.data import Dataset from tqdm import tqdm -from utils.general import xyxy2xywh, xywh2xyxy, xywhn2xyxy, clean_str +from utils.general import xyxy2xywh, xywh2xyxy, xywhn2xyxy, xyn2xy, segment2box, segments2boxes, resample_segments, \ + clean_str from utils.torch_utils import torch_distributed_zero_first # Parameters @@ -381,14 +382,14 @@ def __init__(self, path, img_size=640, batch_size=16, augment=False, hyp=None, r cache = self.cache_labels(cache_path, prefix) # cache # Display cache - [nf, nm, ne, nc, n] = cache.pop('results') # found, missing, empty, corrupted, total + nf, nm, ne, nc, n = cache.pop('results') # found, missing, empty, corrupted, total desc = f"Scanning '{cache_path}' for images and labels... {nf} found, {nm} missing, {ne} empty, {nc} corrupted" tqdm(None, desc=prefix + desc, total=n, initial=n) assert nf > 0 or not augment, f'{prefix}No labels in {cache_path}. Can not train without labels. See {help_url}' # Read cache cache.pop('hash') # remove hash - labels, shapes = zip(*cache.values()) + labels, shapes, self.segments = zip(*cache.values()) self.labels = list(labels) self.shapes = np.array(shapes, dtype=np.float64) self.img_files = list(cache.keys()) # update @@ -451,6 +452,7 @@ def cache_labels(self, path=Path('./labels.cache'), prefix=''): im = Image.open(im_file) im.verify() # PIL verify shape = exif_size(im) # image size + segments = [] # instance segments assert (shape[0] > 9) & (shape[1] > 9), f'image size {shape} <10 pixels' assert im.format.lower() in img_formats, f'invalid image format {im.format}' @@ -458,7 +460,13 @@ def cache_labels(self, path=Path('./labels.cache'), prefix=''): if os.path.isfile(lb_file): nf += 1 # label found with open(lb_file, 'r') as f: - l = np.array([x.split() for x in f.read().strip().splitlines()], dtype=np.float32) # labels + l = [x.split() for x in f.read().strip().splitlines()] + if any([len(x) >= 9 for x in l]): # is segment + classes = np.array([x[0] for x in l], dtype=np.float32) + segments = [np.array(x[1:], dtype=np.float32).reshape(-1, 2) for x in l] # (cls, xy1...) + l = np.concatenate((classes.reshape(-1, 1), segments2boxes(segments)), 1) # (cls, xywh) + segments = resample_segments(segments) # upsample + l = np.array(l, dtype=np.float32) if len(l): assert l.shape[1] == 5, 'labels require 5 columns each' assert (l >= 0).all(), 'negative labels' @@ -470,7 +478,7 @@ def cache_labels(self, path=Path('./labels.cache'), prefix=''): else: nm += 1 # label missing l = np.zeros((0, 5), dtype=np.float32) - x[im_file] = [l, shape] + x[im_file] = [l, shape, segments] except Exception as e: nc += 1 print(f'{prefix}WARNING: Ignoring corrupted image and/or label {im_file}: {e}') @@ -652,7 +660,7 @@ def hist_equalize(img, clahe=True, bgr=False): def load_mosaic(self, index): # loads images in a 4-mosaic - labels4 = [] + labels4, segments4 = [], [] s = self.img_size yc, xc = [int(random.uniform(-x, 2 * s + x)) for x in self.mosaic_border] # mosaic center x, y indices = [index] + [self.indices[random.randint(0, self.n - 1)] for _ in range(3)] # 3 additional image indices @@ -680,19 +688,21 @@ def load_mosaic(self, index): padh = y1a - y1b # Labels - labels = self.labels[index].copy() + labels, segments = self.labels[index].copy(), self.segments[index].copy() if labels.size: labels[:, 1:] = xywhn2xyxy(labels[:, 1:], w, h, padw, padh) # normalized xywh to pixel xyxy format + segments = [xyn2xy(x, w, h, padw, padh) for x in segments] labels4.append(labels) + segments4.extend(segments) # Concat/clip labels - if len(labels4): - labels4 = np.concatenate(labels4, 0) - np.clip(labels4[:, 1:], 0, 2 * s, out=labels4[:, 1:]) # use with random_perspective - # img4, labels4 = replicate(img4, labels4) # replicate + labels4 = np.concatenate(labels4, 0) + for x in (labels4[:, 1:], *segments4): + np.clip(x, 0, 2 * s, out=x) # clip when using random_perspective() + # img4, labels4 = replicate(img4, labels4) # replicate # Augment - img4, labels4 = random_perspective(img4, labels4, + img4, labels4 = random_perspective(img4, labels4, segments4, degrees=self.hyp['degrees'], translate=self.hyp['translate'], scale=self.hyp['scale'], @@ -823,7 +833,8 @@ def letterbox(img, new_shape=(640, 640), color=(114, 114, 114), auto=True, scale return img, ratio, (dw, dh) -def random_perspective(img, targets=(), degrees=10, translate=.1, scale=.1, shear=10, perspective=0.0, border=(0, 0)): +def random_perspective(img, targets=(), segments=(), degrees=10, translate=.1, scale=.1, shear=10, perspective=0.0, + border=(0, 0)): # torchvision.transforms.RandomAffine(degrees=(-10, 10), translate=(.1, .1), scale=(.9, 1.1), shear=(-10, 10)) # targets = [cls, xyxy] @@ -875,37 +886,45 @@ def random_perspective(img, targets=(), degrees=10, translate=.1, scale=.1, shea # Transform label coordinates n = len(targets) if n: - # warp points - xy = np.ones((n * 4, 3)) - xy[:, :2] = targets[:, [1, 2, 3, 4, 1, 4, 3, 2]].reshape(n * 4, 2) # x1y1, x2y2, x1y2, x2y1 - xy = xy @ M.T # transform - if perspective: - xy = (xy[:, :2] / xy[:, 2:3]).reshape(n, 8) # rescale - else: # affine - xy = xy[:, :2].reshape(n, 8) - - # create new boxes - x = xy[:, [0, 2, 4, 6]] - y = xy[:, [1, 3, 5, 7]] - xy = np.concatenate((x.min(1), y.min(1), x.max(1), y.max(1))).reshape(4, n).T - - # # apply angle-based reduction of bounding boxes - # radians = a * math.pi / 180 - # reduction = max(abs(math.sin(radians)), abs(math.cos(radians))) ** 0.5 - # x = (xy[:, 2] + xy[:, 0]) / 2 - # y = (xy[:, 3] + xy[:, 1]) / 2 - # w = (xy[:, 2] - xy[:, 0]) * reduction - # h = (xy[:, 3] - xy[:, 1]) * reduction - # xy = np.concatenate((x - w / 2, y - h / 2, x + w / 2, y + h / 2)).reshape(4, n).T - - # clip boxes - xy[:, [0, 2]] = xy[:, [0, 2]].clip(0, width) - xy[:, [1, 3]] = xy[:, [1, 3]].clip(0, height) + use_segments = any(x.any() for x in segments) + new = np.zeros((n, 4)) + if use_segments: # warp segments + for i, segment in enumerate(segments): + xy = np.ones((len(segment), 3)) + xy[:, :2] = segment + xy = xy @ M.T # transform + if perspective: + xy = xy[:, :2] / xy[:, 2:3] # rescale + else: # affine + xy = xy[:, :2] + + # clip + # np.clip(xy[:, 0], 0, width, out=xy[:, 0]) + # np.clip(xy[:, 1], 0, height, out=xy[:, 1]) + new[i] = segment2box(xy, width, height) + + else: # warp boxes + xy = np.ones((n * 4, 3)) + xy[:, :2] = targets[:, [1, 2, 3, 4, 1, 4, 3, 2]].reshape(n * 4, 2) # x1y1, x2y2, x1y2, x2y1 + xy = xy @ M.T # transform + if perspective: + xy = (xy[:, :2] / xy[:, 2:3]).reshape(n, 8) # rescale + else: # affine + xy = xy[:, :2].reshape(n, 8) + + # create new boxes + x = xy[:, [0, 2, 4, 6]] + y = xy[:, [1, 3, 5, 7]] + new = np.concatenate((x.min(1), y.min(1), x.max(1), y.max(1))).reshape(4, n).T + + # clip boxes + new[:, [0, 2]] = new[:, [0, 2]].clip(0, width) + new[:, [1, 3]] = new[:, [1, 3]].clip(0, height) # filter candidates - i = box_candidates(box1=targets[:, 1:5].T * s, box2=xy.T) + i = box_candidates(box1=targets[:, 1:5].T * s, box2=new.T, area_thr=0.01 if use_segments else 0.10) targets = targets[i] - targets[:, 1:5] = xy[i] + targets[:, 1:5] = new[i] return img, targets diff --git a/utils/general.py b/utils/general.py index bbc0f32b8425..407bb37ff017 100755 --- a/utils/general.py +++ b/utils/general.py @@ -225,7 +225,7 @@ def xywh2xyxy(x): return y -def xywhn2xyxy(x, w=640, h=640, padw=32, padh=32): +def xywhn2xyxy(x, w=640, h=640, padw=0, padh=0): # Convert nx4 boxes from [x, y, w, h] normalized to [x1, y1, x2, y2] where xy1=top-left, xy2=bottom-right y = x.clone() if isinstance(x, torch.Tensor) else np.copy(x) y[:, 0] = w * (x[:, 0] - x[:, 2] / 2) + padw # top left x @@ -235,6 +235,40 @@ def xywhn2xyxy(x, w=640, h=640, padw=32, padh=32): return y +def xyn2xy(x, w=640, h=640, padw=0, padh=0): + # Convert (n,2) normalized segments into (n,2) segments + y = x.clone() if isinstance(x, torch.Tensor) else np.copy(x) + y[:, 0] = w * x[:, 0] + padw # top left x + y[:, 1] = h * x[:, 1] + padh # top left y + return y + + +def segment2box(segment, width=640, height=640): + # Convert 1 segment label to 1 box labels, i.e. (xy1, xy2, ...) to (xyxy) + x, y = segment.T # segment xy + inside = (x >= 0) & (y >= 0) & (x <= width) & (y <= height) + x, y, = x[inside], y[inside] + return np.array([x.min(), y.min(), x.max(), y.max()]) if any(x) else np.zeros((1, 4)) # cls, xyxy + + +def segments2boxes(segments): + # Convert segment labels to box labels, i.e. (cls, xy1, xy2, ...) to (cls, xywh) + boxes = [] + for s in segments: + x, y = s.T # segment xy + boxes.append([x.min(), y.min(), x.max(), y.max()]) # cls, xyxy + return xyxy2xywh(np.array(boxes)) # cls, xywh + + +def resample_segments(segments, n=1000): + # Up-sample an (n,2) segment + for i, s in enumerate(segments): + x = np.linspace(0, len(s) - 1, n) + xp = np.arange(len(s)) + segments[i] = np.concatenate([np.interp(x, xp, s[:, i]) for i in range(2)]).reshape(2, -1).T # segment xy + return segments + + def scale_coords(img1_shape, coords, img0_shape, ratio_pad=None): # Rescale coords (xyxy) from img1_shape to img0_shape if ratio_pad is None: # calculate from img0_shape From 275021b183473a7b871cbfb406ba5ed8582097f4 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 8 Feb 2021 22:36:48 -0800 Subject: [PATCH 158/176] updates --- data/coco_segments.yaml | 35 +++++++++++++++++++++++++++++++ data/scripts/get_coco_segments.sh | 28 +++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 data/coco_segments.yaml create mode 100755 data/scripts/get_coco_segments.sh diff --git a/data/coco_segments.yaml b/data/coco_segments.yaml new file mode 100644 index 000000000000..9e841819291e --- /dev/null +++ b/data/coco_segments.yaml @@ -0,0 +1,35 @@ +# COCO 2017 dataset http://cocodataset.org +# Train command: python train.py --data coco.yaml +# Default dataset location is next to /yolov5: +# /parent_folder +# /coco +# /yolov5 + + +# download command/URL (optional) +download: bash data/scripts/get_coco_segments.sh + +# train and val data as 1) directory: path/images/, 2) file: path/images.txt, or 3) list: [path1/images/, path2/images/] +train: ../coco_segments/train2017.txt # 118287 images +val: ../coco_segments/val2017.txt # 5000 images +test: ../coco_segments/test-dev2017.txt # 20288 of 40670 images, submit to https://competitions.codalab.org/competitions/20794 + +# number of classes +nc: 80 + +# class names +names: [ 'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light', + 'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow', + 'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', + 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard', + 'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', + 'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', + 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone', + 'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear', + 'hair drier', 'toothbrush' ] + +# Print classes +# with open('data/coco.yaml') as f: +# d = yaml.load(f, Loader=yaml.FullLoader) # dict +# for i, x in enumerate(d['names']): +# print(i, x) diff --git a/data/scripts/get_coco_segments.sh b/data/scripts/get_coco_segments.sh new file mode 100755 index 000000000000..857ef8dc49b9 --- /dev/null +++ b/data/scripts/get_coco_segments.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# COCO 2017 dataset http://cocodataset.org +# Download command: bash data/scripts/get_coco.sh +# Train command: python train.py --data coco.yaml +# Default dataset location is next to /yolov5: +# /parent_folder +# /coco +# /yolov5 + +# Download/unzip labels +d='../' # unzip directory +url=https://github.com/ultralytics/yolov5/releases/download/v1.0/ +f='coco2017labels-segments.zip' # 68 MB +echo 'Downloading' $url$f ' ...' +curl -L $url$f -o $f && unzip -q $f -d $d && rm $f & # download, unzip, remove in background + +# Download/unzip images +d='../coco/images' # unzip directory +url=http://images.cocodataset.org/zips/ +f1='train2017.zip' # 19G, 118k images +f2='val2017.zip' # 1G, 5k images +f3='test2017.zip' # 7G, 41k images (optional) +for f in $f1 $f2; do + echo 'Downloading' $url$f '...' + curl -L $url$f -o $f && unzip -q $f -d $d && rm $f & # download, unzip, remove in background +done +wait # finish background tasks +mv ../coco ../coco_segments From 7564b6052cffa360df7655bd47c4f388b9076786 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 8 Feb 2021 23:21:20 -0800 Subject: [PATCH 159/176] updates --- utils/datasets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/datasets.py b/utils/datasets.py index 513367e13a55..ae63f60fc8d3 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -465,7 +465,6 @@ def cache_labels(self, path=Path('./labels.cache'), prefix=''): classes = np.array([x[0] for x in l], dtype=np.float32) segments = [np.array(x[1:], dtype=np.float32).reshape(-1, 2) for x in l] # (cls, xy1...) l = np.concatenate((classes.reshape(-1, 1), segments2boxes(segments)), 1) # (cls, xywh) - segments = resample_segments(segments) # upsample l = np.array(l, dtype=np.float32) if len(l): assert l.shape[1] == 5, 'labels require 5 columns each' @@ -889,6 +888,7 @@ def random_perspective(img, targets=(), segments=(), degrees=10, translate=.1, s use_segments = any(x.any() for x in segments) new = np.zeros((n, 4)) if use_segments: # warp segments + segments = resample_segments(segments) # upsample for i, segment in enumerate(segments): xy = np.ones((len(segment), 3)) xy[:, :2] = segment From 27bc6b0cb3ef289d1082206115cd7ae4e13923f7 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 8 Feb 2021 23:28:33 -0800 Subject: [PATCH 160/176] updates --- utils/datasets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/datasets.py b/utils/datasets.py index ae63f60fc8d3..2bc87e0c065c 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -470,7 +470,7 @@ def cache_labels(self, path=Path('./labels.cache'), prefix=''): assert l.shape[1] == 5, 'labels require 5 columns each' assert (l >= 0).all(), 'negative labels' assert (l[:, 1:] <= 1).all(), 'non-normalized or out of bounds coordinate labels' - assert np.unique(l, axis=0).shape[0] == l.shape[0], 'duplicate labels' + # assert np.unique(l, axis=0).shape[0] == l.shape[0], 'duplicate labels' else: ne += 1 # label empty l = np.zeros((0, 5), dtype=np.float32) From abfe6c5f652390ea3a33946a4e23356dd35e80ab Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 9 Feb 2021 13:59:26 -0800 Subject: [PATCH 161/176] updates --- utils/loss.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/loss.py b/utils/loss.py index 2490d4bb7cfc..4eeede3863c5 100644 --- a/utils/loss.py +++ b/utils/loss.py @@ -105,7 +105,7 @@ def __init__(self, model, autobalance=False): BCEcls, BCEobj = FocalLoss(BCEcls, g), FocalLoss(BCEobj, g) det = model.module.model[-1] if is_parallel(model) else model.model[-1] # Detect() module - self.balance = {3: [3.67, 1.0, 0.43], 4: [4.0, 1.0, 0.25, 0.06], 5: [4.0, 1.0, 0.25, 0.06, .02]}[det.nl] + self.balance = {3: [4.0, 1.0, 0.25], 4: [4.0, 1.0, 0.25, 0.06], 5: [4.0, 1.0, 0.25, 0.06, .02]}[det.nl] self.ssi = (det.stride == 16).nonzero(as_tuple=False).item() # stride 16 index self.BCEcls, self.BCEobj, self.gr, self.hyp, self.autobalance = BCEcls, BCEobj, model.gr, h, autobalance for k in 'na', 'nc', 'nl', 'anchors': From 6b2910767462cb43d6741c39daba0d1e72b5e470 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 11 Feb 2021 14:51:15 -0800 Subject: [PATCH 162/176] update --- data/hyp.master.yaml | 33 +++++++++++++++++++++++++++++++++ data/hyp.master09scale.yaml | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 data/hyp.master.yaml create mode 100644 data/hyp.master09scale.yaml diff --git a/data/hyp.master.yaml b/data/hyp.master.yaml new file mode 100644 index 000000000000..44f26b6658ae --- /dev/null +++ b/data/hyp.master.yaml @@ -0,0 +1,33 @@ +# Hyperparameters for COCO training from scratch +# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 +# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials + + +lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) +lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) +momentum: 0.937 # SGD momentum/Adam beta1 +weight_decay: 0.0005 # optimizer weight decay 5e-4 +warmup_epochs: 3.0 # warmup epochs (fractions ok) +warmup_momentum: 0.8 # warmup initial momentum +warmup_bias_lr: 0.1 # warmup initial bias lr +box: 0.05 # box loss gain +cls: 0.5 # cls loss gain +cls_pw: 1.0 # cls BCELoss positive_weight +obj: 1.0 # obj loss gain (scale with pixels) +obj_pw: 1.0 # obj BCELoss positive_weight +iou_t: 0.20 # IoU training threshold +anchor_t: 4.0 # anchor-multiple threshold +# anchors: 3 # anchors per output layer (0 to ignore) +fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) +hsv_h: 0.015 # image HSV-Hue augmentation (fraction) +hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) +hsv_v: 0.4 # image HSV-Value augmentation (fraction) +degrees: 0.0 # image rotation (+/- deg) +translate: 0.1 # image translation (+/- fraction) +scale: 0.5 # image scale (+/- gain) +shear: 0.0 # image shear (+/- deg) +perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 +flipud: 0.0 # image flip up-down (probability) +fliplr: 0.5 # image flip left-right (probability) +mosaic: 1.0 # image mosaic (probability) +mixup: 0.0 # image mixup (probability) diff --git a/data/hyp.master09scale.yaml b/data/hyp.master09scale.yaml new file mode 100644 index 000000000000..14fbd3d2fab9 --- /dev/null +++ b/data/hyp.master09scale.yaml @@ -0,0 +1,33 @@ +# Hyperparameters for COCO training from scratch +# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 +# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials + + +lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) +lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) +momentum: 0.937 # SGD momentum/Adam beta1 +weight_decay: 0.0005 # optimizer weight decay 5e-4 +warmup_epochs: 3.0 # warmup epochs (fractions ok) +warmup_momentum: 0.8 # warmup initial momentum +warmup_bias_lr: 0.1 # warmup initial bias lr +box: 0.05 # box loss gain +cls: 0.5 # cls loss gain +cls_pw: 1.0 # cls BCELoss positive_weight +obj: 1.0 # obj loss gain (scale with pixels) +obj_pw: 1.0 # obj BCELoss positive_weight +iou_t: 0.20 # IoU training threshold +anchor_t: 4.0 # anchor-multiple threshold +# anchors: 3 # anchors per output layer (0 to ignore) +fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) +hsv_h: 0.015 # image HSV-Hue augmentation (fraction) +hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) +hsv_v: 0.4 # image HSV-Value augmentation (fraction) +degrees: 0.0 # image rotation (+/- deg) +translate: 0.1 # image translation (+/- fraction) +scale: 0.9 # image scale (+/- gain) +shear: 0.0 # image shear (+/- deg) +perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 +flipud: 0.0 # image flip up-down (probability) +fliplr: 0.5 # image flip left-right (probability) +mosaic: 1.0 # image mosaic (probability) +mixup: 0.0 # image mixup (probability) From 6ad18e8dddb2cb166ba600f0799dd32931455f32 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 11 Feb 2021 18:12:02 -0800 Subject: [PATCH 163/176] update --- utils/general.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/general.py b/utils/general.py index 1fc060519d63..24807483f5f4 100755 --- a/utils/general.py +++ b/utils/general.py @@ -236,7 +236,7 @@ def xywhn2xyxy(x, w=640, h=640, padw=0, padh=0): def xyn2xy(x, w=640, h=640, padw=0, padh=0): - # Convert (n,2) normalized segments into (n,2) segments + # Convert normalized segments into pixel segments, shape (n,2) y = x.clone() if isinstance(x, torch.Tensor) else np.copy(x) y[:, 0] = w * x[:, 0] + padw # top left x y[:, 1] = h * x[:, 1] + padh # top left y @@ -244,7 +244,7 @@ def xyn2xy(x, w=640, h=640, padw=0, padh=0): def segment2box(segment, width=640, height=640): - # Convert 1 segment label to 1 box labels, i.e. (xy1, xy2, ...) to (xyxy) + # Convert 1 segment label to 1 box label, applying inside-image constraint, i.e. (xy1, xy2, ...) to (xyxy) x, y = segment.T # segment xy inside = (x >= 0) & (y >= 0) & (x <= width) & (y <= height) x, y, = x[inside], y[inside] From 5a1e6770d45d076515de58ee3f50956e987696fc Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 11 Feb 2021 18:16:35 -0800 Subject: [PATCH 164/176] update --- utils/loss.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/loss.py b/utils/loss.py index 4eeede3863c5..481d25e207f2 100644 --- a/utils/loss.py +++ b/utils/loss.py @@ -105,7 +105,7 @@ def __init__(self, model, autobalance=False): BCEcls, BCEobj = FocalLoss(BCEcls, g), FocalLoss(BCEobj, g) det = model.module.model[-1] if is_parallel(model) else model.model[-1] # Detect() module - self.balance = {3: [4.0, 1.0, 0.25], 4: [4.0, 1.0, 0.25, 0.06], 5: [4.0, 1.0, 0.25, 0.06, .02]}[det.nl] + self.balance = {3: [4.0, 1.0, 0.4], 4: [4.0, 1.0, 0.25, 0.06], 5: [4.0, 1.0, 0.25, 0.06, .02]}[det.nl] self.ssi = (det.stride == 16).nonzero(as_tuple=False).item() # stride 16 index self.BCEcls, self.BCEobj, self.gr, self.hyp, self.autobalance = BCEcls, BCEobj, model.gr, h, autobalance for k in 'na', 'nc', 'nl', 'anchors': From 0c57c475ccaa403875a842096ac0a0902bdac20f Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 11 Feb 2021 18:41:49 -0800 Subject: [PATCH 165/176] update --- train.py | 2 +- utils/datasets.py | 14 +++----------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/train.py b/train.py index 4065e1f149ef..3223c8b47e1e 100644 --- a/train.py +++ b/train.py @@ -440,7 +440,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): parser = argparse.ArgumentParser() parser.add_argument('--weights', type=str, default='yolov5s.pt', help='initial weights path') parser.add_argument('--cfg', type=str, default='', help='model.yaml path') - parser.add_argument('--data', type=str, default='data/coco128.yaml', help='data.yaml path') + parser.add_argument('--data', type=str, default='data/coco128segments.yaml', help='data.yaml path') parser.add_argument('--hyp', type=str, default='data/hyp.scratch.yaml', help='hyperparameters path') parser.add_argument('--epochs', type=int, default=300) parser.add_argument('--batch-size', type=int, default=16, help='total batch size for all GPUs') diff --git a/utils/datasets.py b/utils/datasets.py index d2b8528746b6..60b2776f5d60 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -893,31 +893,23 @@ def random_perspective(img, targets=(), segments=(), degrees=10, translate=.1, s xy = np.ones((len(segment), 3)) xy[:, :2] = segment xy = xy @ M.T # transform - if perspective: - xy = xy[:, :2] / xy[:, 2:3] # rescale - else: # affine - xy = xy[:, :2] + xy = xy[:, :2] / xy[:, 2:3] if perspective else xy[:, :2] # perspective rescale or affine # clip - # np.clip(xy[:, 0], 0, width, out=xy[:, 0]) - # np.clip(xy[:, 1], 0, height, out=xy[:, 1]) new[i] = segment2box(xy, width, height) else: # warp boxes xy = np.ones((n * 4, 3)) xy[:, :2] = targets[:, [1, 2, 3, 4, 1, 4, 3, 2]].reshape(n * 4, 2) # x1y1, x2y2, x1y2, x2y1 xy = xy @ M.T # transform - if perspective: - xy = (xy[:, :2] / xy[:, 2:3]).reshape(n, 8) # rescale - else: # affine - xy = xy[:, :2].reshape(n, 8) + xy = (xy[:, :2] / xy[:, 2:3] if perspective else xy[:, :2]).reshape(n, 8) # perspective rescale or affine # create new boxes x = xy[:, [0, 2, 4, 6]] y = xy[:, [1, 3, 5, 7]] new = np.concatenate((x.min(1), y.min(1), x.max(1), y.max(1))).reshape(4, n).T - # clip boxes + # clip new[:, [0, 2]] = new[:, [0, 2]].clip(0, width) new[:, [1, 3]] = new[:, [1, 3]].clip(0, height) From 73e297162a77945ef1adb3e050851f971167f633 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 11 Feb 2021 18:42:09 -0800 Subject: [PATCH 166/176] update --- train.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/train.py b/train.py index 3223c8b47e1e..4065e1f149ef 100644 --- a/train.py +++ b/train.py @@ -440,7 +440,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): parser = argparse.ArgumentParser() parser.add_argument('--weights', type=str, default='yolov5s.pt', help='initial weights path') parser.add_argument('--cfg', type=str, default='', help='model.yaml path') - parser.add_argument('--data', type=str, default='data/coco128segments.yaml', help='data.yaml path') + parser.add_argument('--data', type=str, default='data/coco128.yaml', help='data.yaml path') parser.add_argument('--hyp', type=str, default='data/hyp.scratch.yaml', help='hyperparameters path') parser.add_argument('--epochs', type=int, default=300) parser.add_argument('--batch-size', type=int, default=16, help='total batch size for all GPUs') From 301a35910e56aae87de03bdb2ca99fbfeacc1a4f Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 11 Feb 2021 19:13:09 -0800 Subject: [PATCH 167/176] mosaic9 --- utils/datasets.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/utils/datasets.py b/utils/datasets.py index 60b2776f5d60..48cf3ede6967 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -715,7 +715,7 @@ def load_mosaic(self, index): def load_mosaic9(self, index): # loads images in a 9-mosaic - labels9 = [] + labels9, segments9 = [], [] s = self.img_size indices = [index] + [self.indices[random.randint(0, self.n - 1)] for _ in range(8)] # 8 additional image indices for i, index in enumerate(indices): @@ -748,30 +748,34 @@ def load_mosaic9(self, index): x1, y1, x2, y2 = [max(x, 0) for x in c] # allocate coords # Labels - labels = self.labels[index].copy() + labels, segments = self.labels[index].copy(), self.segments[index].copy() if labels.size: labels[:, 1:] = xywhn2xyxy(labels[:, 1:], w, h, padx, pady) # normalized xywh to pixel xyxy format + segments = [xyn2xy(x, w, h, padx, pady) for x in segments] labels9.append(labels) + segments9.extend(segments) # Image img9[y1:y2, x1:x2] = img[y1 - pady:, x1 - padx:] # img9[ymin:ymax, xmin:xmax] hp, wp = h, w # height, width previous # Offset - yc, xc = [int(random.uniform(0, s)) for x in self.mosaic_border] # mosaic center x, y + yc, xc = [int(random.uniform(0, s)) for _ in self.mosaic_border] # mosaic center x, y img9 = img9[yc:yc + 2 * s, xc:xc + 2 * s] # Concat/clip labels - if len(labels9): - labels9 = np.concatenate(labels9, 0) - labels9[:, [1, 3]] -= xc - labels9[:, [2, 4]] -= yc + labels9 = np.concatenate(labels9, 0) + labels9[:, [1, 3]] -= xc + labels9[:, [2, 4]] -= yc + c = np.array([xc, yc]) # centers + segments9 = [x - c for x in segments9] - np.clip(labels9[:, 1:], 0, 2 * s, out=labels9[:, 1:]) # use with random_perspective - # img9, labels9 = replicate(img9, labels9) # replicate + for x in (labels9[:, 1:], *segments9): + np.clip(x, 0, 2 * s, out=x) # clip when using random_perspective() + # img9, labels9 = replicate(img9, labels9) # replicate # Augment - img9, labels9 = random_perspective(img9, labels9, + img9, labels9 = random_perspective(img9, labels9, segments9, degrees=self.hyp['degrees'], translate=self.hyp['translate'], scale=self.hyp['scale'], From ebc79d8db99f40309a72e109db0ad9f3432b9ce9 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 11 Feb 2021 19:20:10 -0800 Subject: [PATCH 168/176] update --- data/coco_segments.yaml | 35 --------- data/hyp.lrf01.yaml | 33 --------- data/hyp.master.yaml | 33 --------- data/hyp.master09scale.yaml | 33 --------- models/hub/experimental/yolov5l2-640-3.yaml | 57 --------------- models/hub/experimental/yolov5l2-640-4.yaml | 58 --------------- models/hub/experimental/yolov5l26-1280.yaml | 69 ------------------ .../hub/experimental/yolov5l6-1280-36666.yaml | 60 ---------------- models/hub/experimental/yolov5l6-1280.yaml | 60 ---------------- models/hub/experimental/yolov5l6-1920.yaml | 60 ---------------- .../hub/experimental/yolov5l6-3only-640.yaml | 45 ------------ .../hub/experimental/yolov5l6-4only-640.yaml | 49 ------------- .../hub/experimental/yolov5l6-5only-640.yaml | 53 -------------- models/hub/experimental/yolov5l6-640.yaml | 60 ---------------- .../hub/experimental/yolov5l6-6only-640.yaml | 57 --------------- models/hub/experimental/yolov5l7-1280.yaml | 72 ------------------- models/hub/experimental/yolov5l7-1920.yaml | 72 ------------------- models/hub/experimental/yolov5l7-640.yaml | 72 ------------------- models/hub/experimental/yolov5m6-1280.yaml | 60 ---------------- models/hub/experimental/yolov5s6-1280.yaml | 60 ---------------- models/hub/experimental/yolov5x6-1280.yaml | 60 ---------------- models/hub/experimental/yolov5x6-1920.yaml | 60 ---------------- models/hub/experimental/yolov5x6-640.yaml | 60 ---------------- models/hub/experimental/yolov5x7-1280.yaml | 72 ------------------- models/hub/experimental/yolov5x7-1920.yaml | 72 ------------------- models/hub/experimental/yolov5x7-640.yaml | 72 ------------------- 26 files changed, 1494 deletions(-) delete mode 100644 data/coco_segments.yaml delete mode 100644 data/hyp.lrf01.yaml delete mode 100644 data/hyp.master.yaml delete mode 100644 data/hyp.master09scale.yaml delete mode 100644 models/hub/experimental/yolov5l2-640-3.yaml delete mode 100644 models/hub/experimental/yolov5l2-640-4.yaml delete mode 100644 models/hub/experimental/yolov5l26-1280.yaml delete mode 100644 models/hub/experimental/yolov5l6-1280-36666.yaml delete mode 100644 models/hub/experimental/yolov5l6-1280.yaml delete mode 100644 models/hub/experimental/yolov5l6-1920.yaml delete mode 100644 models/hub/experimental/yolov5l6-3only-640.yaml delete mode 100644 models/hub/experimental/yolov5l6-4only-640.yaml delete mode 100644 models/hub/experimental/yolov5l6-5only-640.yaml delete mode 100644 models/hub/experimental/yolov5l6-640.yaml delete mode 100644 models/hub/experimental/yolov5l6-6only-640.yaml delete mode 100644 models/hub/experimental/yolov5l7-1280.yaml delete mode 100644 models/hub/experimental/yolov5l7-1920.yaml delete mode 100644 models/hub/experimental/yolov5l7-640.yaml delete mode 100644 models/hub/experimental/yolov5m6-1280.yaml delete mode 100644 models/hub/experimental/yolov5s6-1280.yaml delete mode 100644 models/hub/experimental/yolov5x6-1280.yaml delete mode 100644 models/hub/experimental/yolov5x6-1920.yaml delete mode 100644 models/hub/experimental/yolov5x6-640.yaml delete mode 100644 models/hub/experimental/yolov5x7-1280.yaml delete mode 100644 models/hub/experimental/yolov5x7-1920.yaml delete mode 100644 models/hub/experimental/yolov5x7-640.yaml diff --git a/data/coco_segments.yaml b/data/coco_segments.yaml deleted file mode 100644 index 9e841819291e..000000000000 --- a/data/coco_segments.yaml +++ /dev/null @@ -1,35 +0,0 @@ -# COCO 2017 dataset http://cocodataset.org -# Train command: python train.py --data coco.yaml -# Default dataset location is next to /yolov5: -# /parent_folder -# /coco -# /yolov5 - - -# download command/URL (optional) -download: bash data/scripts/get_coco_segments.sh - -# train and val data as 1) directory: path/images/, 2) file: path/images.txt, or 3) list: [path1/images/, path2/images/] -train: ../coco_segments/train2017.txt # 118287 images -val: ../coco_segments/val2017.txt # 5000 images -test: ../coco_segments/test-dev2017.txt # 20288 of 40670 images, submit to https://competitions.codalab.org/competitions/20794 - -# number of classes -nc: 80 - -# class names -names: [ 'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light', - 'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow', - 'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', - 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard', - 'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', - 'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', - 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone', - 'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear', - 'hair drier', 'toothbrush' ] - -# Print classes -# with open('data/coco.yaml') as f: -# d = yaml.load(f, Loader=yaml.FullLoader) # dict -# for i, x in enumerate(d['names']): -# print(i, x) diff --git a/data/hyp.lrf01.yaml b/data/hyp.lrf01.yaml deleted file mode 100644 index 4c619fede914..000000000000 --- a/data/hyp.lrf01.yaml +++ /dev/null @@ -1,33 +0,0 @@ -# Hyperparameters for COCO training from scratch -# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 -# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials - - -lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) -lrf: 0.10 # final OneCycleLR learning rate (lr0 * lrf) -momentum: 0.937 # SGD momentum/Adam beta1 -weight_decay: 0.0005 # optimizer weight decay 5e-4 -warmup_epochs: 3.0 # warmup epochs (fractions ok) -warmup_momentum: 0.8 # warmup initial momentum -warmup_bias_lr: 0.1 # warmup initial bias lr -box: 0.05 # box loss gain -cls: 0.3 # cls loss gain -cls_pw: 1.0 # cls BCELoss positive_weight -obj: 0.52 # obj loss gain (scale with pixels) -obj_pw: 1.0 # obj BCELoss positive_weight -iou_t: 0.20 # IoU training threshold -anchor_t: 4.0 # anchor-multiple threshold -# anchors: 3 # anchors per output layer (0 to ignore) -fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) -hsv_h: 0.015 # image HSV-Hue augmentation (fraction) -hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) -hsv_v: 0.4 # image HSV-Value augmentation (fraction) -degrees: 0.0 # image rotation (+/- deg) -translate: 0.1 # image translation (+/- fraction) -scale: 0.95 # image scale (+/- gain) -shear: 0.0 # image shear (+/- deg) -perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 -flipud: 0.0 # image flip up-down (probability) -fliplr: 0.5 # image flip left-right (probability) -mosaic: 1.0 # image mosaic (probability) -mixup: 0.01 # image mixup (probability) diff --git a/data/hyp.master.yaml b/data/hyp.master.yaml deleted file mode 100644 index 44f26b6658ae..000000000000 --- a/data/hyp.master.yaml +++ /dev/null @@ -1,33 +0,0 @@ -# Hyperparameters for COCO training from scratch -# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 -# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials - - -lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) -lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) -momentum: 0.937 # SGD momentum/Adam beta1 -weight_decay: 0.0005 # optimizer weight decay 5e-4 -warmup_epochs: 3.0 # warmup epochs (fractions ok) -warmup_momentum: 0.8 # warmup initial momentum -warmup_bias_lr: 0.1 # warmup initial bias lr -box: 0.05 # box loss gain -cls: 0.5 # cls loss gain -cls_pw: 1.0 # cls BCELoss positive_weight -obj: 1.0 # obj loss gain (scale with pixels) -obj_pw: 1.0 # obj BCELoss positive_weight -iou_t: 0.20 # IoU training threshold -anchor_t: 4.0 # anchor-multiple threshold -# anchors: 3 # anchors per output layer (0 to ignore) -fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) -hsv_h: 0.015 # image HSV-Hue augmentation (fraction) -hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) -hsv_v: 0.4 # image HSV-Value augmentation (fraction) -degrees: 0.0 # image rotation (+/- deg) -translate: 0.1 # image translation (+/- fraction) -scale: 0.5 # image scale (+/- gain) -shear: 0.0 # image shear (+/- deg) -perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 -flipud: 0.0 # image flip up-down (probability) -fliplr: 0.5 # image flip left-right (probability) -mosaic: 1.0 # image mosaic (probability) -mixup: 0.0 # image mixup (probability) diff --git a/data/hyp.master09scale.yaml b/data/hyp.master09scale.yaml deleted file mode 100644 index 14fbd3d2fab9..000000000000 --- a/data/hyp.master09scale.yaml +++ /dev/null @@ -1,33 +0,0 @@ -# Hyperparameters for COCO training from scratch -# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 -# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials - - -lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) -lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) -momentum: 0.937 # SGD momentum/Adam beta1 -weight_decay: 0.0005 # optimizer weight decay 5e-4 -warmup_epochs: 3.0 # warmup epochs (fractions ok) -warmup_momentum: 0.8 # warmup initial momentum -warmup_bias_lr: 0.1 # warmup initial bias lr -box: 0.05 # box loss gain -cls: 0.5 # cls loss gain -cls_pw: 1.0 # cls BCELoss positive_weight -obj: 1.0 # obj loss gain (scale with pixels) -obj_pw: 1.0 # obj BCELoss positive_weight -iou_t: 0.20 # IoU training threshold -anchor_t: 4.0 # anchor-multiple threshold -# anchors: 3 # anchors per output layer (0 to ignore) -fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) -hsv_h: 0.015 # image HSV-Hue augmentation (fraction) -hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) -hsv_v: 0.4 # image HSV-Value augmentation (fraction) -degrees: 0.0 # image rotation (+/- deg) -translate: 0.1 # image translation (+/- fraction) -scale: 0.9 # image scale (+/- gain) -shear: 0.0 # image shear (+/- deg) -perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 -flipud: 0.0 # image flip up-down (probability) -fliplr: 0.5 # image flip left-right (probability) -mosaic: 1.0 # image mosaic (probability) -mixup: 0.0 # image mixup (probability) diff --git a/models/hub/experimental/yolov5l2-640-3.yaml b/models/hub/experimental/yolov5l2-640-3.yaml deleted file mode 100644 index 1dd3cc1b3168..000000000000 --- a/models/hub/experimental/yolov5l2-640-3.yaml +++ /dev/null @@ -1,57 +0,0 @@ -# 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, [ 128, 1, 1 ] ], - [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], - [ [ -1, 2 ], 1, Concat, [ 1 ] ], # cat backbone P2 - [ -1, 1, C3, [ 128, False ] ], # 21 (P2/4-xsmall) - - [ -1, 1, Conv, [ 128, 3, 2 ] ], - [ [ -1, 18 ], 1, Concat, [ 1 ] ], # cat head P3 - [ -1, 3, C3, [ 256, False ] ], # 24 (P3/8-small) - - [ -1, 1, Conv, [ 256, 3, 2 ] ], - [ [ -1, 14 ], 1, Concat, [ 1 ] ], # cat head P4 - [ -1, 3, C3, [ 512, False ] ], # 27 (P4/16-medium) - - [ -1, 1, Conv, [ 512, 3, 2 ] ], - [ [ -1, 10 ], 1, Concat, [ 1 ] ], # cat head P5 - [ -1, 3, C3, [ 1024, False ] ], # 30 (P5/32-large) - - [ [ 24, 27, 30 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5) - ] diff --git a/models/hub/experimental/yolov5l2-640-4.yaml b/models/hub/experimental/yolov5l2-640-4.yaml deleted file mode 100644 index ec0559d469a2..000000000000 --- a/models/hub/experimental/yolov5l2-640-4.yaml +++ /dev/null @@ -1,58 +0,0 @@ -# parameters -nc: 80 # number of classes -depth_multiple: 1.0 # model depth multiple -width_multiple: 1.0 # layer channel multiple - -# anchors -anchors: - - [ 9,11, 21,19, 17,41 ] # P3/8 - - [ 43,32, 39,70, 86,64 ] # P4/16 - - [ 65,131, 134,130, 120,265 ] # P5/32 - - [ 282,180, 247,354, 512,387 ] # P6/64 - -# 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, [ 128, 1, 1 ] ], - [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], - [ [ -1, 2 ], 1, Concat, [ 1 ] ], # cat backbone P2 - [ -1, 1, C3, [ 128, False ] ], # 21 (P2/4-xsmall) - - [ -1, 1, Conv, [ 128, 3, 2 ] ], - [ [ -1, 18 ], 1, Concat, [ 1 ] ], # cat head P3 - [ -1, 3, C3, [ 256, False ] ], # 24 (P3/8-small) - - [ -1, 1, Conv, [ 256, 3, 2 ] ], - [ [ -1, 14 ], 1, Concat, [ 1 ] ], # cat head P4 - [ -1, 3, C3, [ 512, False ] ], # 27 (P4/16-medium) - - [ -1, 1, Conv, [ 512, 3, 2 ] ], - [ [ -1, 10 ], 1, Concat, [ 1 ] ], # cat head P5 - [ -1, 3, C3, [ 1024, False ] ], # 30 (P5/32-large) - - [ [ 21, 24, 27, 30 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5) - ] diff --git a/models/hub/experimental/yolov5l26-1280.yaml b/models/hub/experimental/yolov5l26-1280.yaml deleted file mode 100644 index 07f72b6e37e3..000000000000 --- a/models/hub/experimental/yolov5l26-1280.yaml +++ /dev/null @@ -1,69 +0,0 @@ -# parameters -nc: 80 # number of classes -depth_multiple: 1.0 # model depth multiple -width_multiple: 1.0 # layer channel multiple - -# anchors -anchors: - - [ 19,27, 44,40, 38,94 ] # P3/8 - - [ 96,68, 86,152, 180,137 ] # P4/16 - - [ 140,301, 303,264, 238,542 ] # P5/32 - - [ 436,615, 739,380, 925,792 ] # P6/64 - -# 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, [ 768, 3, 2 ] ], # 7-P5/32 - [ -1, 3, C3, [ 768 ] ], - [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 - [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ], - [ -1, 3, C3, [ 1024, False ] ], # 11 - ] - -# YOLOv5 head -head: - [ [ -1, 1, Conv, [ 768, 1, 1 ] ], - [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], - [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 - [ -1, 3, C3, [ 768, False ] ], # 15 - - [ -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 ] ], # 19 - - [ -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 ] ], # 23 - - [ -1, 1, Conv, [ 128, 1, 1 ] ], - [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], - [ [ -1, 2 ], 1, Concat, [ 1 ] ], # cat backbone P2 - [ -1, 1, C3, [ 128, False ] ], # 27 (P2/4-xsmall) - - [ -1, 1, Conv, [ 128, 3, 2 ] ], - [ [ -1, 24 ], 1, Concat, [ 1 ] ], # cat head P3 - [ -1, 3, C3, [ 256, False ] ], # 30 (P3/8-small) - - [ -1, 1, Conv, [ 256, 3, 2 ] ], - [ [ -1, 20 ], 1, Concat, [ 1 ] ], # cat head P4 - [ -1, 3, C3, [ 512, False ] ], # 33 (P4/16-medium) - - [ -1, 1, Conv, [ 512, 3, 2 ] ], - [ [ -1, 16 ], 1, Concat, [ 1 ] ], # cat head P5 - [ -1, 3, C3, [ 768, False ] ], # 36 (P5/32-large) - - [ -1, 1, Conv, [ 768, 3, 2 ] ], - [ [ -1, 12 ], 1, Concat, [ 1 ] ], # cat head P6 - [ -1, 3, C3, [ 1024, False ] ], # 39 (P5/64-xlarge) - - [ [ 30, 33, 36, 39 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) - ] diff --git a/models/hub/experimental/yolov5l6-1280-36666.yaml b/models/hub/experimental/yolov5l6-1280-36666.yaml deleted file mode 100644 index 6ecb76381fc7..000000000000 --- a/models/hub/experimental/yolov5l6-1280-36666.yaml +++ /dev/null @@ -1,60 +0,0 @@ -# parameters -nc: 80 # number of classes -depth_multiple: 1.0 # model depth multiple -width_multiple: 1.0 # layer channel multiple - -# anchors -anchors: - - [ 19,27, 44,40, 38,94 ] # P3/8 - - [ 96,68, 86,152, 180,137 ] # P4/16 - - [ 140,301, 303,264, 238,542 ] # P5/32 - - [ 436,615, 739,380, 925,792 ] # P6/64 - -# 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, 6, C3, [ 256 ] ], - [ -1, 1, Conv, [ 512, 3, 2 ] ], # 5-P4/16 - [ -1, 6, C3, [ 512 ] ], - [ -1, 1, Conv, [ 768, 3, 2 ] ], # 7-P5/32 - [ -1, 6, C3, [ 768 ] ], - [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 - [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ], - [ -1, 6, C3, [ 1024, False ] ], # 11 - ] - -# YOLOv5 head -head: - [ [ -1, 1, Conv, [ 768, 1, 1 ] ], - [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], - [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 - [ -1, 3, C3, [ 768, False ] ], # 15 - - [ -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 ] ], # 19 - - [ -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 ] ], # 23 (P3/8-small) - - [ -1, 1, Conv, [ 256, 3, 2 ] ], - [ [ -1, 20 ], 1, Concat, [ 1 ] ], # cat head P4 - [ -1, 3, C3, [ 512, False ] ], # 26 (P4/16-medium) - - [ -1, 1, Conv, [ 512, 3, 2 ] ], - [ [ -1, 16 ], 1, Concat, [ 1 ] ], # cat head P5 - [ -1, 3, C3, [ 768, False ] ], # 29 (P5/32-large) - - [ -1, 1, Conv, [ 768, 3, 2 ] ], - [ [ -1, 12 ], 1, Concat, [ 1 ] ], # cat head P6 - [ -1, 3, C3, [ 1024, False ] ], # 32 (P5/64-xlarge) - - [ [ 23, 26, 29, 32 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) - ] diff --git a/models/hub/experimental/yolov5l6-1280.yaml b/models/hub/experimental/yolov5l6-1280.yaml deleted file mode 100644 index e0699d413c9f..000000000000 --- a/models/hub/experimental/yolov5l6-1280.yaml +++ /dev/null @@ -1,60 +0,0 @@ -# parameters -nc: 80 # number of classes -depth_multiple: 1.0 # model depth multiple -width_multiple: 1.0 # layer channel multiple - -# anchors -anchors: - - [ 19,27, 44,40, 38,94 ] # P3/8 - - [ 96,68, 86,152, 180,137 ] # P4/16 - - [ 140,301, 303,264, 238,542 ] # P5/32 - - [ 436,615, 739,380, 925,792 ] # P6/64 - -# 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, [ 768, 3, 2 ] ], # 7-P5/32 - [ -1, 3, C3, [ 768 ] ], - [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 - [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ], - [ -1, 3, C3, [ 1024, False ] ], # 11 - ] - -# YOLOv5 head -head: - [ [ -1, 1, Conv, [ 768, 1, 1 ] ], - [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], - [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 - [ -1, 3, C3, [ 768, False ] ], # 15 - - [ -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 ] ], # 19 - - [ -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 ] ], # 23 (P3/8-small) - - [ -1, 1, Conv, [ 256, 3, 2 ] ], - [ [ -1, 20 ], 1, Concat, [ 1 ] ], # cat head P4 - [ -1, 3, C3, [ 512, False ] ], # 26 (P4/16-medium) - - [ -1, 1, Conv, [ 512, 3, 2 ] ], - [ [ -1, 16 ], 1, Concat, [ 1 ] ], # cat head P5 - [ -1, 3, C3, [ 768, False ] ], # 29 (P5/32-large) - - [ -1, 1, Conv, [ 768, 3, 2 ] ], - [ [ -1, 12 ], 1, Concat, [ 1 ] ], # cat head P6 - [ -1, 3, C3, [ 1024, False ] ], # 32 (P5/64-xlarge) - - [ [ 23, 26, 29, 32 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) - ] diff --git a/models/hub/experimental/yolov5l6-1920.yaml b/models/hub/experimental/yolov5l6-1920.yaml deleted file mode 100644 index 6350ef9b17b5..000000000000 --- a/models/hub/experimental/yolov5l6-1920.yaml +++ /dev/null @@ -1,60 +0,0 @@ -# parameters -nc: 80 # number of classes -depth_multiple: 1.0 # model depth multiple -width_multiple: 1.0 # layer channel multiple - -# anchors -anchors: - - [ 28,41, 67,59, 57,141 ] # P3/8 - - [ 144,103, 129,227, 270,205 ] # P4/16 - - [ 209,452, 455,396, 358,812 ] # P5/32 - - [ 653,922, 1109,570, 1387,1187 ] # P6/64 - -# 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, [ 768, 3, 2 ] ], # 7-P5/32 - [ -1, 3, C3, [ 768 ] ], - [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 - [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ], - [ -1, 3, C3, [ 1024, False ] ], # 11 - ] - -# YOLOv5 head -head: - [ [ -1, 1, Conv, [ 768, 1, 1 ] ], - [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], - [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 - [ -1, 3, C3, [ 768, False ] ], # 15 - - [ -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 ] ], # 19 - - [ -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 ] ], # 23 (P3/8-small) - - [ -1, 1, Conv, [ 256, 3, 2 ] ], - [ [ -1, 20 ], 1, Concat, [ 1 ] ], # cat head P4 - [ -1, 3, C3, [ 512, False ] ], # 26 (P4/16-medium) - - [ -1, 1, Conv, [ 512, 3, 2 ] ], - [ [ -1, 16 ], 1, Concat, [ 1 ] ], # cat head P5 - [ -1, 3, C3, [ 768, False ] ], # 29 (P5/32-large) - - [ -1, 1, Conv, [ 768, 3, 2 ] ], - [ [ -1, 12 ], 1, Concat, [ 1 ] ], # cat head P6 - [ -1, 3, C3, [ 1024, False ] ], # 32 (P5/64-xlarge) - - [ [ 23, 26, 29, 32 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) - ] diff --git a/models/hub/experimental/yolov5l6-3only-640.yaml b/models/hub/experimental/yolov5l6-3only-640.yaml deleted file mode 100644 index e8c2db1365d5..000000000000 --- a/models/hub/experimental/yolov5l6-3only-640.yaml +++ /dev/null @@ -1,45 +0,0 @@ -# parameters -nc: 80 # number of classes -depth_multiple: 1.0 # model depth multiple -width_multiple: 1.0 # layer channel multiple - -# anchors -anchors: - - [ 9,11, 21,19, 17,41 ] # P3/8 - -# 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, [ 768, 3, 2 ] ], # 7-P5/32 - [ -1, 3, C3, [ 768 ] ], - [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 - [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ], - [ -1, 3, C3, [ 1024, False ] ], # 11 - ] - -# YOLOv5 head -head: - [ [ -1, 1, Conv, [ 768, 1, 1 ] ], - [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], - [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 - [ -1, 3, C3, [ 768, False ] ], # 15 - - [ -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 ] ], # 19 - - [ -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 ] ], # 23 (P3/8-small) - - [ [ 23 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) - ] diff --git a/models/hub/experimental/yolov5l6-4only-640.yaml b/models/hub/experimental/yolov5l6-4only-640.yaml deleted file mode 100644 index 997f1351bb62..000000000000 --- a/models/hub/experimental/yolov5l6-4only-640.yaml +++ /dev/null @@ -1,49 +0,0 @@ -# parameters -nc: 80 # number of classes -depth_multiple: 1.0 # model depth multiple -width_multiple: 1.0 # layer channel multiple - -# anchors -anchors: - - [ 43,32, 39,70, 86,64 ] # P4/16 - -# 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, [ 768, 3, 2 ] ], # 7-P5/32 - [ -1, 3, C3, [ 768 ] ], - [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 - [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ], - [ -1, 3, C3, [ 1024, False ] ], # 11 - ] - -# YOLOv5 head -head: - [ [ -1, 1, Conv, [ 768, 1, 1 ] ], - [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], - [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 - [ -1, 3, C3, [ 768, False ] ], # 15 - - [ -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 ] ], # 19 - - [ -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 ] ], # 23 (P3/8-small) - - [ -1, 1, Conv, [ 256, 3, 2 ] ], - [ [ -1, 20 ], 1, Concat, [ 1 ] ], # cat head P4 - [ -1, 3, C3, [ 512, False ] ], # 26 (P4/16-medium) - - [ [ 26 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) - ] diff --git a/models/hub/experimental/yolov5l6-5only-640.yaml b/models/hub/experimental/yolov5l6-5only-640.yaml deleted file mode 100644 index db4dc33d9b3a..000000000000 --- a/models/hub/experimental/yolov5l6-5only-640.yaml +++ /dev/null @@ -1,53 +0,0 @@ -# parameters -nc: 80 # number of classes -depth_multiple: 1.0 # model depth multiple -width_multiple: 1.0 # layer channel multiple - -# anchors -anchors: - - [ 65,131, 134,130, 120,265 ] # 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, [ 768, 3, 2 ] ], # 7-P5/32 - [ -1, 3, C3, [ 768 ] ], - [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 - [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ], - [ -1, 3, C3, [ 1024, False ] ], # 11 - ] - -# YOLOv5 head -head: - [ [ -1, 1, Conv, [ 768, 1, 1 ] ], - [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], - [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 - [ -1, 3, C3, [ 768, False ] ], # 15 - - [ -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 ] ], # 19 - - [ -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 ] ], # 23 (P3/8-small) - - [ -1, 1, Conv, [ 256, 3, 2 ] ], - [ [ -1, 20 ], 1, Concat, [ 1 ] ], # cat head P4 - [ -1, 3, C3, [ 512, False ] ], # 26 (P4/16-medium) - - [ -1, 1, Conv, [ 512, 3, 2 ] ], - [ [ -1, 16 ], 1, Concat, [ 1 ] ], # cat head P5 - [ -1, 3, C3, [ 768, False ] ], # 29 (P5/32-large) - - [ [ 29 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) - ] diff --git a/models/hub/experimental/yolov5l6-640.yaml b/models/hub/experimental/yolov5l6-640.yaml deleted file mode 100644 index 1db7f3caec58..000000000000 --- a/models/hub/experimental/yolov5l6-640.yaml +++ /dev/null @@ -1,60 +0,0 @@ -# parameters -nc: 80 # number of classes -depth_multiple: 1.0 # model depth multiple -width_multiple: 1.0 # layer channel multiple - -# anchors -anchors: - - [ 9,11, 21,19, 17,41 ] # P3/8 - - [ 43,32, 39,70, 86,64 ] # P4/16 - - [ 65,131, 134,130, 120,265 ] # P5/32 - - [ 282,180, 247,354, 512,387 ] # P6/64 - -# 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, [ 768, 3, 2 ] ], # 7-P5/32 - [ -1, 3, C3, [ 768 ] ], - [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 - [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ], - [ -1, 3, C3, [ 1024, False ] ], # 11 - ] - -# YOLOv5 head -head: - [ [ -1, 1, Conv, [ 768, 1, 1 ] ], - [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], - [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 - [ -1, 3, C3, [ 768, False ] ], # 15 - - [ -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 ] ], # 19 - - [ -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 ] ], # 23 (P3/8-small) - - [ -1, 1, Conv, [ 256, 3, 2 ] ], - [ [ -1, 20 ], 1, Concat, [ 1 ] ], # cat head P4 - [ -1, 3, C3, [ 512, False ] ], # 26 (P4/16-medium) - - [ -1, 1, Conv, [ 512, 3, 2 ] ], - [ [ -1, 16 ], 1, Concat, [ 1 ] ], # cat head P5 - [ -1, 3, C3, [ 768, False ] ], # 29 (P5/32-large) - - [ -1, 1, Conv, [ 768, 3, 2 ] ], - [ [ -1, 12 ], 1, Concat, [ 1 ] ], # cat head P6 - [ -1, 3, C3, [ 1024, False ] ], # 32 (P5/64-xlarge) - - [ [ 23, 26, 29, 32 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) - ] diff --git a/models/hub/experimental/yolov5l6-6only-640.yaml b/models/hub/experimental/yolov5l6-6only-640.yaml deleted file mode 100644 index d77a1449ea08..000000000000 --- a/models/hub/experimental/yolov5l6-6only-640.yaml +++ /dev/null @@ -1,57 +0,0 @@ -# parameters -nc: 80 # number of classes -depth_multiple: 1.0 # model depth multiple -width_multiple: 1.0 # layer channel multiple - -# anchors -anchors: - - [ 282,180, 247,354, 512,387 ] # P6/64 - -# 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, [ 768, 3, 2 ] ], # 7-P5/32 - [ -1, 3, C3, [ 768 ] ], - [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 - [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ], - [ -1, 3, C3, [ 1024, False ] ], # 11 - ] - -# YOLOv5 head -head: - [ [ -1, 1, Conv, [ 768, 1, 1 ] ], - [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], - [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 - [ -1, 3, C3, [ 768, False ] ], # 15 - - [ -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 ] ], # 19 - - [ -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 ] ], # 23 (P3/8-small) - - [ -1, 1, Conv, [ 256, 3, 2 ] ], - [ [ -1, 20 ], 1, Concat, [ 1 ] ], # cat head P4 - [ -1, 3, C3, [ 512, False ] ], # 26 (P4/16-medium) - - [ -1, 1, Conv, [ 512, 3, 2 ] ], - [ [ -1, 16 ], 1, Concat, [ 1 ] ], # cat head P5 - [ -1, 3, C3, [ 768, False ] ], # 29 (P5/32-large) - - [ -1, 1, Conv, [ 768, 3, 2 ] ], - [ [ -1, 12 ], 1, Concat, [ 1 ] ], # cat head P6 - [ -1, 3, C3, [ 1024, False ] ], # 32 (P5/64-xlarge) - - [ [ 32 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) - ] diff --git a/models/hub/experimental/yolov5l7-1280.yaml b/models/hub/experimental/yolov5l7-1280.yaml deleted file mode 100644 index 1e430c520059..000000000000 --- a/models/hub/experimental/yolov5l7-1280.yaml +++ /dev/null @@ -1,72 +0,0 @@ -# parameters -nc: 80 # number of classes -depth_multiple: 1.0 # model depth multiple -width_multiple: 1.0 # layer channel multiple - -# anchors -anchors: - - [ 19,22, 54,36, 32,77 ] # P3/8 - - [ 70,83, 138,71, 75,173 ] # P4/16 - - [ 165,159, 148,334, 375,151 ] # P5/32 - - [ 334,317, 251,626, 499,474 ] # P6/64 - - [ 750,326, 534,814, 1079,818 ] # P7/128 - -# 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, [ 768, 3, 2 ] ], # 7-P5/32 - [ -1, 3, C3, [ 768 ] ], - [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 - [ -1, 3, C3, [ 1024 ] ], - [ -1, 1, Conv, [ 1280, 3, 2 ] ], # 11-P7/128 - [ -1, 1, SPP, [ 1280, [ 3, 5, 7 ] ] ], - [ -1, 3, C3, [ 1280, False ] ], # 13 - ] - -# YOLOv5 head -head: - [ [ -1, 1, Conv, [ 1024, 1, 1 ] ], - [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], - [ [ -1, 10 ], 1, Concat, [ 1 ] ], # cat backbone P6 - [ -1, 3, C3, [ 1024, False ] ], # 17 - - [ -1, 1, Conv, [ 768, 1, 1 ] ], - [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], - [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 - [ -1, 3, C3, [ 768, False ] ], # 21 - - [ -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 ] ], # 25 - - [ -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 ] ], # 29 (P3/8-small) - - [ -1, 1, Conv, [ 256, 3, 2 ] ], - [ [ -1, 26 ], 1, Concat, [ 1 ] ], # cat head P4 - [ -1, 3, C3, [ 512, False ] ], # 32 (P4/16-medium) - - [ -1, 1, Conv, [ 512, 3, 2 ] ], - [ [ -1, 22 ], 1, Concat, [ 1 ] ], # cat head P5 - [ -1, 3, C3, [ 768, False ] ], # 35 (P5/32-large) - - [ -1, 1, Conv, [ 768, 3, 2 ] ], - [ [ -1, 18 ], 1, Concat, [ 1 ] ], # cat head P6 - [ -1, 3, C3, [ 1024, False ] ], # 38 (P6/64-xlarge) - - [ -1, 1, Conv, [ 1024, 3, 2 ] ], - [ [ -1, 14 ], 1, Concat, [ 1 ] ], # cat head P7 - [ -1, 3, C3, [ 1280, False ] ], # 41 (P7/128-xxlarge) - - [ [ 29, 32, 35, 38, 41 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) - ] diff --git a/models/hub/experimental/yolov5l7-1920.yaml b/models/hub/experimental/yolov5l7-1920.yaml deleted file mode 100644 index 15c7a93bfd3b..000000000000 --- a/models/hub/experimental/yolov5l7-1920.yaml +++ /dev/null @@ -1,72 +0,0 @@ -# parameters -nc: 80 # number of classes -depth_multiple: 1.0 # model depth multiple -width_multiple: 1.0 # layer channel multiple - -# anchors -anchors: - - [ 29,34, 81,55, 47,115 ] # P3/8 - - [ 105,124, 207,107, 113,259 ] # P4/16 - - [ 247,238, 222,500, 563,227 ] # P5/32 - - [ 501,476, 376,939, 749,711 ] # P6/64 - - [ 1126,489, 801,1222, 1618,1227 ] # P7/128 - -# 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, [ 768, 3, 2 ] ], # 7-P5/32 - [ -1, 3, C3, [ 768 ] ], - [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 - [ -1, 3, C3, [ 1024 ] ], - [ -1, 1, Conv, [ 1280, 3, 2 ] ], # 11-P7/128 - [ -1, 1, SPP, [ 1280, [ 3, 5, 7 ] ] ], - [ -1, 3, C3, [ 1280, False ] ], # 13 - ] - -# YOLOv5 head -head: - [ [ -1, 1, Conv, [ 1024, 1, 1 ] ], - [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], - [ [ -1, 10 ], 1, Concat, [ 1 ] ], # cat backbone P6 - [ -1, 3, C3, [ 1024, False ] ], # 17 - - [ -1, 1, Conv, [ 768, 1, 1 ] ], - [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], - [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 - [ -1, 3, C3, [ 768, False ] ], # 21 - - [ -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 ] ], # 25 - - [ -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 ] ], # 29 (P3/8-small) - - [ -1, 1, Conv, [ 256, 3, 2 ] ], - [ [ -1, 26 ], 1, Concat, [ 1 ] ], # cat head P4 - [ -1, 3, C3, [ 512, False ] ], # 32 (P4/16-medium) - - [ -1, 1, Conv, [ 512, 3, 2 ] ], - [ [ -1, 22 ], 1, Concat, [ 1 ] ], # cat head P5 - [ -1, 3, C3, [ 768, False ] ], # 35 (P5/32-large) - - [ -1, 1, Conv, [ 768, 3, 2 ] ], - [ [ -1, 18 ], 1, Concat, [ 1 ] ], # cat head P6 - [ -1, 3, C3, [ 1024, False ] ], # 38 (P6/64-xlarge) - - [ -1, 1, Conv, [ 1024, 3, 2 ] ], - [ [ -1, 14 ], 1, Concat, [ 1 ] ], # cat head P7 - [ -1, 3, C3, [ 1280, False ] ], # 41 (P7/128-xxlarge) - - [ [ 29, 32, 35, 38, 41 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) - ] diff --git a/models/hub/experimental/yolov5l7-640.yaml b/models/hub/experimental/yolov5l7-640.yaml deleted file mode 100644 index 78d896afbdec..000000000000 --- a/models/hub/experimental/yolov5l7-640.yaml +++ /dev/null @@ -1,72 +0,0 @@ -# parameters -nc: 80 # number of classes -depth_multiple: 1.0 # model depth multiple -width_multiple: 1.0 # layer channel multiple - -# anchors -anchors: - - [ 11,11, 13,30, 29,20 ] # P3/8 - - [ 30,46, 61,38, 39,92 ] # P4/16 - - [ 78,80, 146,66, 79,163 ] # P5/32 - - [ 149,150, 321,143, 157,303 ] # P6/64 - - [ 257,402, 359,290, 524,372 ] # P7/128 - -# 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, [ 768, 3, 2 ] ], # 7-P5/32 - [ -1, 3, C3, [ 768 ] ], - [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 - [ -1, 3, C3, [ 1024 ] ], - [ -1, 1, Conv, [ 1280, 3, 2 ] ], # 11-P7/128 - [ -1, 1, SPP, [ 1280, [ 3, 5, 7 ] ] ], - [ -1, 3, C3, [ 1280, False ] ], # 13 - ] - -# YOLOv5 head -head: - [ [ -1, 1, Conv, [ 1024, 1, 1 ] ], - [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], - [ [ -1, 10 ], 1, Concat, [ 1 ] ], # cat backbone P6 - [ -1, 3, C3, [ 1024, False ] ], # 17 - - [ -1, 1, Conv, [ 768, 1, 1 ] ], - [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], - [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 - [ -1, 3, C3, [ 768, False ] ], # 21 - - [ -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 ] ], # 25 - - [ -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 ] ], # 29 (P3/8-small) - - [ -1, 1, Conv, [ 256, 3, 2 ] ], - [ [ -1, 26 ], 1, Concat, [ 1 ] ], # cat head P4 - [ -1, 3, C3, [ 512, False ] ], # 32 (P4/16-medium) - - [ -1, 1, Conv, [ 512, 3, 2 ] ], - [ [ -1, 22 ], 1, Concat, [ 1 ] ], # cat head P5 - [ -1, 3, C3, [ 768, False ] ], # 35 (P5/32-large) - - [ -1, 1, Conv, [ 768, 3, 2 ] ], - [ [ -1, 18 ], 1, Concat, [ 1 ] ], # cat head P6 - [ -1, 3, C3, [ 1024, False ] ], # 38 (P6/64-xlarge) - - [ -1, 1, Conv, [ 1024, 3, 2 ] ], - [ [ -1, 14 ], 1, Concat, [ 1 ] ], # cat head P7 - [ -1, 3, C3, [ 1280, False ] ], # 41 (P7/128-xxlarge) - - [ [ 29, 32, 35, 38, 41 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) - ] diff --git a/models/hub/experimental/yolov5m6-1280.yaml b/models/hub/experimental/yolov5m6-1280.yaml deleted file mode 100644 index 71ff2ca89936..000000000000 --- a/models/hub/experimental/yolov5m6-1280.yaml +++ /dev/null @@ -1,60 +0,0 @@ -# parameters -nc: 80 # number of classes -depth_multiple: .67 # model depth multiple -width_multiple: .75 # layer channel multiple - -# anchors -anchors: - - [ 19,27, 44,40, 38,94 ] # P3/8 - - [ 96,68, 86,152, 180,137 ] # P4/16 - - [ 140,301, 303,264, 238,542 ] # P5/32 - - [ 436,615, 739,380, 925,792 ] # P6/64 - -# 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, [ 768, 3, 2 ] ], # 7-P5/32 - [ -1, 3, C3, [ 768 ] ], - [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 - [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ], - [ -1, 3, C3, [ 1024, False ] ], # 11 - ] - -# YOLOv5 head -head: - [ [ -1, 1, Conv, [ 768, 1, 1 ] ], - [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], - [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 - [ -1, 3, C3, [ 768, False ] ], # 15 - - [ -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 ] ], # 19 - - [ -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 ] ], # 23 (P3/8-small) - - [ -1, 1, Conv, [ 256, 3, 2 ] ], - [ [ -1, 20 ], 1, Concat, [ 1 ] ], # cat head P4 - [ -1, 3, C3, [ 512, False ] ], # 26 (P4/16-medium) - - [ -1, 1, Conv, [ 512, 3, 2 ] ], - [ [ -1, 16 ], 1, Concat, [ 1 ] ], # cat head P5 - [ -1, 3, C3, [ 768, False ] ], # 29 (P5/32-large) - - [ -1, 1, Conv, [ 768, 3, 2 ] ], - [ [ -1, 12 ], 1, Concat, [ 1 ] ], # cat head P6 - [ -1, 3, C3, [ 1024, False ] ], # 32 (P5/64-xlarge) - - [ [ 23, 26, 29, 32 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) - ] diff --git a/models/hub/experimental/yolov5s6-1280.yaml b/models/hub/experimental/yolov5s6-1280.yaml deleted file mode 100644 index 876cd764515b..000000000000 --- a/models/hub/experimental/yolov5s6-1280.yaml +++ /dev/null @@ -1,60 +0,0 @@ -# parameters -nc: 80 # number of classes -depth_multiple: .33 # model depth multiple -width_multiple: .50 # layer channel multiple - -# anchors -anchors: - - [ 19,27, 44,40, 38,94 ] # P3/8 - - [ 96,68, 86,152, 180,137 ] # P4/16 - - [ 140,301, 303,264, 238,542 ] # P5/32 - - [ 436,615, 739,380, 925,792 ] # P6/64 - -# 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, [ 768, 3, 2 ] ], # 7-P5/32 - [ -1, 3, C3, [ 768 ] ], - [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 - [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ], - [ -1, 3, C3, [ 1024, False ] ], # 11 - ] - -# YOLOv5 head -head: - [ [ -1, 1, Conv, [ 768, 1, 1 ] ], - [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], - [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 - [ -1, 3, C3, [ 768, False ] ], # 15 - - [ -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 ] ], # 19 - - [ -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 ] ], # 23 (P3/8-small) - - [ -1, 1, Conv, [ 256, 3, 2 ] ], - [ [ -1, 20 ], 1, Concat, [ 1 ] ], # cat head P4 - [ -1, 3, C3, [ 512, False ] ], # 26 (P4/16-medium) - - [ -1, 1, Conv, [ 512, 3, 2 ] ], - [ [ -1, 16 ], 1, Concat, [ 1 ] ], # cat head P5 - [ -1, 3, C3, [ 768, False ] ], # 29 (P5/32-large) - - [ -1, 1, Conv, [ 768, 3, 2 ] ], - [ [ -1, 12 ], 1, Concat, [ 1 ] ], # cat head P6 - [ -1, 3, C3, [ 1024, False ] ], # 32 (P5/64-xlarge) - - [ [ 23, 26, 29, 32 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) - ] diff --git a/models/hub/experimental/yolov5x6-1280.yaml b/models/hub/experimental/yolov5x6-1280.yaml deleted file mode 100644 index eda764406e93..000000000000 --- a/models/hub/experimental/yolov5x6-1280.yaml +++ /dev/null @@ -1,60 +0,0 @@ -# parameters -nc: 80 # number of classes -depth_multiple: 1.33 # model depth multiple -width_multiple: 1.25 # layer channel multiple - -# anchors -anchors: - - [ 19,27, 44,40, 38,94 ] # P3/8 - - [ 96,68, 86,152, 180,137 ] # P4/16 - - [ 140,301, 303,264, 238,542 ] # P5/32 - - [ 436,615, 739,380, 925,792 ] # P6/64 - -# 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, [ 768, 3, 2 ] ], # 7-P5/32 - [ -1, 3, C3, [ 768 ] ], - [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 - [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ], - [ -1, 3, C3, [ 1024, False ] ], # 11 - ] - -# YOLOv5 head -head: - [ [ -1, 1, Conv, [ 768, 1, 1 ] ], - [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], - [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 - [ -1, 3, C3, [ 768, False ] ], # 15 - - [ -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 ] ], # 19 - - [ -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 ] ], # 23 (P3/8-small) - - [ -1, 1, Conv, [ 256, 3, 2 ] ], - [ [ -1, 20 ], 1, Concat, [ 1 ] ], # cat head P4 - [ -1, 3, C3, [ 512, False ] ], # 26 (P4/16-medium) - - [ -1, 1, Conv, [ 512, 3, 2 ] ], - [ [ -1, 16 ], 1, Concat, [ 1 ] ], # cat head P5 - [ -1, 3, C3, [ 768, False ] ], # 29 (P5/32-large) - - [ -1, 1, Conv, [ 768, 3, 2 ] ], - [ [ -1, 12 ], 1, Concat, [ 1 ] ], # cat head P6 - [ -1, 3, C3, [ 1024, False ] ], # 32 (P5/64-xlarge) - - [ [ 23, 26, 29, 32 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) - ] diff --git a/models/hub/experimental/yolov5x6-1920.yaml b/models/hub/experimental/yolov5x6-1920.yaml deleted file mode 100644 index cbc12312d533..000000000000 --- a/models/hub/experimental/yolov5x6-1920.yaml +++ /dev/null @@ -1,60 +0,0 @@ -# parameters -nc: 80 # number of classes -depth_multiple: 1.33 # model depth multiple -width_multiple: 1.25 # layer channel multiple - -# anchors -anchors: - - [ 28,41, 67,59, 57,141 ] # P3/8 - - [ 144,103, 129,227, 270,205 ] # P4/16 - - [ 209,452, 455,396, 358,812 ] # P5/32 - - [ 653,922, 1109,570, 1387,1187 ] # P6/64 - -# 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, [ 768, 3, 2 ] ], # 7-P5/32 - [ -1, 3, C3, [ 768 ] ], - [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 - [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ], - [ -1, 3, C3, [ 1024, False ] ], # 11 - ] - -# YOLOv5 head -head: - [ [ -1, 1, Conv, [ 768, 1, 1 ] ], - [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], - [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 - [ -1, 3, C3, [ 768, False ] ], # 15 - - [ -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 ] ], # 19 - - [ -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 ] ], # 23 (P3/8-small) - - [ -1, 1, Conv, [ 256, 3, 2 ] ], - [ [ -1, 20 ], 1, Concat, [ 1 ] ], # cat head P4 - [ -1, 3, C3, [ 512, False ] ], # 26 (P4/16-medium) - - [ -1, 1, Conv, [ 512, 3, 2 ] ], - [ [ -1, 16 ], 1, Concat, [ 1 ] ], # cat head P5 - [ -1, 3, C3, [ 768, False ] ], # 29 (P5/32-large) - - [ -1, 1, Conv, [ 768, 3, 2 ] ], - [ [ -1, 12 ], 1, Concat, [ 1 ] ], # cat head P6 - [ -1, 3, C3, [ 1024, False ] ], # 32 (P5/64-xlarge) - - [ [ 23, 26, 29, 32 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) - ] diff --git a/models/hub/experimental/yolov5x6-640.yaml b/models/hub/experimental/yolov5x6-640.yaml deleted file mode 100644 index be0bc4bdcd3a..000000000000 --- a/models/hub/experimental/yolov5x6-640.yaml +++ /dev/null @@ -1,60 +0,0 @@ -# parameters -nc: 80 # number of classes -depth_multiple: 1.33 # model depth multiple -width_multiple: 1.25 # layer channel multiple - -# anchors -anchors: - - [ 9,11, 21,19, 17,41 ] # P3/8 - - [ 43,32, 39,70, 86,64 ] # P4/16 - - [ 65,131, 134,130, 120,265 ] # P5/32 - - [ 282,180, 247,354, 512,387 ] # P6/64 - -# 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, [ 768, 3, 2 ] ], # 7-P5/32 - [ -1, 3, C3, [ 768 ] ], - [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 - [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ], - [ -1, 3, C3, [ 1024, False ] ], # 11 - ] - -# YOLOv5 head -head: - [ [ -1, 1, Conv, [ 768, 1, 1 ] ], - [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], - [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 - [ -1, 3, C3, [ 768, False ] ], # 15 - - [ -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 ] ], # 19 - - [ -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 ] ], # 23 (P3/8-small) - - [ -1, 1, Conv, [ 256, 3, 2 ] ], - [ [ -1, 20 ], 1, Concat, [ 1 ] ], # cat head P4 - [ -1, 3, C3, [ 512, False ] ], # 26 (P4/16-medium) - - [ -1, 1, Conv, [ 512, 3, 2 ] ], - [ [ -1, 16 ], 1, Concat, [ 1 ] ], # cat head P5 - [ -1, 3, C3, [ 768, False ] ], # 29 (P5/32-large) - - [ -1, 1, Conv, [ 768, 3, 2 ] ], - [ [ -1, 12 ], 1, Concat, [ 1 ] ], # cat head P6 - [ -1, 3, C3, [ 1024, False ] ], # 32 (P5/64-xlarge) - - [ [ 23, 26, 29, 32 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) - ] diff --git a/models/hub/experimental/yolov5x7-1280.yaml b/models/hub/experimental/yolov5x7-1280.yaml deleted file mode 100644 index 6189f5f85c34..000000000000 --- a/models/hub/experimental/yolov5x7-1280.yaml +++ /dev/null @@ -1,72 +0,0 @@ -# parameters -nc: 80 # number of classes -depth_multiple: 1.33 # model depth multiple -width_multiple: 1.25 # layer channel multiple - -# anchors -anchors: - - [ 19,22, 54,36, 32,77 ] # P3/8 - - [ 70,83, 138,71, 75,173 ] # P4/16 - - [ 165,159, 148,334, 375,151 ] # P5/32 - - [ 334,317, 251,626, 499,474 ] # P6/64 - - [ 750,326, 534,814, 1079,818 ] # P7/128 - -# 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, [ 768, 3, 2 ] ], # 7-P5/32 - [ -1, 3, C3, [ 768 ] ], - [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 - [ -1, 3, C3, [ 1024 ] ], - [ -1, 1, Conv, [ 1280, 3, 2 ] ], # 11-P7/128 - [ -1, 1, SPP, [ 1280, [ 3, 5 ] ] ], - [ -1, 3, C3, [ 1280, False ] ], # 13 - ] - -# YOLOv5 head -head: - [ [ -1, 1, Conv, [ 1024, 1, 1 ] ], - [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], - [ [ -1, 10 ], 1, Concat, [ 1 ] ], # cat backbone P6 - [ -1, 3, C3, [ 1024, False ] ], # 17 - - [ -1, 1, Conv, [ 768, 1, 1 ] ], - [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], - [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 - [ -1, 3, C3, [ 768, False ] ], # 21 - - [ -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 ] ], # 25 - - [ -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 ] ], # 29 (P3/8-small) - - [ -1, 1, Conv, [ 256, 3, 2 ] ], - [ [ -1, 26 ], 1, Concat, [ 1 ] ], # cat head P4 - [ -1, 3, C3, [ 512, False ] ], # 32 (P4/16-medium) - - [ -1, 1, Conv, [ 512, 3, 2 ] ], - [ [ -1, 22 ], 1, Concat, [ 1 ] ], # cat head P5 - [ -1, 3, C3, [ 768, False ] ], # 35 (P5/32-large) - - [ -1, 1, Conv, [ 768, 3, 2 ] ], - [ [ -1, 18 ], 1, Concat, [ 1 ] ], # cat head P6 - [ -1, 3, C3, [ 1024, False ] ], # 38 (P6/64-xlarge) - - [ -1, 1, Conv, [ 1024, 3, 2 ] ], - [ [ -1, 14 ], 1, Concat, [ 1 ] ], # cat head P7 - [ -1, 3, C3, [ 1280, False ] ], # 41 (P7/128-xxlarge) - - [ [ 29, 32, 35, 38, 41 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) - ] diff --git a/models/hub/experimental/yolov5x7-1920.yaml b/models/hub/experimental/yolov5x7-1920.yaml deleted file mode 100644 index ba6a79a5e7ea..000000000000 --- a/models/hub/experimental/yolov5x7-1920.yaml +++ /dev/null @@ -1,72 +0,0 @@ -# parameters -nc: 80 # number of classes -depth_multiple: 1.33 # model depth multiple -width_multiple: 1.25 # layer channel multiple - -# anchors -anchors: - - [ 29,34, 81,55, 47,115 ] # P3/8 - - [ 105,124, 207,107, 113,259 ] # P4/16 - - [ 247,238, 222,500, 563,227 ] # P5/32 - - [ 501,476, 376,939, 749,711 ] # P6/64 - - [ 1126,489, 801,1222, 1618,1227 ] # P7/128 - -# 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, [ 768, 3, 2 ] ], # 7-P5/32 - [ -1, 3, C3, [ 768 ] ], - [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 - [ -1, 3, C3, [ 1024 ] ], - [ -1, 1, Conv, [ 1280, 3, 2 ] ], # 11-P7/128 - [ -1, 1, SPP, [ 1280, [ 3, 5 ] ] ], - [ -1, 3, C3, [ 1280, False ] ], # 13 - ] - -# YOLOv5 head -head: - [ [ -1, 1, Conv, [ 1024, 1, 1 ] ], - [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], - [ [ -1, 10 ], 1, Concat, [ 1 ] ], # cat backbone P6 - [ -1, 3, C3, [ 1024, False ] ], # 17 - - [ -1, 1, Conv, [ 768, 1, 1 ] ], - [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], - [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 - [ -1, 3, C3, [ 768, False ] ], # 21 - - [ -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 ] ], # 25 - - [ -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 ] ], # 29 (P3/8-small) - - [ -1, 1, Conv, [ 256, 3, 2 ] ], - [ [ -1, 26 ], 1, Concat, [ 1 ] ], # cat head P4 - [ -1, 3, C3, [ 512, False ] ], # 32 (P4/16-medium) - - [ -1, 1, Conv, [ 512, 3, 2 ] ], - [ [ -1, 22 ], 1, Concat, [ 1 ] ], # cat head P5 - [ -1, 3, C3, [ 768, False ] ], # 35 (P5/32-large) - - [ -1, 1, Conv, [ 768, 3, 2 ] ], - [ [ -1, 18 ], 1, Concat, [ 1 ] ], # cat head P6 - [ -1, 3, C3, [ 1024, False ] ], # 38 (P6/64-xlarge) - - [ -1, 1, Conv, [ 1024, 3, 2 ] ], - [ [ -1, 14 ], 1, Concat, [ 1 ] ], # cat head P7 - [ -1, 3, C3, [ 1280, False ] ], # 41 (P7/128-xxlarge) - - [ [ 29, 32, 35, 38, 41 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) - ] diff --git a/models/hub/experimental/yolov5x7-640.yaml b/models/hub/experimental/yolov5x7-640.yaml deleted file mode 100644 index a89f9f4867f9..000000000000 --- a/models/hub/experimental/yolov5x7-640.yaml +++ /dev/null @@ -1,72 +0,0 @@ -# parameters -nc: 80 # number of classes -depth_multiple: 1.33 # model depth multiple -width_multiple: 1.25 # layer channel multiple - -# anchors -anchors: - - [ 11,11, 13,30, 29,20 ] # P3/8 - - [ 30,46, 61,38, 39,92 ] # P4/16 - - [ 78,80, 146,66, 79,163 ] # P5/32 - - [ 149,150, 321,143, 157,303 ] # P6/64 - - [ 257,402, 359,290, 524,372 ] # P7/128 - -# 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, [ 768, 3, 2 ] ], # 7-P5/32 - [ -1, 3, C3, [ 768 ] ], - [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64 - [ -1, 3, C3, [ 1024 ] ], - [ -1, 1, Conv, [ 1280, 3, 2 ] ], # 11-P7/128 - [ -1, 1, SPP, [ 1280, [ 3, 5 ] ] ], - [ -1, 3, C3, [ 1280, False ] ], # 13 - ] - -# YOLOv5 head -head: - [ [ -1, 1, Conv, [ 1024, 1, 1 ] ], - [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], - [ [ -1, 10 ], 1, Concat, [ 1 ] ], # cat backbone P6 - [ -1, 3, C3, [ 1024, False ] ], # 17 - - [ -1, 1, Conv, [ 768, 1, 1 ] ], - [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], - [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5 - [ -1, 3, C3, [ 768, False ] ], # 21 - - [ -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 ] ], # 25 - - [ -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 ] ], # 29 (P3/8-small) - - [ -1, 1, Conv, [ 256, 3, 2 ] ], - [ [ -1, 26 ], 1, Concat, [ 1 ] ], # cat head P4 - [ -1, 3, C3, [ 512, False ] ], # 32 (P4/16-medium) - - [ -1, 1, Conv, [ 512, 3, 2 ] ], - [ [ -1, 22 ], 1, Concat, [ 1 ] ], # cat head P5 - [ -1, 3, C3, [ 768, False ] ], # 35 (P5/32-large) - - [ -1, 1, Conv, [ 768, 3, 2 ] ], - [ [ -1, 18 ], 1, Concat, [ 1 ] ], # cat head P6 - [ -1, 3, C3, [ 1024, False ] ], # 38 (P6/64-xlarge) - - [ -1, 1, Conv, [ 1024, 3, 2 ] ], - [ [ -1, 14 ], 1, Concat, [ 1 ] ], # cat head P7 - [ -1, 3, C3, [ 1280, False ] ], # 41 (P7/128-xxlarge) - - [ [ 29, 32, 35, 38, 41 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6) - ] From f1c3e52e41ec0c586e03a0793c281abba82d84a5 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 11 Feb 2021 19:24:16 -0800 Subject: [PATCH 169/176] update --- data/hyp.scratch.yaml | 8 ++++---- data/scripts/get_coco.sh | 2 +- data/scripts/get_coco_segments.sh | 28 ---------------------------- 3 files changed, 5 insertions(+), 33 deletions(-) delete mode 100755 data/scripts/get_coco_segments.sh diff --git a/data/hyp.scratch.yaml b/data/hyp.scratch.yaml index 51d2fda3d51b..44f26b6658ae 100644 --- a/data/hyp.scratch.yaml +++ b/data/hyp.scratch.yaml @@ -11,9 +11,9 @@ warmup_epochs: 3.0 # warmup epochs (fractions ok) warmup_momentum: 0.8 # warmup initial momentum warmup_bias_lr: 0.1 # warmup initial bias lr box: 0.05 # box loss gain -cls: 0.3 # cls loss gain +cls: 0.5 # cls loss gain cls_pw: 1.0 # cls BCELoss positive_weight -obj: 0.7 # obj loss gain (scale with pixels) +obj: 1.0 # obj loss gain (scale with pixels) obj_pw: 1.0 # obj BCELoss positive_weight iou_t: 0.20 # IoU training threshold anchor_t: 4.0 # anchor-multiple threshold @@ -24,10 +24,10 @@ hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) hsv_v: 0.4 # image HSV-Value augmentation (fraction) degrees: 0.0 # image rotation (+/- deg) translate: 0.1 # image translation (+/- fraction) -scale: 0.9 # image scale (+/- gain) +scale: 0.5 # image scale (+/- gain) shear: 0.0 # image shear (+/- deg) perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 flipud: 0.0 # image flip up-down (probability) fliplr: 0.5 # image flip left-right (probability) mosaic: 1.0 # image mosaic (probability) -mixup: 0.01 # image mixup (probability) +mixup: 0.0 # image mixup (probability) diff --git a/data/scripts/get_coco.sh b/data/scripts/get_coco.sh index 02634c000dfe..bbb1e9291d5b 100755 --- a/data/scripts/get_coco.sh +++ b/data/scripts/get_coco.sh @@ -10,7 +10,7 @@ # Download/unzip labels d='../' # unzip directory url=https://github.com/ultralytics/yolov5/releases/download/v1.0/ -f='coco2017labels.zip' # 68 MB +f='coco2017labels.zip' # or 'coco2017labels-segments.zip', 68 MB echo 'Downloading' $url$f ' ...' curl -L $url$f -o $f && unzip -q $f -d $d && rm $f & # download, unzip, remove in background diff --git a/data/scripts/get_coco_segments.sh b/data/scripts/get_coco_segments.sh deleted file mode 100755 index 857ef8dc49b9..000000000000 --- a/data/scripts/get_coco_segments.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -# COCO 2017 dataset http://cocodataset.org -# Download command: bash data/scripts/get_coco.sh -# Train command: python train.py --data coco.yaml -# Default dataset location is next to /yolov5: -# /parent_folder -# /coco -# /yolov5 - -# Download/unzip labels -d='../' # unzip directory -url=https://github.com/ultralytics/yolov5/releases/download/v1.0/ -f='coco2017labels-segments.zip' # 68 MB -echo 'Downloading' $url$f ' ...' -curl -L $url$f -o $f && unzip -q $f -d $d && rm $f & # download, unzip, remove in background - -# Download/unzip images -d='../coco/images' # unzip directory -url=http://images.cocodataset.org/zips/ -f1='train2017.zip' # 19G, 118k images -f2='val2017.zip' # 1G, 5k images -f3='test2017.zip' # 7G, 41k images (optional) -for f in $f1 $f2; do - echo 'Downloading' $url$f '...' - curl -L $url$f -o $f && unzip -q $f -d $d && rm $f & # download, unzip, remove in background -done -wait # finish background tasks -mv ../coco ../coco_segments From 73669a046a87e351eb15320d6e0c4901b486faf1 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 11 Feb 2021 19:26:11 -0800 Subject: [PATCH 170/176] update --- utils/datasets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/datasets.py b/utils/datasets.py index 48cf3ede6967..9ccc86bf004c 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -470,7 +470,7 @@ def cache_labels(self, path=Path('./labels.cache'), prefix=''): assert l.shape[1] == 5, 'labels require 5 columns each' assert (l >= 0).all(), 'negative labels' assert (l[:, 1:] <= 1).all(), 'non-normalized or out of bounds coordinate labels' - # assert np.unique(l, axis=0).shape[0] == l.shape[0], 'duplicate labels' + assert np.unique(l, axis=0).shape[0] == l.shape[0], 'duplicate labels' else: ne += 1 # label empty l = np.zeros((0, 5), dtype=np.float32) From 90d502682ce40f3e9a0a3ad8610d081646d94cba Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 11 Feb 2021 19:28:12 -0800 Subject: [PATCH 171/176] update --- utils/datasets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/datasets.py b/utils/datasets.py index 9ccc86bf004c..7a7882c79a7c 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -461,7 +461,7 @@ def cache_labels(self, path=Path('./labels.cache'), prefix=''): nf += 1 # label found with open(lb_file, 'r') as f: l = [x.split() for x in f.read().strip().splitlines()] - if any([len(x) >= 9 for x in l]): # is segment + if any([len(x) > 8 for x in l]): # is segment classes = np.array([x[0] for x in l], dtype=np.float32) segments = [np.array(x[1:], dtype=np.float32).reshape(-1, 2) for x in l] # (cls, xy1...) l = np.concatenate((classes.reshape(-1, 1), segments2boxes(segments)), 1) # (cls, xywh) From d36268ac52c2a1523c0666971fcc2fa13ee376dc Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 11 Feb 2021 19:40:24 -0800 Subject: [PATCH 172/176] update --- utils/datasets.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/utils/datasets.py b/utils/datasets.py index 7a7882c79a7c..6946679a6819 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -376,7 +376,7 @@ def __init__(self, path, img_size=640, batch_size=16, augment=False, hyp=None, r cache_path = (p if p.is_file() else Path(self.label_files[0]).parent).with_suffix('.cache') # cached labels if cache_path.is_file(): cache = torch.load(cache_path) # load - if cache['hash'] != get_hash(self.label_files + self.img_files) or 'results' not in cache: # changed + if cache['hash'] != get_hash(self.label_files + self.img_files) or 'segments' not in cache: # changed cache = self.cache_labels(cache_path, prefix) # re-cache else: cache = self.cache_labels(cache_path, prefix) # cache @@ -489,7 +489,8 @@ def cache_labels(self, path=Path('./labels.cache'), prefix=''): print(f'{prefix}WARNING: No labels found in {path}. See {help_url}') x['hash'] = get_hash(self.label_files + self.img_files) - x['results'] = [nf, nm, ne, nc, i + 1] + x['results'] = nf, nm, ne, nc, i + 1 + x['segments'] = True # supports segments torch.save(x, path) # save for next time logging.info(f'{prefix}New cache created: {path}') return x From ffe8a01339014e51c459633b8497ecdb5b9768ec Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 11 Feb 2021 19:43:38 -0800 Subject: [PATCH 173/176] update --- utils/datasets.py | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/datasets.py b/utils/datasets.py index 6946679a6819..d60ddaaf3906 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -389,6 +389,7 @@ def __init__(self, path, img_size=640, batch_size=16, augment=False, hyp=None, r # Read cache cache.pop('hash') # remove hash + cache.pop('segments') # remove segments boolean labels, shapes, self.segments = zip(*cache.values()) self.labels = list(labels) self.shapes = np.array(shapes, dtype=np.float64) From 1934fe80546c9f74461dbd5a8bebb3a110a33483 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 11 Feb 2021 19:47:00 -0800 Subject: [PATCH 174/176] institute cache versioning --- utils/datasets.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/datasets.py b/utils/datasets.py index d60ddaaf3906..86f91f047dcd 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -376,7 +376,7 @@ def __init__(self, path, img_size=640, batch_size=16, augment=False, hyp=None, r cache_path = (p if p.is_file() else Path(self.label_files[0]).parent).with_suffix('.cache') # cached labels if cache_path.is_file(): cache = torch.load(cache_path) # load - if cache['hash'] != get_hash(self.label_files + self.img_files) or 'segments' not in cache: # changed + if cache['hash'] != get_hash(self.label_files + self.img_files) or 'version' not in cache: # changed cache = self.cache_labels(cache_path, prefix) # re-cache else: cache = self.cache_labels(cache_path, prefix) # cache @@ -389,7 +389,7 @@ def __init__(self, path, img_size=640, batch_size=16, augment=False, hyp=None, r # Read cache cache.pop('hash') # remove hash - cache.pop('segments') # remove segments boolean + cache.pop('version') # remove version labels, shapes, self.segments = zip(*cache.values()) self.labels = list(labels) self.shapes = np.array(shapes, dtype=np.float64) @@ -491,7 +491,7 @@ def cache_labels(self, path=Path('./labels.cache'), prefix=''): x['hash'] = get_hash(self.label_files + self.img_files) x['results'] = nf, nm, ne, nc, i + 1 - x['segments'] = True # supports segments + x['version'] = 0.1 # cache version torch.save(x, path) # save for next time logging.info(f'{prefix}New cache created: {path}') return x From d11487ecdca38309924d8ee638d3c7ada4472d1b Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 11 Feb 2021 19:53:26 -0800 Subject: [PATCH 175/176] only display on existing cache --- utils/datasets.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/utils/datasets.py b/utils/datasets.py index 86f91f047dcd..e97af7aa6382 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -375,16 +375,17 @@ def __init__(self, path, img_size=640, batch_size=16, augment=False, hyp=None, r self.label_files = img2label_paths(self.img_files) # labels cache_path = (p if p.is_file() else Path(self.label_files[0]).parent).with_suffix('.cache') # cached labels if cache_path.is_file(): - cache = torch.load(cache_path) # load + cache, exists = torch.load(cache_path), False # load if cache['hash'] != get_hash(self.label_files + self.img_files) or 'version' not in cache: # changed - cache = self.cache_labels(cache_path, prefix) # re-cache + cache, exists = self.cache_labels(cache_path, prefix), True # re-cache else: - cache = self.cache_labels(cache_path, prefix) # cache + cache, exists = self.cache_labels(cache_path, prefix), True # cache # Display cache nf, nm, ne, nc, n = cache.pop('results') # found, missing, empty, corrupted, total - desc = f"Scanning '{cache_path}' for images and labels... {nf} found, {nm} missing, {ne} empty, {nc} corrupted" - tqdm(None, desc=prefix + desc, total=n, initial=n) + if exists: + d = f"Scanning '{cache_path}' for images and labels... {nf} found, {nm} missing, {ne} empty, {nc} corrupted" + tqdm(None, desc=prefix + d, total=n, initial=n) # display cache results assert nf > 0 or not augment, f'{prefix}No labels in {cache_path}. Can not train without labels. See {help_url}' # Read cache From 4ca9c31aaab3be77d9fbf5e9c552bbef892ceb98 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 11 Feb 2021 19:57:25 -0800 Subject: [PATCH 176/176] reverse cache exists booleans --- utils/datasets.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/datasets.py b/utils/datasets.py index e97af7aa6382..29a8812a20a2 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -375,11 +375,11 @@ def __init__(self, path, img_size=640, batch_size=16, augment=False, hyp=None, r self.label_files = img2label_paths(self.img_files) # labels cache_path = (p if p.is_file() else Path(self.label_files[0]).parent).with_suffix('.cache') # cached labels if cache_path.is_file(): - cache, exists = torch.load(cache_path), False # load + cache, exists = torch.load(cache_path), True # load if cache['hash'] != get_hash(self.label_files + self.img_files) or 'version' not in cache: # changed - cache, exists = self.cache_labels(cache_path, prefix), True # re-cache + cache, exists = self.cache_labels(cache_path, prefix), False # re-cache else: - cache, exists = self.cache_labels(cache_path, prefix), True # cache + cache, exists = self.cache_labels(cache_path, prefix), False # cache # Display cache nf, nm, ne, nc, n = cache.pop('results') # found, missing, empty, corrupted, total