WaveformInput¶
- class torch_ecg.components.WaveformInput(config: InputConfig)[source]¶
Bases:
BaseInput
Waveform input.
Examples
>>> from torch_ecg.cfg import DEFAULTS >>> BATCH_SIZE = 32 >>> N_CHANNELS = 12 >>> N_SAMPLES = 5000 >>> input_config = InputConfig( ... input_type="waveform", ... n_channels=N_CHANNELS, ... n_samples=N_SAMPLES, ... ) >>> inputer = WaveformInput(input_config) >>> waveform = torch.randn(BATCH_SIZE, N_CHANNELS, N_SAMPLES) >>> inputer(waveform).shape torch.Size([32, 12, 5000]) >>> waveform = DEFAULTS.RNG.uniform(size=(N_CHANNELS, N_SAMPLES)) >>> inputer(waveform).shape torch.Size([1, 12, 5000]) >>> input_config = InputConfig( ... input_type="waveform", ... n_channels=N_CHANNELS, ... n_samples=N_SAMPLES, ... ensure_batch_dim=False, ... ) >>> inputer = WaveformInput(input_config) >>> waveform = DEFAULTS.RNG.uniform(size=(N_CHANNELS, N_SAMPLES)) >>> inputer(waveform).shape torch.Size([12, 5000])
- from_waveform(waveform: ndarray | Tensor) Tensor [source]¶
Converts the input
ndarray
orTensor
waveform to aTensor
.- Parameters:
waveform (numpy.ndarray or torch.Tensor) – The waveform to be transformed, of shape
(batch_size, n_channels, n_samples)
or(n_channels, n_samples)
.- Returns:
The transformed waveform, of shape
(batch_size, n_channels, n_samples)
.- Return type:
Note
If the input is a 2D tensor, then the batch dimension is added (batch_size = 1).