Image-to-Image
Diffusers
English
histopathology
diffusion
image-generation
medical-imaging
latent-diffusion
semantic-synthesis
tissue-synthesis
computational-pathology
stable-diffusion
Instructions to use Saghir/HeteroTissueDiffuse with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use Saghir/HeteroTissueDiffuse with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline from diffusers.utils import load_image # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("Saghir/HeteroTissueDiffuse", dtype=torch.bfloat16, device_map="cuda") prompt = "Turn this cat into a dog" input_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png") image = pipe(image=input_image, prompt=prompt).images[0] - Notebooks
- Google Colab
- Kaggle
File size: 7,892 Bytes
e59e2b1 a8b54cc e59e2b1 b986260 e59e2b1 3f00a5b e59e2b1 c6c114d e59e2b1 a8b54cc e59e2b1 c6c114d a8b54cc c6c114d a8b54cc c6c114d a8b54cc c6c114d e59e2b1 c6c114d e59e2b1 c6c114d a8b54cc e59e2b1 c6c114d a8b54cc c6c114d a8b54cc c6c114d e59e2b1 a8b54cc e59e2b1 a8b54cc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | ---
license: creativeml-openrail-m
language:
- en
tags:
- histopathology
- diffusion
- image-generation
- medical-imaging
- latent-diffusion
- semantic-synthesis
- tissue-synthesis
- computational-pathology
- stable-diffusion
datasets:
- Camelyon16
- PANDA
- TCGA
pipeline_tag: image-to-image
library_name: diffusers
model_name: HeteroTissueDiffuse
arxiv: 2509.17847
---
# HeteroTissueDiffuse
**Semantic and Visual Crop-Guided Diffusion Models for Heterogeneous Tissue Synthesis in Histopathology**
*NeurIPS 2025*
[Saghir Alfasly](https://saghiralfasly.github.io/) · [Wataru Uegami](https://www.linkedin.com/in/wataru-uegami-8b106920a/) · [MD Enamul Hoq](https://www.linkedin.com/in/mhoq89/) · [Ghazal Alabtah](https://www.linkedin.com/in/ghazal-alabtah-00/) · [H.R. Tizhoosh](https://tizhoosh.com/)
KIMIA Lab, Department of AI & Informatics, Mayo Clinic, Rochester, MN, USA
[](https://arxiv.org/abs/2509.17847)
[](https://kimialabmayo.github.io/hetero_tissue_diffuse_page/)
[](https://github.com/KimiaLabMayo/hetero_tissue_diffuse)
---
## Model Description
**HeteroTissueDiffuse** is a latent diffusion model (LDM) that synthesizes heterogeneous histopathology images by conditioning on both a **binary semantic map** and **raw tissue crop exemplars**. Unlike text- or embedding-guided approaches, it injects actual tissue appearance directly into the diffusion process, preserving staining characteristics, nuclear morphology, and cellular texture.
The model addresses a fundamental limitation of prior generative methods in histopathology: the tendency to produce homogeneous (single-tissue-type) images. By providing spatially-registered visual prompts for each tissue class, the model generates realistic heterogeneous slides that accurately reflect real-world tissue organization.
### Architecture
- **Base**: CompVis Latent Diffusion Model with VQ-regularized autoencoder
- **First stage**: `VQModelInterface` (3-channel latent, 8192 codebook)
- **Conditioning encoder**: `SpatialRescaler` with `in_channels=8` (replaces ADE20K default of 182)
- **U-Net**: 128 base channels, attention at resolutions 32/16/8
- **Image size**: 256×256 pixels
- **Sampling**: DDIM, 200 steps, η=1
### 8-Channel Conditioning Tensor
```
Channel 0: normal onehot mask (1 where segmentation == 0)
Channels 1–3: normal tissue crop RGB (float32, normalized to [-1,1])
Channel 4: tumor onehot mask (1 where segmentation == 1)
Channels 5–7: tumor tissue crop RGB (float32, normalized to [-1,1])
```
The tissue crops are small patches (typically 30–60px) extracted from a reference slide and pasted spatially within the corresponding mask region. This lets users control staining appearance at inference time without any fine-tuning.
---
## Available Checkpoints
| File | Dataset | Description |
|------|---------|-------------|
| `camelyon16/epoch=000064.ckpt` | Camelyon16 | Binary tumor/normal masks, 256×256, 64 epochs |
| `panda/last.ckpt` | PANDA | Gleason tissue regions, 256×256 |
| `tcga/last.ckpt` | TCGA (self-supervised) | 100 pseudo-phenotype clusters, 256×256, 232 epochs |
---
## Quick Start
### 1. Clone the inference code
```bash
git clone https://github.com/CompVis/stable-diffusion.git
cd stable-diffusion
# Apply the 2 required patches (see GitHub README for details)
# Then copy our inference script
wget https://raw.githubusercontent.com/Saghir/HeteroTissueDiffuse/main/inference_heteroTissueDiffuse_camelyon.py
```
### 2. Download the checkpoint
```bash
pip install huggingface_hub
python - <<'EOF'
from huggingface_hub import hf_hub_download
# Camelyon16
hf_hub_download(repo_id="Saghir/HeteroTissueDiffuse",
filename="camelyon16/epoch=000064.ckpt", local_dir="inference/")
# PANDA
hf_hub_download(repo_id="Saghir/HeteroTissueDiffuse",
filename="panda/last.ckpt", local_dir="inference/")
# TCGA
hf_hub_download(repo_id="Saghir/HeteroTissueDiffuse",
filename="tcga/last.ckpt", local_dir="inference/")
EOF
```
Or via CLI (download one dataset at a time):
```bash
# Camelyon16
huggingface-cli download Saghir/HeteroTissueDiffuse \
camelyon16/epoch=000064.ckpt --local-dir inference/
# PANDA
huggingface-cli download Saghir/HeteroTissueDiffuse \
panda/last.ckpt --local-dir inference/
# TCGA
huggingface-cli download Saghir/HeteroTissueDiffuse \
tcga/last.ckpt --local-dir inference/
```
### 3. Run inference
```bash
conda activate diff # PyTorch 2.0.1 + CUDA 11+
python inference_heteroTissueDiffuse_camelyon.py \
--normal_prompt inference/promptNormal2.png \
--tumor_prompt inference/promptTumor2.png \
--segmentation_root inference/masks \
--ckpt_path inference/epoch=000064.ckpt \
--output_dir outputs/inference_results
```
**Inputs:**
- `--normal_prompt` / `--tumor_prompt`: small PNG crops of representative tissue regions (provided as examples in the [GitHub repo](https://github.com/Saghir/HeteroTissueDiffuse/tree/main/inference))
- `--segmentation_root`: folder of `.npy` binary masks (512×512, dtype bool, 0=normal, 1=tumor)
**Outputs** (per mask):
- `frame_XXX.png` — generated histopathology image
- `prompt_frame_XXX.png` — visualization of the conditioning (mask + overlaid crops)
---
## Performance
### Downstream Segmentation (IoU)
| Training data | Camelyon16 | PANDA |
|---------------|-----------|-------|
| Real images | 0.72 | 0.96 |
| **Synthetic (ours)** | **0.71** | **0.95** |
| Synthetic (no conditioning) | 0.51 | 0.82 |
### Pathologist Assessment
A certified pathologist evaluated 120 images in a blinded study. Synthetic images conditioned with visual prompts received quality scores **indistinguishable from real images**:
> *"The generated images tended to have equal or higher quality than the real images."*
---
## Intended Use
- **Research**: generating large annotated synthetic histopathology datasets for downstream model training
- **Augmentation**: expanding small annotated datasets with realistic diverse tissue variations
- **Privacy-preserving data sharing**: synthetic data as a substitute for patient slides
- **Education**: illustrating tissue morphology variations
---
## Training Details
### Camelyon16 Checkpoint
- **Dataset**: Camelyon16 (lymph node whole-slide images, binary tumor/normal segmentation)
- **Patch size**: 256×256 pixels at 0.5 µm/px
- **Training steps**: 64 epochs
- **Optimizer**: Adam, lr=1e-6
- **Hardware**: A100 GPU
- **Framework**: PyTorch 2.0.1 + pytorch-lightning 1.4.2
### Self-Supervised Extension (TCGA)
Patches from 11,765 TCGA whole-slide images were embedded using a histopathology foundation model (PathDino), then clustered into 100 tissue phenotypes via k-means. These clusters form pseudo-semantic maps for training without manual annotation.
---
## Citation
```bibtex
@InProceedings{Alfasly2025HeteroTissueDiffuse,
author = {Alfasly, Saghir and Uegami, Wataru and Hoq, MD Enamul and Alabtah, Ghazal and Tizhoosh, H.R.},
title = {Semantic and Visual Crop-Guided Diffusion Models for Heterogeneous Tissue Synthesis in Histopathology},
booktitle = {Neural Information Processing Systems (NeurIPS)},
month = {December},
year = {2025}
}
```
---
## License
This model is released under the **CreativeML Open RAIL-M** license, inherited from [CompVis/stable-diffusion](https://github.com/CompVis/stable-diffusion). This license permits research and commercial use but prohibits use cases that cause harm (e.g., generating deceptive or malicious content). See the full license [here](https://huggingface.co/spaces/CompVis/stable-diffusion-license).
|