Skip to main content

MedVAE: Efficient Automated Interpretation of Medical Images with Large-Scale Generalizable Autoencoders

Hugging Face    pypi    arXiv    Watch the Talk on YouTube    License

This repository contains the official PyTorch implementation for MedVAE: Efficient Automated Interpretation of Medical Images with Large-Scale Generalizable Autoencoders (MIDL 2025; Best Oral Paper Award).

🫁 What is MedVAE?

MedVAE is a family of six large-scale, generalizable 2D and 3D variational autoencoders (VAEs) designed for medical imaging. It is trained on over one million medical images across multiple anatomical regions and modalities. MedVAE autoencoders encode medical images as downsized latent representations and decode latent representations back to high-resolution images. Across diverse tasks obtained from 20 medical image datasets, we demonstrate that utilizing MedVAE latent representations in place of high-resolution images when training downstream models can lead to efficiency benefits (up to 70x improvement in throughput) while simultaneously preserving clinically-relevant features.

⚡️ Installation

To install MedVAE, you can simply run:

pip install medvae

For an editable installation, use the following commands to clone and install this repository.

git clone https://github.com/StanfordMIMI/MedVAE.git
cd MedVAE
pip install -e .[dev]
pre-commit install
pre-commit

🚀 Inference Instructions

import torch
from medvae import MVAE

fpath = "documentation/data/mmg_data/isJV8hQ2hhJsvEP5rdQNiy.png"
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

model = MVAE(model_name="medvae_4_3_2d", modality="xray").to(device)
img = model.apply_transform(fpath).to(device)

model.requires_grad_(False)
model.eval()

with torch.no_grad():
    latent = model(img)

We also developed an easy-to-use CLI inference tool for compressing your high-dimensional medical images into usable latents:

medvae_inference -i INPUT_FOLDER -o OUTPUT_FOLDER -model_name MED_VAE_MODEL -modality MODALITY

For more information, please check our inference documentation and demo.

🔧 Finetuning Instructions

Easily finetune MedVAE on your own dataset! Follow the instructions below (requires Python 3.9 and cloning the repository).

Run the following commands depending on your finetuning scenario:

Stage 1 (2D) Finetuning

medvae_finetune experiment=medvae_4x_1c_2d_finetuning

Stage 2 (2D) Finetuning:

medvae_finetune_s2 experiment=medvae_4x_1c_2d_s2_finetuning

Stage 2 (3D) Finetuning:

medvae_finetune experiment=medvae_4x_1c_3d_finetuning

This setup supports multi-GPU training and includes integration with Weights & Biases for experiment tracking.

For detailed finetuning guidelines, see the Finetuning Documentation.

To create classification models using downsized latent representations, refer to the Classification Documentation.

📎 Citation

If you find this repository useful for your work, please cite the following paper:

@misc{varma2025medvaeefficientautomatedinterpretation,
      title={MedVAE: Efficient Automated Interpretation of Medical Images with Large-Scale Generalizable Autoencoders}, 
      author={Maya Varma and Ashwin Kumar and Rogier van der Sluijs and Sophie Ostmeier and Louis Blankemeier and Pierre Chambon and Christian Bluethgen and Jip Prince and Curtis Langlotz and Akshay Chaudhari},
      year={2025},
      eprint={2502.14753},
      archivePrefix={arXiv},
      primaryClass={eess.IV},
      url={https://arxiv.org/abs/2502.14753}, 
}

This repository is powered by Hydra and HuggingFace Accelerate. Our implementation of MedVAE is inspired by prior work on diffusion models from CompVis and Stability AI.

Metadata

Release files for medvae 0.1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for medvae 0.1.7
File Size Uploaded
medvae-0.1.7.tar.gz 38.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for medvae 0.1.7
File Interpreter ABI Platform
medvae-0.1.7-py3-none-any.whl Python 3 none any Details

Total release size: 85.1 kB

Release files / medvae-0.1.7.tar.gz

Download URL medvae-0.1.7.tar.gz
Size 38.1 kB
Tags Source
SHA-256 checksum
How to use checksums
fc4a335cd7c7d3288761a641b93b3a04cebacf154dfd30356698e3419c3db803
BLAKE2b-256 checksum
How to use checksums
b304f45df8cc701ef8e5542b53d899da15cc26d869a01246b1f98db3157f544c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.0 CPython/3.10.14

Release files / medvae-0.1.7-py3-none-any.whl

Download URL medvae-0.1.7-py3-none-any.whl
Size 47.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3511812b0254aae831c234442f505bb4d12ead7c4deba9f835caff789fde65f5
BLAKE2b-256 checksum
How to use checksums
9c96a85f2b9ed2f92b7194291ad00e13ccdcea74759d9f66d7733dd468ccf551
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.0 CPython/3.10.14

Release history Release notifications | RSS feed

This release

0.1.7 This release

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page