class_docstr: Image to Patch Embedding.
  
  We use a conv layer to implement PatchEmbed.
  
  Args:
      in_channels (int): The num of input channels. Default: 3
      embed_dims (int): The dimensions of embedding. Default: 768
      conv_type (str): The config dict for embedding
          conv layer type selection. Default: "Conv2d.
      kernel_size (int): The kernel_size of embedding conv. Default: 16.
      stride (int): The slide stride of embedding conv.
          Default: None (Would be set as `kernel_size`).
      padding (int | tuple | string ): The padding length of
          embedding conv. When it is a string, it means the mode
          of adaptive padding, support "same" and "corner" now.
          Default: "corner".
      dilation (int): The dilation rate of embedding conv. Default: 1.
      bias (bool): Bias of embed conv. Default: True.
      norm_cfg (dict, optional): Config dict for normalization layer.
          Default: None.
      input_size (int | tuple | None): The size of input, which will be
          used to calculate the out size. Only work when `dynamic_size`
          is False. Default: None.
      init_cfg (`mmengine.ConfigDict`, optional): The Config for
          initialization. Default: None.
class_docstr_tok: ["Image","to","Patch","Embedding",".","We","use","a","conv","layer","to","implement","PatchEmbed",".","Args",":","in_channels","(","int",")",":","The","num","of","input","channels",".","Default",":","3","embed_dims","(","int",")",":","The","dimensions","of","embedding",".","Default",":","768","conv_type","(","str",")",":","The","config","dict","for","embedding","conv","layer","type","selection",".","Default",":","``","Conv2d",".","kernel_size","(","int",")",":","The","kernel_size","of","embedding","conv",".","Default",":","16.","stride","(","int",")",":","The","slide","stride","of","embedding","conv",".","Default",":","None","(","Would","be","set","as","`","kernel_size","`",")",".","padding","(","int","|","tuple","|","string",")",":","The","padding","length","of","embedding","conv",".","When","it","is","a","string",",","it","means","the","mode","of","adaptive","padding",",","support","``","same","''","and","``","corner","''","now",".","Default",":","``","corner","''",".","dilation","(","int",")",":","The","dilation","rate","of","embedding","conv",".","Default",":","1.","bias","(","bool",")",":","Bias","of","embed","conv",".","Default",":","True",".","norm_cfg","(","dict",",","optional",")",":","Config","dict","for","normalization","layer",".","Default",":","None",".","input_size","(","int","|","tuple","|","None",")",":","The","size","of","input",",","which","will","be","used","to","calculate","the","out","size",".","Only","work","when","`","dynamic_size","`","is","False",".","Default",":","None",".","init_cfg","(","`","mmengine.ConfigDict","`",",","optional",")",":","The","Config","for","initialization",".","Default",":","None","."]
code: def __init__(
      self,
      in_channels: int = 3,
      embed_dims: int = 768,
      conv_type: str = "Conv2d",
      kernel_size: int = 16,
      stride: int = 16,
      padding: Union[int, tuple, str] = "corner",
      dilation: int = 1,
      bias: bool = True,
      norm_cfg: OptConfigType = None,
      input_size: Union[int, tuple] = None,
      init_cfg: OptConfigType = None,
  ) -> None:
      super(PatchEmbed, self).__init__(init_cfg=init_cfg)
  
      self.embed_dims = embed_dims
      if stride is None:
          stride = kernel_size
  
      kernel_size = to_2tuple(kernel_size)
      stride = to_2tuple(stride)
      dilation = to_2tuple(dilation)
  
      if isinstance(padding, str):
          self.adap_padding = AdaptivePadding(
              kernel_size=kernel_size,
              stride=stride,
              dilation=dilation,
              padding=padding,
          )
          # disable the padding of conv
          padding = 0
      else:
          self.adap_padding = None
      padding = to_2tuple(padding)
  
      self.projection = build_conv_layer(
          dict(type=conv_type),
          in_channels=in_channels,
          out_channels=embed_dims,
          kernel_size=kernel_size,
          stride=stride,
          padding=padding,
          dilation=dilation,
          bias=bias,
      )
  
      if norm_cfg is not None:
          self.norm = build_norm_layer(norm_cfg, embed_dims)[1]
      else:
          self.norm = None
  
      if input_size:
          input_size = to_2tuple(input_size)
          # `init_out_size` would be used outside to
          # calculate the num_patches
          # when `use_abs_pos_embed` outside
          self.init_input_size = input_size
          if self.adap_padding:
              pad_h, pad_w = self.adap_padding.get_pad_shape(input_size)
              input_h, input_w = input_size
              input_h = input_h + pad_h
              input_w = input_w + pad_w
              input_size = (input_h, input_w)
  
          # https://pytorch.org/docs/stable/generated/torch.nn.Conv2d.html
          h_out = (
              input_size[0]
              + 2 * padding[0]
              - dilation[0] * (kernel_size[0] - 1)
              - 1
          ) // stride[0] + 1
          w_out = (
              input_size[1]
              + 2 * padding[1]
              - dilation[1] * (kernel_size[1] - 1)
              - 1
          ) // stride[1] + 1
          self.init_out_size = (h_out, w_out)
      else:
          self.init_input_size = None
          self.init_out_size = None
  
imports: import math
  import warnings
  from typing import Optional, Sequence, Tuple, Union
  import torch
  import torch.nn.functional
  from mmcv.cnn import Linear, build_activation_layer, build_conv_layer, build_norm_layer
  from mmcv.cnn.bricks.drop import Dropout
  from mmengine.model import BaseModule, ModuleList
  from mmengine.utils import to_2tuple
  from torch import Tensor, nn
  from mmdet.registry import MODELS
  from mmdet.utils import OptConfigType, OptMultiConfig
label_desc: Use image node_id 1 to create a new PatchEmbed object from inherited base classes: BaseModule with example: obj = PatchEmbed(in_channels, embed_dims, conv_type, kernel_size, stride, padding, dilation, bias, norm_cfg, input_size, init_cfg)