priors.ImplicitPrior#
- class bartorch.priors.ImplicitPrior#
Bases:
ModuleDenoiser in place of a regularization term’s proximal operator (plug-and-play).
The proximal step is
denoiser(x, sigma), ordenoiser(x)without asigma, independently of the solver’s step size. Unlike BART’s proximal operators it is differentiable, so a solve containing it can be differentiated end to end. The proximal solvers ofbartorch.optimtake it in place of a term.With
transform, the term is \(g(G x)\): the denoiser is applied on the codomain of \(G\), and the alternating-direction and primal-dual iterations split the variable at \(G x\), as for a BART term with a transform. This places a prior learned in another representation, such as contrast-weighted images synthesized from subspace coefficients.- Parameters:
denoiser (callable) – Called as
denoiser(x)ordenoiser(x, sigma), withstep=kadded understep. Withoutspatial,xis the complex tensor(batch, *shape), withshapethe image’s or the codomain of \(G\); withspatial, a network on real(n, channels, *spatial)tensors of order unity, such as adeepinvormonaimodel.sigma (float or sequence of float, default=None) – Noise level passed to the denoiser, in its own units. A sequence is a schedule, one per iteration, the last repeated beyond its end. Held as a frozen
torch.nn.Parameter.transform (LinearOperator, default=None) – \(G\), with domain the image; the identity when omitted.
spatial ({2, 3}, default=None) – Trailing axes the network takes; the axes in front are folded into its batch axis.
Nonepasses the complex tensor unconverted.channels ({1, 2, 3}, default=1) – Input channels of the network: 1 for grayscale, 3 for RGB (the plane is repeated and the three outputs averaged), 2 for the real and imaginary parts jointly. Only with
spatial.parts ({"channels", "separate", "magnitude"}, default=None) – Real and imaginary parts as two channels, each part denoised separately in one call, or the modulus denoised with the phase kept.
"channels"for two channels and"separate"otherwise when omitted. Only withspatial.normalize (bool, default=True) – Divide each image by its peak modulus around the call, so
sigmais relative to that peak. Only withspatial.step (bool, default=False) – Pass the iteration index to the denoiser as
step.
- Raises:
TypeError –
denoiseris not callable.ValueError –
channels,partsornormalizewithoutspatial, or an inconsistent combination of them; asigmathat is empty or not one-dimensional.
Notes
A
sigmaschedule orstep=Truemakes each iteration a different map (annealed plug-and-play, or a network shared by the iterations of an unrolled reconstruction, such asbartorch.learning.UNetwithsteps=True);bartorch.optim.FixedPointrefuses both.Examples
>>> from deepinv.models import DRUNet >>> prior = priors.ImplicitPrior(DRUNet(in_channels=1, out_channels=1), sigma=0.05, spatial=2) >>> image = optim.fista(y, A, prior) >>> priors.ImplicitPrior(denoiser, transform=linop.MultiplySum(basis, ...))
- property stationary#
no schedule and no index.
- Type:
Whether every iteration applies the same denoiser
- prox()#
Apply the denoiser to
x;gammais ignored.- Parameters:
x (tensor) – Of
prox_shape(), or with a leading batch axis.gamma (float, default=1.0) – Ignored: the denoising strength is
sigma.image_shape (tuple of int, default=None) – Image shape, which tells a single
xfrom a batch; without itxis a single item.iteration (int, default=0) – Iteration index, which selects the
sigmaof a schedule and is passed asstepunderstep=True.
- Returns:
Of
x’s shape.- Return type:
torch.Tensor
- prox_shape()#
Shape the denoiser is applied on: the image’s, or the codomain of
transform.
- apply_transform()#
Apply \(G\), \(G^H\) or \(G^H G\) to
x, recorded for autograd.The identity without
transform.- Parameters:
x (torch.Tensor) – Input of the mode, with or without a leading batch axis, applied item by item.
image_shape (tuple of int, default=None) – Image shape, checked against the domain of \(G\).
mode ({"forward", "adjoint", "normal"}, default="forward") – \(G\), \(G^H\) or \(G^H G\).
- Return type:
torch.Tensor
- transform_is_identity()#
Whether the term has no
transform.
- rewind()#
Do nothing: the term draws no random shifts.