class_docstr: Vision Transformer.
  
  A PyTorch impl of : `An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale`
      - https://arxiv.org/abs/2010.11929
  
  Includes distillation token & head support for `DeiT: Data-efficient Image Transformers`
      - https://arxiv.org/abs/2012.12877
docstr: Args:
      img_size (int, tuple): input image size
      patch_size (int, tuple): patch size
      in_channels (int): number of input channels
      num_classes (int): number of classes for classification head
      embed_dim (int): embedding dimension
      depth (int): depth of transformer
      num_heads (int): number of attention heads
      mlp_ratio (int): ratio of mlp hidden dim to embedding dim
      qkv_bias (bool): enable bias for qkv if True
      drop_rate (float): dropout rate
      attn_drop_rate (float): attention dropout rate
      drop_path_rate (float): stochastic depth rate
      embed_layer (nn.Module): patch embedding layer
      norm_layer: (nn.Module): normalization layer
      pretrained: (str): pretrained path
docstr_tok: ["Args",":","img_size","(","int",",","tuple",")",":","input","image","size","patch_size","(","int",",","tuple",")",":","patch","size","in_channels","(","int",")",":","number","of","input","channels","num_classes","(","int",")",":","number","of","classes","for","classification","head","embed_dim","(","int",")",":","embedding","dimension","depth","(","int",")",":","depth","of","transformer","num_heads","(","int",")",":","number","of","attention","heads","mlp_ratio","(","int",")",":","ratio","of","mlp","hidden","dim","to","embedding","dim","qkv_bias","(","bool",")",":","enable","bias","for","qkv","if","True","drop_rate","(","float",")",":","dropout","rate","attn_drop_rate","(","float",")",":","attention","dropout","rate","drop_path_rate","(","float",")",":","stochastic","depth","rate","embed_layer","(","nn.Module",")",":","patch","embedding","layer","norm_layer",":","(","nn.Module",")",":","normalization","layer","pretrained",":","(","str",")",":","pretrained","path"]
code: def __init__(
      self,
      img_size=224,
      patch_size=16,
      in_channels=3,
      num_classes=1000,
      embed_dim=768,
      depth=12,
      num_heads=12,
      mlp_ratio=4.0,
      qkv_bias=True,
      drop_rate=0.0,
      attn_drop_rate=0.0,
      drop_path_rate=0.0,
      layer_scale=True,
      embed_layer=PatchEmbed,
      norm_layer=partial(nn.LayerNorm, epsilon=1e-6),
      act_layer=nn.GELU,
      pretrained=None,
  ):
      """
      Args:
          img_size (int, tuple): input image size
          patch_size (int, tuple): patch size
          in_channels (int): number of input channels
          num_classes (int): number of classes for classification head
          embed_dim (int): embedding dimension
          depth (int): depth of transformer
          num_heads (int): number of attention heads
          mlp_ratio (int): ratio of mlp hidden dim to embedding dim
          qkv_bias (bool): enable bias for qkv if True
          drop_rate (float): dropout rate
          attn_drop_rate (float): attention dropout rate
          drop_path_rate (float): stochastic depth rate
          embed_layer (nn.Module): patch embedding layer
          norm_layer: (nn.Module): normalization layer
          pretrained: (str): pretrained path
      """
      super().__init__()
      self.num_classes = num_classes
      self.num_features = (
          self.embed_dim
      ) = embed_dim  # num_features for consistency with other models
      self.num_tokens = 1
      norm_layer = norm_layer or partial(nn.LayerNorm, epsilon=1e-6)
      act_layer = act_layer or nn.GELU
      self.norm_layer = norm_layer
      self.act_layer = act_layer
      self.pretrain_size = img_size
      self.drop_path_rate = drop_path_rate
      self.drop_rate = drop_rate
  
      self.patch_embed = embed_layer(
          img_size=img_size,
          patch_size=patch_size,
          in_chans=in_channels,
          embed_dim=embed_dim,
      )
      num_patches = self.patch_embed.num_patches
  
      self.pos_embed = self.create_parameter(
          shape=(1, num_patches + self.num_tokens, embed_dim),
          default_initializer=paddle.nn.initializer.Constant(value=0.0),
      )
      self.pos_drop = nn.Dropout(p=drop_rate)
  
      dpr = np.linspace(
          0, drop_path_rate, depth
      )  # stochastic depth decay rule
      self.blocks = nn.Sequential(
          *[
              Block(
                  dim=embed_dim,
                  num_heads=num_heads,
                  mlp_ratio=mlp_ratio,
                  qkv_bias=qkv_bias,
                  drop=drop_rate,
                  attn_drop=attn_drop_rate,
                  drop_path=dpr[i],
                  norm_layer=norm_layer,
                  act_layer=act_layer,
                  layer_scale=layer_scale,
              )
              for i in range(depth)
          ]
      )
  
      self.pretrained = pretrained
      self.init_weight()
  
imports: import math
  from functools import partial
  import numpy
  import paddle
  import paddle.nn
  import paddle.nn.functional
  from paddleseg.cvlibs import manager
  from paddleseg.utils import utils, logger
  from paddleseg.cvlibs.param_init import normal_init, trunc_normal_init, constant_init
  from paddleseg.models.backbones.transformer_utils import to_2tuple, DropPath
  from paddleseg.models.layers.vit_adapter_layers import SpatialPriorModule, InteractionBlock, deform_inputs
  from paddleseg.models.layers.ms_deformable_attention import MSDeformAttn
label_desc: Use image node_id 1 to create a new VisionTransformer object from inherited base classes: nn with example: obj = VisionTransformer(img_size, patch_size, in_channels, num_classes, embed_dim, depth, num_heads, mlp_ratio, qkv_bias, drop_rate, attn_drop_rate, drop_path_rate, layer_scale, embed_layer, norm_layer, act_layer, pretrained)