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.
      in_channels (int): Number of input image channels. Normally 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.
      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.
  
  Example:
      >>> from annotator.uniformer.mmseg.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)
class_docstr_tok: ["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",".","in_channels","(","int",")",":","Number","of","input","image","channels",".","Normally","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",".","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",".","Example",":",">",">",">","from","annotator.uniformer.mmseg.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",")"]
docstr: Make each stage.
docstr_tok: ["Make","each","stage","."]
code: def _make_stage(
      self, layer_config, in_channels, multiscale_output=True
  ):
      """Make each stage."""
      num_modules = layer_config["num_modules"]
      num_branches = layer_config["num_branches"]
      num_blocks = layer_config["num_blocks"]
      num_channels = layer_config["num_channels"]
      block = self.blocks_dict[layer_config["block"]]
  
      hr_modules = []
      for i in range(num_modules):
          # multi_scale_output is only used for the last module
          if not multiscale_output and i == num_modules - 1:
              reset_multiscale_output = False
          else:
              reset_multiscale_output = True
  
          hr_modules.append(
              HRModule(
                  num_branches,
                  block,
                  num_blocks,
                  in_channels,
                  num_channels,
                  reset_multiscale_output,
                  with_cp=self.with_cp,
                  norm_cfg=self.norm_cfg,
                  conv_cfg=self.conv_cfg,
              )
          )
  
      return nn.Sequential(*hr_modules), in_channels
  
imports: import torch.nn
  from annotator.uniformer.mmcv.cnn import build_conv_layer, build_norm_layer, constant_init, kaiming_init
  from annotator.uniformer.mmcv.runner import load_checkpoint
  from annotator.uniformer.mmcv.utils.parrots_wrapper import _BatchNorm
  from annotator.uniformer.mmseg.ops import Upsample, resize
  from annotator.uniformer.mmseg.utils import get_root_logger
  from ..builder import BACKBONES
  from .resnet import BasicBlock, Bottleneck
label_desc: Use image node_id 6 for calling the HRNet obj's underlying member method code with example usage: obj._make_stage(layer_config, in_channels, multiscale_output) and returns: nn,  in_channels