Skip to content

Commit 33a67b4

Browse files
authored
Update P2-P7 models/hub variants (#6230)
* Update p2-p7 `models/hub` variants * Update common.py * AutoAnchor camelcase corrections
1 parent ad565e3 commit 33a67b4

File tree

7 files changed

+50
-9
lines changed

7 files changed

+50
-9
lines changed

models/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ def __init__(self, weights='yolov5s.pt', device=None, dnn=False, data=None):
306306

307307
if pt: # PyTorch
308308
model = attempt_load(weights if isinstance(weights, list) else w, map_location=device)
309-
stride = int(model.stride.max()) # model stride
309+
stride = max(int(model.stride.max()), 32) # model stride
310310
names = model.module.names if hasattr(model, 'module') else model.names # get class names
311311
self.model = model # explicitly assign for to(), cpu(), cuda(), half()
312312
elif jit: # TorchScript

models/hub/yolov5-p2.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
nc: 80 # number of classes
55
depth_multiple: 1.0 # model depth multiple
66
width_multiple: 1.0 # layer channel multiple
7-
anchors: 3 # auto-anchor evolves 3 anchors per P output layer
7+
anchors: 3 # AutoAnchor evolves 3 anchors per P output layer
88

99
# YOLOv5 v6.0 backbone
1010
backbone:
@@ -21,7 +21,7 @@ backbone:
2121
[-1, 1, SPPF, [1024, 5]], # 9
2222
]
2323

24-
# YOLOv5 v6.0 head
24+
# YOLOv5 v6.0 head with (P2, P3, P4, P5) outputs
2525
head:
2626
[[-1, 1, Conv, [512, 1, 1]],
2727
[-1, 1, nn.Upsample, [None, 2, 'nearest']],

models/hub/yolov5-p34.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
2+
3+
# Parameters
4+
nc: 80 # number of classes
5+
depth_multiple: 0.33 # model depth multiple
6+
width_multiple: 0.50 # layer channel multiple
7+
anchors: 3 # AutoAnchor evolves 3 anchors per P output layer
8+
9+
# YOLOv5 v6.0 backbone
10+
backbone:
11+
# [from, number, module, args]
12+
[ [ -1, 1, Conv, [ 64, 6, 2, 2 ] ], # 0-P1/2
13+
[ -1, 1, Conv, [ 128, 3, 2 ] ], # 1-P2/4
14+
[ -1, 3, C3, [ 128 ] ],
15+
[ -1, 1, Conv, [ 256, 3, 2 ] ], # 3-P3/8
16+
[ -1, 6, C3, [ 256 ] ],
17+
[ -1, 1, Conv, [ 512, 3, 2 ] ], # 5-P4/16
18+
[ -1, 9, C3, [ 512 ] ],
19+
[ -1, 1, Conv, [ 1024, 3, 2 ] ], # 7-P5/32
20+
[ -1, 3, C3, [ 1024 ] ],
21+
[ -1, 1, SPPF, [ 1024, 5 ] ], # 9
22+
]
23+
24+
# YOLOv5 v6.0 head with (P3, P4) outputs
25+
head:
26+
[ [ -1, 1, Conv, [ 512, 1, 1 ] ],
27+
[ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ],
28+
[ [ -1, 6 ], 1, Concat, [ 1 ] ], # cat backbone P4
29+
[ -1, 3, C3, [ 512, False ] ], # 13
30+
31+
[ -1, 1, Conv, [ 256, 1, 1 ] ],
32+
[ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ],
33+
[ [ -1, 4 ], 1, Concat, [ 1 ] ], # cat backbone P3
34+
[ -1, 3, C3, [ 256, False ] ], # 17 (P3/8-small)
35+
36+
[ -1, 1, Conv, [ 256, 3, 2 ] ],
37+
[ [ -1, 14 ], 1, Concat, [ 1 ] ], # cat head P4
38+
[ -1, 3, C3, [ 512, False ] ], # 20 (P4/16-medium)
39+
40+
[ [ 17, 20 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4)
41+
]

models/hub/yolov5-p6.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
nc: 80 # number of classes
55
depth_multiple: 1.0 # model depth multiple
66
width_multiple: 1.0 # layer channel multiple
7-
anchors: 3 # auto-anchor 3 anchors per P output layer
7+
anchors: 3 # AutoAnchor evolves 3 anchors per P output layer
88

99
# YOLOv5 v6.0 backbone
1010
backbone:
@@ -23,7 +23,7 @@ backbone:
2323
[-1, 1, SPPF, [1024, 5]], # 11
2424
]
2525

26-
# YOLOv5 v6.0 head
26+
# YOLOv5 v6.0 head with (P3, P4, P5, P6) outputs
2727
head:
2828
[[-1, 1, Conv, [768, 1, 1]],
2929
[-1, 1, nn.Upsample, [None, 2, 'nearest']],

models/hub/yolov5-p7.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
nc: 80 # number of classes
55
depth_multiple: 1.0 # model depth multiple
66
width_multiple: 1.0 # layer channel multiple
7-
anchors: 3 # auto-anchor 3 anchors per P output layer
7+
anchors: 3 # AutoAnchor evolves 3 anchors per P output layer
88

99
# YOLOv5 v6.0 backbone
1010
backbone:
@@ -25,7 +25,7 @@ backbone:
2525
[-1, 1, SPPF, [1280, 5]], # 13
2626
]
2727

28-
# YOLOv5 head
28+
# YOLOv5 v6.0 head with (P3, P4, P5, P6, P7) outputs
2929
head:
3030
[[-1, 1, Conv, [1024, 1, 1]],
3131
[-1, 1, nn.Upsample, [None, 2, 'nearest']],

train.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ def parse_opt(known=False):
461461
parser.add_argument('--resume', nargs='?', const=True, default=False, help='resume most recent training')
462462
parser.add_argument('--nosave', action='store_true', help='only save final checkpoint')
463463
parser.add_argument('--noval', action='store_true', help='only validate final epoch')
464-
parser.add_argument('--noautoanchor', action='store_true', help='disable autoanchor check')
464+
parser.add_argument('--noautoanchor', action='store_true', help='disable AutoAnchor')
465465
parser.add_argument('--evolve', type=int, nargs='?', const=300, help='evolve hyperparameters for x generations')
466466
parser.add_argument('--bucket', type=str, default='', help='gsutil bucket')
467467
parser.add_argument('--cache', type=str, nargs='?', const='ram', help='--cache images in "ram" (default) or "disk"')

tutorial.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@
777777
"\u001b[34m\u001b[1mval: \u001b[0mCaching images (0.1GB ram): 100% 128/128 [00:01<00:00, 121.58it/s]\n",
778778
"Plotting labels... \n",
779779
"\n",
780-
"\u001b[34m\u001b[1mautoanchor: \u001b[0mAnalyzing anchors... anchors/target = 4.27, Best Possible Recall (BPR) = 0.9935\n",
780+
"\u001b[34m\u001b[1mAutoAnchor: \u001b[0mAnalyzing anchors... anchors/target = 4.27, Best Possible Recall (BPR) = 0.9935\n",
781781
"Image sizes 640 train, 640 val\n",
782782
"Using 2 dataloader workers\n",
783783
"Logging results to \u001b[1mruns/train/exp\u001b[0m\n",

0 commit comments

Comments
 (0)