RandomRenormalize

class torch_ecg.augmenters.RandomRenormalize(mean: Iterable[Real] = [-0.05, 0.1], std: Iterable[Real] = [0.08, 0.32], per_channel: bool = False, prob: float = 0.5, inplace: bool = True, **kwargs: Any)[source]

Bases: Augmenter

Randomly re-normalize the ECG tensor, using the Z-score normalization method.

Parameters:
  • mean (array_like, default [-0.05, 0.1]) – Range of mean value of the re-normalized signal, of shape (2,); or range of mean values for each lead of the re-normalized signal, of shape (lead, 2).

  • std (array_like, default [0.08, 0.32]) – Range of standard deviation of the re-normalized signal, of shape (2,); or range of standard deviations for each lead of the re-normalized signal, of shape (lead, 2).

  • per_channel (bool, default False) – If True, re-normalization will be done per channel.

  • prob (float, default 0.5) – Probability of applying the random re-normalization augmenter.

  • inplace (bool, default True) – Whether to apply the random re-normalization augmenter in-place.

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

Examples

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

Extra keys for __repr__() and __str__().

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

Forward function of the RandomRenormalize augmenter.

Parameters:
  • sig (torch.Tensor) – The input ECG tensor, of shape (batch, lead, siglen).

  • label (torch.Tensor, optional) – The input ECG label tensor. Not used, but kept for compatibility with other augmenters.

  • 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 randomly re-normalized ECG tensor.

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

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