PreprocManager¶
- class torch_ecg.preprocessors.PreprocManager(*pps: Tuple[Module, ...] | None, random: bool = False, inplace: bool = True)[source]¶
-
Manager class for preprocessors.
- Parameters:
pps (Tuple[torch.nn.Module], optional) – The sequence of preprocessors to be added to the manager.
random (bool, default False) – Whether to apply the preprocessors in random order.
inplace (bool, default True) – Whether to apply the preprocessors in-place.
Examples
import torch from torch_ecg.cfg import CFG from torch_ecg.preprocessors import PreprocManager config = CFG( random=False, bandpass={"fs":500}, normalize={"method": "min-max"}, ) ppm = PreprocManager.from_config(config) sig = torch.randn(2, 12, 8000) sig = ppm(sig)
- add_(pp: Module, pos: int = -1) None [source]¶
Add a (custom) preprocessor to the manager.
This method is preferred against directly manipulating the internal list of preprocessors via
PreprocManager.preprocessors.append(pp)
.- Parameters:
pp (torch.nn.Module) – The preprocessor to be added.
pos (int, default -1) – The position to insert the preprocessor. Should be >= -1, with -1 being the indicator of the end.
- forward(sig: Tensor) Tensor [source]¶
Apply the preprocessors to the signal tensor.
- Parameters:
sig (torch.Tensor) – The signal tensor to be preprocessed.
- Returns:
The preprocessed signal tensor.
- Return type:
- classmethod from_config(config: dict) PreprocManager [source]¶
Initialize a
PreprocManager
instance from a configuration.- Parameters:
config (dict) – The configuration of the preprocessors, better to be an
OrderedDict
.- Returns:
ppm – A new instance of
PreprocManager
.- Return type: