Skip to content

Repository files navigation

CineMA logo

pythonpytorchcodecovHugging Face SpacesLicense: MIT

CineMA: Development and validation of a versatile foundation model for cine cardiac magnetic resonance image analysis 🎥🫀

Tip

Check out our interactive demos on Hugging Face to see CineMA in action!

Multiple training and inference examples/scripts have also been provided in cinema/examples.

📝 Overview

CineMA is a vision foundation model for Cine cardiac magnetic resonance (CMR) imaging, built on Masked-Autoencoder. Pre-trained on the extensive UK Biobank dataset, CineMA has been fine-tuned for various clinically relevant tasks:

  • 🫀 Ventricle and myocardium segmentation
  • 📊 Ejection fraction (EF) regression
  • 🏥 Cardiovascular disease (CVD) detection and classification
  • 📍 Mid-valve plane and apical landmark localization

The model has demonstrated improved or comparative performance against convolutional neural network baselines (UNet, ResNet) across multiple datasets, including ACDC, M&Ms, M&Ms2, Kaggle, Rescan, and Landmark.

🚀 Getting Started

Installation

Option 1: Quick Install with pip

pip install git+https://github.com/mathpluscode/CineMA

Note: This method does not install dependencies automatically.

Option 2: Full Installation with Dependencies

git clone https://github.com/mathpluscode/CineMA.git
cd CineMA
conda env update -f envs/environment.yml
conda activate cinema
pip install -e .

⚠️Important: Install PyTorch separately following the official instructions.

🎯 Using Fine-tuned Models

All fine-tuned models are available on HuggingFace. Try them out using our example inference scripts:

# Segmentation
python examples/inference/segmentation_sax.py
python examples/inference/segmentation_lax_4c.py
# Classification
python examples/inference/classification_cvd.py
python examples/inference/classification_sex.py
python examples/inference/classification_vendor.py
# Regression
python examples/inference/regression_ef.py
python examples/inference/regression_bmi.py
python examples/inference/regression_age.py
# Landmark Detection
python examples/inference/landmark_heatmap.py
python examples/inference/landmark_coordinate.py

Available tasks and models are listed below.

TaskInput ViewInput TimeframesInference Script
Ventricle and myocardium segmentationSAX1segmentation_sax.py
Ventricle and myocardium segmentationLAX 4C1segmentation_lax_4c.py
CVD classificationSAX or LAX 4C2 (ED and ES)classification_cvd.py
Patient sex classificationSAX2 (ED and ES)classification_sex.py
CMR machine vendor classificationSAX or LAX 4C2 (ED and ES)classification_vendor.py
EF regressionSAX or LAX 4C2 (ED and ES)regression_ef.py
Patient BMI regressionSAX2 (ED and ES)regression_bmi.py
Patient age regressionSAX2 (ED and ES)regression_age.py
Landmark localization by heatmap regressionLAX 2C or LAX 4C1landmark_heatmap.py
Landmark localization by coordinates regressionLAX 2C or LAX 4C1landmark_coordinate.py

🔧 Using Pre-trained Models

The pre-trained CineMA backbone is available at HuggingFace. Fine-tune it using our example scripts and the preprocessed ACDC dataset for following tasks:

TaskFine-tuning Script
Ventricle and myocardium segmentationsegmentation.py
Cardiovascular disease classificationclassification.py
Ejection fraction regressionregression.py

The commandlines are:

# Fine-tuning Scripts
python examples/train/segmentation.py
python examples/train/classification.py
python examples/train/regression.py

You can also explore the reconstruction performance of extract features using following example scripts.

# MAE Examples
python examples/inference/mae.py
python examples/inference/mae_feature_extraction.py

📚 Dataset Support

For fine-tuning CineMA on other datasets, pre-process can be performed using the provided scripts following the documentations. It is recommended to download the data under ~/.cache/cinema_datasets as the integration tests uses this path. For instance, the mnms preprocessed data would be ~/.cache/cinema_datasets/mnms/processed. Otherwise define the path using environment variable CINEMA_DATA_DIR.

DatasetDocumentation
ACDCREADME.md
M&MsREADME.md
M&Ms2README.md
KaggleREADME.md
RescanREADME.md
LandmarkREADME.md
EMIDECREADME.md
Myops2020README.md

The code for training and evaluating models on these datasets are available.

TaskDataDocumentation
Ventricle and myocardium segmentationACDCcinema/segmentation/acdc/README.md
Ventricle and myocardium segmentationM&Mscinema/segmentation/mnms/README.md
Ventricle and myocardium segmentationM&Ms2cinema/segmentation/mnms2/README.md
Ventricle and myocardium segmentationKagglecinema/segmentation/kaggle/README.md
Ventricle and myocardium segmentationRescancinema/segmentation/rescan/README.md
Scar segmentationEMIDECcinema/segmentation/emidec/README.md
Scar segmentationMyops2020cinema/segmentation/myops2020/README.md
Image classificationACDCcinema/classification/acdc/README.md
Image classificationM&Mscinema/classification/mnms/README.md
Image classificationM&Ms2cinema/classification/mnms2/README.md
Image regressionACDCcinema/regression/acdc/README.md
Image regressionM&Mscinema/regression/mnms/README.md
Image regressionM&Ms2cinema/regression/mnms2/README.md
Landmark localization by heatmap regressionLandmarkcinema/segmentation/landmark/README.md
Landmark localization by coordinates regressionLandmarkcinema/regression/landmark/README.md

🏗️ Training Your Own Foundation Model

Start with our simplified pretraining script:

python examples/train/pretrain.py

For distributed training support, check cinema/mae/pretrain.py.

❤️ Acknowledgement

This research has been conducted using the UK Biobank Resource under Application Number 71702. The authors acknowledge the use of resources provided by the Isambard-AI National AI Research Resource (AIRR). Isambard-AI is operated by the University of Bristol and is funded by the UK Government’s Department for Science, Innovation and Technology (DSIT) via UK Research and Innovation; and the Science and Technology Facilities Council [ST/AIRR/I-A-I/1023].

📖 References

CineMA builds upon these open-source projects:

🤝 Contributing

We welcome contributions! Please create an issue for questions or suggestions.

📧 Contact

For collaborations, reach out to Yunguan Fu (yunguan.fu.18@ucl.ac.uk).

📄 Citation

@article{fu2026development,
title={Development and validation of a versatile foundation model for cine cardiac magnetic resonance image analysis},
author={Fu, Yunguan and Bai, Wenjia and Yi, Weixi and Manisty, Charlotte and Bhuva, Anish N and Treibel, Thomas A and Moon, James C and Clarkson, Matthew J and Davies, Rhodri Huw and Hu, Yipeng},
journal={Communications Medicine},
year={2026},
publisher={Nature Publishing Group UK London}
}

About

A Vision Foundation Model for Cine Cardiac Magnetic Resonance Imaging

Topics

Resources

Stars

61 stars

Watchers

2 watching

Forks

Used by

Contributors

Languages