code: def __init__(
      self,
      *,
      image_size,
      num_classes,
      dim,
      depth=None,
      heads=None,
      mlp_dim=None,
      pool="cls",
      channels=3,
      dim_head=64,
      dropout=0.0,
      emb_dropout=0.0,
      transformer=None,
      t2t_layers=((7, 4), (3, 2), (3, 2)),
  ):
      super().__init__()
      assert pool in {
          "cls",
          "mean",
      }, "pool type must be either cls (cls token) or mean (mean pooling)"
  
      layers = []
      layer_dim = channels
      output_image_size = image_size
  
      for i, (kernel_size, stride) in enumerate(t2t_layers):
          layer_dim *= kernel_size**2
          is_first = i == 0
          is_last = i == (len(t2t_layers) - 1)
          output_image_size = conv_output_size(
              output_image_size, kernel_size, stride, stride // 2
          )
  
          layers.extend(
              [
                  RearrangeImage() if not is_first else nn.Identity(),
                  nn.Unfold(
                      kernel_size=kernel_size,
                      stride=stride,
                      padding=stride // 2,
                  ),
                  Rearrange("b c n -> b n c"),
                  Transformer(
                      dim=layer_dim,
                      heads=1,
                      depth=1,
                      dim_head=layer_dim,
                      mlp_dim=layer_dim,
                      dropout=dropout,
                  )
                  if not is_last
                  else nn.Identity(),
              ]
          )
  
      layers.append(nn.Linear(layer_dim, dim))
      self.to_patch_embedding = nn.Sequential(*layers)
  
      self.pos_embedding = nn.Parameter(
          torch.randn(1, output_image_size**2 + 1, dim)
      )
      self.cls_token = nn.Parameter(torch.randn(1, 1, dim))
      self.dropout = nn.Dropout(emb_dropout)
  
      if not exists(transformer):
          assert all(
              [exists(depth), exists(heads), exists(mlp_dim)]
          ), "depth, heads, and mlp_dim must be supplied"
          self.transformer = Transformer(
              dim, depth, heads, dim_head, mlp_dim, dropout
          )
      else:
          self.transformer = transformer
  
      self.pool = pool
      self.to_latent = nn.Identity()
  
      self.mlp_head = nn.Sequential(
          nn.LayerNorm(dim), nn.Linear(dim, num_classes)
      )
  
file_path: vit-pytorch/vit_pytorch/t2t.py
imports: import math
  import torch
  from torch import nn
  from vit_pytorch.vit import Transformer
  from einops import rearrange, repeat
  from einops.layers.torch import Rearrange
label_desc: Use image node_id 1 to create a new T2TViT object from inherited base classes: nn with example: obj = T2TViT()