GaussianNoise#

class deepinv.physics.GaussianNoise(sigma=0.1, rng=None)[source]#

Bases: NoiseModel

Gaussian noise \(y=z+\epsilon\) where \(\epsilon\sim \mathcal{N}(0,I\sigma^2)\).


Examples:

Adding gaussian noise to a physics operator by setting the noise_model attribute of the physics operator:

>>> from deepinv.physics import Denoising, GaussianNoise
>>> import torch
>>> physics = Denoising()
>>> physics.noise_model = GaussianNoise()
>>> x = torch.rand(3, 1, 2, 2)
>>> y = physics(x)

We can sum 2 GaussianNoise instances:

>>> gaussian_noise_1 = GaussianNoise(sigma=3.0)
>>> gaussian_noise_2 = GaussianNoise(sigma=4.0)
>>> gaussian_noise = gaussian_noise_1 + gaussian_noise_2
>>> y = gaussian_noise(x)
>>> gaussian_noise.sigma.item()
5.0

We can also multiply a GaussianNoise by a float:

\(scaled\_gaussian\_noise(x) = \lambda \times gaussian\_noise(x)\)
>>> scaled_gaussian_noise = 3.0 * gaussian_noise
>>> y = scaled_gaussian_noise(x)
>>> scaled_gaussian_noise.sigma.item()
15.0

We can also create a batch of GaussianNoise with different standard deviations:

\(x=[x_1, ..., x_b]\)
\(t=[[[[\lambda_1]]], ..., [[[\lambda_b]]]]\) a batch of scaling factors.
\([t \times gaussian](x) = [\lambda_1 \times gaussian(x_1), ..., \lambda_b \times gaussian(x_b)]\)
>>> t = torch.rand((x.size(0),) + (1,) * (x.dim() - 1)) # if x.shape = (b, 3, 32, 32) then t.shape = (b, 1, 1, 1)
>>> batch_gaussian_noise = t * gaussian_noise
>>> y = batch_gaussian_noise(x)
>>> assert (t[0]*gaussian_noise).sigma.item() == batch_gaussian_noise.sigma[0].item(), "Wrong standard deviation value for the first GaussianNoise."
Parameters:
  • sigma (float) – Standard deviation of the noise.

  • rng (torch.Generator) – (optional) a pseudorandom random number generator for the parameter generation.

__add__(other)[source]#

Sum of 2 gaussian noises via + operator.

\(\sigma = \sqrt{\sigma_1^2 + \sigma_2^2}\)

Parameters:

other (deepinv.physics.GaussianNoise) – Gaussian with standard deviation \(\sigma\)

Returns:

(deepinv.physics.GaussianNoise) – Gaussian noise with the sum of the linears operators.

__mul__(other)[source]#

Element-wise multiplication of a GaussianNoise via * operator.

  1. If other is a NoiseModel, then applies the multiplication from NoiseModel.

  2. If other is a float, then the standard deviation of the GaussianNoise is multiplied by other.

    \(x=[x_1, ..., x_b]\) a batch of images.
    \(\lambda\) a float.
    \(\sigma = [\lambda \times \sigma_1, ..., \lambda \times \sigma_b]\)
  3. If other is a torch.Tensor, then the standard deviation of the GaussianNoise is multiplied by other.

    \(x=[x_1, ..., x_b]\) a batch of images.
    \(other=[[[[\lambda_1]]], ..., [[[\lambda_b]]]]\) a batch of scaling factors.
    \(\sigma = [\lambda \times \sigma_1, ..., \lambda \times \sigma_b]\)
Parameters:

other (float or torch.Tensor) – Scaling factor for the GaussianNoise’s standard deviation.

Returns:

(deepinv.physics.GaussianNoise) – A new GaussianNoise with the new standard deviation.

forward(x, sigma=None, seed=None, **kwargs)[source]#

Adds the noise to measurements x

Parameters:
  • x (torch.Tensor) – measurements

  • sigma (float, torch.Tensor) – standard deviation of the noise. If not None, it will overwrite the current noise level.

  • seed (int) – the seed for the random number generator, if rng is provided.

Returns:

noisy measurements

update_parameters(sigma=None, **kwargs)[source]#

Updates the standard deviation of the noise.

Parameters:

sigma (float, torch.Tensor) – standard deviation of the noise.

Examples using GaussianNoise:#

Image deblurring with custom deep explicit prior.

Image deblurring with custom deep explicit prior.

Creating your own dataset

Creating your own dataset

Reconstructing an image using the deep image prior.

Reconstructing an image using the deep image prior.

Creating a forward operator.

Creating a forward operator.

A tour of forward sensing operators

A tour of forward sensing operators

Image transforms for equivariance & augmentations

Image transforms for equivariance & augmentations

3D wavelet denoising

3D wavelet denoising

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

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)

Regularization by Denoising (RED) for Super-Resolution.

Regularization by Denoising (RED) for Super-Resolution.

Vanilla PnP for computed tomography (CT).

Vanilla PnP for computed tomography (CT).

Building your custom MCMC sampling algorithm.

Building your custom MCMC sampling algorithm.

Image reconstruction with a diffusion model

Image reconstruction with a diffusion model

Implementing DiffPIR

Implementing DiffPIR

Uncertainty quantification with PnP-ULA.

Uncertainty quantification with PnP-ULA.

Self-supervised denoising with the Generalized R2R loss.

Self-supervised denoising with the Generalized R2R loss.

Self-supervised learning with measurement splitting

Self-supervised learning with measurement splitting

Self-supervised denoising with the UNSURE loss.

Self-supervised denoising with the UNSURE loss.

Deep Equilibrium (DEQ) algorithms for image deblurring

Deep Equilibrium (DEQ) algorithms for image deblurring

Learned Primal-Dual algorithm for CT scan.

Learned Primal-Dual algorithm for CT scan.

Vanilla Unfolded algorithm for super-resolution

Vanilla Unfolded algorithm for super-resolution