PyTorch torch.quantized_max_pool1d Function


Pytorch torch 参考手册Pytorch torch Reference Manual

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

Function Definition

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

Parameter Description

  • input: The input quantized tensor (3D: batch x channel x length)
  • 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, 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)

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

The output result is:

输入形状: torch.Size([1, 1, 10])
输出形状: torch.Size([1, 1, 5])

Pytorch torch 参考手册Pytorch torch Reference Manual

Other Extensions