DPS#

class deepinv.sampling.DPS(denoiser, schedule='vp', solver='ddpm', alpha=1.0, num_steps=1000, weight=1.0, guidance='norm', verbose=False, device='cpu', dtype=torch.float64, rng=None, **kwargs)[source]#

Bases: PosteriorDiffusion

Diffusion Posterior Sampling (DPS).

This class implements the Diffusion Posterior Sampling algorithm (DPS) described in Chung et al.[1].

DPS is an approximation of a gradient-based posterior sampling algorithm, which has minimal assumptions on the forward model. The only restriction is that the measurement model has to be differentiable, which is generally the case.

The algorithm solves the reverse-time SDE specified by the schedule argument, using the solver specified by the solver argument, and approximating the conditional score by the DPS data fidelity term, which is defined as follows:

\[\nabla_{x_t} \log p_t(y|x_t) \approx -\lambda \nabla_{x_t} \|y - A D_{\sigma_t}(x_t)\|\]

where \(\denoiser{\cdot}{\sigma}\) is a denoising network for noise level \(\sigma\), and \(\lambda\) is a hyperparameter that controls the weight of the data fidelity term in the approximation of the likelihood gradient.

Note

This method inherits from the general posterior sampling framework deepinv.sampling.PosteriorDiffusion, using the DPS data fidelity deepinv.sampling.DPSDataFidelity. It can be coupled with any denoiser, SDE and solver, which allows for a wide range of sampling algorithms. The default parameters correspond to the original DPS algorithm in Chung et al. [29].

Please refer to the example Building your diffusion posterior sampling method using SDEs for more examples on diffusion-based sampling methods.

Parameters:
  • denoiser (deepinv.models.Denoiser) – a denoiser network that can handle different noise levels

  • schedule (str) – the noise schedule to use, either "vp" (default, which matches the original implementation) for the variance preserving noise schedule, or "ve" for the variance exploding noise schedule.

  • solver (str, deepinv.sampling.BaseSDESolver) –

    the solver of the reverse-time SDE, either a solver instance, or one of:

    The alpha of the SDE is ignored by "ddpm" and "ddim". A solver instance is used as is, with its own time steps and random number generator, so that num_steps and rng are then ignored.

  • num_steps (int) – the number of time steps of the solver (default: 1000)

  • alpha (Callable, float) – the weight of the noise in the reverse-time SDE, possibly time-dependent, see deepinv.sampling.DiffusionSDE. Default to 1.0, which corresponds to the original DDPM sampling scheme. Setting it to 0 corresponds to the deterministic DDIM sampling scheme. Intermediate values differ from the parameter \(\eta\) of DDIM, see deepinv.sampling.AncestralSolver for the exact relation.

  • weight (float) – the weight of the data fidelity term in the approximation of the likelihood gradient. Default to 1.0.

  • guidance (str) – the form of the guidance, passed to deepinv.sampling.DPSDataFidelity. "norm" (default) differentiates the residual norm, as in the original paper; "annealed" differentiates the Gaussian negative log-likelihood with the annealed variance \(\sigma_y^2 + \sigma_t^2\), which puts weight on the same scale as the other noisy data-fidelity terms.

  • verbose (bool) – if True, print the progress of the algorithm

  • device (str) – the device to use for the computations

Tip

For few steps sampling (e.g. num_steps < 50), the ancestral solvers ("ancestral", "ddpm" or "ddim") are recommended over "euler". For many steps sampling, all solvers give similar results.


References:

Examples using DPS:#

DPS – Posterior Sampling with Diffusion Models

DPS -- Posterior Sampling with Diffusion Models