Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Kornia Kornia Blur Pool

From Leeroopedia


Knowledge Sources
Domains Vision, Image_Filtering
Last Updated 2026-02-09 15:00 GMT

Overview

Provides anti-aliased downsampling operations by combining blur (low-pass) filtering with pooling on 2D feature maps.

Description

This module is part of the Kornia library's filters subpackage. It implements blur pooling as described by Zhang (2019) for shift-invariant downsampling. The file contains three nn.Module classes (BlurPool2D, MaxBlurPool2D, EdgeAwareBlurPool2D) and their corresponding functional interfaces (blur_pool2d, max_blur_pool2d, edge_aware_blur_pool2d). BlurPool2D applies a Pascal (binomial) kernel followed by strided convolution for anti-aliased downsampling. MaxBlurPool2D combines max pooling with blur pooling. EdgeAwareBlurPool2D performs blur pooling while preserving edges using an edge-intensity threshold and dilation.

Usage

Import these classes or functions when you need to downsample feature maps or images in a shift-invariant manner, for example as a replacement for strided convolution or standard pooling in convolutional neural networks.

Code Reference

Source Location

Signature

class BlurPool2D(nn.Module):
    def __init__(self, kernel_size: tuple[int, int] | int, stride: int = 2) -> None: ...
    def forward(self, input: torch.Tensor) -> torch.Tensor: ...

class MaxBlurPool2D(nn.Module):
    def __init__(self, kernel_size: tuple[int, int] | int, stride: int = 2,
                 max_pool_size: int = 2, ceil_mode: bool = False) -> None: ...
    def forward(self, input: torch.Tensor) -> torch.Tensor: ...

class EdgeAwareBlurPool2D(nn.Module):
    def __init__(self, kernel_size: tuple[int, int] | int,
                 edge_threshold: float = 1.25,
                 edge_dilation_kernel_size: int = 3) -> None: ...
    def forward(self, input: torch.Tensor, epsilon: float = 1e-6) -> torch.Tensor: ...

def blur_pool2d(input: torch.Tensor, kernel_size: tuple[int, int] | int,
                stride: int = 2) -> torch.Tensor: ...

def max_blur_pool2d(input: torch.Tensor, kernel_size: tuple[int, int] | int,
                    stride: int = 2, max_pool_size: int = 2,
                    ceil_mode: bool = False) -> torch.Tensor: ...

def edge_aware_blur_pool2d(input: torch.Tensor, kernel_size: tuple[int, int] | int,
                           edge_threshold: float = 1.25,
                           edge_dilation_kernel_size: int = 3,
                           epsilon: float = 1e-6) -> torch.Tensor: ...

Import

from kornia.filters import blur_pool2d, max_blur_pool2d, edge_aware_blur_pool2d
from kornia.filters import BlurPool2D, MaxBlurPool2D, EdgeAwareBlurPool2D

I/O Contract

Inputs (blur_pool2d)

Name Type Required Description
input torch.Tensor (B, C, H, W) Yes The input feature map to blur and downsample.
kernel_size tuple[int, int] or int Yes Size of the Pascal (binomial) blur kernel.
stride int No (default 2) Stride for the downsampling convolution.

Inputs (max_blur_pool2d)

Name Type Required Description
input torch.Tensor (B, C, H, W) Yes The input feature map.
kernel_size tuple[int, int] or int Yes Size of the blur kernel.
stride int No (default 2) Stride for pooling.
max_pool_size int No (default 2) Kernel size for max pooling applied before blur.
ceil_mode bool No (default False) Whether to use ceil mode in max pooling.

Inputs (edge_aware_blur_pool2d)

Name Type Required Description
input torch.Tensor (B, C, H, W) Yes The input image to blur while preserving edges.
kernel_size tuple[int, int] or int Yes Size of the Gaussian blur kernel.
edge_threshold float No (default 1.25) Positive threshold for edge detection.
edge_dilation_kernel_size int No (default 3) Kernel size for dilating the edge map.
epsilon float No (default 1e-6) Small value for numerical stability.

Outputs

Name Type Description
output torch.Tensor The blurred and downsampled feature map. Shape depends on stride and kernel_size: (B, C, H_out, W_out) for blur_pool2d/max_blur_pool2d, or (B, C, H, W) for edge_aware_blur_pool2d (stride=1 internally).

Usage Examples

import torch
from kornia.filters import blur_pool2d, max_blur_pool2d, BlurPool2D

# Functional blur pool
input = torch.eye(5)[None, None]  # (1, 1, 5, 5)
output = blur_pool2d(input, kernel_size=3, stride=2)
print(output.shape)  # torch.Size([1, 1, 3, 3])

# Module-based blur pool
bp = BlurPool2D(kernel_size=3, stride=2)
output = bp(input)

# Max blur pool: equivalent to nn.MaxPool2d + BlurPool2D
output = max_blur_pool2d(input, kernel_size=3, stride=2, max_pool_size=2)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment