PreprocManager¶
- class torch_ecg.preprocessors.PreprocManager(*pps: Optional[Tuple[torch.nn.modules.module.Module, ...]], random: bool = False, inplace: bool = True)[source]¶
Bases:
torch_ecg.utils.misc.ReprMixin
,torch.nn.modules.module.Module
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: torch.nn.modules.module.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: torch.Tensor) torch.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) torch_ecg.preprocessors.preproc_manager.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