How winterblossom0/dl-mini-project works
1. Repository shape
- This is a small, notebook-driven research repo rather than a packaged application.
- The main execution path lives in simclr_ecg_classification.ipynb, with ecg_datasets.py acting as the only reusable support module.
2. Primary goal
- The project compares self-supervised SimCLR pretraining on ECG signals against a fully supervised baseline for arrhythmia classification.
- The architecture is centered on label-efficient representation learning, not deployment or inference services.
3. Data boundary
- Input data comes from the MIT-BIH Arrhythmia Database, typically downloaded from Kaggle or loaded from CSV files (mitbih_train.csv, mitbih_test.csv).
- This is the external data source boundary: raw ECG samples enter the repo here, and everything else is internal processing.
4. Dataset/pipeline layer
- ecg_datasets.py likely contains the dataset and augmentation utilities used by the notebook.
- Based on the README, this layer handles signal preparation and augmentation for training, keeping data concerns separate from model/training logic.
5. Augmentation subsystem
- SimCLR training depends on ECG-specific augmentations: time warping, Gaussian noise, amplitude scaling, and circular time shift.
- These augmentations are used to create two correlated views of the same ECG sample, which is the core input structure for contrastive learning.
6. Representation model
- The encoder is a 1D ResNet designed for time-series input, with four residual stages using 64, 128, 256, and 512 channels.
- This encoder is the main feature extractor and is the shared backbone for pretraining and downstream classification.
7. Projection head for contrastive learning
- During SimCLR pretraining, the encoder output is passed through a small MLP projection head: 512 → 256 → 128.
- This head is used only for contrastive optimization; the encoder is the part reused for classification evaluation.
8. Self-supervised training flow
- The notebook builds paired augmented views, encodes them, and optimizes NT-Xent / InfoNCE loss with temperature = 0.5.
- Data flow is: raw ECG → augmented pair generation → encoder → projection head → contrastive loss.
9. Downstream evaluation flow
- After pretraining, the encoder is evaluated with linear probe / fine-tuning using label fractions of 1%, 10%, 50%, and 100%.
- This isolates the quality of learned representations and shows how much labeled data is needed to achieve useful performance.
10. Supervised comparison path
- The notebook also trains a fully supervised baseline on the same classification task.
- This provides the reference line for judging whether SimCLR improves label efficiency.
11. Artifacts and outputs
- Pretrained weights are saved as simclr_pretrained.pth.
- The notebook also produces evaluation plots such as results_comparison.png, which summarize performance across label fractions.
12. Runtime and tooling
- The project is Python-based and depends on the packages listed in requirements.txt.
- Execution is notebook-centric via Jupyter, with Kaggle credentials used only for dataset acquisition.
13. Architectural summary
- The repo has one main pipeline: ECG dataset ingestion → augmentation → 1D-ResNet encoder pretraining with contrastive loss → downstream linear probe/supervised evaluation.
- There are no obvious web, API, or service boundaries; the important architecture is the separation between data loading/augmentation, representation learning, and classification evaluation.
Main entry points: simclr_ecg_classification.ipynb Main Notebook · ecg_datasets.py ECG Datasets · README.md Project Notes
Components 17
Data Ingestion
External ECG data boundary and reusable dataset utilities.
- Project Notes · High-level experiment description and usage context.
README.md - ECG Datasets · Reusable dataset and preprocessing helpers for ECG experiments.
ecg_datasets.py - MIT-BIH Data · MIT-BIH Arrhythmia Database source boundary for ECG samples.
- Train CSV · Training split of the ECG classification data, if loaded from CSV.
- Test CSV · Test split of the ECG classification data, if loaded from CSV.
- Augmentations · Time warping, Gaussian noise, amplitude scaling, and circular shift.
Representation Model
Shared encoder and SimCLR projection components.
- 1D ResNet · Four-stage time-series backbone with 64, 128, 256, and 512 channels.
- Projection MLP · SimCLR head mapping 512 to 256 to 128 for contrastive optimization.
Self-Supervised Flow
Contrastive pretraining path for ECG representation learning.
- Main Notebook · Notebook-centric entrypoint coordinating the experiment pipeline.
simclr_ecg_classification.ipynb - View Pair · Two correlated augmented views of the same ECG sample.
- NT-Xent Loss · InfoNCE-style objective with temperature 0.5.
- SimCLR Pretrain · Self-supervised pretraining loop over paired ECG views.
- Pretrained Weights · Saved checkpoint produced by SimCLR pretraining.
Downstream Evaluation
Label-efficient and fully supervised comparison paths.
- Linear Probe · Label-efficient downstream evaluation across label fractions.
- Fine-tuning · Downstream supervised adaptation of the pretrained encoder.
- Supervised Baseline · Fully supervised arrhythmia classifier on the same task.
- Results Plot · Comparison figure summarizing results across label fractions.
Connections 22
- Main Notebook → ECG Datasets: uses · Notebook imports dataset and augmentation helpers.
- Main Notebook → SimCLR Pretrain: runs · Notebook orchestrates SimCLR pretraining.
- Main Notebook → Linear Probe: runs · Notebook evaluates label-efficient representations.
- Main Notebook → Supervised Baseline: runs · Notebook trains the supervised comparison model.
- Project Notes → Main Notebook: describes · README explains the notebook-driven workflow.
- MIT-BIH Data → Train CSV: provides · External MIT-BIH data can be represented as a training split.
- MIT-BIH Data → Test CSV: provides · External MIT-BIH data can be represented as a test split.
- Train CSV → ECG Datasets: loaded by · Training split is consumed by dataset utilities.
- Test CSV → ECG Datasets: loaded by · Test split is consumed by dataset utilities.
- ECG Datasets → Augmentations: prepares · Dataset layer applies ECG-specific augmentations.
- Augmentations → View Pair: creates · Augmentations produce two correlated views per sample.
- View Pair → 1D ResNet: encoded by · Each augmented view is passed through the shared backbone.
- 1D ResNet → Projection MLP: feeds · Encoder embeddings are projected for contrastive learning.
- Projection MLP → NT-Xent Loss: optimized by · Projection outputs are compared with NT-Xent.
- NT-Xent Loss → SimCLR Pretrain: drives · Contrastive loss supervises the pretraining loop.
- SimCLR Pretrain → Pretrained Weights: saves · Pretraining produces reusable encoder weights.
- Pretrained Weights → Linear Probe: initializes · Pretrained weights seed linear probing.
- Pretrained Weights → Fine-tuning: initializes · Pretrained weights seed fine-tuning.
- Linear Probe → Results Plot: summarizes in · Linear-probe results feed the comparison plot.
- Fine-tuning → Results Plot: summarizes in · Fine-tuning results feed the comparison plot.
- Supervised Baseline → Results Plot: compares in · Baseline results are included in the summary plot.
- Linear Probe → Supervised Baseline: compares against · Label-efficient performance is judged relative to the supervised baseline.