Skip to content

ai-med/SBDM

Repository files navigation

BBDM process

Spherical Brownian Bridge Diffusion Model (SBDM)

A PyTorch implementation of a diffusion model for conditional cortical thickness forecasting using spherical convolutions and Brownian bridge processes.

Paper

Spherical Brownian Bridge Diffusion Models for Conditional Cortical Thickness Forecasting

Ivan Stoyanov*, Fabian Bongratz*, Christian Wachinger

*Equal contribution

Overview

This repository contains the implementation of a Spherical Brownian Bridge Diffusion Model (SBDM) designed for longitudinal cortical surface analysis. The model learns to predict cortical morphology changes between baseline and follow-up scans using:

  • Spherical Convolutions: Adapted for cortical surface processing using icosahedral meshes
  • Brownian Bridge Process: A diffusion process that bridges between baseline and follow-up states
  • Conditional Generation: Incorporates demographic and clinical variables (age, sex, diagnosis)
  • Longitudinal Analysis: Handles multiple time points and temporal dependencies

Note: This implementation is adapted from the original BBDM (Brownian Bridge Diffusion Models) for image-to-image translation by Li et al. (2023). The original paper can be found at: https://arxiv.org/abs/2205.07680

Features

  • 🧠 Cortical Surface Processing: Specialized for brain cortical surface data
  • 🔄 Longitudinal Modeling: Predicts morphology changes over time
  • 🎯 Conditional Generation: Incorporates clinical and demographic variables
  • 📊 Comprehensive Evaluation: Multiple loss functions and evaluation metrics
  • ⚙️ Configurable: Flexible configuration system using Hydra
  • 🚀 Scalable: Supports distributed training with Accelerate

Installation

Prerequisites

  • Python 3.8+
  • PyTorch 1.12+
  • CUDA 11.3+ (for GPU acceleration)

Setup

Option 1: Automated Installation (Recommended)

  1. Clone the repository:
git clone https://github.com/ai-med/SBDM.git
cd SBDM
  1. Run the installation script:
# On Linux/macOS:
./install.sh

# On Windows:
install.bat

Option 2: Manual Installation

  1. Clone the repository:
git clone <repository-url>
cd SBDM
  1. Create a conda environment:
conda env create -f environment.yml
conda activate sbdm
  1. Install the package:
pip install -e .

Option 3: Minimal Installation

For a minimal installation with just the core dependencies:

pip install -r requirements-minimal.txt

Additional Setup

Install SphericalUNet (if not available):

# Follow instructions from https://github.com/Deep-MI/SphericalUNetPackage

Quick Start

Basic Training

python train.py

Training with Custom Configuration

python train.py data=your_data_config model=your_model_config train.batch_size=32

Training with Weights & Biases Logging

python train.py use_wandb=true wandb.project=your_project_name

Configuration

The project uses Hydra for configuration management. Key configuration files are located in the configs/ directory:

Data Configuration (configs/data/)

# Example: configs/data/adni_thickness.yaml
split_files:
  train: "data/ADNI/train.feather"
  val: "data/ADNI/val.feather"
  test: "data/ADNI/test.feather"

morph_scaler_path: "data/scalers/thickness_scaler.pkl"
age_scaler_path: "data/scalers/age_scaler.pkl"

template_ico: 4
morph: thickness

Model Configuration (configs/model/)

# Example: configs/model/bbdm_sphere_condition.yaml
architecture:
  type: ConditionalSphericalUNet
  dim: 64
  ico_order_in: 4
  dim_mults: [1, 2, 4, 8]

diffusion:
  seq_length: 2562
  num_timesteps: 1000
  objective: grad
  loss_type: l2

Data Format

Input Data

The model expects data in the following format:

  • Feather files: Containing cortical thickness and metadata
  • Required columns:
    • PTID: Subject identifier
    • IMAGEUID: Scan identifier
    • AGE: Age at scan
    • PTGENDER: Sex (Male/Female)
    • DX: Diagnosis (CN/MCI/Dementia)
    • Month: Follow-up month
    • Cortical thickness: Last N columns (where N = number of vertices)

Data Structure

data/
├── ADNI/
│   ├── train.feather
│   ├── val.feather
│   └── test.feather
├── scalers/
│   ├── thickness_scaler.pkl
│   └── age_scaler.pkl
└── templates/
    └── sphericalunet/
        ├── ico_0.ply
        ├── ico_1.ply
        └── ...

