class_docstr: Swin Transformer
  A PyTorch implement of : `Swin Transformer:
  Hierarchical Vision Transformer using Shifted Windows`  -
      https://arxiv.org/abs/2103.14030
  
  Inspiration from
  https://github.com/microsoft/Swin-Transformer
  
  Args:
      pretrain_img_size (int | tuple[int]): The size of input image when
          pretrain. Defaults: 224.
      in_channels (int): The num of input channels.
          Defaults: 3.
      embed_dims (int): The feature dimension. Default: 96.
      patch_size (int | tuple[int]): Patch size. Default: 4.
      window_size (int): Window size. Default: 7.
      mlp_ratio (int): Ratio of mlp hidden dim to embedding dim.
          Default: 4.
      depths (tuple[int]): Depths of each Swin Transformer stage.
          Default: (2, 2, 6, 2).
      num_heads (tuple[int]): Parallel attention heads of each Swin
          Transformer stage. Default: (3, 6, 12, 24).
      strides (tuple[int]): The patch merging or patch embedding stride of
          each Swin Transformer stage. (In swin, we set kernel size equal to
          stride.) Default: (4, 2, 2, 2).
      out_indices (tuple[int]): Output from which stages.
          Default: (0, 1, 2, 3).
      qkv_bias (bool, optional): If True, add a learnable bias to query, key,
          value. Default: True
      qk_scale (float | None, optional): Override default qk scale of
          head_dim ** -0.5 if set. Default: None.
      patch_norm (bool): If add a norm layer for patch embed and patch
          merging. Default: True.
      drop_rate (float): Dropout rate. Defaults: 0.
      attn_drop_rate (float): Attention dropout rate. Default: 0.
      drop_path_rate (float): Stochastic depth rate. Defaults: 0.1.
      use_abs_pos_embed (bool): If True, add absolute position embedding to
          the patch embedding. Defaults: False.
      act_cfg (dict): Config dict for activation layer.
          Default: dict(type='GELU').
      norm_cfg (dict): Config dict for normalization layer at
          output of backone. Defaults: dict(type='LN').
      with_cp (bool, optional): Use checkpoint or not. Using checkpoint
          will save some memory while slowing down the training speed.
          Default: False.
      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: False.
      frozen_stages (int): Stages to be frozen (stop grad and set eval mode).
          Default: -1 (-1 means not freezing any parameters).
      init_cfg (dict, optional): The Config for initialization.
          Defaults to None.
class_docstr_tok: ["Swin","Transformer","A","PyTorch","implement","of",":","`","Swin","Transformer",":","Hierarchical","Vision","Transformer","using","Shifted","Windows","`","-","https",":","\/\/arxiv.org\/abs\/2103.14030","Inspiration","from","https",":","\/\/github.com\/microsoft\/Swin-Transformer","Args",":","pretrain_img_size","(","int","|","tuple","[","int","]",")",":","The","size","of","input","image","when","pretrain",".","Defaults",":","224.","in_channels","(","int",")",":","The","num","of","input","channels",".","Defaults",":","3.","embed_dims","(","int",")",":","The","feature","dimension",".","Default",":","96.","patch_size","(","int","|","tuple","[","int","]",")",":","Patch","size",".","Default",":","4.","window_size","(","int",")",":","Window","size",".","Default",":","7.","mlp_ratio","(","int",")",":","Ratio","of","mlp","hidden","dim","to","embedding","dim",".","Default",":","4.","depths","(","tuple","[","int","]",")",":","Depths","of","each","Swin","Transformer","stage",".","Default",":","(","2",",","2",",","6",",","2",")",".","num_heads","(","tuple","[","int","]",")",":","Parallel","attention","heads","of","each","Swin","Transformer","stage",".","Default",":","(","3",",","6",",","12",",","24",")",".","strides","(","tuple","[","int","]",")",":","The","patch","merging","or","patch","embedding","stride","of","each","Swin","Transformer","stage",".","(","In","swin",",","we","set","kernel","size","equal","to","stride",".",")","Default",":","(","4",",","2",",","2",",","2",")",".","out_indices","(","tuple","[","int","]",")",":","Output","from","which","stages",".","Default",":","(","0",",","1",",","2",",","3",")",".","qkv_bias","(","bool",",","optional",")",":","If","True",",","add","a","learnable","bias","to","query",",","key",",","value",".","Default",":","True","qk_scale","(","float","|","None",",","optional",")",":","Override","default","qk","scale","of","head_dim","*","*","-0.5","if","set",".","Default",":","None",".","patch_norm","(","bool",")",":","If","add","a","norm","layer","for","patch","embed","and","patch","merging",".","Default",":","True",".","drop_rate","(","float",")",":","Dropout","rate",".","Defaults",":","0.","attn_drop_rate","(","float",")",":","Attention","dropout","rate",".","Default",":","0.","drop_path_rate","(","float",")",":","Stochastic","depth","rate",".","Defaults",":","0.1.","use_abs_pos_embed","(","bool",")",":","If","True",",","add","absolute","position","embedding","to","the","patch","embedding",".","Defaults",":","False",".","act_cfg","(","dict",")",":","Config","dict","for","activation","layer",".","Default",":","dict","(","type='GELU","'",")",".","norm_cfg","(","dict",")",":","Config","dict","for","normalization","layer","at","output","of","backone",".","Defaults",":","dict","(","type='LN","'",")",".","with_cp","(","bool",",","optional",")",":","Use","checkpoint","or","not",".","Using","checkpoint","will","save","some","memory","while","slowing","down","the","training","speed",".","Default",":","False",".","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",":","False",".","frozen_stages","(","int",")",":","Stages","to","be","frozen","(","stop","grad","and","set","eval","mode",")",".","Default",":","-1","(","-1","means","not","freezing","any","parameters",")",".","init_cfg","(","dict",",","optional",")",":","The","Config","for","initialization",".","Defaults","to","None","."]
code: def _freeze_stages(self):
      if self.frozen_stages >= 0:
          self.patch_embed.eval()
          for param in self.patch_embed.parameters():
              param.requires_grad = False
          if self.use_abs_pos_embed:
              self.absolute_pos_embed.requires_grad = False
          self.drop_after_pos.eval()
  
      for i in range(1, self.frozen_stages + 1):
          if (i - 1) in self.out_indices:
              norm_layer = getattr(self, f"norm{i-1}")
              norm_layer.eval()
              for param in norm_layer.parameters():
                  param.requires_grad = False
  
          m = self.stages[i - 1]
          m.eval()
          for param in m.parameters():
              param.requires_grad = False
  
imports: import warnings
  from collections import OrderedDict
  from copy import deepcopy
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.utils.checkpoint
  from mmcv.cnn import build_norm_layer
  from mmcv.cnn.bricks.transformer import FFN, build_dropout
  from mmengine.logging import MMLogger
  from mmengine.model import BaseModule, ModuleList
  from mmengine.model.weight_init import constant_init, trunc_normal_, trunc_normal_init
  from mmengine.runner.checkpoint import CheckpointLoader
  from mmengine.utils import to_2tuple
  from mmdet.registry import MODELS
  from ..layers import PatchEmbed, PatchMerging
label_desc: Use image node_id 3 for calling the SwinTransformer obj's underlying member method code with example usage: obj._freeze_stages() without return types