class_docstr: ResNet backbone.
  
  Args:
      depth (int): Depth of resnet, from {18, 34, 50, 101, 152}.
      stem_channels (int | None): Number of stem channels. If not specified,
          it will be the same as `base_channels`. Default: None.
      base_channels (int): Number of base channels of res layer. Default: 64.
      in_channels (int): Number of input image channels. Default: 3.
      num_stages (int): Resnet stages. Default: 4.
      strides (Sequence[int]): Strides of the first block of each stage.
      dilations (Sequence[int]): Dilation of each stage.
      out_indices (Sequence[int]): Output from which stages.
      style (str): `pytorch` or `caffe`. If set to "pytorch", the stride-two
          layer is the 3x3 conv layer, otherwise the stride-two layer is
          the first 1x1 conv layer.
      deep_stem (bool): Replace 7x7 conv in input stem with 3 3x3 conv
      avg_down (bool): Use AvgPool instead of stride conv when
          downsampling in the bottleneck.
      frozen_stages (int): Stages to be frozen (stop grad and set eval mode).
          -1 means not freezing any parameters.
      norm_cfg (dict): Dictionary to construct and config norm layer.
      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.
      plugins (list[dict]): List of plugins for stages, each dict contains:
  
          - cfg (dict, required): Cfg dict to build plugin.
          - position (str, required): Position inside block to insert
            plugin, options are 'after_conv1', 'after_conv2', 'after_conv3'.
          - stages (tuple[bool], optional): Stages to apply plugin, length
            should be same as 'num_stages'.
      with_cp (bool): Use checkpoint or not. Using checkpoint will save some
          memory while slowing down the training speed.
      zero_init_residual (bool): Whether to use zero init for last norm layer
          in resblocks to let them behave as identity.
      pretrained (str, optional): model pretrained path. Default: None
      init_cfg (dict or list[dict], optional): Initialization config dict.
          Default: None
  
  Example:
      >>> from mmdet.models import ResNet
      >>> import torch
      >>> self = ResNet(depth=18)
      >>> self.eval()
      >>> inputs = torch.rand(1, 3, 32, 32)
      >>> level_outputs = self.forward(inputs)
      >>> for level_out in level_outputs:
      ...     print(tuple(level_out.shape))
      (1, 64, 8, 8)
      (1, 128, 4, 4)
      (1, 256, 2, 2)
      (1, 512, 1, 1)