Model Architecture

Spherical UNet

The core architecture is a U-Net adapted for spherical data:

  • Spherical Convolutions: 1-ring convolutions on icosahedral meshes
  • Spherical Pooling: Hierarchical downsampling preserving mesh structure
  • Cross-Attention: Attention mechanisms for conditioning
  • Residual Blocks: Skip connections for stable training

Brownian Bridge Process

The diffusion process bridges between baseline and follow-up states:

  • Forward Process: Adds noise according to a Brownian bridge schedule
  • Reverse Process: Denoises to predict morphology changes
  • Conditioning: Incorporates demographic and clinical variables

Training

Training Loop

The training process includes:

  1. Data Loading: Longitudinal cortical surface data
  2. Forward Diffusion: Add noise to ground truth changes
  3. Model Prediction: Predict the noise/objective
  4. Loss Computation: L1/L2 loss with optional masking
  5. Optimization: Adam optimizer with learning rate scheduling

Key Parameters

  • batch_size: Training batch size (default: 64)
  • learning_rate: Learning rate (default: 1e-4)
  • num_steps: Number of training steps (default: 2000)
  • num_timesteps: Diffusion timesteps (default: 1000)
  • objective: Training objective ('grad', 'noise', 'ysubx')

Evaluation

Metrics

  • L1 Loss: Mean absolute error
  • L2 Loss: Mean squared error
  • Region-wise Loss: Per-cortical-region evaluation
  • Longitudinal Consistency: Temporal coherence metrics

Evaluation Script

python evaluate.py --checkpoint path/to/checkpoint.pt --data configs/data/test.yaml

Results

The model outputs:

  • Predicted Changes: Cortical morphology changes over time
  • Uncertainty Estimates: Confidence in predictions
  • Visualizations: Surface maps and statistical plots

File Structure

SBDM/
├── src/                    # Source code
│   ├── data/              # Data loading and preprocessing
│   ├── models/            # Model architectures
│   └── utils/             # Utility functions
├── configs/               # Configuration files
│   ├── data/              # Data configurations
│   └── model/             # Model configurations
├── train.py               # Training script
├── evaluate.py            # Evaluation script
├── requirements.txt       # Python dependencies
├── environment.yml        # Conda environment
└── README.md             # This file

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Acknowledgments

This work builds upon several open-source projects and datasets:

  • BBDM: Original Brownian Bridge Diffusion Models implementation by Li et al. (2023)
  • SphericalUNet: Spherical convolution operations from SphericalUNetPackage by Zhao et al. (2019)
  • Denoising Diffusion Probabilistic Models (DDPM): For the diffusion framework
  • ADNI dataset: For cortical surface data

Citation

If you use this work in your research, please cite our paper:

@article{stoyanov2025sbdm,
  title={Spherical Brownian Bridge Diffusion Models for Conditional Cortical Thickness Forecasting},
  author={Stoyanov, Ivan and Bongratz, Fabian and Wachinger, Christian},
  journal={arXiv preprint arXiv:2509.08442},
  year={2025}
}

Please also cite the foundational works that this research builds upon:

@article{li2023bbdm,
  title={BBDM: Image-to-image translation with Brownian bridge diffusion models},
  author={Li, Bo and Xue, Kaitao and Liu, Bin and Lai, Yu-Kun},
  booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  pages={1952--1961},
  year={2023}
}
@article{zhao2019spherical,
  title={Spherical U-Net on Cortical Surfaces: Methods and Applications},
  author={Zhao, Fenqiang and Xia, Shunren and Wu, Zhengwang and Duan, Dingna and Wang, Li and Lin, Weili and Gilmore, John H and Shen, Dinggang and Li, Gang},
  journal={arXiv preprint arXiv:1904.00906},
  year={2019}
}

Troubleshooting

Common Issues

  1. SphericalUNet Import Error: Ensure the SphericalUNet package is properly installed
  2. CUDA Out of Memory: Reduce batch size or use gradient accumulation
  3. Data Loading Issues: Check file paths and data format
  4. Template Mesh Missing: Ensure template meshes are in the correct location

Getting Help

  • Check the issues page for common problems
  • Create a new issue with detailed error messages
  • Include your configuration and system information

Changelog

Version 1.0.0

  • Initial release
  • Spherical UNet architecture
  • Brownian bridge diffusion process
  • Longitudinal cortical morphology prediction
  • Comprehensive evaluation framework

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages