class_docstr: This class turns `pixel_values` of shape `(batch_size, num_channels, height, width)` into the initial
  `hidden_states` (patch embeddings) to be consumed by a Transformer.
class_docstr_tok: ["This","class","turns","`","pixel_values","`","of","shape","`","(","batch_size",",","num_channels",",","height",",","width",")","`","into","the","initial","`","hidden_states","`","(","patch","embeddings",")","to","be","consumed","by","a","Transformer","."]
code: def __init__(self, config):
      super().__init__()
      image_size, patch_size = (
          config.pretrain_image_size,
          config.patch_size,
      )
      num_channels, hidden_size = (
          config.num_channels,
          config.hidden_size,
      )
  
      image_size = (
          image_size
          if isinstance(image_size, collections.abc.Iterable)
          else (image_size, image_size)
      )
      patch_size = (
          patch_size
          if isinstance(patch_size, collections.abc.Iterable)
          else (patch_size, patch_size)
      )
      num_patches = (image_size[1] // patch_size[1]) * (
          image_size[0] // patch_size[0]
      )
      self.image_size = image_size
      self.patch_size = patch_size
      self.num_channels = num_channels
      self.num_patches = num_patches
  
      if config.use_absolute_position_embeddings:
          # Initialize absolute positional embedding with pretrain image size.
          num_positions = num_patches + 1
          self.position_embeddings = nn.Parameter(
              torch.zeros(1, num_positions, config.hidden_size)
          )
      else:
          self.position_embeddings = None
  
      self.projection = nn.Conv2d(
          num_channels,
          hidden_size,
          kernel_size=patch_size,
          stride=patch_size,
      )
  
imports: import collections.abc
  import math
  from typing import Dict, List, Optional, Tuple, Union
  import torch
  import torch.utils.checkpoint
  from torch import nn
  from ...activations import ACT2FN
  from ...modeling_outputs import BackboneOutput, BaseModelOutput
  from ...modeling_utils import PreTrainedModel
  from ...utils import add_start_docstrings, add_start_docstrings_to_model_forward, logging, replace_return_docstrings
  from ...utils.backbone_utils import BackboneMixin
  from .configuration_vitdet import VitDetConfig
label_desc: Use image node_id 1 to create a new VitDetEmbeddings object from inherited base classes: nn with example: obj = VitDetEmbeddings(config)