class_docstr: Compute 2D patch embeddings with cls token and positional encoding
class_docstr_tok: ["Compute","2D","patch","embeddings","with","cls","token","and","positional","encoding"]
code: def __init__(
      self,
      input_shape: Tuple[int, int, int],
      embed_dim: int,
      patch_size: Tuple[int, int],
  ) -> None:
      super().__init__()
      height, width, _ = input_shape
      self.patch_size = patch_size
      self.interpolate = (
          True if patch_size[0] == patch_size[1] else False
      )
      self.grid_size = tuple(
          [s // p for s, p in zip((height, width), self.patch_size)]
      )
      self.num_patches = self.grid_size[0] * self.grid_size[1]
  
      self.cls_token = self.add_weight(
          shape=(1, 1, embed_dim),
          initializer="zeros",
          trainable=True,
          name="cls_token",
      )
      self.positions = self.add_weight(
          shape=(1, self.num_patches + 1, embed_dim),
          initializer="zeros",
          trainable=True,
          name="positions",
      )
      self.projection = layers.Conv2D(
          filters=embed_dim,
          kernel_size=self.patch_size,
          strides=self.patch_size,
          padding="valid",
          data_format="channels_last",
          use_bias=True,
          kernel_initializer="glorot_uniform",
          bias_initializer="zeros",
          name="projection",
      )
  
file_path: doctr/doctr/models/modules/vision_transformer/tensorflow.py
imports: import math
  from typing import Any, Tuple
  import tensorflow
  from tensorflow.keras import layers
  from doctr.utils.repr import NestedObject
label_desc: Use image node_id 1 to create a new PatchEmbedding object from inherited base classes: layers, NestedObject with example: obj = PatchEmbedding(input_shape, embed_dim, patch_size)