class_docstr: Patch Merging Layer
  Args:
      dim (int): Number of input channels.
      norm_layer (nn.Module, optional): Normalization layer.  Default: nn.LayerNorm
class_docstr_tok: ["Patch","Merging","Layer","Args",":","dim","(","int",")",":","Number","of","input","channels",".","norm_layer","(","nn.Module",",","optional",")",":","Normalization","layer",".","Default",":","nn.LayerNorm"]
docstr: Forward function.
  Args:
      x: Input feature, tensor size (B, D, H, W, C).
docstr_tok: ["Forward","function",".","Args",":","x",":","Input","feature",",","tensor","size","(","B",",","D",",","H",",","W",",","C",")","."]
code: def forward(self, x):
      """Forward function.
      Args:
          x: Input feature, tensor size (B, D, H, W, C).
      """
      _, _, h, w, _ = x.shape
  
      # padding
      pad_input = (h % 2 == 1) or (w % 2 == 1)
      if pad_input:
          x = F.pad(x, (0, 0, 0, w % 2, 0, h % 2))
  
      x0 = x[:, :, 0::2, 0::2, :]  # B D H/2 W/2 C
      x1 = x[:, :, 1::2, 0::2, :]  # B D H/2 W/2 C
      x2 = x[:, :, 0::2, 1::2, :]  # B D H/2 W/2 C
      x3 = x[:, :, 1::2, 1::2, :]  # B D H/2 W/2 C
      x = torch.cat([x0, x1, x2, x3], -1)  # B D H/2 W/2 4*C
  
      x = self.norm(x)
      x = self.reduction(x)
  
      return x
  
file_path: towhee/towhee/models/layers/patch_merging3d.py
imports: import torch
  from torch import nn
  import torch.nn.functional
label_desc: Use image node_id 2 for calling the PatchMerging obj's underlying member method code with example usage: obj.forward(x) and returns: x