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:
ModuleIsotropic 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 totorch.nn.functional.pad.out_channels (
int|None(default:None)) – Number of filters. IfNone, inferred from shape ofstd.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
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:
x (
Tensor) – The input tensor, should be 4d (batch, channel, height, width).**conv2d_kwargs (
Any) – Passed totorch.nn.functional.conv2d.
- Return type:
- 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...>
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 ...>