DPSDataFidelity#

class deepinv.sampling.DPSDataFidelity(denoiser=None, weight=1.0, clip=None, *args, **kwargs)[source]#

Bases: NoisyDataFidelity

Diffusion posterior sampling data-fidelity term.

This corresponds to the \(p(y|x_t)\) approximation proposed in Diffusion Posterior Sampling for General Noisy Inverse Problems.

\[\begin{aligned} \nabla_x \log p_t(y|x) &= \nabla_x \frac{\lambda}{2\sqrt{m}} \| \forw{\denoiser{x}{\sigma}} - y \| \end{aligned}\]

where \(\sigma = \sigma(t)\) is the noise level, \(m\) is the number of measurements (size of \(y\)), and \(\lambda\) controls the strength of the approximation.

See also

This class can be used for building custom DPS-based diffusion models. A self-contained implementation of the original DPS algorithm can be find in deepinv.sampling.DPS.

Parameters:
  • denoiser (deepinv.models.Denoiser) – Denoiser network

  • weight (float) – Weighting factor for the data fidelity term. Default to 100.

  • clip (tuple[float]) – If not None, clip the denoised output into [clip[0], clip[1]] interval. Default to None.

forward(x, y, physics, sigma, *args, **kwargs)[source]#

Returns the loss term \(\frac{\lambda}{2\sqrt{m}} \| \forw{\denoiser{x}{\sigma}} - y \|\).

Parameters:
Returns:

(torch.Tensor) loss term.

Return type:

Tensor

grad(x, y, physics, sigma, *args, **kwargs)[source]#
Parameters:
Returns:

(torch.Tensor) score term.

Return type:

Tensor

Examples using DPSDataFidelity:#

Building your diffusion posterior sampling method using SDEs

Building your diffusion posterior sampling method using SDEs