Skip to content

About

Unofficial reimplementation of Parallel Diffusion Models (PDM) for sparse-sampling photoacoustic microscopy (Optics Express 2024).

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Parallel Diffusion Models

Jie Wu et al., Parallel diffusion models promote high detail-fidelity photoacoustic microscopy in sparse sampling, Optics Express 32(16): 27574–27590 (2024). 10.1364/OE.528474, publisher page.

Noise task and Image task are trained in parallel with $L = L_{\mathrm{Noise}} + \gamma L_{\mathrm{Image}}$ and $\gamma=0.02$.

Method

PDM maps a sparsely sampled PAM image $x$ to a fully sampled image $y\sim p(y|x)$. Two tasks are trained in parallel:

  1. Noise task: predict noise with the variational lower bound / $L_{\mathrm{simple}}$ $\ell_2$ objective (Eq. 12).
  2. Image task: recover $\tilde{y}0$ from the predicted noise (Eq. 14), then $L{\mathrm{Image}}=1-\mathrm{SSIM}(y_0,\tilde{y}_0)$ (Eq. 16).

$$ \tilde{y}_0 = \frac{y_t - \sqrt{1-\bar{\alpha}_t},\epsilon_\theta(x,y_t,\bar{\alpha})}{\sqrt{\bar{\alpha}_t}} $$

$$ L = L_{\mathrm{Noise}} + \gamma L_{\mathrm{Image}},\quad \gamma=0.02 $$

Sparse sampling (Sec. 4.1)

High-speed PAM is simulated with step sizes of 2×, 4×, and 8× in the scanning directions. Relative to full sampling this is 4×, 16×, and 64×, with effective pixels of 25%, 6.25%, and 1.5625%.

sparse_step in the config is that scanning step (2 / 4 / 8): keep every sparse_step pixel on both scan axes, then restore the condition image $x$ to $128\times128$.

Setting Scan step Speed-up Effective pixels Config
4× high-speed 2 4× 25% configs/pdm_pam_4x.json (sparse_step=2)
16× high-speed 4 16× 6.25% configs/pdm_pam_16x.json (sparse_step=4)
64× high-speed 8 64× 1.5625% configs/pdm_pam_64x.json (sparse_step=8)

The JSON files use the paper setup: $T=1000$, $\gamma=0.02$, quad variance in $[10^{-6},10^{-2}]$, U-Net channel ratio [1,2,4,8], self-attention at $32\times32$, Adam $1\times10^{-4}$, batch size 16, $128\times128$ grayscale, Kaiming init. Main run is -c configs/pdm_pam_16x.json. Noise-task-only ablation is --gamma 0. Reverse sampling is $T=1000$ unless --sample_steps is set. upsample_mode (nearest / bicubic / zero) interpolates the condition image; default nearest.

Installation

conda env create -f environment.yml
conda activate pdm

If the conda env already has PyTorch:

pip install -r requirements.txt

Data

Request training and test data from tracy_wufz@163.com.

Public mouse-brain PAM patches (Duke, $128\times128$, used for pre-training): Zenodo 10.5281/zenodo.4042171, axd465/pam_dataset.

python scripts/prepare_data.py --input /path/to/duke_patches --output data --ratio 8:1:1
data/train/*.png
data/val/*.png
data/test/*.png

Training uses fully sampled images. Sparse sampling is applied at runtime from sparse_step.

Train

python scripts/train.py -c configs/pdm_pam_16x.json --train_hr data/train --val_hr data/val
python scripts/train.py -c configs/pdm_pam_4x.json
python scripts/train.py -c configs/pdm_pam_64x.json
python scripts/train.py -c configs/pdm_pam_16x.json --gamma 0

Checkpoints: experiments/<name>/checkpoint/.

Inference

python scripts/infer.py -c configs/pdm_pam_16x.json --ckpt experiments/pdm_pam_16x/checkpoint/latest.pt --input path/to/hr.png --output results/pred.png --from_hr
python scripts/infer.py -c configs/pdm_pam_16x.json --ckpt experiments/pdm_pam_16x/checkpoint/latest.pt --input path/to/sparse.png --output results/pred.png
python scripts/eval_metrics.py --pred results/pred_dir --gt data/test

--from_hr: fully sampled input, sparse sampling follows sparse_step. Without it, the input is already a same-size condition image.

Baselines

Paper Table 1 / Sec. 5.1: Bicubic, UNet, FD-UNet, p2pGAN. In baselines/, --model bicubic / unet / fdunet. The folder also has SRCNN, VDSR, EDSR, FSRCNN, DRCN, SRGAN, DBPN, SubPixelCNN.

python baselines/train.py --model unet --scan_step 4 --train_hr data/train --val_hr data/val
python baselines/infer.py --model unet --scan_step 4 --ckpt experiments/unet_step4/checkpoint/latest.pt --input path/to/hr.png --output results/unet.png --from_hr
python baselines/infer.py --model bicubic --scan_step 4 --input path/to/hr.png --output results/bicubic.png --from_hr

--scan_step 2/4/8 is 4× / 16× / 64× speed-up.

Citation

@article{Wu:24,
  author  = {Jie Wu and Kaipeng Zhang and Chengeng Huang and Yuanzheng Ma and Rui Ma and Xin Chen and Ting Guo and Sihua Yang and Zhen Yuan and Zhenhui Zhang},
  title   = {Parallel diffusion models promote high detail-fidelity photoacoustic microscopy in sparse sampling},
  journal = {Opt. Express},
  volume  = {32},
  number  = {16},
  pages   = {27574--27590},
  year    = {2024},
  doi     = {10.1364/OE.528474}
}

License

Apache License 2.0 (LICENSE, NOTICE). Paper © 2024 Optica Publishing Group.

About

Unofficial reimplementation of Parallel Diffusion Models (PDM) for sparse-sampling photoacoustic microscopy (Optics Express 2024).

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages