class_docstr: <a id="PatchEmbeddings"></a>
  
  ## Get patch embeddings
  
  The paper splits the image into patches of equal size and do a linear transformation
  on the flattened pixels for each patch.
  
  We implement the same thing through a convolution layer, because it's simpler to implement.
class_docstr_tok: ["<","a","id=","''","PatchEmbeddings","''",">","<","\/a",">","#","#","Get","patch","embeddings","The","paper","splits","the","image","into","patches","of","equal","size","and","do","a","linear","transformation","on","the","flattened","pixels","for","each","patch",".","We","implement","the","same","thing","through","a","convolution","layer",",","because","it","'s","simpler","to","implement","."]
docstr: * `d_model` is the transformer embeddings size
  * `patch_size` is the size of the patch
  * `in_channels` is the number of channels in the input image (3 for rgb)
docstr_tok: ["*","`","d_model","`","is","the","transformer","embeddings","size","*","`","patch_size","`","is","the","size","of","the","patch","*","`","in_channels","`","is","the","number","of","channels","in","the","input","image","(","3","for","rgb",")"]
code: def __init__(self, d_model: int, patch_size: int, in_channels: int):
      """
      * `d_model` is the transformer embeddings size
      * `patch_size` is the size of the patch
      * `in_channels` is the number of channels in the input image (3 for rgb)
      """
      super().__init__()
  
      # We create a convolution layer with a kernel size and and stride length equal to patch size.
      # This is equivalent to splitting the image into patches and doing a linear
      # transformation on each patch.
      self.conv = nn.Conv2d(
          in_channels, d_model, patch_size, stride=patch_size
      )
  
imports: import torch
  from torch import nn
  from labml_helpers.module import Module
  from labml_nn.transformers import TransformerLayer
  from labml_nn.utils import clone_module_list
label_desc: Use image node_id 1 to create a new PatchEmbeddings object from inherited base classes: Module with example: obj = PatchEmbeddings(d_model, patch_size, in_channels)