class_docstr: Cross Stage Partial Layer.
  
  Args:
      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. Defaults to 0.5.
      num_blocks (int): Number of blocks. Defaults to 1.
      add_identity (bool): Whether to add identity in blocks.
          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. 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.
          Defaults to None, which means using conv2d.
      norm_cfg (dict): Config dict for normalization layer.
          Defaults to dict(type='BN')
      act_cfg (dict): Config dict for activation layer.
          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.
class_docstr_tok: ["Cross","Stage","Partial","Layer",".","Args",":","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",".","Defaults","to","0.5.","num_blocks","(","int",")",":","Number","of","blocks",".","Defaults","to","1.","add_identity","(","bool",")",":","Whether","to","add","identity","in","blocks",".","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",".","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",".","Defaults","to","None",",","which","means","using","conv2d",".","norm_cfg","(","dict",")",":","Config","dict","for","normalization","layer",".","Defaults","to","dict","(","type='BN","'",")","act_cfg","(","dict",")",":","Config","dict","for","activation","layer",".","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","."]
code: def __init__(
      self,
      in_channels: int,
      out_channels: int,
      expand_ratio: float = 0.5,
      num_blocks: int = 1,
      add_identity: bool = True,
      use_depthwise: bool = False,
      use_cspnext_block: bool = False,
      channel_attention: 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)
      block = CSPNeXtBlock if use_cspnext_block else DarknetBottleneck
      mid_channels = int(out_channels * expand_ratio)
      self.channel_attention = channel_attention
      self.main_conv = ConvModule(
          in_channels,
          mid_channels,
          1,
          conv_cfg=conv_cfg,
          norm_cfg=norm_cfg,
          act_cfg=act_cfg,
      )
      self.short_conv = ConvModule(
          in_channels,
          mid_channels,
          1,
          conv_cfg=conv_cfg,
          norm_cfg=norm_cfg,
          act_cfg=act_cfg,
      )
      self.final_conv = ConvModule(
          2 * mid_channels,
          out_channels,
          1,
          conv_cfg=conv_cfg,
          norm_cfg=norm_cfg,
          act_cfg=act_cfg,
      )
  
      self.blocks = nn.Sequential(
          *[
              block(
                  mid_channels,
                  mid_channels,
                  1.0,
                  add_identity,
                  use_depthwise,
                  conv_cfg=conv_cfg,
                  norm_cfg=norm_cfg,
                  act_cfg=act_cfg,
              )
              for _ in range(num_blocks)
          ]
      )
      if channel_attention:
          self.attention = ChannelAttention(2 * mid_channels)
  
file_path: mmdetection/mmdet/models/layers/csp_layer.py
imports: import torch
  import torch.nn
  from mmcv.cnn import ConvModule, DepthwiseSeparableConvModule
  from mmengine.model import BaseModule
  from torch import Tensor
  from mmdet.utils import ConfigType, OptConfigType, OptMultiConfig
  from .se_layer import ChannelAttention
label_desc: Use image node_id 1 to create a new CSPLayer object from inherited base classes: BaseModule with example: obj = CSPLayer(in_channels, out_channels, expand_ratio, num_blocks, add_identity, use_depthwise, use_cspnext_block, channel_attention, conv_cfg, norm_cfg, act_cfg, init_cfg)