Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 29 additions & 24 deletions mmdet/models/layers/csp_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,32 @@ class DarknetBottleneck(BaseModule):
Args:
in_channels (int): The input channels of this Module.
out_channels (int): The output channels of this Module.
expansion (int): The kernel size of the convolution. Default: 0.5
expansion (float): The kernel size of the convolution.
Defaults to 0.5.
add_identity (bool): Whether to add identity to the out.
Default: True
Defaults to True.
use_depthwise (bool): Whether to use depthwise separable convolution.
Default: False
conv_cfg (dict): Config dict for convolution layer. Default: None,
Defaults to False.
conv_cfg (dict): Config dict for convolution layer. Defaults to None,
which means using conv2d.
norm_cfg (dict): Config dict for normalization layer.
Default: dict(type='BN').
Defaults to dict(type='BN').
act_cfg (dict): Config dict for activation layer.
Default: dict(type='Swish').
Defaults to dict(type='Swish').
"""

def __init__(self,
in_channels,
out_channels,
expansion=0.5,
add_identity=True,
use_depthwise=False,
conv_cfg=None,
norm_cfg=dict(type='BN', momentum=0.03, eps=0.001),
act_cfg=dict(type='Swish'),
init_cfg=None):
super().__init__(init_cfg)
in_channels: int,
out_channels: int,
expansion: float = 0.5,
add_identity: bool = True,
use_depthwise: bool = False,
conv_cfg: OptConfigType = None,
norm_cfg: ConfigType = dict(
type='BN', momentum=0.03, eps=0.001),
act_cfg: ConfigType = dict(type='Swish'),
init_cfg: OptMultiConfig = None) -> None:
super().__init__(init_cfg=init_cfg)
hidden_channels = int(out_channels * expansion)
conv = DepthwiseSeparableConvModule if use_depthwise else ConvModule
self.conv1 = ConvModule(
Expand All @@ -65,7 +67,8 @@ def __init__(self,
self.add_identity = \
add_identity and in_channels == out_channels

def forward(self, x):
def forward(self, x: Tensor) -> Tensor:
"""Forward function."""
identity = x
out = self.conv1(x)
out = self.conv2(out)
Expand Down Expand Up @@ -136,6 +139,7 @@ def __init__(self,
add_identity and in_channels == out_channels

def forward(self, x: Tensor) -> Tensor:
"""Forward function."""
identity = x
out = self.conv1(x)
out = self.conv2(out)
Expand All @@ -153,22 +157,22 @@ class CSPLayer(BaseModule):
in_channels (int): The input channels of the CSP layer.
out_channels (int): The output channels of the CSP layer.
expand_ratio (float): Ratio to adjust the number of channels of the
hidden layer. Default: 0.5
num_blocks (int): Number of blocks. Default: 1
hidden layer. Defaults to 0.5.
num_blocks (int): Number of blocks. Defaults to 1.
add_identity (bool): Whether to add identity in blocks.
Default: True
Defaults to True.
use_cspnext_block (bool): Whether to use CSPNeXt block.
Defaults to False.
use_depthwise (bool): Whether to use depthwise separable convolution in
blocks. Default: False
blocks. Defaults to False.
channel_attention (bool): Whether to add channel attention in each
stage. Defaults to True.
conv_cfg (dict, optional): Config dict for convolution layer.
Default: None, which means using conv2d.
Defaults to None, which means using conv2d.
norm_cfg (dict): Config dict for normalization layer.
Default: dict(type='BN')
Defaults to dict(type='BN')
act_cfg (dict): Config dict for activation layer.
Default: dict(type='Swish')
Defaults to dict(type='Swish')
init_cfg (:obj:`ConfigDict` or dict or list[dict] or
list[:obj:`ConfigDict`], optional): Initialization config dict.
Defaults to None.
Expand Down Expand Up @@ -229,6 +233,7 @@ def __init__(self,
self.attention = ChannelAttention(2 * mid_channels)

def forward(self, x: Tensor) -> Tensor:
"""Forward function."""
x_short = self.short_conv(x)

x_main = self.main_conv(x)
Expand Down