Mixup

class torch_ecg.augmenters.Mixup(fs: Optional[int] = None, alpha: numbers.Real = 0.5, beta: Optional[numbers.Real] = None, prob: float = 0.5, inplace: bool = True, **kwargs: Any)[source]

Bases: torch_ecg.augmenters.base.Augmenter

Mixup augmentor.

Mixup is a data augmentation technique originally proposed in 1. The PDF file of the paper can be found on arXiv 2. The official implementation is provided in 3. This technique was designed for image classification tasks, but it is also widely used for ECG tasks.

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

  • alpha (numbers.Real, default 0.5) – alpha parameter of the Beta distribution used in Mixup.

  • beta (numbers.Real, optional) – beta parameter of the Beta distribution used in Mixup, defaults to alpha.

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

  • inplace (bool, default True) – If True, ECG signal tensors will be modified inplace.

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

Examples

mixup = Mixup(alpha=0.3, beta=0.6, prob=0.7)
sig = torch.randn(32, 12, 5000)
label = torch.randint(0, 2, (32, 26), dtype=torch.float32)
sig, label = mixup(sig, label)

References

1

Zhang, Hongyi, et al. “mixup: Beyond Empirical Risk Minimization.” International Conference on Learning Representations. 2018.

2

https://arxiv.org/abs/1710.09412

3

https://github.com/facebookresearch/mixup-cifar10/blob/master/train.py

extra_repr_keys() List[str][source]

Extra keys for __repr__() and __str__().

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

Forward method of the Mixup augmenter.

Parameters
  • sig (torch.Tensor) – Batched ECGs to be augmented, of shape (batch, lead, siglen).

  • label (torch.Tensor) – Label tensor of the ECGs.

  • 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 augmented ECGs.

  • label (torch.Tensor) – The augmented labels.

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