# shayliu/cmr-ai-segmentation-workbench architecture

> Architecture diagram of the GitHub repository shayliu/cmr-ai-segmentation-workbench, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shayliu/cmr-ai-segmentation-workbench
- Repository: https://github.com/shayliu/cmr-ai-segmentation-workbench

## Overview

CMR AI Segmentation Workbench is a reproducible cardiac-MRI segmentation workflow, centered on preparing datasets, running nnU-Net training and inference, evaluating predictions with Dice/HD95, and producing visual QC. Data preparation supports ACDC, MSD Cardiac, and local CorSeg SAX pseudo-labels; evaluation, conservative postprocessing, and overlays are separate capabilities. The README documents the main ACDC sequence, but the excerpts do not show shell-wrapper internals or a wired postprocessing step, so those relationships are not asserted.

Main entry points: [`scripts/predict_nnunet_acdc.sh`](https://github.com/shayliu/cmr-ai-segmentation-workbench/blob/main/scripts/predict_nnunet_acdc.sh) (Prediction wrapper), [`scripts/evaluate_segmentation.py`](https://github.com/shayliu/cmr-ai-segmentation-workbench/blob/main/scripts/evaluate_segmentation.py) (Metric evaluation), [`scripts/visualize_segmentation.py`](https://github.com/shayliu/cmr-ai-segmentation-workbench/blob/main/scripts/visualize_segmentation.py) (QC overlays), [`scripts/train_nnunet_acdc.sh`](https://github.com/shayliu/cmr-ai-segmentation-workbench/blob/main/scripts/train_nnunet_acdc.sh) (Training wrapper)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_preparation["Data preparation"]
  node_prep_acdc["Prepare ACDC<br/>[prepare_acdc.py]"]
  node_prep_msd["Prepare MSD"]
  node_prep_corseg["Prepare CorSeg"]
end

subgraph group_model["Model workflow"]
  node_nnunet["nnU-Net v2"]
  node_train["Training wrapper"]
  node_predict["Prediction wrapper"]
end

subgraph group_analysis["Evaluation and QC"]
  node_postprocess["Mask cleanup"]
  node_evaluate["Metric evaluation"]
  node_visualize["QC overlays"]
end

subgraph group_artifacts["Research artifacts"]
  node_metrics["Metric reports"]
  node_qc["QC figures"]
end

node_user(("Researcher"))
node_acdc[("ACDC data")]
node_msd[("MSD data")]
node_corseg[("CorSeg data")]

node_user -->|"prepares data"| node_prep_acdc
node_user -->|"prepares data"| node_prep_msd
node_user -->|"prepares data"| node_prep_corseg
node_acdc -->|"converts"| node_prep_acdc
node_msd -->|"converts"| node_prep_msd
node_corseg -->|"converts"| node_prep_corseg
node_user -->|"starts training"| node_train
node_train -->|"runs training"| node_nnunet
node_user -->|"starts inference"| node_predict
node_predict -->|"runs prediction"| node_nnunet
node_user -->|"evaluates results"| node_evaluate
node_predict -->|"supplies predictions"| node_evaluate
node_evaluate -->|"writes metrics"| node_metrics
node_user -->|"renders QC"| node_visualize
node_predict -->|"supplies prediction"| node_visualize
node_visualize -->|"writes overlays"| node_qc
node_user -->|"cleans masks"| node_postprocess

click node_prep_acdc "https://github.com/shayliu/cmr-ai-segmentation-workbench/blob/main/scripts/prepare_acdc.py"
click node_prep_msd "https://github.com/shayliu/cmr-ai-segmentation-workbench/blob/main/scripts/prepare_msd_cardiac.py"
click node_prep_corseg "https://github.com/shayliu/cmr-ai-segmentation-workbench/blob/main/scripts/prepare_corseg_sax_pseudolabels.py"
click node_train "https://github.com/shayliu/cmr-ai-segmentation-workbench/blob/main/scripts/train_nnunet_acdc.sh"
click node_predict "https://github.com/shayliu/cmr-ai-segmentation-workbench/blob/main/scripts/predict_nnunet_acdc.sh"
click node_postprocess "https://github.com/shayliu/cmr-ai-segmentation-workbench/blob/main/scripts/postprocess_segmentation.py"
click node_evaluate "https://github.com/shayliu/cmr-ai-segmentation-workbench/blob/main/scripts/evaluate_segmentation.py"
click node_visualize "https://github.com/shayliu/cmr-ai-segmentation-workbench/blob/main/scripts/visualize_segmentation.py"
click node_metrics "https://github.com/shayliu/cmr-ai-segmentation-workbench/blob/main/results/acdc_300epoch_fold0_val_metrics.csv"
click node_qc "https://github.com/shayliu/cmr-ai-segmentation-workbench/tree/main/docs/assets"

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_prep_acdc,node_prep_msd,node_prep_corseg toneBlue
class node_nnunet,node_train,node_predict,node_acdc,node_msd,node_corseg toneAmber
class node_postprocess,node_evaluate,node_visualize toneMint
class node_metrics,node_qc toneRose
class node_user toneIndigo
```

## Components

### Data preparation

- [Prepare ACDC](https://github.com/shayliu/cmr-ai-segmentation-workbench/blob/main/scripts/prepare_acdc.py): `scripts/prepare_acdc.py`
- [Prepare MSD](https://github.com/shayliu/cmr-ai-segmentation-workbench/blob/main/scripts/prepare_msd_cardiac.py): `scripts/prepare_msd_cardiac.py`
- [Prepare CorSeg](https://github.com/shayliu/cmr-ai-segmentation-workbench/blob/main/scripts/prepare_corseg_sax_pseudolabels.py): `scripts/prepare_corseg_sax_pseudolabels.py`

### Model workflow

- **nnU-Net v2**
- [Training wrapper](https://github.com/shayliu/cmr-ai-segmentation-workbench/blob/main/scripts/train_nnunet_acdc.sh): `scripts/train_nnunet_acdc.sh`
- [Prediction wrapper](https://github.com/shayliu/cmr-ai-segmentation-workbench/blob/main/scripts/predict_nnunet_acdc.sh): `scripts/predict_nnunet_acdc.sh`

### Evaluation and QC

- [Mask cleanup](https://github.com/shayliu/cmr-ai-segmentation-workbench/blob/main/scripts/postprocess_segmentation.py): `scripts/postprocess_segmentation.py`
- [Metric evaluation](https://github.com/shayliu/cmr-ai-segmentation-workbench/blob/main/scripts/evaluate_segmentation.py): `scripts/evaluate_segmentation.py`
- [QC overlays](https://github.com/shayliu/cmr-ai-segmentation-workbench/blob/main/scripts/visualize_segmentation.py): `scripts/visualize_segmentation.py`

### Research artifacts

- [Metric reports](https://github.com/shayliu/cmr-ai-segmentation-workbench/blob/main/results/acdc_300epoch_fold0_val_metrics.csv): `results/acdc_300epoch_fold0_val_metrics.csv`
- [QC figures](https://github.com/shayliu/cmr-ai-segmentation-workbench/tree/main/docs/assets): `docs/assets`

### Other components

- **Researcher**
- **ACDC data**
- **MSD data**
- **CorSeg data**

## Connections

- Researcher → Prepare ACDC: prepares data (evidence: `README.md`)
- Researcher → Prepare MSD: prepares data (evidence: `README.md`)
- Researcher → Prepare CorSeg: prepares data (evidence: `README.md`)
- ACDC data → Prepare ACDC: converts (evidence: `README.md`)
- MSD data → Prepare MSD: converts (evidence: `README.md`)
- CorSeg data → Prepare CorSeg: converts (evidence: `README.md`)
- Researcher → Training wrapper: starts training (evidence: `README.md`)
- Training wrapper → nnU-Net v2: runs training (evidence: `README.md`)
- Researcher → Prediction wrapper: starts inference (evidence: `README.md`)
- Prediction wrapper → nnU-Net v2: runs prediction (evidence: `README.md`)
- Researcher → Metric evaluation: evaluates results (evidence: `README.md`)
- Prediction wrapper → Metric evaluation: supplies predictions (evidence: `README.md`)
- Metric evaluation → Metric reports: writes metrics (evidence: `scripts/evaluate_segmentation.py`)
- Researcher → QC overlays: renders QC (evidence: `README.md`)
- Prediction wrapper → QC overlays: supplies prediction (evidence: `README.md`)
- QC overlays → QC figures: writes overlays (evidence: `README.md`)
- Researcher → Mask cleanup: cleans masks (evidence: `scripts/postprocess_segmentation.py`)
