spd_learn.modules.PatchEmbeddingLayer#

class spd_learn.modules.PatchEmbeddingLayer(n_chans: int, n_patches: int, stride: int | None = None, device: device | None = None, dtype: dtype | None = None)[source]#

Bases: Module

Patch Embedding Layer.

This layer extracts patches from an input signal using an unfolding operation, which is similar to a convolution.

Parameters:
  • n_chans (int) – Number of input channels.

  • n_patches (int) – Number of patches to extract.

  • stride (int, optional) – The step size between patches. If None, it defaults to the patch size, resulting in non-overlapping patches.

forward(x: Tensor) → Tensor[source]#

Forward pass of the PatchEmbeddingLayer.

Parameters:

x (torch.Tensor) – Input tensor of shape (batch, channels, time).

Returns:

A tensor of patches with shape (batch, n_patches, channels, patch_size).

Return type:

torch.Tensor