class_docstr_tok: ["ResNet","backbone",".","Args",":","depth","(","int",")",":","Depth","of","resnet",",","from","{","18",",","34",",","50",",","101",",","152","}",".","stem_channels","(","int","|","None",")",":","Number","of","stem","channels",".","If","not","specified",",","it","will","be","the","same","as","`","base_channels","`",".","Default",":","None",".","base_channels","(","int",")",":","Number","of","base","channels","of","res","layer",".","Default",":","64.","in_channels","(","int",")",":","Number","of","input","image","channels",".","Default",":","3.","num_stages","(","int",")",":","Resnet","stages",".","Default",":","4.","strides","(","Sequence","[","int","]",")",":","Strides","of","the","first","block","of","each","stage",".","dilations","(","Sequence","[","int","]",")",":","Dilation","of","each","stage",".","out_indices","(","Sequence","[","int","]",")",":","Output","from","which","stages",".","style","(","str",")",":","`","pytorch","`","or","`","caffe","`",".","If","set","to","``","pytorch","''",",","the","stride-two","layer","is","the","3x3","conv","layer",",","otherwise","the","stride-two","layer","is","the","first","1x1","conv","layer",".","deep_stem","(","bool",")",":","Replace","7x7","conv","in","input","stem","with","3","3x3","conv","avg_down","(","bool",")",":","Use","AvgPool","instead","of","stride","conv","when","downsampling","in","the","bottleneck",".","frozen_stages","(","int",")",":","Stages","to","be","frozen","(","stop","grad","and","set","eval","mode",")",".","-1","means","not","freezing","any","parameters",".","norm_cfg","(","dict",")",":","Dictionary","to","construct","and","config","norm","layer",".","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",".","plugins","(","list","[","dict","]",")",":","List","of","plugins","for","stages",",","each","dict","contains",":","-","cfg","(","dict",",","required",")",":","Cfg","dict","to","build","plugin",".","-","position","(","str",",","required",")",":","Position","inside","block","to","insert","plugin",",","options","are","'after_conv1","'",",","'after_conv2","'",",","'after_conv3","'",".","-","stages","(","tuple","[","bool","]",",","optional",")",":","Stages","to","apply","plugin",",","length","should","be","same","as","'num_stages","'",".","with_cp","(","bool",")",":","Use","checkpoint","or","not",".","Using","checkpoint","will","save","some","memory","while","slowing","down","the","training","speed",".","zero_init_residual","(","bool",")",":","Whether","to","use","zero","init","for","last","norm","layer","in","resblocks","to","let","them","behave","as","identity",".","pretrained","(","str",",","optional",")",":","model","pretrained","path",".","Default",":","None","init_cfg","(","dict","or","list","[","dict","]",",","optional",")",":","Initialization","config","dict",".","Default",":","None","Example",":",">",">",">","from","mmdet.models","import","ResNet",">",">",">","import","torch",">",">",">","self","=","ResNet","(","depth=18",")",">",">",">","self.eval","(",")",">",">",">","inputs","=","torch.rand","(","1",",","3",",","32",",","32",")",">",">",">","level_outputs","=","self.forward","(","inputs",")",">",">",">","for","level_out","in","level_outputs",":","...","print","(","tuple","(","level_out.shape",")",")","(","1",",","64",",","8",",","8",")","(","1",",","128",",","4",",","4",")","(","1",",","256",",","2",",","2",")","(","1",",","512",",","1",",","1",")"]
code: def __init__(
      self,
      depth,
      in_channels=3,
      stem_channels=None,
      base_channels=64,
      num_stages=4,
      strides=(1, 2, 2, 2),
      dilations=(1, 1, 1, 1),
      out_indices=(0, 1, 2, 3),
      style="pytorch",
      deep_stem=False,
      avg_down=False,
      frozen_stages=-1,
      conv_cfg=None,
      norm_cfg=dict(type="BN", requires_grad=True),
      norm_eval=True,
      dcn=None,
      stage_with_dcn=(False, False, False, False),
      plugins=None,
      with_cp=False,
      zero_init_residual=True,
      pretrained=None,
      init_cfg=None,
  ):
      super(ResNet, self).__init__(init_cfg)
      self.zero_init_residual = zero_init_residual
      if depth not in self.arch_settings:
          raise KeyError(f"invalid depth {depth} for resnet")
  
      block_init_cfg = None
      assert not (
          init_cfg and pretrained
      ), "init_cfg and pretrained cannot be specified at the same time"
      if isinstance(pretrained, str):
          warnings.warn(
              "DeprecationWarning: pretrained is deprecated, "
              'please use "init_cfg" instead'
          )
          self.init_cfg = dict(type="Pretrained", checkpoint=pretrained)
      elif pretrained is None:
          if init_cfg is None:
              self.init_cfg = [
                  dict(type="Kaiming", layer="Conv2d"),
                  dict(
                      type="Constant",
                      val=1,
                      layer=["_BatchNorm", "GroupNorm"],
                  ),
              ]
              block = self.arch_settings[depth][0]
              if self.zero_init_residual:
                  if block is BasicBlock:
                      block_init_cfg = dict(
                          type="Constant",
                          val=0,
                          override=dict(name="norm2"),
                      )
                  elif block is Bottleneck:
                      block_init_cfg = dict(
                          type="Constant",
                          val=0,
                          override=dict(name="norm3"),
                      )
      else:
          raise TypeError("pretrained must be a str or None")
  
      self.depth = depth
      if stem_channels is None:
          stem_channels = base_channels
      self.stem_channels = stem_channels
      self.base_channels = base_channels
      self.num_stages = num_stages
      assert num_stages >= 1 and num_stages <= 4
      self.strides = strides
      self.dilations = dilations
      assert len(strides) == len(dilations) == num_stages
      self.out_indices = out_indices
      assert max(out_indices) < num_stages
      self.style = style
      self.deep_stem = deep_stem
      self.avg_down = avg_down
      self.frozen_stages = frozen_stages
      self.conv_cfg = conv_cfg
      self.norm_cfg = norm_cfg
      self.with_cp = with_cp
      self.norm_eval = norm_eval
      self.dcn = dcn
      self.stage_with_dcn = stage_with_dcn
      if dcn is not None:
          assert len(stage_with_dcn) == num_stages
      self.plugins = plugins
      self.block, stage_blocks = self.arch_settings[depth]
      self.stage_blocks = stage_blocks[:num_stages]
      self.inplanes = stem_channels
  
      self._make_stem_layer(in_channels, stem_channels)
  
      self.res_layers = []
      for i, num_blocks in enumerate(self.stage_blocks):
          stride = strides[i]
          dilation = dilations[i]
          dcn = self.dcn if self.stage_with_dcn[i] else None
          if plugins is not None:
              stage_plugins = self.make_stage_plugins(plugins, i)
          else:
              stage_plugins = None
          planes = base_channels * 2**i
          res_layer = self.make_res_layer(
              block=self.block,
              inplanes=self.inplanes,
              planes=planes,
              num_blocks=num_blocks,
              stride=stride,
              dilation=dilation,
              style=self.style,
              avg_down=self.avg_down,
              with_cp=with_cp,
              conv_cfg=conv_cfg,
              norm_cfg=norm_cfg,
              dcn=dcn,
              plugins=stage_plugins,
              init_cfg=block_init_cfg,
          )
          self.inplanes = planes * self.block.expansion
          layer_name = f"layer{i + 1}"
          self.add_module(layer_name, res_layer)
          self.res_layers.append(layer_name)
  
      self._freeze_stages()
  
      self.feat_dim = (
          self.block.expansion
          * base_channels
          * 2 ** (len(self.stage_blocks) - 1)
      )
  
imports: import warnings
  import torch.nn
  import torch.utils.checkpoint
  from mmcv.cnn import build_conv_layer, build_norm_layer, build_plugin_layer
  from mmengine.model import BaseModule
  from torch.nn.modules.batchnorm import _BatchNorm
  from mmdet.registry import MODELS
  from ..layers import ResLayer
label_desc: Use image node_id 1 to create a new ResNet object from inherited base classes: BaseModule with example: obj = ResNet(depth, in_channels, stem_channels, base_channels, num_stages, strides, dilations, out_indices, style, deep_stem, avg_down, frozen_stages, conv_cfg, norm_cfg, norm_eval, dcn, stage_with_dcn, plugins, with_cp, zero_init_residual, pretrained, init_cfg)