RandomFlip

class torch_ecg.augmenters.RandomFlip(fs: Optional[int] = None, per_channel: bool = True, prob: Union[Sequence[float], float] = [0.4, 0.2], inplace: bool = True, **kwargs: Any)[source]

Bases: torch_ecg.augmenters.base.Augmenter

Randomly flip the ECGs along the voltage axis.

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

  • per_channel (bool, default True) – Whether to flip each channel independently.

  • prob (float or Sequence[float], default [0.4, 0.2]) – Probability of performing flip, the first probality is for the batch dimension, the second probability is for the lead dimension.

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

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

Examples

rf = RandomFlip()
sig = torch.randn(32, 12, 5000)
sig, _ = rf(sig, None)
extra_repr_keys() List[str][source]

Extra keys for __repr__() and __str__().

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

Forward function of the RandomFlip augmenter.

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

  • label (torch.Tensor, optional) – Label tensor of the ECGs. Not used, but kept for consistency with other augmenters.

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

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

Returns

  • sig (torch.Tensor) – The augmented ECGs.

  • label (torch.Tensor) – The label tensor of the augmented ECGs, unchanged.

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