class_docstr: Pyramid Vision Transformer (PVT)
  
  Implementation of `Pyramid Vision Transformer: A Versatile Backbone for
  Dense Prediction without Convolutions
  <https://arxiv.org/pdf/2102.12122.pdf>`_.
  
  Args:
      pretrain_img_size (int | tuple[int]): The size of input image when
          pretrain. Defaults: 224.
      in_channels (int): Number of input channels. Default: 3.
      embed_dims (int): Embedding dimension. Default: 64.
      num_stags (int): The num of stages. Default: 4.
      num_layers (Sequence[int]): The layer number of each transformer encode
          layer. Default: [3, 4, 6, 3].
      num_heads (Sequence[int]): The attention heads of each transformer
          encode layer. Default: [1, 2, 5, 8].
      patch_sizes (Sequence[int]): The patch_size of each patch embedding.
          Default: [4, 2, 2, 2].
      strides (Sequence[int]): The stride of each patch embedding.
          Default: [4, 2, 2, 2].
      paddings (Sequence[int]): The padding of each patch embedding.
          Default: [0, 0, 0, 0].
      sr_ratios (Sequence[int]): The spatial reduction rate of each
          transformer encode layer. Default: [8, 4, 2, 1].
      out_indices (Sequence[int] | int): Output from which stages.
          Default: (0, 1, 2, 3).
      mlp_ratios (Sequence[int]): The ratio of the mlp hidden dim to the
          embedding dim of each transformer encode layer.
          Default: [8, 8, 4, 4].
      qkv_bias (bool): Enable bias for qkv if True. Default: True.
      drop_rate (float): Probability of an element to be zeroed.
          Default 0.0.
      attn_drop_rate (float): The drop out rate for attention layer.
          Default 0.0.
      drop_path_rate (float): stochastic depth rate. Default 0.1.
      use_abs_pos_embed (bool): If True, add absolute position embedding to
          the patch embedding. Defaults: True.
      use_conv_ffn (bool): If True, use Convolutional FFN to replace FFN.
          Default: False.
      act_cfg (dict): The activation config for FFNs.
          Default: dict(type='GELU').
      norm_cfg (dict): Config dict for normalization layer.
          Default: dict(type='LN').
      pretrained (str, optional): model pretrained path. Default: None.
      convert_weights (bool): The flag indicates whether the
          pre-trained model is from the original repo. We may need
          to convert some keys to make it compatible.
          Default: True.
      init_cfg (dict or list[dict], optional): Initialization config dict.
          Default: None.
