Spatial pyramid pooling layer used in YOLOv3-SPP
| 120 | |
| 121 | |
| 122 | class SPPBottleneck(nn.Module): |
| 123 | """Spatial pyramid pooling layer used in YOLOv3-SPP""" |
| 124 | |
| 125 | def __init__( |
| 126 | self, in_channels, out_channels, kernel_sizes=(5, 9, 13), activation="silu" |
| 127 | ): |
| 128 | super().__init__() |
| 129 | hidden_channels = in_channels // 2 |
| 130 | self.conv1 = BaseConv(in_channels, hidden_channels, 1, stride=1, act=activation) |
| 131 | self.m = nn.ModuleList( |
| 132 | [ |
| 133 | nn.MaxPool2d(kernel_size=ks, stride=1, padding=ks // 2) |
| 134 | for ks in kernel_sizes |
| 135 | ] |
| 136 | ) |
| 137 | conv2_channels = hidden_channels * (len(kernel_sizes) + 1) |
| 138 | self.conv2 = BaseConv(conv2_channels, out_channels, 1, stride=1, act=activation) |
| 139 | |
| 140 | def forward(self, x): |
| 141 | x = self.conv1(x) |
| 142 | x = torch.cat([x] + [m(x) for m in self.m], dim=1) |
| 143 | x = self.conv2(x) |
| 144 | return x |
| 145 | |
| 146 | |
| 147 | class CSPLayer(nn.Module): |
no outgoing calls
no test coverage detected