plenoptic.models.Gaussian#

Note

This object is a torch.nn.Module. It therefore has all the methods and attributes from that class, even though they are not documented here (to avoid cluttering this page).

class plenoptic.models.Gaussian(kernel_size, std=3.0, pad_mode='reflect', out_channels=None, cache_filt=False)[source]#

Bases: Module

Isotropic Gaussian convolutional filter.

Kernel elements are normalized and sum to one.

Parameters:
  • kernel_size (int | tuple[int, int]) – Size of convolutional kernel.

  • std (int | list[int] | float | list[float] | Tensor (default: 3.0)) – Standard deviation of circularly symmetric Gaussian kernel.

  • pad_mode (str (default: 'reflect')) – Padding mode argument to pass to torch.nn.functional.pad.

  • out_channels (int | None (default: None)) – Number of filters. If None, inferred from shape of std.

  • cache_filt (bool (default: False)) – Whether or not to cache the filter. Avoids regenerating filt with each forward pass.

Raises:
  • ValueError – If out_channels is not a positive integer.

  • ValueError – If kernel_size is not a positive integer.

  • ValueError – If std is not positive.

  • ValueError – If std is non-scalar and len(std) != out_channels

Examples

>>> import plenoptic as po
>>> gaussian_model = po.models.Gaussian(kernel_size=10)
>>> gaussian_model
Gaussian()

Methods

forward(x, **conv2d_kwargs)

Convolve Gaussian filter with input tensor.

Attributes

filt

Gaussian filter(s).

forward(x, **conv2d_kwargs)[source]#

Convolve Gaussian filter with input tensor.

We use same-padding to ensure that the output and input shapes are matched.

Parameters:
Return type:

Tensor

Returns:

y – A linear convolution of the input image, of same shape as the input.

Examples

>>> import plenoptic as po
>>> gaussian_model = po.models.Gaussian(kernel_size=10)
>>> img = po.data.curie()
>>> y = gaussian_model.forward(img)
>>> po.plot.imshow([img, y], title=["Input image", "Output"])
<PyrFigure size...>

(png, hires.png, pdf)

../../_images/plenoptic-models-Gaussian-1.png

Multiple output channels with different standard deviations.

>>> import plenoptic as po
>>> gaussian_model = po.models.Gaussian(
...     kernel_size=10, std=[2, 5], out_channels=2
... )
>>> img = po.data.curie()
>>> y = gaussian_model.forward(img)
>>> po.plot.imshow(
...     [img, y],
...     title=["Input image", "Output Channel 0", "Output Channel 1"],
... )
<PyrFigure ...>

(png, hires.png, pdf)

../../_images/plenoptic-models-Gaussian-2.png
property filt: Tensor#

Gaussian filter(s).