class_docstr: Add a cls token and apply a spatiotemporal encoding to a tensor.
class_docstr_tok: ["Add","a","cls","token","and","apply","a","spatiotemporal","encoding","to","a","tensor","."]
docstr: Args:
      embed_dim (int): Embedding dimension for input sequence.
      patch_embed_shape (Tuple): The number of patches in each dimension
          (T, H, W) after patch embedding.
      sep_pos_embed (bool): If set to true, one positional encoding is used for
          spatial patches and another positional encoding is used for temporal
          sequence. Otherwise, only one positional encoding is used for all the
          patches.
      has_cls (bool): If set to true, a cls token is added in the beginning of each
          input sequence.
docstr_tok: ["Args",":","embed_dim","(","int",")",":","Embedding","dimension","for","input","sequence",".","patch_embed_shape","(","Tuple",")",":","The","number","of","patches","in","each","dimension","(","T",",","H",",","W",")","after","patch","embedding",".","sep_pos_embed","(","bool",")",":","If","set","to","true",",","one","positional","encoding","is","used","for","spatial","patches","and","another","positional","encoding","is","used","for","temporal","sequence",".","Otherwise",",","only","one","positional","encoding","is","used","for","all","the","patches",".","has_cls","(","bool",")",":","If","set","to","true",",","a","cls","token","is","added","in","the","beginning","of","each","input","sequence","."]
code: def __init__(
      self,
      embed_dim: int,
      patch_embed_shape: Tuple[int, int, int],
      sep_pos_embed: bool = False,
      has_cls: bool = True,
  ) -> None:
      """
      Args:
          embed_dim (int): Embedding dimension for input sequence.
          patch_embed_shape (Tuple): The number of patches in each dimension
              (T, H, W) after patch embedding.
          sep_pos_embed (bool): If set to true, one positional encoding is used for
              spatial patches and another positional encoding is used for temporal
              sequence. Otherwise, only one positional encoding is used for all the
              patches.
          has_cls (bool): If set to true, a cls token is added in the beginning of each
              input sequence.
      """
      super().__init__()
      assert (
          len(patch_embed_shape) == 3
      ), "Patch_embed_shape should be in the form of (T, H, W)."
      self.cls_embed_on = has_cls
      self.sep_pos_embed = sep_pos_embed
      self._patch_embed_shape = tuple(patch_embed_shape)
      self.num_spatial_patch = (
          patch_embed_shape[1] * patch_embed_shape[2]
      )
      self.num_temporal_patch = patch_embed_shape[0]
  
      if self.cls_embed_on:
          self.cls_token = nn.Parameter(torch.zeros(1, 1, embed_dim))
          num_patches = (
              self.num_spatial_patch * self.num_temporal_patch + 1
          )
      else:
          self.cls_token = torch.tensor(0)
          num_patches = self.num_spatial_patch * self.num_temporal_patch
  
      if self.sep_pos_embed:
          self.pos_embed_spatial = nn.Parameter(
              torch.zeros(1, self.num_spatial_patch, embed_dim)
          )
          self.pos_embed_temporal = nn.Parameter(
              torch.zeros(1, self.num_temporal_patch, embed_dim)
          )
          if self.cls_embed_on:
              self.pos_embed_class = nn.Parameter(
                  torch.zeros(1, 1, embed_dim)
              )
          else:
              self.pos_embed_class = torch.tensor(
                  []
              )  # for torchscriptability
          self.pos_embed = torch.tensor([])
  
      else:
          self.pos_embed = nn.Parameter(
              torch.zeros(1, num_patches, embed_dim)
          )
          # Placeholders for torchscriptability, won't be used
          self.pos_embed_spatial = torch.tensor([])
          self.pos_embed_temporal = torch.tensor([])
          self.pos_embed_class = torch.tensor([])
  
file_path: pytorchvideo/pytorchvideo/layers/positional_encoding.py
imports: import math
  from typing import Tuple
  import numpy
  import torch
  from torch import nn
label_desc: Use image node_id 1 to create a new SpatioTemporalClsPositionalEncoding object from inherited base classes: nn with example: obj = SpatioTemporalClsPositionalEncoding(embed_dim, patch_embed_shape, sep_pos_embed, has_cls)