class_docstr: HRNet backbone.
  
  `High-Resolution Representations for Labeling Pixels and Regions
  arXiv: <https://arxiv.org/abs/1904.04514>`_.
  
  Args:
      extra (dict): Detailed configuration for each stage of HRNet.
          There must be 4 stages, the configuration for each stage must have
          5 keys:
  
              - num_modules(int): The number of HRModule in this stage.
              - num_branches(int): The number of branches in the HRModule.
              - block(str): The type of convolution block.
              - num_blocks(tuple): The number of blocks in each branch.
                  The length must be equal to num_branches.
              - num_channels(tuple): The number of channels in each branch.
                  The length must be equal to num_branches.
      in_channels (int): Number of input image channels. Default: 3.
      conv_cfg (dict): Dictionary to construct and config conv layer.
      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. Default: True.
      with_cp (bool): Use checkpoint or not. Using checkpoint will save some
          memory while slowing down the training speed. Default: False.
      zero_init_residual (bool): Whether to use zero init for last norm layer
          in resblocks to let them behave as identity. Default: False.
      multiscale_output (bool): Whether to output multi-level features
          produced by multiple branches. If False, only the first level
          feature will be output. Default: True.
      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 HRNet
      >>> import torch
      >>> extra = dict(
      >>>     stage1=dict(
      >>>         num_modules=1,
      >>>         num_branches=1,
      >>>         block='BOTTLENECK',
      >>>         num_blocks=(4, ),
      >>>         num_channels=(64, )),
      >>>     stage2=dict(
      >>>         num_modules=1,
      >>>         num_branches=2,
      >>>         block='BASIC',
      >>>         num_blocks=(4, 4),
      >>>         num_channels=(32, 64)),
      >>>     stage3=dict(
      >>>         num_modules=4,
      >>>         num_branches=3,
      >>>         block='BASIC',
      >>>         num_blocks=(4, 4, 4),
      >>>         num_channels=(32, 64, 128)),
      >>>     stage4=dict(
      >>>         num_modules=3,
      >>>         num_branches=4,
      >>>         block='BASIC',
      >>>         num_blocks=(4, 4, 4, 4),
      >>>         num_channels=(32, 64, 128, 256)))
      >>> self = HRNet(extra, in_channels=1)
      >>> self.eval()
      >>> inputs = torch.rand(1, 1, 32, 32)
      >>> level_outputs = self.forward(inputs)
      >>> for level_out in level_outputs:
      ...     print(tuple(level_out.shape))
      (1, 32, 8, 8)
      (1, 64, 4, 4)
      (1, 128, 2, 2)
      (1, 256, 1, 1)
code: def __init__(
      self,
      extra,
      in_channels=3,
      conv_cfg=None,
      norm_cfg=dict(type="BN"),
      norm_eval=True,
      with_cp=False,
      zero_init_residual=False,
      multiscale_output=True,
      pretrained=None,
      init_cfg=None,
  ):
      super(HRNet, self).__init__(init_cfg)
  
      self.pretrained = pretrained
      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"],
                  ),
              ]
      else:
          raise TypeError("pretrained must be a str or None")
  
      # Assert configurations of 4 stages are in extra
      assert (
          "stage1" in extra
          and "stage2" in extra
          and "stage3" in extra
          and "stage4" in extra
      )
      # Assert whether the length of `num_blocks` and `num_channels` are
      # equal to `num_branches`
      for i in range(4):
          cfg = extra[f"stage{i + 1}"]
          assert (
              len(cfg["num_blocks"]) == cfg["num_branches"]
              and len(cfg["num_channels"]) == cfg["num_branches"]
          )
  
      self.extra = extra
      self.conv_cfg = conv_cfg
      self.norm_cfg = norm_cfg
      self.norm_eval = norm_eval
      self.with_cp = with_cp
      self.zero_init_residual = zero_init_residual
  
      # stem net
      self.norm1_name, norm1 = build_norm_layer(
          self.norm_cfg, 64, postfix=1
      )
      self.norm2_name, norm2 = build_norm_layer(
          self.norm_cfg, 64, postfix=2
      )
  
      self.conv1 = build_conv_layer(
          self.conv_cfg,
          in_channels,
          64,
          kernel_size=3,
          stride=2,
          padding=1,
          bias=False,
      )
  
      self.add_module(self.norm1_name, norm1)
      self.conv2 = build_conv_layer(
          self.conv_cfg,
          64,
          64,
          kernel_size=3,
          stride=2,
          padding=1,
          bias=False,
      )
  
      self.add_module(self.norm2_name, norm2)
      self.relu = nn.ReLU(inplace=True)
  
      # stage 1
      self.stage1_cfg = self.extra["stage1"]
      num_channels = self.stage1_cfg["num_channels"][0]
      block_type = self.stage1_cfg["block"]
      num_blocks = self.stage1_cfg["num_blocks"][0]
  
      block = self.blocks_dict[block_type]
      stage1_out_channels = num_channels * block.expansion
      self.layer1 = self._make_layer(
          block, 64, num_channels, num_blocks
      )
  
      # stage 2
      self.stage2_cfg = self.extra["stage2"]
      num_channels = self.stage2_cfg["num_channels"]
      block_type = self.stage2_cfg["block"]
  
      block = self.blocks_dict[block_type]
      num_channels = [
          channel * block.expansion for channel in num_channels
      ]
      self.transition1 = self._make_transition_layer(
          [stage1_out_channels], num_channels
      )
      self.stage2, pre_stage_channels = self._make_stage(
          self.stage2_cfg, num_channels
      )
  
      # stage 3
      self.stage3_cfg = self.extra["stage3"]
      num_channels = self.stage3_cfg["num_channels"]
      block_type = self.stage3_cfg["block"]
  
      block = self.blocks_dict[block_type]
      num_channels = [
          channel * block.expansion for channel in num_channels
      ]
      self.transition2 = self._make_transition_layer(
          pre_stage_channels, num_channels
      )
      self.stage3, pre_stage_channels = self._make_stage(
          self.stage3_cfg, num_channels
      )
  
      # stage 4
      self.stage4_cfg = self.extra["stage4"]
      num_channels = self.stage4_cfg["num_channels"]
      block_type = self.stage4_cfg["block"]
  
      block = self.blocks_dict[block_type]
      num_channels = [
          channel * block.expansion for channel in num_channels
      ]
      self.transition3 = self._make_transition_layer(
          pre_stage_channels, num_channels
      )
      self.stage4, pre_stage_channels = self._make_stage(
          self.stage4_cfg,
          num_channels,
          multiscale_output=multiscale_output,
      )
  
imports: import warnings
  import torch.nn
  from mmcv.cnn import build_conv_layer, build_norm_layer
  from mmengine.model import BaseModule, ModuleList, Sequential
  from torch.nn.modules.batchnorm import _BatchNorm
  from mmdet.registry import MODELS
  from .resnet import BasicBlock, Bottleneck
label_desc: Use image node_id 1 to create a new HRNet object from inherited base classes: BaseModule with example: obj = HRNet(extra, in_channels, conv_cfg, norm_cfg, norm_eval, with_cp, zero_init_residual, multiscale_output, pretrained, init_cfg)