glenn-jocher commited on
Commit
c14368d
·
1 Parent(s): 854ccb9

new CSP model release

Browse files
README.md CHANGED
@@ -4,11 +4,11 @@
4
 
5
  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.
6
 
7
- <img src="https://user-images.githubusercontent.com/26833433/83359175-63b6c680-a32d-11ea-970a-9f602e022468.png" width="1000">** GPU Latency measures end-to-end latency per image averaged over 5000 COCO val2017 images using a V100 GPU with batch size 16, and includes image preprocessing, FP32 inference, postprocessing and NMS.
8
 
9
- - **May 27, 2020**: Public release of repo. yolov3-spp implementation (this repo) is SOTA at 45.5 mAP among all known yolo implementations, yolov5 family will be undergoing architecture research and development over Q2/Q3 2020 to increase performance. Updates may include [CSP](https://github.com/WongKinYiu/CrossStagePartialNetworks) bottlenecks from [yolov4](https://github.com/AlexeyAB/darknet), as well as PANet or BiFPN head features.
10
- - **May 24, 2020**: Training yolov5s/x and yolov3-spp. yolov5m/l suffered early overfitting and also code 137 early docker terminations, cause unknown. yolov5l underperforms yolov3-spp due to earlier overfitting, cause unknown.
11
- - **April 1, 2020**: Begin development of a 100% pytorch scaleable yolov3/4-based group of future models, in small, medium, large and extra large sizes, collectively known as yolov5. Models will be defined by new user-friendly yaml-based configuration files for ease of construction and modification. Datasets will likewise use yaml configuration files. New training platform will be simpler use, harder to break, and more robust to training a wider variety of custom dataset.
12
 
13
 
14
  ## Ultralytics Professional Support
@@ -25,15 +25,15 @@ For business inquiries and professional support requests please visit us at http
25
 
26
  | Model | AP<sup>val</sup> | AP<sup>test</sup> | AP<sub>50</sub> | Latency<sub>GPU</sub> | FPS<sub>GPU</sub> || params | FLOPs |
27
  |---------- |------ |------ |------ | -------- | ------| ------ |------ | :------: |
28
- | YOLOv5-s ([ckpt](https://drive.google.com/open?id=1Drs_Aiu7xx6S-ix95f9kNsA6ueKRpN2J)) | 33.0 | 33.0 | 53.2 | **2.9ms** | **345** || 7.0M | 14.0B
29
- | YOLOv5-m ([ckpt](https://drive.google.com/open?id=1Drs_Aiu7xx6S-ix95f9kNsA6ueKRpN2J)) | 41.4 | 41.4 | 61.5 | 5.0ms | 200 || 25.2M | 50.2B
30
- | YOLOv5-l ([ckpt](https://drive.google.com/open?id=1Drs_Aiu7xx6S-ix95f9kNsA6ueKRpN2J)) | 44.3 | 44.5 | 64.3 | 8.9ms | 112 || 61.8M | 123.1B
31
- | YOLOv5-x ([ckpt](https://drive.google.com/open?id=1Drs_Aiu7xx6S-ix95f9kNsA6ueKRpN2J)) | **47.1** | **47.2** | **66.7** | 15.2ms | 66 || 123.1M | 245.7B
32
- | YOLOv3-SPP ([ckpt](https://drive.google.com/open?id=1Drs_Aiu7xx6S-ix95f9kNsA6ueKRpN2J)) | 45.6 | 45.5 | 65.2 | 8.3ms | 120 || 63.0M | 118.0B
33
 
34
  ** AP<sup>test</sup> denotes COCO [test-dev2017](http://cocodataset.org/#upload) server results, all other AP results in the table denote val2017 accuracy.
35
  ** All AP numbers are for single-model single-scale without ensemble or test-time augmentation. Reproduce by `python test.py --img 736 --conf 0.001`
36
- ** Latency<sub>GPU</sub> measures end-to-end latency per image averaged over 5000 COCO val2017 images using a GCP [n1-standard-16](https://cloud.google.com/compute/docs/machine-types#n1_standard_machine_types) instance with one V100 GPU, and includes image preprocessing, pytorch FP32 inference at batch size 16, postprocessing and NMS. Average NMS time included in this chart is 1-2ms/img. Reproduce by `python test.py --img 640 --conf 0.1`
37
  ** All checkpoints are trained to 300 epochs with default settings and hyperparameters (no autoaugmentation).
38
 
39
 
@@ -85,11 +85,11 @@ Results saved to /content/yolov5/inference/output
85
 
86
  ## Reproduce Our Training
87
 
88
- Run commands below. Training takes a few days for yolov5s, to a few weeks for yolov5x on a 2080Ti GPU.
89
  ```bash
90
- $ python train.py --data coco.yaml --cfg yolov5s.yaml --weights '' --batch-size 16
91
  ```
92
- <img src="https://user-images.githubusercontent.com/26833433/82960433-5a191180-9f6f-11ea-85cc-c49dbd1555e1.png" width="900">
93
 
94
 
95
  ## Reproduce Our Environment
 
4
 
5
  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.
6
 
7
+ <img src="https://user-images.githubusercontent.com/26833433/84200349-729f2680-aa5b-11ea-8f9a-604c9e01a658.png" width="1000">** GPU Latency measures end-to-end latency per image averaged over 5000 COCO val2017 images using a V100 GPU with batch size 32, and includes image preprocessing, FP32 inference, postprocessing and NMS.
8
 
9
+ - **June 9, 2020**: [CSP](https://github.com/WongKinYiu/CrossStagePartialNetworks) updates to all YOLOv5 models. New models are faster, smaller and more accurate. Credit to @WongKinYiu for his excellent work with CSP.
10
+ - **May 27, 2020**: Public release of repo. YOLOv5 models are SOTA among all known YOLO implementations, YOLOv5 family will be undergoing architecture research and development over Q2/Q3 2020 to increase performance. Updates may include [CSP](https://github.com/WongKinYiu/CrossStagePartialNetworks) bottlenecks, [YOLOv4](https://github.com/AlexeyAB/darknet) features, as well as PANet or BiFPN heads.
11
+ - **April 1, 2020**: Begin development of a 100% PyTorch, scaleable YOLOv3/4-based group of future models, in a range of compound-scaled sizes, collectively known as YOLOv5. Models will be defined by new user-friendly *.yaml files. New training platform will be simpler use, harder to break, and more robust to training a wider variety of custom dataset.
12
 
13
 
14
  ## Ultralytics Professional Support
 
25
 
26
  | Model | AP<sup>val</sup> | AP<sup>test</sup> | AP<sub>50</sub> | Latency<sub>GPU</sub> | FPS<sub>GPU</sub> || params | FLOPs |
27
  |---------- |------ |------ |------ | -------- | ------| ------ |------ | :------: |
28
+ | YOLOv5-s ([ckpt](https://drive.google.com/open?id=1Drs_Aiu7xx6S-ix95f9kNsA6ueKRpN2J)) | 35.5 | 35.5 | 55.0 | **2.5ms** | **400** || 7.1M | 12.6B
29
+ | YOLOv5-m ([ckpt](https://drive.google.com/open?id=1Drs_Aiu7xx6S-ix95f9kNsA6ueKRpN2J)) | 42.7 | 42.7 | 62.4 | 4.4ms | 227 || 22.0M | 39.0B
30
+ | YOLOv5-l ([ckpt](https://drive.google.com/open?id=1Drs_Aiu7xx6S-ix95f9kNsA6ueKRpN2J)) | 45.7 | 45.9 | 65.1 | 6.8ms | 147 || 50.3M | 89.0B
31
+ | YOLOv5-x ([ckpt](https://drive.google.com/open?id=1Drs_Aiu7xx6S-ix95f9kNsA6ueKRpN2J)) | **47.2** | **47.3** | **66.6** | 11.7ms | 85 || 95.9M | 170.3B
32
+ | YOLOv3-SPP ([ckpt](https://drive.google.com/open?id=1Drs_Aiu7xx6S-ix95f9kNsA6ueKRpN2J)) | 45.6 | 45.5 | 65.2 | 7.9ms | 127 || 63.0M | 118.0B
33
 
34
  ** AP<sup>test</sup> denotes COCO [test-dev2017](http://cocodataset.org/#upload) server results, all other AP results in the table denote val2017 accuracy.
35
  ** All AP numbers are for single-model single-scale without ensemble or test-time augmentation. Reproduce by `python test.py --img 736 --conf 0.001`
36
+ ** Latency<sub>GPU</sub> measures end-to-end latency per image averaged over 5000 COCO val2017 images using a GCP [n1-standard-16](https://cloud.google.com/compute/docs/machine-types#n1_standard_machine_types) instance with one V100 GPU, and includes image preprocessing, PyTorch FP32 inference at batch size 32, postprocessing and NMS. Average NMS time included in this chart is 1-2ms/img. Reproduce by `python test.py --img 640 --conf 0.1`
37
  ** All checkpoints are trained to 300 epochs with default settings and hyperparameters (no autoaugmentation).
38
 
39
 
 
85
 
86
  ## Reproduce Our Training
87
 
88
+ Run command below. Training times for yolov5s/m/l/x are 2/4/6/8 days on a single V100 (multi-GPU times faster).
89
  ```bash
90
+ $ python train.py --data coco.yaml --cfg yolov5s.yaml --weights '' --batch-size 16
91
  ```
92
+ <img src="https://user-images.githubusercontent.com/26833433/84186698-c4d54d00-aa45-11ea-9bde-c632c1230ccd.png" width="900">
93
 
94
 
95
  ## Reproduce Our Environment
detect.py CHANGED
@@ -3,8 +3,6 @@ import argparse
3
  from utils.datasets import *
4
  from utils.utils import *
5
 
6
- ONNX_EXPORT = False
7
-
8
 
9
  def detect(save_img=False):
10
  out, source, weights, half, view_img, save_txt, imgsz = \
 
3
  from utils.datasets import *
4
  from utils.utils import *
5
 
 
 
6
 
7
  def detect(save_img=False):
8
  out, source, weights, half, view_img, save_txt, imgsz = \
models/yolo.py CHANGED
@@ -45,14 +45,17 @@ class Detect(nn.Module):
45
 
46
 
47
  class Model(nn.Module):
48
- def __init__(self, model_yaml='yolov5s.yaml', ch=3, nc=None): # model, input channels, number of classes
49
  super(Model, self).__init__()
50
- with open(model_yaml) as f:
51
- self.md = yaml.load(f, Loader=yaml.FullLoader) # model dict
52
- if nc:
53
- self.md['nc'] = nc # override yaml value
 
54
 
55
  # Define model
 
 
56
  self.model, self.save, ch = parse_model(self.md, ch=[ch]) # model, savelist, ch_out
57
  # print([x.shape for x in self.forward(torch.zeros(1, 3, 64, 64))])
58
 
 
45
 
46
 
47
  class Model(nn.Module):
48
+ def __init__(self, model_cfg='yolov5s.yaml', ch=3, nc=None): # model, input channels, number of classes
49
  super(Model, self).__init__()
50
+ if type(model_cfg) is dict:
51
+ self.md = model_cfg # model dict
52
+ else: # is *.yaml
53
+ with open(model_cfg) as f:
54
+ self.md = yaml.load(f, Loader=yaml.FullLoader) # model dict
55
 
56
  # Define model
57
+ if nc:
58
+ self.md['nc'] = nc # override yaml value
59
  self.model, self.save, ch = parse_model(self.md, ch=[ch]) # model, savelist, ch_out
60
  # print([x.shape for x in self.forward(torch.zeros(1, 3, 64, 64))])
61
 
models/yolov5l.yaml CHANGED
@@ -16,29 +16,29 @@ backbone:
16
  [-1, 1, Conv, [128, 3, 2]], # 2-P2/4
17
  [-1, 3, Bottleneck, [128]],
18
  [-1, 1, Conv, [256, 3, 2]], # 4-P3/8
19
- [-1, 9, Bottleneck, [256]],
20
  [-1, 1, Conv, [512, 3, 2]], # 6-P4/16
21
- [-1, 9, Bottleneck, [512]],
22
  [-1, 1, Conv, [1024, 3, 2]], # 8-P5/32
23
  [-1, 1, SPP, [1024, [5, 9, 13]]],
24
- [-1, 3, Bottleneck, [1024]], # 10
25
  ]
26
 
27
  # yolov5 head
28
  head:
29
- [[-1, 3, Bottleneck, [1024, False]], # 11
30
  [-1, 1, nn.Conv2d, [na * (nc + 5), 1, 1, 0]], # 12 (P5/32-large)
31
 
32
  [-2, 1, nn.Upsample, [None, 2, 'nearest']],
33
  [[-1, 6], 1, Concat, [1]], # cat backbone P4
34
  [-1, 1, Conv, [512, 1, 1]],
35
- [-1, 3, Bottleneck, [512, False]],
36
  [-1, 1, nn.Conv2d, [na * (nc + 5), 1, 1, 0]], # 17 (P4/16-medium)
37
 
38
  [-2, 1, nn.Upsample, [None, 2, 'nearest']],
39
  [[-1, 4], 1, Concat, [1]], # cat backbone P3
40
  [-1, 1, Conv, [256, 1, 1]],
41
- [-1, 3, Bottleneck, [256, False]],
42
  [-1, 1, nn.Conv2d, [na * (nc + 5), 1, 1, 0]], # 22 (P3/8-small)
43
 
44
  [[], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
 
16
  [-1, 1, Conv, [128, 3, 2]], # 2-P2/4
17
  [-1, 3, Bottleneck, [128]],
18
  [-1, 1, Conv, [256, 3, 2]], # 4-P3/8
19
+ [-1, 9, BottleneckCSP, [256]],
20
  [-1, 1, Conv, [512, 3, 2]], # 6-P4/16
21
+ [-1, 9, BottleneckCSP, [512]],
22
  [-1, 1, Conv, [1024, 3, 2]], # 8-P5/32
23
  [-1, 1, SPP, [1024, [5, 9, 13]]],
24
+ [-1, 6, BottleneckCSP, [1024]], # 10
25
  ]
26
 
27
  # yolov5 head
28
  head:
29
+ [[-1, 3, BottleneckCSP, [1024, False]], # 11
30
  [-1, 1, nn.Conv2d, [na * (nc + 5), 1, 1, 0]], # 12 (P5/32-large)
31
 
32
  [-2, 1, nn.Upsample, [None, 2, 'nearest']],
33
  [[-1, 6], 1, Concat, [1]], # cat backbone P4
34
  [-1, 1, Conv, [512, 1, 1]],
35
+ [-1, 3, BottleneckCSP, [512, False]],
36
  [-1, 1, nn.Conv2d, [na * (nc + 5), 1, 1, 0]], # 17 (P4/16-medium)
37
 
38
  [-2, 1, nn.Upsample, [None, 2, 'nearest']],
39
  [[-1, 4], 1, Concat, [1]], # cat backbone P3
40
  [-1, 1, Conv, [256, 1, 1]],
41
+ [-1, 3, BottleneckCSP, [256, False]],
42
  [-1, 1, nn.Conv2d, [na * (nc + 5), 1, 1, 0]], # 22 (P3/8-small)
43
 
44
  [[], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
models/yolov5m.yaml CHANGED
@@ -16,29 +16,29 @@ backbone:
16
  [-1, 1, Conv, [128, 3, 2]], # 2-P2/4
17
  [-1, 3, Bottleneck, [128]],
18
  [-1, 1, Conv, [256, 3, 2]], # 4-P3/8
19
- [-1, 9, Bottleneck, [256]],
20
  [-1, 1, Conv, [512, 3, 2]], # 6-P4/16
21
- [-1, 9, Bottleneck, [512]],
22
  [-1, 1, Conv, [1024, 3, 2]], # 8-P5/32
23
  [-1, 1, SPP, [1024, [5, 9, 13]]],
24
- [-1, 3, Bottleneck, [1024]], # 10
25
  ]
26
 
27
  # yolov5 head
28
  head:
29
- [[-1, 3, Bottleneck, [1024, False]], # 11
30
  [-1, 1, nn.Conv2d, [na * (nc + 5), 1, 1, 0]], # 12 (P5/32-large)
31
 
32
  [-2, 1, nn.Upsample, [None, 2, 'nearest']],
33
  [[-1, 6], 1, Concat, [1]], # cat backbone P4
34
  [-1, 1, Conv, [512, 1, 1]],
35
- [-1, 3, Bottleneck, [512, False]],
36
  [-1, 1, nn.Conv2d, [na * (nc + 5), 1, 1, 0]], # 17 (P4/16-medium)
37
 
38
  [-2, 1, nn.Upsample, [None, 2, 'nearest']],
39
  [[-1, 4], 1, Concat, [1]], # cat backbone P3
40
  [-1, 1, Conv, [256, 1, 1]],
41
- [-1, 3, Bottleneck, [256, False]],
42
  [-1, 1, nn.Conv2d, [na * (nc + 5), 1, 1, 0]], # 22 (P3/8-small)
43
 
44
  [[], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
 
16
  [-1, 1, Conv, [128, 3, 2]], # 2-P2/4
17
  [-1, 3, Bottleneck, [128]],
18
  [-1, 1, Conv, [256, 3, 2]], # 4-P3/8
19
+ [-1, 9, BottleneckCSP, [256]],
20
  [-1, 1, Conv, [512, 3, 2]], # 6-P4/16
21
+ [-1, 9, BottleneckCSP, [512]],
22
  [-1, 1, Conv, [1024, 3, 2]], # 8-P5/32
23
  [-1, 1, SPP, [1024, [5, 9, 13]]],
24
+ [-1, 6, BottleneckCSP, [1024]], # 10
25
  ]
26
 
27
  # yolov5 head
28
  head:
29
+ [[-1, 3, BottleneckCSP, [1024, False]], # 11
30
  [-1, 1, nn.Conv2d, [na * (nc + 5), 1, 1, 0]], # 12 (P5/32-large)
31
 
32
  [-2, 1, nn.Upsample, [None, 2, 'nearest']],
33
  [[-1, 6], 1, Concat, [1]], # cat backbone P4
34
  [-1, 1, Conv, [512, 1, 1]],
35
+ [-1, 3, BottleneckCSP, [512, False]],
36
  [-1, 1, nn.Conv2d, [na * (nc + 5), 1, 1, 0]], # 17 (P4/16-medium)
37
 
38
  [-2, 1, nn.Upsample, [None, 2, 'nearest']],
39
  [[-1, 4], 1, Concat, [1]], # cat backbone P3
40
  [-1, 1, Conv, [256, 1, 1]],
41
+ [-1, 3, BottleneckCSP, [256, False]],
42
  [-1, 1, nn.Conv2d, [na * (nc + 5), 1, 1, 0]], # 22 (P3/8-small)
43
 
44
  [[], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
models/yolov5s.yaml CHANGED
@@ -16,29 +16,29 @@ backbone:
16
  [-1, 1, Conv, [128, 3, 2]], # 2-P2/4
17
  [-1, 3, Bottleneck, [128]],
18
  [-1, 1, Conv, [256, 3, 2]], # 4-P3/8
19
- [-1, 9, Bottleneck, [256]],
20
  [-1, 1, Conv, [512, 3, 2]], # 6-P4/16
21
- [-1, 9, Bottleneck, [512]],
22
  [-1, 1, Conv, [1024, 3, 2]], # 8-P5/32
23
  [-1, 1, SPP, [1024, [5, 9, 13]]],
24
- [-1, 3, Bottleneck, [1024]], # 10
25
  ]
26
 
27
  # yolov5 head
28
  head:
29
- [[-1, 3, Bottleneck, [1024, False]], # 11
30
  [-1, 1, nn.Conv2d, [na * (nc + 5), 1, 1, 0]], # 12 (P5/32-large)
31
 
32
  [-2, 1, nn.Upsample, [None, 2, 'nearest']],
33
  [[-1, 6], 1, Concat, [1]], # cat backbone P4
34
  [-1, 1, Conv, [512, 1, 1]],
35
- [-1, 3, Bottleneck, [512, False]],
36
  [-1, 1, nn.Conv2d, [na * (nc + 5), 1, 1, 0]], # 17 (P4/16-medium)
37
 
38
  [-2, 1, nn.Upsample, [None, 2, 'nearest']],
39
  [[-1, 4], 1, Concat, [1]], # cat backbone P3
40
  [-1, 1, Conv, [256, 1, 1]],
41
- [-1, 3, Bottleneck, [256, False]],
42
  [-1, 1, nn.Conv2d, [na * (nc + 5), 1, 1, 0]], # 22 (P3/8-small)
43
 
44
  [[], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
 
16
  [-1, 1, Conv, [128, 3, 2]], # 2-P2/4
17
  [-1, 3, Bottleneck, [128]],
18
  [-1, 1, Conv, [256, 3, 2]], # 4-P3/8
19
+ [-1, 9, BottleneckCSP, [256]],
20
  [-1, 1, Conv, [512, 3, 2]], # 6-P4/16
21
+ [-1, 9, BottleneckCSP, [512]],
22
  [-1, 1, Conv, [1024, 3, 2]], # 8-P5/32
23
  [-1, 1, SPP, [1024, [5, 9, 13]]],
24
+ [-1, 6, BottleneckCSP, [1024]], # 10
25
  ]
26
 
27
  # yolov5 head
28
  head:
29
+ [[-1, 3, BottleneckCSP, [1024, False]], # 11
30
  [-1, 1, nn.Conv2d, [na * (nc + 5), 1, 1, 0]], # 12 (P5/32-large)
31
 
32
  [-2, 1, nn.Upsample, [None, 2, 'nearest']],
33
  [[-1, 6], 1, Concat, [1]], # cat backbone P4
34
  [-1, 1, Conv, [512, 1, 1]],
35
+ [-1, 3, BottleneckCSP, [512, False]],
36
  [-1, 1, nn.Conv2d, [na * (nc + 5), 1, 1, 0]], # 17 (P4/16-medium)
37
 
38
  [-2, 1, nn.Upsample, [None, 2, 'nearest']],
39
  [[-1, 4], 1, Concat, [1]], # cat backbone P3
40
  [-1, 1, Conv, [256, 1, 1]],
41
+ [-1, 3, BottleneckCSP, [256, False]],
42
  [-1, 1, nn.Conv2d, [na * (nc + 5), 1, 1, 0]], # 22 (P3/8-small)
43
 
44
  [[], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
models/yolov5x.yaml CHANGED
@@ -16,29 +16,29 @@ backbone:
16
  [-1, 1, Conv, [128, 3, 2]], # 2-P2/4
17
  [-1, 3, Bottleneck, [128]],
18
  [-1, 1, Conv, [256, 3, 2]], # 4-P3/8
19
- [-1, 9, Bottleneck, [256]],
20
  [-1, 1, Conv, [512, 3, 2]], # 6-P4/16
21
- [-1, 9, Bottleneck, [512]],
22
  [-1, 1, Conv, [1024, 3, 2]], # 8-P5/32
23
  [-1, 1, SPP, [1024, [5, 9, 13]]],
24
- [-1, 3, Bottleneck, [1024]], # 10
25
  ]
26
 
27
  # yolov5 head
28
  head:
29
- [[-1, 3, Bottleneck, [1024, False]], # 11
30
  [-1, 1, nn.Conv2d, [na * (nc + 5), 1, 1, 0]], # 12 (P5/32-large)
31
 
32
  [-2, 1, nn.Upsample, [None, 2, 'nearest']],
33
  [[-1, 6], 1, Concat, [1]], # cat backbone P4
34
  [-1, 1, Conv, [512, 1, 1]],
35
- [-1, 3, Bottleneck, [512, False]],
36
  [-1, 1, nn.Conv2d, [na * (nc + 5), 1, 1, 0]], # 17 (P4/16-medium)
37
 
38
  [-2, 1, nn.Upsample, [None, 2, 'nearest']],
39
  [[-1, 4], 1, Concat, [1]], # cat backbone P3
40
  [-1, 1, Conv, [256, 1, 1]],
41
- [-1, 3, Bottleneck, [256, False]],
42
  [-1, 1, nn.Conv2d, [na * (nc + 5), 1, 1, 0]], # 22 (P3/8-small)
43
 
44
  [[], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
 
16
  [-1, 1, Conv, [128, 3, 2]], # 2-P2/4
17
  [-1, 3, Bottleneck, [128]],
18
  [-1, 1, Conv, [256, 3, 2]], # 4-P3/8
19
+ [-1, 9, BottleneckCSP, [256]],
20
  [-1, 1, Conv, [512, 3, 2]], # 6-P4/16
21
+ [-1, 9, BottleneckCSP, [512]],
22
  [-1, 1, Conv, [1024, 3, 2]], # 8-P5/32
23
  [-1, 1, SPP, [1024, [5, 9, 13]]],
24
+ [-1, 6, BottleneckCSP, [1024]], # 10
25
  ]
26
 
27
  # yolov5 head
28
  head:
29
+ [[-1, 3, BottleneckCSP, [1024, False]], # 11
30
  [-1, 1, nn.Conv2d, [na * (nc + 5), 1, 1, 0]], # 12 (P5/32-large)
31
 
32
  [-2, 1, nn.Upsample, [None, 2, 'nearest']],
33
  [[-1, 6], 1, Concat, [1]], # cat backbone P4
34
  [-1, 1, Conv, [512, 1, 1]],
35
+ [-1, 3, BottleneckCSP, [512, False]],
36
  [-1, 1, nn.Conv2d, [na * (nc + 5), 1, 1, 0]], # 17 (P4/16-medium)
37
 
38
  [-2, 1, nn.Upsample, [None, 2, 'nearest']],
39
  [[-1, 4], 1, Concat, [1]], # cat backbone P3
40
  [-1, 1, Conv, [256, 1, 1]],
41
+ [-1, 3, BottleneckCSP, [256, False]],
42
  [-1, 1, nn.Conv2d, [na * (nc + 5), 1, 1, 0]], # 22 (P3/8-small)
43
 
44
  [[], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
utils/utils.py CHANGED
@@ -994,10 +994,7 @@ def plot_study_txt(f='study.txt', x=None): # from utils.utils import *; plot_st
994
  ax = ax.ravel()
995
 
996
  fig2, ax2 = plt.subplots(1, 1, figsize=(8, 4), tight_layout=True)
997
- ax2.plot(1E3 / np.array([209, 140, 97, 58, 35, 18][:-1]), [33.5, 39.1, 42.5, 45.9, 49., 50.5][:-1],
998
- '.-', linewidth=2, markersize=8, alpha=0.3, label='EfficientDet')
999
-
1000
- for f in sorted(glob.glob('study*.txt')):
1001
  y = np.loadtxt(f, dtype=np.float32, usecols=[0, 1, 2, 3, 7, 8, 9], ndmin=2).T
1002
  x = np.arange(y.shape[1]) if x is None else np.array(x)
1003
  s = ['P', 'R', 'mAP@.5', 'mAP@.5:.95', 't_inference (ms/img)', 't_NMS (ms/img)', 't_total (ms/img)']
@@ -1009,7 +1006,9 @@ def plot_study_txt(f='study.txt', x=None): # from utils.utils import *; plot_st
1009
  ax2.plot(y[6, :j], y[3, :j] * 1E2, '.-', linewidth=2, markersize=8,
1010
  label=Path(f).stem.replace('study_coco_', '').replace('yolo', 'YOLO'))
1011
 
1012
- ax2.set_xlim(0)
 
 
1013
  ax2.set_ylim(23, 50)
1014
  ax2.set_xlabel('GPU Latency (ms)')
1015
  ax2.set_ylabel('COCO AP val')
@@ -1085,8 +1084,8 @@ def plot_results_overlay(start=0, stop=0): # from utils.utils import *; plot_re
1085
  fig.savefig(f.replace('.txt', '.png'), dpi=200)
1086
 
1087
 
1088
- def plot_results(start=0, stop=0, bucket='', id=()): # from utils.utils import *; plot_results()
1089
- # Plot training 'results*.txt' as seen in https://github.com/ultralytics/yolov3#training
1090
  fig, ax = plt.subplots(2, 5, figsize=(12, 6))
1091
  ax = ax.ravel()
1092
  s = ['GIoU', 'Objectness', 'Classification', 'Precision', 'Recall',
@@ -1096,7 +1095,7 @@ def plot_results(start=0, stop=0, bucket='', id=()): # from utils.utils import
1096
  files = ['https://storage.googleapis.com/%s/results%g.txt' % (bucket, x) for x in id]
1097
  else:
1098
  files = glob.glob('results*.txt') + glob.glob('../../Downloads/results*.txt')
1099
- for f in sorted(files):
1100
  try:
1101
  results = np.loadtxt(f, usecols=[2, 3, 4, 8, 9, 12, 13, 14, 10, 11], ndmin=2).T
1102
  n = results.shape[1] # number of rows
@@ -1106,7 +1105,8 @@ def plot_results(start=0, stop=0, bucket='', id=()): # from utils.utils import
1106
  if i in [0, 1, 2, 5, 6, 7]:
1107
  y[y == 0] = np.nan # dont show zero loss values
1108
  # y /= y[0] # normalize
1109
- ax[i].plot(x, y, marker='.', label=Path(f).stem, linewidth=2, markersize=8)
 
1110
  ax[i].set_title(s[i])
1111
  # if i in [5, 6, 7]: # share train and val loss y axes
1112
  # ax[i].get_shared_y_axes().join(ax[i], ax[i - 5])
 
994
  ax = ax.ravel()
995
 
996
  fig2, ax2 = plt.subplots(1, 1, figsize=(8, 4), tight_layout=True)
997
+ for f in ['coco_study/study_coco_yolov5%s.txt' % x for x in ['s', 'm', 'l', 'x']]:
 
 
 
998
  y = np.loadtxt(f, dtype=np.float32, usecols=[0, 1, 2, 3, 7, 8, 9], ndmin=2).T
999
  x = np.arange(y.shape[1]) if x is None else np.array(x)
1000
  s = ['P', 'R', 'mAP@.5', 'mAP@.5:.95', 't_inference (ms/img)', 't_NMS (ms/img)', 't_total (ms/img)']
 
1006
  ax2.plot(y[6, :j], y[3, :j] * 1E2, '.-', linewidth=2, markersize=8,
1007
  label=Path(f).stem.replace('study_coco_', '').replace('yolo', 'YOLO'))
1008
 
1009
+ ax2.plot(1E3 / np.array([209, 140, 97, 58, 35, 18]), [33.5, 39.1, 42.5, 45.9, 49., 50.5],
1010
+ 'k.-', linewidth=2, markersize=8, alpha=.25, label='EfficientDet')
1011
+ ax2.set_xlim(0, 30)
1012
  ax2.set_ylim(23, 50)
1013
  ax2.set_xlabel('GPU Latency (ms)')
1014
  ax2.set_ylabel('COCO AP val')
 
1084
  fig.savefig(f.replace('.txt', '.png'), dpi=200)
1085
 
1086
 
1087
+ def plot_results(start=0, stop=0, bucket='', id=(), labels=()): # from utils.utils import *; plot_results()
1088
+ # Plot training 'results*.txt' as seen in https://github.com/ultralytics/yolov5#reproduce-our-training
1089
  fig, ax = plt.subplots(2, 5, figsize=(12, 6))
1090
  ax = ax.ravel()
1091
  s = ['GIoU', 'Objectness', 'Classification', 'Precision', 'Recall',
 
1095
  files = ['https://storage.googleapis.com/%s/results%g.txt' % (bucket, x) for x in id]
1096
  else:
1097
  files = glob.glob('results*.txt') + glob.glob('../../Downloads/results*.txt')
1098
+ for fi, f in enumerate(files):
1099
  try:
1100
  results = np.loadtxt(f, usecols=[2, 3, 4, 8, 9, 12, 13, 14, 10, 11], ndmin=2).T
1101
  n = results.shape[1] # number of rows
 
1105
  if i in [0, 1, 2, 5, 6, 7]:
1106
  y[y == 0] = np.nan # dont show zero loss values
1107
  # y /= y[0] # normalize
1108
+ label = labels[fi] if len(labels) else Path(f).stem
1109
+ ax[i].plot(x, y, marker='.', label=label, linewidth=2, markersize=8)
1110
  ax[i].set_title(s[i])
1111
  # if i in [5, 6, 7]: # share train and val loss y axes
1112
  # ax[i].get_shared_y_axes().join(ax[i], ax[i - 5])