# winterblossom0/dl-mini-project architecture

> Architecture diagram of the GitHub repository winterblossom0/dl-mini-project, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/winterblossom0/dl-mini-project
- Repository: https://github.com/winterblossom0/dl-mini-project

## Overview

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`](https://github.com/winterblossom0/dl-mini-project/blob/main/simclr_ecg_classification.ipynb) (Main Notebook), [`ecg_datasets.py`](https://github.com/winterblossom0/dl-mini-project/blob/main/ecg_datasets.py) (ECG Datasets), [`README.md`](https://github.com/winterblossom0/dl-mini-project/blob/main/README.md) (Project Notes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g_input["Data Ingestion"]
  node_n_readme["Project Notes<br/>documentation<br/>[README.md]"]
  node_n_datasets["ECG Datasets<br/>dataset utilities<br/>[ecg_datasets.py]"]
  node_n_mitbih[("MIT-BIH Data<br/>external dataset")]
  node_n_csv_train["Train CSV<br/>data split"]
  node_n_csv_test["Test CSV<br/>data split"]
  node_n_aug["Augmentations<br/>signal augments"]
end

subgraph group_g_model["Representation Model"]
  node_n_encoder["1D ResNet<br/>encoder"]
  node_n_proj["Projection MLP<br/>projection head"]
end

subgraph group_g_ssl["Self-Supervised Flow"]
  node_n_notebook["Main Notebook<br/>orchestration"]
  node_n_pair(("View Pair<br/>contrastive input"))
  node_n_loss(("NT-Xent Loss<br/>contrastive loss"))
  node_n_pretrain["SimCLR Pretrain<br/>training stage"]
  node_n_weights["Pretrained Weights<br/>artifact"]
end

subgraph group_g_eval["Downstream Evaluation"]
  node_n_probe["Linear Probe<br/>evaluation"]
  node_n_finetune["Fine-tuning<br/>evaluation"]
  node_n_supervised["Supervised Baseline<br/>baseline training"]
  node_n_plot["Results Plot<br/>report artifact"]
end

node_n_notebook -->|"uses"| node_n_datasets
node_n_notebook -->|"runs"| node_n_pretrain
node_n_notebook -->|"runs"| node_n_probe
node_n_notebook -->|"runs"| node_n_supervised
node_n_readme -.->|"describes"| node_n_notebook
node_n_mitbih -->|"provides"| node_n_csv_train
node_n_mitbih -->|"provides"| node_n_csv_test
node_n_csv_train -->|"loaded by"| node_n_datasets
node_n_csv_test -->|"loaded by"| node_n_datasets
node_n_datasets -->|"prepares"| node_n_aug
node_n_aug -->|"creates"| node_n_pair
node_n_pair -->|"encoded by"| node_n_encoder
node_n_encoder -->|"feeds"| node_n_proj
node_n_proj -->|"optimized by"| node_n_loss
node_n_loss -->|"drives"| node_n_pretrain
node_n_pretrain -->|"saves"| node_n_weights
node_n_weights -->|"initializes"| node_n_probe
node_n_weights -->|"initializes"| node_n_finetune
node_n_probe -->|"summarizes in"| node_n_plot
node_n_finetune -->|"summarizes in"| node_n_plot
node_n_supervised -->|"compares in"| node_n_plot
node_n_probe -->|"compares against"| node_n_supervised

click node_n_notebook "https://github.com/winterblossom0/dl-mini-project/blob/main/simclr_ecg_classification.ipynb"
click node_n_readme "https://github.com/winterblossom0/dl-mini-project/blob/main/README.md"
click node_n_datasets "https://github.com/winterblossom0/dl-mini-project/blob/main/ecg_datasets.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_n_readme,node_n_datasets,node_n_mitbih,node_n_csv_train,node_n_csv_test,node_n_aug toneBlue
class node_n_encoder,node_n_proj toneAmber
class node_n_notebook,node_n_pair,node_n_loss,node_n_pretrain,node_n_weights toneMint
class node_n_probe,node_n_finetune,node_n_supervised,node_n_plot toneRose
```

## Components

### Data Ingestion

External ECG data boundary and reusable dataset utilities.

- [Project Notes](https://github.com/winterblossom0/dl-mini-project/blob/main/README.md): documentation · High-level experiment description and usage context. · `README.md`
- [ECG Datasets](https://github.com/winterblossom0/dl-mini-project/blob/main/ecg_datasets.py): dataset utilities · Reusable dataset and preprocessing helpers for ECG experiments. · `ecg_datasets.py`
- **MIT-BIH Data**: external dataset · MIT-BIH Arrhythmia Database source boundary for ECG samples.
- **Train CSV**: data split · Training split of the ECG classification data, if loaded from CSV.
- **Test CSV**: data split · Test split of the ECG classification data, if loaded from CSV.
- **Augmentations**: signal augments · Time warping, Gaussian noise, amplitude scaling, and circular shift.

### Representation Model

Shared encoder and SimCLR projection components.

- **1D ResNet**: encoder · Four-stage time-series backbone with 64, 128, 256, and 512 channels.
- **Projection MLP**: projection head · SimCLR head mapping 512 to 256 to 128 for contrastive optimization.

### Self-Supervised Flow

Contrastive pretraining path for ECG representation learning.

- [Main Notebook](https://github.com/winterblossom0/dl-mini-project/blob/main/simclr_ecg_classification.ipynb): orchestration · Notebook-centric entrypoint coordinating the experiment pipeline. · `simclr_ecg_classification.ipynb`
- **View Pair**: contrastive input · Two correlated augmented views of the same ECG sample.
- **NT-Xent Loss**: contrastive loss · InfoNCE-style objective with temperature 0.5.
- **SimCLR Pretrain**: training stage · Self-supervised pretraining loop over paired ECG views.
- **Pretrained Weights**: artifact · Saved checkpoint produced by SimCLR pretraining.

### Downstream Evaluation

Label-efficient and fully supervised comparison paths.

- **Linear Probe**: evaluation · Label-efficient downstream evaluation across label fractions.
- **Fine-tuning**: evaluation · Downstream supervised adaptation of the pretrained encoder.
- **Supervised Baseline**: baseline training · Fully supervised arrhythmia classifier on the same task.
- **Results Plot**: report artifact · Comparison figure summarizing results across label fractions.

## Connections

- 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.
