Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Tumo505/SSL-for-ECG-classification/llms.txt
Use this file to discover all available pages before exploring further.
ContrastiveAugmentationPipeline is a lightweight wrapper around ECGAugmentations that provides a clean, named entry-point for contrastive self-supervised learning pipelines. It accepts the same constructor arguments and produces the same (view1, view2) output, but signals intent clearly in training code — making it the preferred class to reference in dataset classes and training loops.
Class Overview
ContrastiveAugmentationPipeline.__init__ instantiates an ECGAugmentations object and delegates every __call__ invocation directly to it. There is no additional logic, state, or configuration beyond what ECGAugmentations already provides.
Constructor
Number of time-steps in the ECG signal. Should match the temporal dimension of your dataset tensors. PTB-XL at 500 Hz for 10 seconds gives
5000.Sampling rate in Hz. Passed directly to the underlying
ECGAugmentations instance and used by frequency-domain transforms. Use 100 for the low-resolution PTB-XL variant.Probability that the strong augmentation block fires on any given call. Forwarded unchanged to
ECGAugmentations. Higher values increase view diversity and are recommended for full pretraining runs.__call__
ECGAugmentations.__call__ and returns two independently augmented views of the input signal.
Input ECG signal tensor. Accepts both:
[channels, time]— single sample, as returned by a dataset__getitem__[batch, channels, time]— collated mini-batch
First augmented view. Shape matches the input exactly. Values clamped to
[-10, 10].Second augmented view, produced by an independent stochastic pass through the augmentation pipeline.
All augmentation behaviour — including individual method probabilities, the weak/strong split, and output clamping — is governed entirely by the underlying
ECGAugmentations instance. See the ECGAugmentations reference for a full breakdown of every transform, its application probability, and what cardiac artefact it simulates.DataLoader Integration
The most common use ofContrastiveAugmentationPipeline is inside a PyTorch Dataset.__getitem__, where a single ECG sample is augmented on the fly during data loading. The two views are then stacked and passed to the contrastive loss function.
Instantiate the pipeline once
Create the pipeline at dataset construction time and store it as an instance attribute. This avoids re-allocating the underlying
ECGAugmentations object on every worker iteration.Generate view pairs in __getitem__
Call the pipeline on a single
[channels, time] tensor inside __getitem__. Both views are returned as a tuple and can be stacked for the contrastive loss.Minimal Usage Example
Relationship to ECGAugmentations
ECGAugmentations
The full augmentation engine. Use directly when you need access to internal augmentation methods, want to subclass and override individual transforms, or are building a custom multi-view pipeline beyond the standard two-view setup.
ContrastiveAugmentationPipeline
The recommended entry-point for standard SimCLR / BYOL / MoCo-style pretraining. Identical behaviour to
ECGAugmentations.__call__, but clearly communicates intent in training code and dataset classes.