class_docstr: This class turns `pixel_values` of shape `(batch_size, num_channels, height, width)` into the initial
  `hidden_states` (patch embeddings) of shape `(batch_size, seq_length, hidden_size)` 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",")","of","shape","`","(","batch_size",",","seq_length",",","hidden_size",")","`","to","be","consumed","by","a","Transformer","."]
code: def __init__(
      self,
      config: PvtConfig,
      image_size: Union[int, Iterable[int]],
      patch_size: Union[int, Iterable[int]],
      stride: int,
      num_channels: int,
      hidden_size: int,
      cls_token: bool = False,
  ):
      super().__init__()
      self.config = config
      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
  
      self.position_embeddings = nn.Parameter(
          torch.randn(
              1,
              num_patches + 1 if cls_token else num_patches,
              hidden_size,
          )
      )
      self.cls_token = (
          nn.Parameter(torch.zeros(1, 1, hidden_size))
          if cls_token
          else None
      )
      self.projection = nn.Conv2d(
          num_channels,
          hidden_size,
          kernel_size=stride,
          stride=patch_size,
      )
      self.layer_norm = nn.LayerNorm(
          hidden_size, eps=config.layer_norm_eps
      )
      self.dropout = nn.Dropout(p=config.hidden_dropout_prob)
  
imports: import collections
  import math
  from typing import Iterable, Optional, Tuple, Union
  import torch
  import torch.nn.functional
  import torch.utils.checkpoint
  from torch import nn
  from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
  from ...activations import ACT2FN
  from ...modeling_outputs import BaseModelOutput, ImageClassifierOutput
  from ...modeling_utils import PreTrainedModel
  from ...pytorch_utils import find_pruneable_heads_and_indices, prune_linear_layer
  from ...utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward, logging
  from .configuration_pvt import PvtConfig
label_desc: Use image node_id 1 to create a new PvtPatchEmbeddings object from inherited base classes: nn with example: obj = PvtPatchEmbeddings(config, image_size, patch_size, stride, num_channels, hidden_size, cls_token)