Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.quantized_max_pool2d function

PyTorch torch.quantized_max_pool2d function


PyTorch torch reference manual 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


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

)

print

(

"Input shape:"

,

input

.

shape

)

print

(

"Output shape:"

,

output.

shape

)

The output is:

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

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


PyTorch torch reference manual PyTorch torch reference manual