class_docstr_tok: ["Pyramid","Vision","Transformer","(","PVT",")","Implementation","of","`","Pyramid","Vision","Transformer",":","A","Versatile","Backbone","for","Dense","Prediction","without","Convolutions","<","https",":","\/\/arxiv.org\/pdf\/2102.12122.pdf",">","`","_",".","Args",":","pretrain_img_size","(","int","|","tuple","[","int","]",")",":","The","size","of","input","image","when","pretrain",".","Defaults",":","224.","in_channels","(","int",")",":","Number","of","input","channels",".","Default",":","3.","embed_dims","(","int",")",":","Embedding","dimension",".","Default",":","64.","num_stags","(","int",")",":","The","num","of","stages",".","Default",":","4.","num_layers","(","Sequence","[","int","]",")",":","The","layer","number","of","each","transformer","encode","layer",".","Default",":","[","3",",","4",",","6",",","3","]",".","num_heads","(","Sequence","[","int","]",")",":","The","attention","heads","of","each","transformer","encode","layer",".","Default",":","[","1",",","2",",","5",",","8","]",".","patch_sizes","(","Sequence","[","int","]",")",":","The","patch_size","of","each","patch","embedding",".","Default",":","[","4",",","2",",","2",",","2","]",".","strides","(","Sequence","[","int","]",")",":","The","stride","of","each","patch","embedding",".","Default",":","[","4",",","2",",","2",",","2","]",".","paddings","(","Sequence","[","int","]",")",":","The","padding","of","each","patch","embedding",".","Default",":","[","0",",","0",",","0",",","0","]",".","sr_ratios","(","Sequence","[","int","]",")",":","The","spatial","reduction","rate","of","each","transformer","encode","layer",".","Default",":","[","8",",","4",",","2",",","1","]",".","out_indices","(","Sequence","[","int","]","|","int",")",":","Output","from","which","stages",".","Default",":","(","0",",","1",",","2",",","3",")",".","mlp_ratios","(","Sequence","[","int","]",")",":","The","ratio","of","the","mlp","hidden","dim","to","the","embedding","dim","of","each","transformer","encode","layer",".","Default",":","[","8",",","8",",","4",",","4","]",".","qkv_bias","(","bool",")",":","Enable","bias","for","qkv","if","True",".","Default",":","True",".","drop_rate","(","float",")",":","Probability","of","an","element","to","be","zeroed",".","Default","0.0.","attn_drop_rate","(","float",")",":","The","drop","out","rate","for","attention","layer",".","Default","0.0.","drop_path_rate","(","float",")",":","stochastic","depth","rate",".","Default","0.1.","use_abs_pos_embed","(","bool",")",":","If","True",",","add","absolute","position","embedding","to","the","patch","embedding",".","Defaults",":","True",".","use_conv_ffn","(","bool",")",":","If","True",",","use","Convolutional","FFN","to","replace","FFN",".","Default",":","False",".","act_cfg","(","dict",")",":","The","activation","config","for","FFNs",".","Default",":","dict","(","type='GELU","'",")",".","norm_cfg","(","dict",")",":","Config","dict","for","normalization","layer",".","Default",":","dict","(","type='LN","'",")",".","pretrained","(","str",",","optional",")",":","model","pretrained","path",".","Default",":","None",".","convert_weights","(","bool",")",":","The","flag","indicates","whether","the","pre-trained","model","is","from","the","original","repo",".","We","may","need","to","convert","some","keys","to","make","it","compatible",".","Default",":","True",".","init_cfg","(","dict","or","list","[","dict","]",",","optional",")",":","Initialization","config","dict",".","Default",":","None","."]
code: def init_weights(self):
      logger = MMLogger.get_current_instance()
      if self.init_cfg is None:
          logger.warn(
              f"No pre-trained weights for "
              f"{self.__class__.__name__}, "
              f"training start from scratch"
          )
          for m in self.modules():
              if isinstance(m, nn.Linear):
                  trunc_normal_init(m, std=0.02, bias=0.0)
              elif isinstance(m, nn.LayerNorm):
                  constant_init(m, 1.0)
              elif isinstance(m, nn.Conv2d):
                  fan_out = (
                      m.kernel_size[0]
                      * m.kernel_size[1]
                      * m.out_channels
                  )
                  fan_out //= m.groups
                  normal_init(m, 0, math.sqrt(2.0 / fan_out))
              elif isinstance(m, AbsolutePositionEmbedding):
                  m.init_weights()
      else:
          assert "checkpoint" in self.init_cfg, (
              f"Only support "
              f"specify `Pretrained` in "
              f"`init_cfg` in "
              f"{self.__class__.__name__} "
          )
          checkpoint = CheckpointLoader.load_checkpoint(
              self.init_cfg.checkpoint,
              logger=logger,
              map_location="cpu",
          )
          logger.warn(
              f"Load pre-trained model for "
              f"{self.__class__.__name__} from original repo"
          )
          if "state_dict" in checkpoint:
              state_dict = checkpoint["state_dict"]
          elif "model" in checkpoint:
              state_dict = checkpoint["model"]
          else:
              state_dict = checkpoint
          if self.convert_weights:
              # Because pvt backbones are not supported by mmpretrain,
              # so we need to convert pre-trained weights to match this
              # implementation.
              state_dict = pvt_convert(state_dict)
          load_state_dict(self, state_dict, strict=False, logger=logger)
  
imports: import math
  import warnings
  from collections import OrderedDict
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import Conv2d, build_activation_layer, build_norm_layer
  from mmcv.cnn.bricks.drop import build_dropout
  from mmcv.cnn.bricks.transformer import MultiheadAttention
  from mmengine.logging import MMLogger
  from mmengine.model import BaseModule, ModuleList, Sequential, constant_init, normal_init, trunc_normal_init
  from mmengine.model.weight_init import trunc_normal_
  from mmengine.runner.checkpoint import CheckpointLoader, load_state_dict
  from torch.nn.modules.utils import _pair
  from mmdet.registry import MODELS
  from ..layers import PatchEmbed, nchw_to_nlc, nlc_to_nchw
label_desc: Use image node_id 2 for calling the PyramidVisionTransformer obj's underlying member method code with example usage: obj.init_weights() without return types