Args: act (str): activation type of conv. Defalut value: "silu". depthwise (bool): wheather apply depthwise conv in conv branch. Defalut value: False.
(
self,
num_classes,
width=1.0,
strides=[8, 16, 32],
in_channels=[256, 512, 1024],
act="silu",
depthwise=False,
)
| 18 | |
| 19 | class YOLOXHead(nn.Module): |
| 20 | def __init__( |
| 21 | self, |
| 22 | num_classes, |
| 23 | width=1.0, |
| 24 | strides=[8, 16, 32], |
| 25 | in_channels=[256, 512, 1024], |
| 26 | act="silu", |
| 27 | depthwise=False, |
| 28 | ): |
| 29 | """ |
| 30 | Args: |
| 31 | act (str): activation type of conv. Defalut value: "silu". |
| 32 | depthwise (bool): wheather apply depthwise conv in conv branch. Defalut value: False. |
| 33 | """ |
| 34 | super().__init__() |
| 35 | |
| 36 | self.n_anchors = 1 |
| 37 | self.num_classes = num_classes |
| 38 | self.decode_in_inference = True # for deploy, set to False |
| 39 | |
| 40 | self.cls_convs = nn.ModuleList() |
| 41 | self.reg_convs = nn.ModuleList() |
| 42 | self.cls_preds = nn.ModuleList() |
| 43 | self.reg_preds = nn.ModuleList() |
| 44 | self.obj_preds = nn.ModuleList() |
| 45 | self.stems = nn.ModuleList() |
| 46 | Conv = DWConv if depthwise else BaseConv |
| 47 | |
| 48 | for i in range(len(in_channels)): |
| 49 | self.stems.append( |
| 50 | BaseConv( |
| 51 | in_channels=int(in_channels[i] * width), |
| 52 | out_channels=int(256 * width), |
| 53 | ksize=1, |
| 54 | stride=1, |
| 55 | act=act, |
| 56 | ) |
| 57 | ) |
| 58 | self.cls_convs.append( |
| 59 | nn.Sequential( |
| 60 | *[ |
| 61 | Conv( |
| 62 | in_channels=int(256 * width), |
| 63 | out_channels=int(256 * width), |
| 64 | ksize=3, |
| 65 | stride=1, |
| 66 | act=act, |
| 67 | ), |
| 68 | Conv( |
| 69 | in_channels=int(256 * width), |
| 70 | out_channels=int(256 * width), |
| 71 | ksize=3, |
| 72 | stride=1, |
| 73 | act=act, |
| 74 | ), |
| 75 | ] |
| 76 | ) |
| 77 | ) |