LabelSmooth

class torch_ecg.augmenters.LabelSmooth(fs: int | None = None, smoothing: float = 0.1, prob: float = 0.5, inplace: bool = True, **kwargs: Any)[source]

Bases: Augmenter

Label smoothing augmentation.

Parameters:
  • fs (int, optional) – Sampling frequency of the ECGs to be augmented.

  • smoothing (float, default 0.1) – The smoothing factor.

  • prob (float, default 0.5) – Probability of applying label smoothing.

  • inplace (bool, default True) – If True, the input tensor will be modified inplace.

  • **kwargs (dict, optional) – Additional keyword arguments.

Examples

ls = LabelSmooth()
label = torch.randint(0, 2, (32, 26), dtype=torch.float32)
_, label = ls(None, label)
extra_repr_keys() List[str][source]

Extra keys for __repr__() and __str__().

forward(sig: Tensor | None, label: Tensor, *extra_tensors: Sequence[Tensor], **kwargs: Any) Tuple[Tensor, ...][source]

Forward method to perform label smoothing.

Parameters:
  • sig (torch.Tensor) – Batched ECGs to be augmented, of shape (batch, lead, siglen). Not used, but kept for compatibility with other augmenters.

  • label (torch.Tensor) – The input label tensor, of shape (batch_size, n_classes) or (batch_size, seq_len, n_classes).

  • extra_tensors (Sequence[torch.Tensor], optional) – Not used, but kept for consistency with other augmenters.

  • **kwargs (dict, optional) – Not used, but kept for consistency with other augmenters.

Returns:

  • sig (torch.Tensor) – The input ECG tensor, unchanged.

  • label (torch.Tensor) – The output label tensor of shape (batch_size, n_classes) or (batch_size, seq_len, n_classes).

  • extra_tensors (Sequence[torch.Tensor], optional) – Unchanged extra tensors.