DecomposablePhysics

class deepinv.physics.DecomposablePhysics(U=<function DecomposablePhysics.<lambda>>, U_adjoint=<function DecomposablePhysics.<lambda>>, V=<function DecomposablePhysics.<lambda>>, V_adjoint=<function DecomposablePhysics.<lambda>>, mask=1.0, **kwargs)[source]

Bases: LinearPhysics

Parent class for linear operators with SVD decomposition.

The singular value decomposition is expressed as

\[A = U\text{diag}(s)V^{\top} \in \mathbb{R}^{m\times n}\]

where \(U\in\mathbb{C}^{n\times n}\) and \(V\in\mathbb{C}^{m\times m}\) are orthonormal linear transformations and \(s\in\mathbb{R}_{+}^{n}\) are the singular values.

Parameters:
  • U (Callable) – orthonormal transformation

  • U_adjoint (Callable) – transpose of U

  • V (Callable) – orthonormal transformation

  • V_adjoint (Callable) – transpose of V

  • params (torch.nn.Parameter, float) – Singular values of the transform


Examples:

Recreation of the Inpainting operator using the DecomposablePhysics class:

>>> from deepinv.physics import DecomposablePhysics
>>> seed = torch.manual_seed(0)  # Random seed for reproducibility
>>> tensor_size = (1, 1, 3, 3)  # Input size
>>> mask = torch.tensor([[1, 0, 1], [1, 0, 1], [1, 0, 1]])  # Binary mask
>>> U = lambda x: x  # U is the identity operation
>>> U_adjoint = lambda x: x  # U_adjoint is the identity operation
>>> V = lambda x: x  # V is the identity operation
>>> V_adjoint = lambda x: x  # V_adjoint is the identity operation
>>> mask_svd = mask.float().unsqueeze(0).unsqueeze(0)  # Convert the mask to torch.Tensor and adjust its dimensions
>>> physics = DecomposablePhysics(U=U, U_adjoint=U_adjoint, V=V, V_adjoint=V_adjoint, mask=mask_svd)

Apply the operator to a random tensor:

>>> x = torch.randn(tensor_size)
>>> with torch.no_grad():
...     physics.A(x)  # Apply the masking
tensor([[[[ 1.5410, -0.0000, -2.1788],
          [ 0.5684, -0.0000, -1.3986],
          [ 0.4033,  0.0000, -0.7193]]]])
A(x, mask=None, **kwargs)[source]

Applies the forward operator \(y = A(x)\).

If a mask/singular values is provided, it is used to apply the forward operator, and also stored as the current mask/singular values.

Parameters:
  • x (torch.Tensor) – input tensor

  • mask (torch.nn.Parameter, float) – singular values.

Returns:

(torch.Tensor) output tensor

A_A_adjoint(y, mask=None, **kwargs)[source]

A helper function that computes \(A A^{\top}y\).

Using the SVD decomposition, we have \(A A^{\top} = U\text{diag}(s^2)U^{\top}\).

Parameters:

y (torch.Tensor) – measurement.

Returns:

(torch.Tensor) the product \(AA^{\top}y\).

A_adjoint(y, mask=None, **kwargs)[source]

Computes the adjoint of the forward operator \(\tilde{x} = A^{\top}y\).

If a mask/singular values is provided, it is used to apply the adjoint operator, and also stored as the current mask/singular values.

Parameters:
  • y (torch.Tensor) – input tensor

  • mask (torch.nn.Parameter, float) – singular values.

Returns:

(torch.Tensor) output tensor

A_adjoint_A(x, mask=None, **kwargs)[source]

A helper function that computes \(A^{\top} A x\).

Using the SVD decomposition, we have \(A^{\top}A = V\text{diag}(s^2)V^{\top}\).

Parameters:

x (torch.Tensor) – signal/image.

Returns:

(torch.Tensor) the product \(A^{\top}Ax\).

A_dagger(y, mask=None, **kwargs)[source]

Computes \(A^{\dagger}y = x\) in an efficient manner leveraging the singular vector decomposition.

Parameters:

y (torch.Tensor) – a measurement \(y\) to reconstruct via the pseudoinverse.

Returns:

(torch.Tensor) The reconstructed image \(x\).

prox_l2(z, y, gamma)[source]

Computes proximal operator of \(f(x)=\frac{\gamma}{2}\|Ax-y\|^2\) in an efficient manner leveraging the singular vector decomposition.

Parameters:
Returns:

(torch.Tensor) estimated signal tensor

update_parameters(**kwargs)[source]

Updates the singular values of the operator.

Examples using DecomposablePhysics:

Stacking and concatenating forward operators.

Stacking and concatenating forward operators.

Reconstructing an image using the deep image prior.

Reconstructing an image using the deep image prior.

Creating your own dataset

Creating your own dataset

Creating a forward operator.

Creating a forward operator.

Training a reconstruction network.

Training a reconstruction network.

A tour of forward sensing operators

A tour of forward sensing operators

Image deblurring with custom deep explicit prior.

Image deblurring with custom deep explicit prior.

Saving and loading models

Saving and loading models

A tour of blur operators

A tour of blur operators

Image deblurring with Total-Variation (TV) prior

Image deblurring with Total-Variation (TV) prior

Image inpainting with wavelet prior

Image inpainting with wavelet prior

Expected Patch Log Likelihood (EPLL) for Denoising and Inpainting

Expected Patch Log Likelihood (EPLL) for Denoising and Inpainting

Patch priors for limited-angle computed tomography

Patch priors for limited-angle computed tomography

DPIR method for PnP image deblurring.

DPIR method for PnP image deblurring.

PnP with custom optimization algorithm (Condat-Vu Primal-Dual)

PnP with custom optimization algorithm (Condat-Vu Primal-Dual)

Uncertainty quantification with PnP-ULA.

Uncertainty quantification with PnP-ULA.

Image reconstruction with a diffusion model

Image reconstruction with a diffusion model

Building your custom sampling algorithm.

Building your custom sampling algorithm.

Implementing DPS

Implementing DPS

Implementing DiffPIR

Implementing DiffPIR

Image transformations for Equivariant Imaging

Image transformations for Equivariant Imaging

Self-supervised MRI reconstruction with Artifact2Artifact

Self-supervised MRI reconstruction with Artifact2Artifact

Self-supervised denoising with the UNSURE loss.

Self-supervised denoising with the UNSURE loss.

Self-supervised denoising with the SURE loss.

Self-supervised denoising with the SURE loss.

Self-supervised denoising with the Neighbor2Neighbor loss.

Self-supervised denoising with the Neighbor2Neighbor loss.

Self-supervised learning with Equivariant Imaging for MRI.

Self-supervised learning with Equivariant Imaging for MRI.

Self-supervised learning from incomplete measurements of multiple operators.

Self-supervised learning from incomplete measurements of multiple operators.

Deep Equilibrium (DEQ) algorithms for image deblurring

Deep Equilibrium (DEQ) algorithms for image deblurring

Unfolded Chambolle-Pock for constrained image inpainting

Unfolded Chambolle-Pock for constrained image inpainting