# mathpluscode/cinema architecture

> Architecture diagram of the GitHub repository mathpluscode/cinema, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mathpluscode/cinema
- Repository: https://github.com/mathpluscode/cinema

## Overview

CineMA is a cardiac MRI foundation-model package: dataset-specific preprocessing prepares imaging data, masked-autoencoder pretraining produces a backbone, and task-specific training and evaluation support segmentation, classification, EF/other regression, and landmark localization. The graph includes the shared model/training layers and the documented dataset and task branches. Several dataset and task modules are unsampled, so their links are limited to capabilities explicitly documented in the README or references recorded in the source index.

Main entry points: [`cinema/segmentation/train.py`](https://github.com/mathpluscode/cinema/blob/main/cinema/segmentation/train.py) (Segmentation training), [`cinema/train.py`](https://github.com/mathpluscode/cinema/blob/main/cinema/train.py) (Training runtime), [`cinema/classification`](https://github.com/mathpluscode/cinema/tree/main/cinema/classification) (Classification tasks), [`cinema/data`](https://github.com/mathpluscode/cinema/tree/main/cinema/data) (Dataset preprocessing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Imaging data"]
  node_preprocess["Dataset preprocessing"]
  node_dicom["DICOM handling<br/>[dicom.py]"]
  node_sitk["Image transforms<br/>[sitk.py]"]
end

subgraph group_foundation["Foundation model"]
  node_mae_pretrain["MAE pretraining<br/>[pretrain.py]"]
  node_mae["CineMA encoder-decoder<br/>[mae.py]"]
  node_vit["Vision Transformer<br/>[vit.py]"]
  node_conv["Convolution blocks<br/>[conv.py]"]
  node_convvit["ConvViT<br/>[convvit.py]"]
end

subgraph group_tasks["Downstream tasks"]
  node_seg_train["Segmentation training<br/>[train.py]"]
  node_seg_model["ConvUNetR<br/>[convunetr.py]"]
  node_seg_data["Segmentation dataset<br/>[dataset.py]"]
  node_seg_eval["Segmentation evaluation<br/>[eval.py]"]
  node_classification["Classification tasks"]
  node_class_data["Classification dataset<br/>[dataset.py]"]
  node_regression["Regression tasks"]
  node_landmarks["Landmark localization"]
end

subgraph group_shared["Shared runtime"]
  node_metrics["Clinical metrics<br/>[metric.py]"]
  node_transforms["Training transforms<br/>[transform.py]"]
  node_trainer["Training runtime<br/>[train.py]"]
  node_device["Device selection<br/>[device.py]"]
  node_logger["Logging<br/>[log.py]"]
end

node_user(("Researcher"))

node_user -->|"prepares datasets"| node_preprocess
node_preprocess -->|"uses image operations"| node_sitk
node_preprocess -->|"uses DICOM utilities"| node_dicom
node_user -->|"pretrains backbone"| node_mae_pretrain
node_mae_pretrain -->|"trains"| node_mae
node_mae -->|"uses transformer"| node_vit
node_mae -->|"uses convolutions"| node_conv
node_user -->|"fine-tunes"| node_seg_train
node_seg_train -->|"uses model"| node_seg_model
node_seg_train -->|"uses transforms"| node_transforms
node_seg_train -->|"uses runtime"| node_trainer
node_seg_data -.->|"reads image data"| node_sitk
node_seg_eval -->|"loads samples"| node_seg_data
node_seg_eval -->|"computes metrics"| node_metrics
node_user -->|"trains or evaluates"| node_classification
node_classification -->|"loads samples"| node_class_data
node_classification -->|"uses runtime"| node_trainer
node_classification -->|"builds model"| node_convvit
node_user -->|"trains or evaluates"| node_regression
node_regression -->|"uses runtime"| node_trainer
node_regression -->|"uses metrics"| node_metrics
node_user -->|"localizes landmarks"| node_landmarks
node_landmarks -->|"uses segmentation framework"| node_seg_train
node_trainer -->|"selects device"| node_device
node_trainer -->|"initializes logging"| node_logger

click node_preprocess "https://github.com/mathpluscode/cinema/tree/main/cinema/data"
click node_dicom "https://github.com/mathpluscode/cinema/blob/main/cinema/data/dicom.py"
click node_sitk "https://github.com/mathpluscode/cinema/blob/main/cinema/data/sitk.py"
click node_mae_pretrain "https://github.com/mathpluscode/cinema/blob/main/cinema/mae/pretrain.py"
click node_mae "https://github.com/mathpluscode/cinema/blob/main/cinema/mae/mae.py"
click node_vit "https://github.com/mathpluscode/cinema/blob/main/cinema/vit.py"
click node_conv "https://github.com/mathpluscode/cinema/blob/main/cinema/conv.py"
click node_convvit "https://github.com/mathpluscode/cinema/blob/main/cinema/convvit.py"
click node_seg_train "https://github.com/mathpluscode/cinema/blob/main/cinema/segmentation/train.py"
click node_seg_model "https://github.com/mathpluscode/cinema/blob/main/cinema/segmentation/convunetr.py"
click node_seg_data "https://github.com/mathpluscode/cinema/blob/main/cinema/segmentation/dataset.py"
click node_seg_eval "https://github.com/mathpluscode/cinema/blob/main/cinema/segmentation/eval.py"
click node_classification "https://github.com/mathpluscode/cinema/tree/main/cinema/classification"
click node_class_data "https://github.com/mathpluscode/cinema/blob/main/cinema/classification/dataset.py"
click node_regression "https://github.com/mathpluscode/cinema/tree/main/cinema/regression"
click node_landmarks "https://github.com/mathpluscode/cinema/tree/main/cinema/segmentation/landmark"
click node_metrics "https://github.com/mathpluscode/cinema/blob/main/cinema/metric.py"
click node_transforms "https://github.com/mathpluscode/cinema/blob/main/cinema/transform.py"
click node_trainer "https://github.com/mathpluscode/cinema/blob/main/cinema/train.py"
click node_device "https://github.com/mathpluscode/cinema/blob/main/cinema/device.py"
click node_logger "https://github.com/mathpluscode/cinema/blob/main/cinema/log.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_preprocess,node_dicom,node_sitk toneBlue
class node_mae_pretrain,node_mae,node_vit,node_conv,node_convvit toneAmber
class node_seg_train,node_seg_model,node_seg_data,node_seg_eval,node_classification,node_class_data,node_regression,node_landmarks toneMint
class node_metrics,node_transforms,node_trainer,node_device,node_logger toneRose
class node_user toneIndigo
```

## Components

### Imaging data

- [Dataset preprocessing](https://github.com/mathpluscode/cinema/tree/main/cinema/data): `cinema/data`
- [DICOM handling](https://github.com/mathpluscode/cinema/blob/main/cinema/data/dicom.py): `cinema/data/dicom.py`
- [Image transforms](https://github.com/mathpluscode/cinema/blob/main/cinema/data/sitk.py): `cinema/data/sitk.py`

### Foundation model

- [MAE pretraining](https://github.com/mathpluscode/cinema/blob/main/cinema/mae/pretrain.py): `cinema/mae/pretrain.py`
- [CineMA encoder-decoder](https://github.com/mathpluscode/cinema/blob/main/cinema/mae/mae.py): `cinema/mae/mae.py`
- [Vision Transformer](https://github.com/mathpluscode/cinema/blob/main/cinema/vit.py): `cinema/vit.py`
- [Convolution blocks](https://github.com/mathpluscode/cinema/blob/main/cinema/conv.py): `cinema/conv.py`
- [ConvViT](https://github.com/mathpluscode/cinema/blob/main/cinema/convvit.py): `cinema/convvit.py`

### Downstream tasks

- [Segmentation training](https://github.com/mathpluscode/cinema/blob/main/cinema/segmentation/train.py): `cinema/segmentation/train.py`
- [ConvUNetR](https://github.com/mathpluscode/cinema/blob/main/cinema/segmentation/convunetr.py): `cinema/segmentation/convunetr.py`
- [Segmentation dataset](https://github.com/mathpluscode/cinema/blob/main/cinema/segmentation/dataset.py): `cinema/segmentation/dataset.py`
- [Segmentation evaluation](https://github.com/mathpluscode/cinema/blob/main/cinema/segmentation/eval.py): `cinema/segmentation/eval.py`
- [Classification tasks](https://github.com/mathpluscode/cinema/tree/main/cinema/classification): `cinema/classification`
- [Classification dataset](https://github.com/mathpluscode/cinema/blob/main/cinema/classification/dataset.py): `cinema/classification/dataset.py`
- [Regression tasks](https://github.com/mathpluscode/cinema/tree/main/cinema/regression): `cinema/regression`
- [Landmark localization](https://github.com/mathpluscode/cinema/tree/main/cinema/segmentation/landmark): `cinema/segmentation/landmark`

### Shared runtime

- [Clinical metrics](https://github.com/mathpluscode/cinema/blob/main/cinema/metric.py): `cinema/metric.py`
- [Training transforms](https://github.com/mathpluscode/cinema/blob/main/cinema/transform.py): `cinema/transform.py`
- [Training runtime](https://github.com/mathpluscode/cinema/blob/main/cinema/train.py): `cinema/train.py`
- [Device selection](https://github.com/mathpluscode/cinema/blob/main/cinema/device.py): `cinema/device.py`
- [Logging](https://github.com/mathpluscode/cinema/blob/main/cinema/log.py): `cinema/log.py`

### Other components

- **Researcher**

## Connections

- Researcher → Dataset preprocessing: prepares datasets (evidence: `README.md`)
- Dataset preprocessing → Image transforms: uses image operations (evidence: `cinema/data/mnms/preprocess.py`)
- Dataset preprocessing → DICOM handling: uses DICOM utilities (evidence: `cinema/data/rescan/preprocess.py`)
- Researcher → MAE pretraining: pretrains backbone (evidence: `README.md`)
- MAE pretraining → CineMA encoder-decoder: trains (evidence: `cinema/mae/pretrain.py`)
- CineMA encoder-decoder → Vision Transformer: uses transformer (evidence: `cinema/mae/mae.py`)
- CineMA encoder-decoder → Convolution blocks: uses convolutions (evidence: `cinema/mae/mae.py`)
- Researcher → Segmentation training: fine-tunes (evidence: `README.md`)
- Segmentation training → ConvUNetR: uses model (evidence: `cinema/segmentation/train.py`)
- Segmentation training → Training transforms: uses transforms (evidence: `cinema/segmentation/train.py`)
- Segmentation training → Training runtime: uses runtime (evidence: `cinema/segmentation/train.py`)
- Segmentation dataset → Image transforms: reads image data
- Segmentation evaluation → Segmentation dataset: loads samples (evidence: `cinema/segmentation/eval.py`)
- Segmentation evaluation → Clinical metrics: computes metrics (evidence: `cinema/segmentation/eval.py`)
- Researcher → Classification tasks: trains or evaluates (evidence: `README.md`)
- Classification tasks → Classification dataset: loads samples (evidence: `cinema/classification/acdc/train.py`)
- Classification tasks → Training runtime: uses runtime (evidence: `cinema/classification/acdc/train.py`)
- Classification tasks → ConvViT: builds model (evidence: `cinema/classification/train.py`)
- Researcher → Regression tasks: trains or evaluates (evidence: `README.md`)
- Regression tasks → Training runtime: uses runtime (evidence: `cinema/regression/acdc/train.py`)
- Regression tasks → Clinical metrics: uses metrics (evidence: `cinema/regression/landmark/train.py`)
- Researcher → Landmark localization: localizes landmarks (evidence: `README.md`)
- Landmark localization → Segmentation training: uses segmentation framework (evidence: `cinema/segmentation/landmark/train.py`)
- Training runtime → Device selection: selects device (evidence: `cinema/train.py`)
- Training runtime → Logging: initializes logging (evidence: `cinema/train.py`)
