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 toNone
.
- forward(x, y, physics, sigma, *args, **kwargs)[source]#
Returns the loss term \(\frac{\lambda}{2\sqrt{m}} \| \forw{\denoiser{x}{\sigma}} - y \|\).
- Parameters:
x (torch.Tensor) – input image
y (torch.Tensor) – measurements
physics (deepinv.physics.Physics) – forward operator
sigma (float) – standard deviation of the noise.
- Returns:
(torch.Tensor) loss term.
- Return type:
- grad(x, y, physics, sigma, *args, **kwargs)[source]#
- Parameters:
x (torch.Tensor) – Current iterate.
y (torch.Tensor) – Input data.
physics (deepinv.physics.Physics) – physics model
sigma (float) – Standard deviation of the noise.
- Returns:
(
torch.Tensor
) score term.- Return type:
Examples using DPSDataFidelity
:#

Building your diffusion posterior sampling method using SDEs