MCPcopy Index your code
hub / github.com/Qiukunpeng/Siamese-Diffusion

github.com/Qiukunpeng/Siamese-Diffusion @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
647 symbols 1,709 edges 54 files 155 documented · 24%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Noise-Consistent Siamese-Diffusion for Medical Image Synthesis and Segmentation

arXiv Hugging Face GitHub Repo stars

🚀 Practical Examples

Polyp Images Comparison

▶ Click to expand more comparison: Polyp Images

Polyp Example

▶ Click to expand comparison: ISIC2016 Images

ISIC2016 Example

▶ Click to expand comparison: ISIC2018 Images

ISIC2018 Example

📥 Download

We provide the model weights and synthesized datasets (Polyps) on Hugging Face.

Resource Description Link
Model Weights Checkpoints for Siamese-Diffusion (Polyps) 🤗 Hugging Face
Datasets Synthesized Polyps Images 🤗 Hugging Face

🛠️ Requirements

The usual installation steps involve the following commands, they should set up the correct CUDA version and all the python packages:

conda create -n Siamese-Diffusion python=3.10
conda activate  Siamese-Diffusion
conda install pytorch==2.4.0 torchvision==0.19.0  pytorch-cuda=11.8 -c pytorch -c nvidia
pip install -U xformers --index-url https://download.pytorch.org/whl/cu118
pip install deepspeed

🗂️ Data and Structure

We evaluated our method on three public datasets: Polyps (as provided by the PraNet project), ISIC2016, and ISIC2018.

--data
  --images
  --masks
  --prompt.json

🏋️‍♂️ Training

💡 Note: All improvements have been integrated into cldm.py, and the DHI module is implemented in dhi.py. Both are located within the cldm folder.

🔥 Recommendation

The DHI module is a plug-and-play enhancement recommended for all ControlNet-based setups.

It significantly accelerates convergence for datasets with large domain gaps from pretrained data, such as:

  • Medical segmentation images
  • Anomaly detection images
  • ...

Especially effective when jointly fine-tuning the Stable Diffusion UNet decoder.

Here are example commands for training:

# Initialize ControlNet with the pretrained UNet encoder weights from Stable Diffusion,  
# then merge them with Stable Diffusion weights and save as: control_sd15.ckpt  
python tool_add_control.py

# For multi-GPU setups, ZeRO-2 can be used to train Siamese-Diffusion  
# to reduce memory consumption.  
python tutorial_train.py

🎨 Sampling

Here are example commands for sampling:

# ZeRO-2 distributed weights are saved under the folder:  
# lightning_logs/version_#/checkpoints/epoch/  
# Run the following commands to merge the weights:  
python zero_to_fp32.py . pytorch_model.bin  
python tool_merge_control.py

# Sampling
python tutorial_inference.py

🖼️ Visualization Results of Ablation Study

Ablation Study Visualization

▶ Click to expand more ablation results: Polyp Images

Polyp Example

📣 Acknowledgements

This code is developed based on ControlNet and incorporates several segmentation models, including SANet, Polyp-PVT, and CTNet.

📖 Citation

If you find our work useful in your research or if you use parts of this code, please consider citing our paper:

@article{qiu2025noise,
  title={Noise-Consistent Siamese-Diffusion for Medical Image Synthesis and Segmentation},
  author={Qiu, Kunpeng and Gao, Zhiqiang and Zhou, Zhiying and Sun, Mingjie and Guo, Yongxin},
  journal={arXiv preprint arXiv:2505.06068},
  year={2025}
}

@article{qiu2025adaptively,
  title={Adaptively Distilled ControlNet: Accelerated Training and Superior Sampling for Medical Image Synthesis},
  author={Qiu, Kunpeng and Zhou, Zhiying and Guo, Yongxin},
  journal={arXiv preprint arXiv:2507.23652},
  year={2025}
}

Core symbols most depended-on inside this repo

expand_dims
called by 78
ldm/models/diffusion/dpm_solver/dpm_solver.py
register_buffer
called by 43
ldm/models/diffusion/ddim.py
extract_into_tensor
called by 25
ldm/modules/diffusionmodules/util.py
conv_nd
called by 24
ldm/modules/diffusionmodules/util.py
exists
called by 21
ldm/util.py
marginal_lambda
called by 19
ldm/models/diffusion/dpm_solver/dpm_solver.py
decode_first_stage
called by 18
ldm/models/diffusion/ddpm.py
marginal_std
called by 18
ldm/models/diffusion/dpm_solver/dpm_solver.py

Shape

Method 351
Function 199
Class 97

Languages

Python100%

Modules by API surface

ldm/models/diffusion/ddpm.py87 symbols
ldm/modules/diffusionmodules/model.py52 symbols
ldm/modules/image_degradation/utils_image.py50 symbols
ldm/modules/diffusionmodules/openaimodel.py40 symbols
ldm/modules/encoders/modules.py31 symbols
ldm/models/diffusion/dpm_solver/dpm_solver.py31 symbols
ldm/modules/attention.py29 symbols
ldm/modules/midas/midas/vit.py25 symbols
ldm/modules/image_degradation/bsrgan.py25 symbols
ldm/modules/diffusionmodules/util.py25 symbols
ldm/modules/image_degradation/bsrgan_light.py24 symbols
ldm/models/autoencoder.py22 symbols

For agents

$ claude mcp add Siamese-Diffusion \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page