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
saghiralfasly Claude Sonnet 4.6 commited on
Commit ·
e59e2b1
0
Parent(s):
Add HuggingFace model card for HeteroTissueDiffuse
Browse filesIncludes YAML frontmatter (license, tags, pipeline), full model description,
8-channel conditioning explanation, performance tables, training details,
and quick-start inference instructions.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- .gitattributes +9 -0
- README.md +214 -0
.gitattributes
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gif filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.png filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
tags:
|
| 6 |
+
- histopathology
|
| 7 |
+
- diffusion
|
| 8 |
+
- image-generation
|
| 9 |
+
- medical-imaging
|
| 10 |
+
- latent-diffusion
|
| 11 |
+
- semantic-synthesis
|
| 12 |
+
- tissue-synthesis
|
| 13 |
+
- computational-pathology
|
| 14 |
+
- stable-diffusion
|
| 15 |
+
datasets:
|
| 16 |
+
- Camelyon16
|
| 17 |
+
- PANDA
|
| 18 |
+
- TCGA
|
| 19 |
+
pipeline_tag: image-to-image
|
| 20 |
+
library_name: diffusers
|
| 21 |
+
model_name: HeteroTissueDiffuse
|
| 22 |
+
arxiv: 2509.17847
|
| 23 |
+
---
|
| 24 |
+
|
| 25 |
+
# HeteroTissueDiffuse
|
| 26 |
+
|
| 27 |
+
**Semantic and Visual Crop-Guided Diffusion Models for Heterogeneous Tissue Synthesis in Histopathology**
|
| 28 |
+
|
| 29 |
+
*NeurIPS 2025*
|
| 30 |
+
|
| 31 |
+
[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/)
|
| 32 |
+
|
| 33 |
+
KIMIA Lab, Mayo Clinic, Rochester, MN, USA
|
| 34 |
+
|
| 35 |
+
[](https://arxiv.org/abs/2509.17847)
|
| 36 |
+
[](https://kimialabmayo.github.io/hetero_tissue_diffuse_page/)
|
| 37 |
+
[](https://github.com/KimiaLabMayo/HeteroTissueDiffuse)
|
| 38 |
+
|
| 39 |
+
---
|
| 40 |
+
|
| 41 |
+

|
| 42 |
+
|
| 43 |
+
---
|
| 44 |
+
|
| 45 |
+
## Model Description
|
| 46 |
+
|
| 47 |
+
**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.
|
| 48 |
+
|
| 49 |
+
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.
|
| 50 |
+
|
| 51 |
+
### Architecture
|
| 52 |
+
|
| 53 |
+
- **Base**: CompVis Latent Diffusion Model with VQ-regularized autoencoder
|
| 54 |
+
- **First stage**: `VQModelInterface` (3-channel latent, 8192 codebook)
|
| 55 |
+
- **Conditioning encoder**: `SpatialRescaler` with `in_channels=8` (replaces ADE20K default of 182)
|
| 56 |
+
- **U-Net**: 128 base channels, attention at resolutions 32/16/8
|
| 57 |
+
- **Image size**: 256×256 pixels
|
| 58 |
+
- **Sampling**: DDIM, 200 steps, η=1
|
| 59 |
+
|
| 60 |
+
### 8-Channel Conditioning Tensor
|
| 61 |
+
|
| 62 |
+
```
|
| 63 |
+
Channel 0: normal onehot mask (1 where segmentation == 0)
|
| 64 |
+
Channels 1–3: normal tissue crop RGB (float32, normalized to [-1,1])
|
| 65 |
+
Channel 4: tumor onehot mask (1 where segmentation == 1)
|
| 66 |
+
Channels 5–7: tumor tissue crop RGB (float32, normalized to [-1,1])
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
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.
|
| 70 |
+
|
| 71 |
+
---
|
| 72 |
+
|
| 73 |
+
## Available Checkpoints
|
| 74 |
+
|
| 75 |
+
| File | Dataset | Description |
|
| 76 |
+
|------|---------|-------------|
|
| 77 |
+
| `camelyon16/epoch=000064.ckpt` | Camelyon16 | Binary tumor/normal masks, 256×256 |
|
| 78 |
+
| `panda/epoch=XXXXXX.ckpt` | PANDA | Gleason grading regions *(coming soon)* |
|
| 79 |
+
| `tcga/epoch=XXXXXX.ckpt` | TCGA (self-supervised) | 100 pseudo-phenotype clusters *(coming soon)* |
|
| 80 |
+
|
| 81 |
+
---
|
| 82 |
+
|
| 83 |
+
## Quick Start
|
| 84 |
+
|
| 85 |
+
### 1. Clone the inference code
|
| 86 |
+
|
| 87 |
+
```bash
|
| 88 |
+
git clone https://github.com/CompVis/stable-diffusion.git
|
| 89 |
+
cd stable-diffusion
|
| 90 |
+
|
| 91 |
+
# Apply the 2 required patches (see GitHub README for details)
|
| 92 |
+
# Then copy our inference script
|
| 93 |
+
wget https://raw.githubusercontent.com/KimiaLabMayo/HeteroTissueDiffuse/main/inference_heteroTissueDiffuse_camelyon.py
|
| 94 |
+
```
|
| 95 |
+
|
| 96 |
+
### 2. Download the checkpoint
|
| 97 |
+
|
| 98 |
+
```bash
|
| 99 |
+
pip install huggingface_hub
|
| 100 |
+
|
| 101 |
+
python - <<'EOF'
|
| 102 |
+
from huggingface_hub import hf_hub_download
|
| 103 |
+
hf_hub_download(
|
| 104 |
+
repo_id="KimiaLabMayo/HeteroTissueDiffuse",
|
| 105 |
+
filename="camelyon16/epoch=000064.ckpt",
|
| 106 |
+
local_dir="inference/"
|
| 107 |
+
)
|
| 108 |
+
EOF
|
| 109 |
+
```
|
| 110 |
+
|
| 111 |
+
Or via CLI:
|
| 112 |
+
```bash
|
| 113 |
+
huggingface-cli download KimiaLabMayo/HeteroTissueDiffuse \
|
| 114 |
+
camelyon16/epoch=000064.ckpt --local-dir inference/
|
| 115 |
+
```
|
| 116 |
+
|
| 117 |
+
### 3. Run inference
|
| 118 |
+
|
| 119 |
+
```bash
|
| 120 |
+
conda activate diff # PyTorch 2.0.1 + CUDA 11+
|
| 121 |
+
|
| 122 |
+
python inference_heteroTissueDiffuse_camelyon.py \
|
| 123 |
+
--normal_prompt inference/promptNormal2.png \
|
| 124 |
+
--tumor_prompt inference/promptTumor2.png \
|
| 125 |
+
--segmentation_root inference/masks \
|
| 126 |
+
--ckpt_path inference/epoch=000064.ckpt \
|
| 127 |
+
--output_dir outputs/inference_results
|
| 128 |
+
```
|
| 129 |
+
|
| 130 |
+
**Inputs:**
|
| 131 |
+
- `--normal_prompt` / `--tumor_prompt`: small PNG crops of representative tissue regions (provided as examples in the [GitHub repo](https://github.com/KimiaLabMayo/HeteroTissueDiffuse/tree/main/inference))
|
| 132 |
+
- `--segmentation_root`: folder of `.npy` binary masks (512×512, dtype bool, 0=normal, 1=tumor)
|
| 133 |
+
|
| 134 |
+
**Outputs** (per mask):
|
| 135 |
+
- `frame_XXX.png` — generated histopathology image
|
| 136 |
+
- `prompt_frame_XXX.png` — visualization of the conditioning (mask + overlaid crops)
|
| 137 |
+
|
| 138 |
+
---
|
| 139 |
+
|
| 140 |
+
## Performance
|
| 141 |
+
|
| 142 |
+
### Fréchet Distance (lower is better)
|
| 143 |
+
|
| 144 |
+
| Method | Camelyon16 | PANDA | TCGA |
|
| 145 |
+
|--------|-----------|-------|------|
|
| 146 |
+
| Unconditional LDM | 430.1 | — | — |
|
| 147 |
+
| **HeteroTissueDiffuse (ours)** | **72.0** | ↓ 2–3× | ↓ 2–3× |
|
| 148 |
+
|
| 149 |
+
### Downstream Segmentation (IoU)
|
| 150 |
+
|
| 151 |
+
| Training data | Camelyon16 | PANDA |
|
| 152 |
+
|---------------|-----------|-------|
|
| 153 |
+
| Real images | 0.72 | 0.96 |
|
| 154 |
+
| **Synthetic (ours)** | **0.71** | **0.95** |
|
| 155 |
+
| Synthetic (no conditioning) | 0.51 | 0.82 |
|
| 156 |
+
|
| 157 |
+
### Pathologist Assessment
|
| 158 |
+
|
| 159 |
+
A certified pathologist evaluated 120 images in a blinded study. Synthetic images conditioned with visual prompts received quality scores **indistinguishable from real images**:
|
| 160 |
+
|
| 161 |
+
> *"The generated images tended to have equal or higher quality than the real images."*
|
| 162 |
+
|
| 163 |
+
---
|
| 164 |
+
|
| 165 |
+
## Intended Use
|
| 166 |
+
|
| 167 |
+
- **Research**: generating large annotated synthetic histopathology datasets for downstream model training
|
| 168 |
+
- **Augmentation**: expanding small annotated datasets with realistic diverse tissue variations
|
| 169 |
+
- **Privacy-preserving data sharing**: synthetic data as a substitute for patient slides
|
| 170 |
+
- **Education**: illustrating tissue morphology variations
|
| 171 |
+
|
| 172 |
+
### Out-of-scope use
|
| 173 |
+
|
| 174 |
+
- Clinical diagnosis or patient care — this is a research model
|
| 175 |
+
- Generating images to deceive or misrepresent clinical findings
|
| 176 |
+
|
| 177 |
+
---
|
| 178 |
+
|
| 179 |
+
## Training Details
|
| 180 |
+
|
| 181 |
+
### Camelyon16 Checkpoint
|
| 182 |
+
|
| 183 |
+
- **Dataset**: Camelyon16 (lymph node whole-slide images, binary tumor/normal segmentation)
|
| 184 |
+
- **Patch size**: 256×256 pixels at 0.5 µm/px
|
| 185 |
+
- **Training steps**: 64 epochs
|
| 186 |
+
- **Optimizer**: Adam, lr=1e-6
|
| 187 |
+
- **Hardware**: A100 GPU
|
| 188 |
+
- **Framework**: PyTorch 2.0.1 + pytorch-lightning 1.4.2
|
| 189 |
+
|
| 190 |
+
### Self-Supervised Extension (TCGA)
|
| 191 |
+
|
| 192 |
+
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.
|
| 193 |
+
|
| 194 |
+
---
|
| 195 |
+
|
| 196 |
+
## Citation
|
| 197 |
+
|
| 198 |
+
```bibtex
|
| 199 |
+
@InProceedings{Alfasly2025HeteroTissueDiffuse,
|
| 200 |
+
author = {Alfasly, Saghir and Uegami, Wataru and Hoq, MD Enamul and Alabtah, Ghazal and Tizhoosh, H.R.},
|
| 201 |
+
title = {Semantic and Visual Crop-Guided Diffusion Models for Heterogeneous Tissue Synthesis in Histopathology},
|
| 202 |
+
booktitle = {Neural Information Processing Systems (NeurIPS)},
|
| 203 |
+
month = {December},
|
| 204 |
+
year = {2025}
|
| 205 |
+
}
|
| 206 |
+
```
|
| 207 |
+
|
| 208 |
+
---
|
| 209 |
+
|
| 210 |
+
## License
|
| 211 |
+
|
| 212 |
+
Apache 2.0. Model weights are released for non-commercial research use. See [LICENSE](LICENSE) for details.
|
| 213 |
+
|
| 214 |
+
The base architecture follows [CompVis/stable-diffusion](https://github.com/CompVis/stable-diffusion) (MIT License).
|