PyTorch torch.quantized_max_pool2d function
PyTorch torch reference manual
torch.quantized_max_pool2d is a function in PyTorch used to perform 2D max pooling on quantized tensors. It 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 sizestride: Stride (optional)padding: Padding (optional)dilation: Dilation (optional)
Usage examples
Example
import
torch
Create a 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
)
(
"Input shape:"
,
input
.
shape
)
(
"Output shape:"
,
output.
shape
)
The output is:
输入形状: torch.Size([1, 1, 4, 4])
输出形状: torch.Size([1, 1, 2, 2])