class_docstr: Vision Transformer as per https://arxiv.org/abs/2010.11929.
class_docstr_tok: ["Vision","Transformer","as","per","https",":","\/\/arxiv.org\/abs\/2010.11929","."]
code: def __init__(
      self,
      image_size,
      patch_size,
      num_layers,
      num_heads,
      hidden_dim,
      mlp_dim,
      dropout_rate=0,
      attention_dropout_rate=0,
      classifier="token",
      conv_stem_layers: Union[
          List[ConvStemLayer], List[Dict], None
      ] = None,
  ):
      super().__init__()
      assert (
          image_size % patch_size == 0
      ), "Input shape indivisible by patch size"
      assert classifier in [
          "token",
          "gap",
      ], "Unexpected classifier mode"
      self.image_size = image_size
      self.patch_size = patch_size
      self.hidden_dim = hidden_dim
      self.mlp_dim = mlp_dim
      self.attention_dropout_rate = attention_dropout_rate
      self.dropout_rate = dropout_rate
      self.classifier = classifier
  
      input_channels = 3
  
      self.conv_stem_layers = conv_stem_layers
      if conv_stem_layers is None:
          # conv_proj is a more efficient version of reshaping, permuting and projecting
          # the input
          self.conv_proj = nn.Conv2d(
              input_channels,
              hidden_dim,
              kernel_size=patch_size,
              stride=patch_size,
          )
      else:
          prev_channels = input_channels
          self.conv_proj = nn.Sequential()
          for i, conv_stem_layer in enumerate(conv_stem_layers):
              if isinstance(conv_stem_layer, Mapping):
                  conv_stem_layer = ConvStemLayer(**conv_stem_layer)
              kernel = conv_stem_layer.kernel
              stride = conv_stem_layer.stride
              out_channels = conv_stem_layer.out_channels
              padding = get_same_padding_for_kernel_size(kernel)
              self.conv_proj.add_module(
                  f"conv_{i}",
                  nn.Conv2d(
                      prev_channels,
                      out_channels,
                      kernel_size=kernel,
                      stride=stride,
                      padding=padding,
                      bias=False,
                  ),
              )
              self.conv_proj.add_module(
                  f"bn_{i}", nn.BatchNorm2d(out_channels)
              )
              self.conv_proj.add_module(f"relu_{i}", nn.ReLU())
              prev_channels = out_channels
          self.conv_proj.add_module(
              f"conv_{i + 1}",
              nn.Conv2d(prev_channels, hidden_dim, kernel_size=1),
          )
  
      seq_length = (image_size // patch_size) ** 2
      if self.classifier == "token":
          # add a class token
          self.class_token = nn.Parameter(torch.zeros(1, 1, hidden_dim))
          seq_length += 1
  
      self.encoder = Encoder(
          seq_length,
          num_layers,
          num_heads,
          hidden_dim,
          mlp_dim,
          dropout_rate,
          attention_dropout_rate,
      )
      self.trunk_output = nn.Identity()
  
      self.seq_length = seq_length
      self.init_weights()
  
imports: import copy
  import logging
  import math
  from collections import OrderedDict
  from functools import partial
  from typing import Dict, List, Mapping, NamedTuple, Union
  import torch
  import torch.nn
  from classy_vision.models import ClassyModel, register_model
  from .lecun_normal_init import lecun_normal_init
label_desc: Use image node_id 1 to create a new VisionTransformer object from inherited base classes: ClassyModel with example: obj = VisionTransformer(image_size, patch_size, num_layers, num_heads, hidden_dim, mlp_dim, dropout_rate, attention_dropout_rate, classifier, conv_stem_layers)