YOLOv3 model. Darknet 53 is the default backbone of this model.
| 10 | |
| 11 | |
| 12 | class YOLOPAFPN(nn.Module): |
| 13 | """ |
| 14 | YOLOv3 model. Darknet 53 is the default backbone of this model. |
| 15 | """ |
| 16 | |
| 17 | def __init__( |
| 18 | self, |
| 19 | depth=1.0, |
| 20 | width=1.0, |
| 21 | in_features=("dark3", "dark4", "dark5"), |
| 22 | in_channels=[256, 512, 1024], |
| 23 | depthwise=False, |
| 24 | act="silu", |
| 25 | ): |
| 26 | super().__init__() |
| 27 | self.backbone = CSPDarknet(depth, width, depthwise=depthwise, act=act) |
| 28 | self.in_features = in_features |
| 29 | self.in_channels = in_channels |
| 30 | Conv = DWConv if depthwise else BaseConv |
| 31 | |
| 32 | self.upsample = nn.Upsample(scale_factor=2, mode="nearest") |
| 33 | self.lateral_conv0 = BaseConv( |
| 34 | int(in_channels[2] * width), int(in_channels[1] * width), 1, 1, act=act |
| 35 | ) |
| 36 | self.C3_p4 = CSPLayer( |
| 37 | int(2 * in_channels[1] * width), |
| 38 | int(in_channels[1] * width), |
| 39 | round(3 * depth), |
| 40 | False, |
| 41 | depthwise=depthwise, |
| 42 | act=act, |
| 43 | ) # cat |
| 44 | |
| 45 | self.reduce_conv1 = BaseConv( |
| 46 | int(in_channels[1] * width), int(in_channels[0] * width), 1, 1, act=act |
| 47 | ) |
| 48 | self.C3_p3 = CSPLayer( |
| 49 | int(2 * in_channels[0] * width), |
| 50 | int(in_channels[0] * width), |
| 51 | round(3 * depth), |
| 52 | False, |
| 53 | depthwise=depthwise, |
| 54 | act=act, |
| 55 | ) |
| 56 | |
| 57 | # bottom-up conv |
| 58 | self.bu_conv2 = Conv( |
| 59 | int(in_channels[0] * width), int(in_channels[0] * width), 3, 2, act=act |
| 60 | ) |
| 61 | self.C3_n3 = CSPLayer( |
| 62 | int(2 * in_channels[0] * width), |
| 63 | int(in_channels[1] * width), |
| 64 | round(3 * depth), |
| 65 | False, |
| 66 | depthwise=depthwise, |
| 67 | act=act, |
| 68 | ) |
| 69 |