class_docstr: Vision Transformer with support for patch or hybrid CNN input stage.
class_docstr_tok: ["Vision","Transformer","with","support","for","patch","or","hybrid","CNN","input","stage","."]
code: def __init__(
      self,
      img_size=1024,
      patch_size=16,
      in_chans=3,
      embed_dim=768,
      depth=12,
      num_heads=12,
      mlp_ratio=4.0,
      qkv_bias=True,
      drop_path_rate=0.0,
      norm_cfg=dict(type="LN", eps=1e-6),
      act_cfg=dict(type="GELU"),
      use_abs_pos=True,
      use_rel_pos=False,
      rel_pos_zero_init=True,
      window_size=0,
      window_block_indexes=(0, 1, 3, 4, 6, 7, 9, 10),
      pretrain_img_size=224,
      pretrain_use_cls_token=True,
      init_cfg=None,
  ):
      super().__init__()
      self.pretrain_use_cls_token = pretrain_use_cls_token
      self.init_cfg = init_cfg
  
      self.patch_embed = PatchEmbed(
          kernel_size=(patch_size, patch_size),
          stride=(patch_size, patch_size),
          in_chans=in_chans,
          embed_dim=embed_dim,
      )
  
      if use_abs_pos:
          num_patches = (pretrain_img_size // patch_size) * (
              pretrain_img_size // patch_size
          )
          num_positions = (
              (num_patches + 1)
              if pretrain_use_cls_token
              else num_patches
          )
          self.pos_embed = nn.Parameter(
              torch.zeros(1, num_positions, embed_dim)
          )
      else:
          self.pos_embed = None
  
      dpr = [x.item() for x in torch.linspace(0, drop_path_rate, depth)]
  
      self.blocks = nn.ModuleList(
          [
              Block(
                  dim=embed_dim,
                  num_heads=num_heads,
                  mlp_ratio=mlp_ratio,
                  qkv_bias=qkv_bias,
                  drop_path=dpr[i],
                  norm_cfg=norm_cfg,
                  act_cfg=act_cfg,
                  use_rel_pos=use_rel_pos,
                  rel_pos_zero_init=rel_pos_zero_init,
                  window_size=window_size
                  if i in window_block_indexes
                  else 0,
                  input_size=(
                      img_size // patch_size,
                      img_size // patch_size,
                  ),
              )
              for i in range(depth)
          ]
      )
  
      if self.pos_embed is not None:
          nn.init.trunc_normal_(self.pos_embed, std=0.02)
  
imports: import math
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import build_activation_layer, build_norm_layer
  from mmcv.cnn.bricks import DropPath
  from mmengine.logging import MMLogger
  from mmengine.model import BaseModule
  from mmengine.runner.checkpoint import CheckpointLoader
  from mmdet.registry import MODELS
label_desc: Use image node_id 1 to create a new ViT object from inherited base classes: BaseModule with example: obj = ViT(img_size, patch_size, in_chans, embed_dim, depth, num_heads, mlp_ratio, qkv_bias, drop_path_rate, norm_cfg, act_cfg, use_abs_pos, use_rel_pos, rel_pos_zero_init, window_size, window_block_indexes, pretrain_img_size, pretrain_use_cls_token, init_cfg)