PyTorch torch.quantized_max_pool1d function
PyTorch torch reference manual
torch.quantized_max_pool1d is a function in PyTorch used to perform 1D max pooling on quantized tensors. It is used for downsampling in quantized convolutional neural networks.
Function definition
torch.quantized_max_pool1d(input, kernel_size, stride, padding, dilation)
Parameter Description
input: Input quantized tensor (3D: batch x channel x length)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, length=10)
input
=
torch.
quantize_per_tensor
(
torch.
randn
(
1
,
1
,
10
)
,
scale
=
0.1
,
zero_point
=
0
,
dtype
=
torch.
quint8
)
Perform quantized max pooling
output
=
torch.
quantized_max_pool1d
(
input
,
kernel_size
=
3
,
stride
=
2
,
padding
=
1
)
(
"Input shape:"
,
input
.
shape
)
(
"Output shape:"
,
output.
shape
)
The output is:
输入形状: torch.Size([1, 1, 10])
输出形状: torch.Size([1, 1, 5])