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: int,
      patch_size: int,
      num_layers: int,
      num_heads: int,
      hidden_dim: int,
      mlp_dim: int,
      dropout: float = 0.0,
      attention_dropout: float = 0.0,
      num_classes: int = 1000,
      representation_size: Optional[int] = None,
      norm_layer: Callable[..., torch.nn.Module] = partial(
          nn.LayerNorm, eps=1e-6
      ),
      conv_stem_configs: Optional[List[ConvStemConfig]] = None,
  ):
      super().__init__()
      _log_api_usage_once(self)
      torch._assert(
          image_size % patch_size == 0,
          "Input shape indivisible by patch size!",
      )
      self.image_size = image_size
      self.patch_size = patch_size
      self.hidden_dim = hidden_dim
      self.mlp_dim = mlp_dim
      self.attention_dropout = attention_dropout
      self.dropout = dropout
      self.num_classes = num_classes
      self.representation_size = representation_size
      self.norm_layer = norm_layer
  
      if conv_stem_configs is not None:
          # As per https://arxiv.org/abs/2106.14881
          seq_proj = nn.Sequential()
          prev_channels = 3
          for i, conv_stem_layer_config in enumerate(conv_stem_configs):
              seq_proj.add_module(
                  f"conv_bn_relu_{i}",
                  Conv2dNormActivation(
                      in_channels=prev_channels,
                      out_channels=conv_stem_layer_config.out_channels,
                      kernel_size=conv_stem_layer_config.kernel_size,
                      stride=conv_stem_layer_config.stride,
                      norm_layer=conv_stem_layer_config.norm_layer,
                      activation_layer=conv_stem_layer_config.activation_layer,
                  ),
              )
              prev_channels = conv_stem_layer_config.out_channels
          seq_proj.add_module(
              "conv_last",
              nn.Conv2d(
                  in_channels=prev_channels,
                  out_channels=hidden_dim,
                  kernel_size=1,
              ),
          )
          self.conv_proj: nn.Module = seq_proj
      else:
          self.conv_proj = nn.Conv2d(
              in_channels=3,
              out_channels=hidden_dim,
              kernel_size=patch_size,
              stride=patch_size,
          )
  
      seq_length = (image_size // patch_size) ** 2
  
      # 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,
          attention_dropout,
          norm_layer,
      )
      self.seq_length = seq_length
  
      heads_layers: OrderedDict[str, nn.Module] = OrderedDict()
      if representation_size is None:
          heads_layers["head"] = nn.Linear(hidden_dim, num_classes)
      else:
          heads_layers["pre_logits"] = nn.Linear(
              hidden_dim, representation_size
          )
          heads_layers["act"] = nn.Tanh()
          heads_layers["head"] = nn.Linear(
              representation_size, num_classes
          )
  
      self.heads = nn.Sequential(heads_layers)
  
      if isinstance(self.conv_proj, nn.Conv2d):
          # Init the patchify stem
          fan_in = (
              self.conv_proj.in_channels
              * self.conv_proj.kernel_size[0]
              * self.conv_proj.kernel_size[1]
          )
          nn.init.trunc_normal_(
              self.conv_proj.weight, std=math.sqrt(1 / fan_in)
          )
          if self.conv_proj.bias is not None:
              nn.init.zeros_(self.conv_proj.bias)
      elif self.conv_proj.conv_last is not None and isinstance(
          self.conv_proj.conv_last, nn.Conv2d
      ):
          # Init the last 1x1 conv of the conv stem
          nn.init.normal_(
              self.conv_proj.conv_last.weight,
              mean=0.0,
              std=math.sqrt(
                  2.0 / self.conv_proj.conv_last.out_channels
              ),
          )
          if self.conv_proj.conv_last.bias is not None:
              nn.init.zeros_(self.conv_proj.conv_last.bias)
  
      if hasattr(self.heads, "pre_logits") and isinstance(
          self.heads.pre_logits, nn.Linear
      ):
          fan_in = self.heads.pre_logits.in_features
          nn.init.trunc_normal_(
              self.heads.pre_logits.weight, std=math.sqrt(1 / fan_in)
          )
          nn.init.zeros_(self.heads.pre_logits.bias)
  
      if isinstance(self.heads.head, nn.Linear):
          nn.init.zeros_(self.heads.head.weight)
          nn.init.zeros_(self.heads.head.bias)
  
imports: import math
  from collections import OrderedDict
  from functools import partial
  from typing import Any, Callable, Dict, List, NamedTuple, Optional
  import torch
  import torch.nn
  from ..ops.misc import Conv2dNormActivation, MLP
  from ..transforms._presets import ImageClassification, InterpolationMode
  from ..utils import _log_api_usage_once
  from ._api import register_model, Weights, WeightsEnum
  from ._meta import _IMAGENET_CATEGORIES
  from ._utils import _ovewrite_named_param, handle_legacy_interface
label_desc: Use image node_id 1 to create a new VisionTransformer object from inherited base classes: nn with example: obj = VisionTransformer(image_size, patch_size, num_layers, num_heads, hidden_dim, mlp_dim, dropout, attention_dropout, num_classes, representation_size, norm_layer, conv_stem_configs)