PyTorch torch.quantized_max_pool2d Function


Pytorch torch 参考手册Pytorch torch Reference Manual

torch.quantized_max_pool2dIs a function in PyTorch used to perform two-dimensional max pooling operations on quantized tensors. This function is commonly used for spatial downsampling in quantized convolutional neural networks.

Function Definition

torch.quantized_max_pool2d(input, kernel_size, stride, padding, dilation)

Parameter Description

  • input: Input quantized tensor (4D: batch x channel x height x width)
  • kernel_size: Pooling window size
  • stride: Stride (optional)
  • padding: Padding (optional)
  • dilation: Dilation (optional)

Usage Example

Example

import torch

# Create quantized input tensor (batch=1, channel=1, height=4, width=4)
input = torch.quantize_per_tensor(torch.randn(1, 1, 4, 4), scale=0.1, zero_point=0, dtype=torch.quint8)

# Perform quantized max pooling (2x2 pooling window)
output = torch.quantized_max_pool2d(input, kernel_size=2, stride=2)

print("Input shape:", input.shape)
print("Output shape:", output.shape)

The output result is:

输入形状: torch.Size([1, 1, 4, 4])
输出形状: torch.Size([1, 1, 2, 2])

Pytorch torch 参考手册Pytorch torch Reference Manual

Other Extensions