不知道如何计算的可以参考这个博客:
https://blog.csdn.net/weixin_43269994/article/details/137175066?spm=1001.2014.3001.5502
下面是原始yolov8-p2.yaml:
# Ultralytics YOLO 🚀, AGPL-3.0 license
# YOLOv8 object detection model with P2-P5 outputs. For Usage examples see https://docs.ultralytics.com/tasks/detect
# Parameters
nc: 80 # number of classes
scales: # model compound scaling constants, i.e. 'model=yolov8n.yaml' will call yolov8.yaml with scale 'n'
# [depth, width, max_channels]
n: [0.33, 0.25, 1024]
s: [0.33, 0.50, 1024]
m: [0.67, 0.75, 768]
l: [1.00, 1.00, 512]
x: [1.00, 1.25, 512]
# YOLOv8.0 backbone
backbone:
# [from, repeats, module, args]
- [-1, 1, Conv, [64, 3, 2]] # 0-P1/2
- [-1, 1, Conv, [128, 3, 2]] # 1-P2/4
- [-1, 3, C2f, [128, True]]
- [-1, 1, Conv, [256, 3, 2]] # 3-P3/8
- [-1, 6, C2f, [256, True]]
- [-1, 1, Conv, [512, 3, 2]] # 5-P4/16
- [-1, 6, C2f, [512, True]]
- [-1, 1, Conv, [1024, 3, 2]] # 7-P5/32
- [-1, 3, C2f, [1024, True]]
- [-1, 1, SPPF, [1024, 5]] # 9
# YOLOv8.0-p2 head
head:
- [-1, 1, nn.Upsample, [None, 2, "nearest"]]
- [[-1, 6], 1, Concat, [1]] # cat backbone P4
- [-1, 3, C2f, [512]] # 12
- [-1, 1, nn.Upsample, [None, 2, "nearest"]]
- [[-1, 4], 1, Concat, [1]] # cat backbone P3
- [-1, 3, C2f, [256]] # 15 (P3/8-small)
- [-1, 1, nn.Upsample, [None, 2, "nearest"]]
- [[-1, 2], 1, Concat, [1]] # cat backbone P2
- [-1, 3, C2f, [128]] # 18 (P2/4-xsmall)
- [-1, 1, Conv, [128, 3, 2]]
- [[-1, 15], 1, Concat, [1]] # cat head P3
- [-1, 3, C2f, [256]] # 21 (P3/8-small)
- [-1, 1, Conv, [256, 3, 2]]
- [[-1, 12], 1, Concat, [1]] # cat head P4
- [-1, 3, C2f, [512]] # 24 (P4/16-medium)
- [-1, 1, Conv, [512, 3, 2]]
- [[-1, 9], 1, Concat, [1]] # cat head P5
- [-1, 3, C2f, [1024]] # 27 (P5/32-large)
- [[18, 21, 24, 27], 1, Detect, [nc]] # Detect(P2, P3, P4, P5)
以下是根据
input_map = {
'channels': 3,
'size': 640
}
细化的yolov8x-p2.yaml,以及网络输出
# Ultralytics YOLO 🚀, AGPL-3.0 license
# YOLOv8 object detection model with P2-P5 outputs. For Usage examples see https://docs.ultralytics.com/tasks/detect
# Parameters
nc: 80 # number of classes
scales: # model compound scaling constants, i.e. 'model=yolov8n.yaml' will call yolov8.yaml with scale 'n'
# [depth, width, max_channels]
x: [1.00, 1.25, 512]
# YOLOv8.0x backbone
backbone:
# [from, repeats, module, args]
- [-1, 1, Conv, [80, 3, 2]] # 0-P1/2=========80x320x320
- [-1, 1, Conv, [160, 3, 2]] # 1-P2/4=========160x160x160
- [-1, 3, C2f, [160, True]] #2=========160x160x160
- [-1, 1, Conv, [320, 3, 2]] # 3-P3/8=========320x80x80
- [-1, 6, C2f, [320, True]] #4=========320x80x80
- [-1, 1, Conv, [640, 3, 2]] # 5-P4/16=========640x40x40
- [-1, 6, C2f, [640, True]] #6=========640x40x40
- [-1, 1, Conv, [640, 3, 2]] # 7-P5/32=========640x20x20
- [-1, 3, C2f, [640, True]] #8=========640x20x20
- [-1, 1, SPPF, [640, 5]] # 9=========640x20x20
# YOLOv8.0x-p2 head
head:
- [-1, 1, nn.Upsample, [None, 2, "nearest"]] #10 ========= 640x40x40
- [[-1, 6], 1, Concat, [1]] #11 cat backbone P4========= 640x40x40+ 640x40x40 = 1280x40x40
- [-1, 3, C2f, [640]] # 12========= 640x40x40
- [-1, 1, nn.Upsample, [None, 2, "nearest"]] #13=========640x80x80
- [[-1, 4], 1, Concat, [1]] #14 cat backbone P3=========640x80x80+ 320x80x80 =960x80x80
- [-1, 3, C2f, [320]] # 15 (P3/8-small)=========320x80x80
- [-1, 1, nn.Upsample, [None, 2, "nearest"]] #16 =========320x160x160
- [[-1, 2], 1, Concat, [1]] #17 cat backbone P2=========320x160x160 + 160x160x160 = 480x160x160
- [-1, 3, C2f, [160]] # 18 (P2/4-xsmall)=========160x160x160
- [-1, 1, Conv, [160, 3, 2]] #19=========160x80x80
- [[-1, 15], 1, Concat, [1]] #20cat head P3=========160x80x80 + 320x80x80 = 480x80x80
- [-1, 3, C2f, [320]] # 21 (P3/8-small)=========320x80x80
- [-1, 1, Conv, [320, 3, 2]] #22=========320x40x40
- [[-1, 12], 1, Concat, [1]] #23 cat head P4=========320x40x40 + 640x40x40 = 960x40x40
- [-1, 3, C2f, [640]] # 24 (P4/16-medium)=========640x40x40
- [-1, 1, Conv, [640, 3, 2]] #25=========640x20x20
- [[-1, 9], 1, Concat, [1]] #26 cat head P5=========640x20x20 + 640x20x20 = 1280x20x20
- [-1, 3, C2f, [640]] # 27 (P5/32-large)=========640x20x20
- [[18, 21, 24, 27], 1, Detect, [nc]] # Detect(P2, P3, P4, P5)