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: * `x` is the input image of shape `[batch_size, channels, height, width]`
docstr_tok: ["*","`","x","`","is","the","input","image","of","shape","`","[","batch_size",",","channels",",","height",",","width","]","`"]
code: def forward(self, x: torch.Tensor):
      """
      * `x` is the input image of shape `[batch_size, channels, height, width]`
      """
      # Apply convolution layer
      x = self.conv(x)
      # Get the shape.
      bs, c, h, w = x.shape
      # Rearrange to shape `[patches, batch_size, d_model]`
      x = x.permute(2, 3, 0, 1)
      x = x.view(h * w, bs, c)
  
      # Return the patch embeddings
      return x
  
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 2 for calling the PatchEmbeddings obj's underlying member method code with example usage: obj.forward(x) and returns: x