PatchPrior#

class deepinv.optim.PatchPrior(negative_patch_log_likelihood, n_patches=-1, patch_size=6, pad=False, *args, **kwargs)[source]#

Bases: Prior

Patch prior \(g(x) = \sum_i h(P_i x)\) for some prior \(h(x)\) on the space of patches.

Given a negative log likelihood (NLL) function on the patch space, this builds a prior by summing the NLLs of all (overlapping) patches in the image.

Parameters:
  • negative_patch_log_likelihood (Callable) – NLL function on the patch space

  • n_patches (int) – number of randomly selected patches for prior evaluation. -1 for taking all patches

  • patch_size (int) – size of the patches

  • pad (bool | str) – whether to use padding on the boundary to avoid undesired boundary effects. If pad is a string, it should be a valid padding mode for torch.nn.functional.pad (e.g. “reflect”, “constant”, etc.). If pad is True, the padding mode is set to “reflect”. Default is False.

fn(x, *args, **kwargs)[source]#

Computes the regularizer

\[\reg{x} = \sum_i h(P_i x)\]

for some prior \(h(x)\) on the space of patches, where \(P_i\) is the operator extracting the \(i\)-th patch from the image.

Parameters:

x (torch.Tensor) – Variable \(x\) at which the prior is computed.

Returns:

(torch.Tensor) prior \(g(x)\).

Return type:

Tensor

Examples using PatchPrior:#

Patch priors for limited-angle computed tomography

Patch priors for limited-angle computed tomography