Implements filters used by models.

class anomalib.models.components.filters.GaussianBlur2d(sigma: float | tuple[float, float], channels: int = 1, kernel_size: int | tuple[int, int] | None = None, normalize: bool = True, border_type: str = 'reflect', padding: str = 'same')[source]

Bases: Module

Compute GaussianBlur in 2d.

Makes use of kornia functions, but most notably the kernel is not computed during the forward pass, and does not depend on the input size. As a caveat, the number of channels that are expected have to be provided during initialization.

Initialize model, setup kernel etc..

  • sigma (float | tuple[float, float]) – standard deviation to use for constructing the Gaussian kernel.

  • channels (int) – channels of the input. Defaults to 1.

  • kernel_size (int | tuple[int, int] | None) – size of the Gaussian kernel to use. Defaults to None.

  • normalize (bool, optional) – Whether to normalize the kernel or not (i.e. all elements sum to 1). Defaults to True.

  • border_type (str, optional) – Border type to use for padding of the input. Defaults to “reflect”.

  • padding (str, optional) – Type of padding to apply. Defaults to “same”.

forward(input_tensor: Tensor) Tensor[source]

Blur the input with the computed Gaussian.


input_tensor (Tensor) – Input tensor to be blurred.


Blurred output tensor.

Return type:


training: bool