class_docstr: MobileNetV3 backbone.
  
  This backbone is the improved implementation of `Searching for MobileNetV3
  <https://ieeexplore.ieee.org/document/9008835>`_.
  
  Args:
      arch (str): Architecture of mobilnetv3, from {'small', 'large'}.
          Default: 'small'.
      conv_cfg (dict): Config dict for convolution layer.
          Default: None, which means using conv2d.
      norm_cfg (dict): Config dict for normalization layer.
          Default: dict(type='BN').
      out_indices (tuple[int]): Output from which layer.
          Default: (0, 1, 12).
      frozen_stages (int): Stages to be frozen (all param fixed).
          Default: -1, which means not freezing any parameters.
      norm_eval (bool): Whether to set norm layers to eval mode, namely,
          freeze running stats (mean and var). Note: Effect on Batch Norm
          and its variants only. Default: False.
      with_cp (bool): Use checkpoint or not. Using checkpoint will save
          some memory while slowing down the training speed.
          Default: False.
class_docstr_tok: ["MobileNetV3","backbone",".","This","backbone","is","the","improved","implementation","of","`","Searching","for","MobileNetV3","<","https",":","\/\/ieeexplore.ieee.org\/document\/9008835",">","`","_",".","Args",":","arch","(","str",")",":","Architecture","of","mobilnetv3",",","from","{","'small","'",",","'large","'","}",".","Default",":","'small","'",".","conv_cfg","(","dict",")",":","Config","dict","for","convolution","layer",".","Default",":","None",",","which","means","using","conv2d",".","norm_cfg","(","dict",")",":","Config","dict","for","normalization","layer",".","Default",":","dict","(","type='BN","'",")",".","out_indices","(","tuple","[","int","]",")",":","Output","from","which","layer",".","Default",":","(","0",",","1",",","12",")",".","frozen_stages","(","int",")",":","Stages","to","be","frozen","(","all","param","fixed",")",".","Default",":","-1",",","which","means","not","freezing","any","parameters",".","norm_eval","(","bool",")",":","Whether","to","set","norm","layers","to","eval","mode",",","namely",",","freeze","running","stats","(","mean","and","var",")",".","Note",":","Effect","on","Batch","Norm","and","its","variants","only",".","Default",":","False",".","with_cp","(","bool",")",":","Use","checkpoint","or","not",".","Using","checkpoint","will","save","some","memory","while","slowing","down","the","training","speed",".","Default",":","False","."]
code: def _make_layer(self):
      layers = []
  
      # build the first layer (layer0)
      in_channels = 16
      layer = ConvModule(
          in_channels=3,
          out_channels=in_channels,
          kernel_size=3,
          stride=2,
          padding=1,
          conv_cfg=dict(type="Conv2dAdaptivePadding"),
          norm_cfg=self.norm_cfg,
          act_cfg=dict(type="HSwish"),
      )
      self.add_module("layer0", layer)
      layers.append("layer0")
  
      layer_setting = self.arch_settings[self.arch]
      for i, params in enumerate(layer_setting):
          (
              kernel_size,
              mid_channels,
              out_channels,
              with_se,
              act,
              stride,
          ) = params
  
          if (
              self.arch == "large"
              and i >= 12
              or self.arch == "small"
              and i >= 8
          ):
              mid_channels = mid_channels // self.reduction_factor
              out_channels = out_channels // self.reduction_factor
  
          if with_se:
              se_cfg = dict(
                  channels=mid_channels,
                  ratio=4,
                  act_cfg=(
                      dict(type="ReLU"),
                      dict(type="HSigmoid", bias=3.0, divisor=6.0),
                  ),
              )
          else:
              se_cfg = None
  
          layer = InvertedResidual(
              in_channels=in_channels,
              out_channels=out_channels,
              mid_channels=mid_channels,
              kernel_size=kernel_size,
              stride=stride,
              se_cfg=se_cfg,
              with_expand_conv=(in_channels != mid_channels),
              conv_cfg=self.conv_cfg,
              norm_cfg=self.norm_cfg,
              act_cfg=dict(type=act),
              with_cp=self.with_cp,
          )
          in_channels = out_channels
          layer_name = "layer{}".format(i + 1)
          self.add_module(layer_name, layer)
          layers.append(layer_name)
  
      # build the last layer
      # block5 layer12 os=32 for small model
      # block6 layer16 os=32 for large model
      layer = ConvModule(
          in_channels=in_channels,
          out_channels=576 if self.arch == "small" else 960,
          kernel_size=1,
          stride=1,
          dilation=4,
          padding=0,
          conv_cfg=self.conv_cfg,
          norm_cfg=self.norm_cfg,
          act_cfg=dict(type="HSwish"),
      )
      layer_name = "layer{}".format(len(layer_setting) + 1)
      self.add_module(layer_name, layer)
      layers.append(layer_name)
  
      # next, convert backbone MobileNetV3 to a semantic segmentation version
      if self.arch == "small":
          self.layer4.depthwise_conv.conv.stride = (1, 1)
          self.layer9.depthwise_conv.conv.stride = (1, 1)
          for i in range(4, len(layers)):
              layer = getattr(self, layers[i])
              if isinstance(layer, InvertedResidual):
                  modified_module = layer.depthwise_conv.conv
              else:
                  modified_module = layer.conv
  
              if i < 9:
                  modified_module.dilation = (2, 2)
                  pad = 2
              else:
                  modified_module.dilation = (4, 4)
                  pad = 4
  
              if not isinstance(modified_module, Conv2dAdaptivePadding):
                  # Adjust padding
                  pad *= (modified_module.kernel_size[0] - 1) // 2
                  modified_module.padding = (pad, pad)
      else:
          self.layer7.depthwise_conv.conv.stride = (1, 1)
          self.layer13.depthwise_conv.conv.stride = (1, 1)
          for i in range(7, len(layers)):
              layer = getattr(self, layers[i])
              if isinstance(layer, InvertedResidual):
                  modified_module = layer.depthwise_conv.conv
              else:
                  modified_module = layer.conv
  
              if i < 13:
                  modified_module.dilation = (2, 2)
                  pad = 2
              else:
                  modified_module.dilation = (4, 4)
                  pad = 4
  
              if not isinstance(modified_module, Conv2dAdaptivePadding):
                  # Adjust padding
                  pad *= (modified_module.kernel_size[0] - 1) // 2
                  modified_module.padding = (pad, pad)
  
      return layers
  
file_path: lavis/lavis/common/annotator/uniformer/mmseg/models/backbones/mobilenet_v3.py
imports: import logging
  import annotator.uniformer.mmcv
  import torch.nn
  from annotator.uniformer.mmcv.cnn import ConvModule, constant_init, kaiming_init
  from annotator.uniformer.mmcv.cnn.bricks import Conv2dAdaptivePadding
  from annotator.uniformer.mmcv.runner import load_checkpoint
  from torch.nn.modules.batchnorm import _BatchNorm
  from ..builder import BACKBONES
  from ..utils import InvertedResidualV3
label_desc: Use image node_id 2 for calling the MobileNetV3 obj's underlying member method code with example usage: obj._make_layer() and returns: layers