| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
MoPaDi combines Diffusion Autoencoders with multiple instance learning (MIL) for explainability of deep learning classifiers in histopathology.
For segmentation of 6 cell types to quantify changes in original and counterfactual images, DeepCMorph pretrained models were used.
For preprocessing of whole slide images (WSIs), please refer to KatherLab's STAMP protocol.
Table of Contents:
Clone the repository and create a virtual environment to install required packages, e.g. with uv (instructions below), conda or mamba.
Install uv
curl -LsSf https://astral.sh/uv/install.sh | shSync dependencies. In the root of this repository, run:
uv syncThis creates a virtual environment at .venv/ and installs all necessary Python dependencies.
Activate the environment:
source .venv/bin/activateYou can obtain access to pretrained models on Hugging Face. Once the environment is set up and access to models has been granted, you can run the example notebooks (all the necessary data for these examples has been provided) or train your own models.
To train the models from scratch, follow these steps:
Prepare the Environment: Ensure you have set up the virtual environment and installed the required packages.
Download Datasets: Obtain the Datasets used in the paper or use your own.
Preprocess the Data: If the dataset consists of WSIs and not tiles, use the STAMP protocol for preprocessing WSIs as needed. The starting point for MoPaDi is folders of tiles (color normalized or not). Multiple cohorts can be used, all tiles do not need to be in the same folder. Resizing, if needed, can be done automatically during the training. Accepted image formats: JPEG, TIFF and PNG.
Tip
ZIP files containing tiles for each patient (STAMP's output) are also accepted and do not need to be extracted beforehand.
Configure Training: Modify conf.yaml file to match your dataset, define output path and desired training parameters.
Run Trainings: Execute the training scripts for the desired models.
mopadi autoenc --config conf.yaml
You can evaluate the trained autoencoder by adapting src/mopadi/utils/reconstruct_1k_images.py for your data to reconstruct images from the test set and compute corresponding metrics: SSIM, MS-SSIM, MSE.
mopadi latent --config conf.yaml
mopadi linear_classifier --config conf.yaml
mopadi mil --config conf.yaml --mode crossval mopadi mil --config conf.yaml --mode train mopadi mil --config conf.yaml --mode manipulate
Pretrained models can be found on Hugging Face. If you have already obtained access to models in that repository, automatic download is set up in example notebooks. Included models are:
If you want to process multiple images/folders, you can use conf.yaml, with use_pretrained parameter set to True, which will trigger automatic download of the selected model, and the following command:
mopadi mil --config conf.yaml --mode manipulate
For this to work, make sure you are logged in to your Hugging Face account:
huggingface-cli login
You can check if you are already logged in by running:
huggingface-cli whoami
Examples of counterfactual images generated with corresponding models (please refer to the paper for more examples):

This project was built upon a DiffAE (MIT license) repository. We thank the developers for making their code open source.
If you find our work useful for your research or if you use parts of the code please consider citing our paper:
Žigutytė, L., Lenz, T., Han, T., Reitsam, N. G., Foersch, S., Hewitt, K. J., ... & Kather, J. N. (2026). Counterfactual Diffusion Models Provide Interpretable Explanations of Artificial Intelligence Models in Pathology. Cancer Research, OF1-OF20.
@article{zigutyte2026,
author = {Zigutyte, Laura and Lenz, Tim and Han, Tianyu and Reitsam, Nic G. and Foersch, Sebastian and Hewitt, Katherine J. and Jesinghaus, Moritz and Carrero, Zunamys I. and Unger, Michaela and Rabasco Meneghetti, Asier and Lurje, Georg and Lurje, Isabella and Herda, Sophia and Pein, Justus and Uluk, Deniz and Schneider, Carolin V. and Pearson, Alexander T. and Truhn, Daniel and Kather, Jakob Nikolas},
title = {Counterfactual Diffusion Models Provide Interpretable Explanations of Artificial Intelligence Models in Pathology},
journal = {Cancer Research},
year = {2026},
doi = {10.1158/0008-5472.CAN-25-5645},
publisher = {American Association for Cancer Research},
note = {Online ahead of print}
}
| Back | FazBrowse Home | New Git URL |