一、网络模型

"""
backbone:
# [from, repeats, module, args]
- [-1, 1, Conv, [32, 3, 2]] # 0-P1/2 320*320*32
- [-1, 1, Conv, [64, 3, 2]] # 1-P2/4 160*160*64
- [-1, 1, C2f, [64, True]] # 2
- [-1, 1, Conv, [128, 3, 2]] # 3-P3/8 80*80*128
- [-1, 2, C2f, [128, True]] # 4
- [-1, 1, SCDown, [256, 3, 2]] # 5-P4/16 40*40*256
- [-1, 2, C2f, [256, True]] # 6
- [-1, 1, SCDown, [512, 3, 2]] # 7-P5/32 20*20*512
- [-1, 1, C2fCIB, [512, True, True]] # 8
- [-1, 1, SPPF, [512, 5]] # 9
- [-1, 1, PSA, [512]] # 10 20*20*512
head:
- [-1, 1, nn.Upsample, [None, 2, "nearest"]] # 11 40*40*512
- [[-1, 6], 1, Concat, [1]] # cat backbone P4 40*40*768
- [-1, 1, C2f, [256]] # 13 40*40*256
- [-1, 1, nn.Upsample, [None, 2, "nearest"]] # 14 80*80*256
- [[-1, 4], 1, Concat, [1]] # cat backbone P3 80*80*384
- [-1, 1, C2f, [128]] # 16 (P3/8-small) 80*80*128
- [-1, 1, Conv, [128, 3, 2]] # 17 40*40*128
- [[-1, 13], 1, Concat, [1]] # cat head P4 40*40*384
- [-1, 1, C2f, [256]] # 19 (P4/16-medium) 40*40*256
- [-1, 1, SCDown, [256, 3, 2]] # 20 20*20*256
- [[-1, 10], 1, Concat, [1]] # cat head P5 20*20*768
- [-1, 1, C2fCIB, [512, True, True]] # 22 (P5/32-large) 20*20*512
- [[16, 19, 22], 1, v10Detect, [nc]] # Detect(P3, P4, P5) 80*80*85 40*40*85 20*20*85
"""
二、特殊结构分解
1、C2f
160*160*64 --> 160*160*64

class C2f(nn.Module):
"""Faster Implementation of CSP Bottleneck with 2 convolutions."""
def __init__(self, c1, c2, n=1, shortcut=False, g=1, e=0.5):
"""Initialize CSP bottleneck layer with two convolutions with arguments ch_in, ch_out, number, shortcut, groups,
expansion.
"""
super().__init__()
self.c = int(c2 * e) # hidden channels
self.cv1 = Conv(c1, 2 * self.c, 1, 1)
self.cv2 = Conv((2 + n) * self.c, c2, 1) # optional act=FReLU(c2)
self.m = nn.ModuleList(Bottleneck(self.c, self.c, shortcut, g, k=((3, 3), (3, 3)), e=1.0) for _ in range(n))
def forward(self, x):
"""Forward pass through C2f layer."""
y = list(self.cv1(x).chunk(2, 1))
y.extend(m(y[-1]) for m in self.m)
return self.cv2(torch.cat(y, 1))

最低0.47元/天 解锁文章
2828

被折叠的 条评论
为什么被折叠?



