Utils

Training and Testing

Training a reconstruction model can be done using the Trainer class, which can be easily customized to fit your needs.

deepinv.Trainer

Trainer class for training a reconstruction network.

We also provide train and test functions that can be used to train and test a model with a single call.

deepinv.train

Alias function for training a model using deepinv.training_utils.Trainer class.

deepinv.test

Tests a reconstruction model (algorithm or network).

Plotting

We provide some basic plotting functions that are adapted to inverse problems.

deepinv.utils.plot

Plots a list of images.

deepinv.utils.plot_curves

Plots the metrics of a Plug-and-Play algorithm.

deepinv.utils.plot_parameters

Plot the parameters of the model before and after training.

deepinv.utils.plot_inset

Plots a list of images with zoomed-in insets extracted from the images.

TensorList

The TensorList class is a wrapper around a list of tensors. It can be used to represent signals or measurements that are naturally better represented as a list of tensors of different sizes, rather than a single tensor. TensorLists can be added, multiplied by a scalar, concatenated, etc., in a similar fashion to torch.tensor.

deepinv.utils.TensorList

Represents a list of torch.Tensor with different shapes.

We also provide functions to quickly create TensorLists of zeros, ones, or random values.

deepinv.utils.zeros_like

Returns a deepinv.utils.TensorList or torch.Tensor with the same type as x, filled with zeros.

deepinv.utils.ones_like

Returns a deepinv.utils.TensorList or torch.Tensor with the same type as x, filled with ones.

deepinv.utils.randn_like

Returns a deepinv.utils.TensorList or torch.Tensor with the same type as x, filled with standard gaussian numbers.

deepinv.utils.rand_like

Returns a deepinv.utils.TensorList or torch.Tensor with the same type as x, filled with random uniform numbers in [0,1].

Other

deepinv.utils.cal_psnr

Computes the peak signal-to-noise ratio (PSNR)

deepinv.utils.get_freer_gpu

Returns the GPU device with the most free memory.

deepinv.utils.load_url_image

Load an image from a URL and return a torch.Tensor.