PyTorch torch.quantized_max_pool2d 関数
torch.quantized_max_pool2dは、PyTorch において量子化テンソルに対して2次元最大プーリング操作を実行するための関数です。この関数は、量子化畳み込みニューラルネットワークで空間ダウンサンプリングを実行するためによく使用されます。
関数定義
torch.quantized_max_pool2d(input, kernel_size, stride, padding, dilation)
パラメータの説明
input: 入力の量子化テンソル(4D: batch x channel x height x width)kernel_size: プーリングウィンドウのサイズstride: ストライド(オプション)padding: パディング(オプション)dilation: 膨張(オプション)
使用例
例
import torch
# 量子化入力テンソルを作成 (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)
# 量子化最大プーリングを実行 (2x2 プーリングウィンドウ)
output = torch.quantized_max_pool2d(input, kernel_size=2, stride=2)
print("入力形状:", input.shape)
print("出力形状:", output.shape)
# 量子化入力テンソルを作成 (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)
# 量子化最大プーリングを実行 (2x2 プーリングウィンドウ)
output = torch.quantized_max_pool2d(input, kernel_size=2, stride=2)
print("入力形状:", input.shape)
print("出力形状:", output.shape)
出力結果は次のとおりです:
输入形状: torch.Size([1, 1, 4, 4]) 输出形状: torch.Size([1, 1, 2, 2])
その他の拡張
Pytorch torch リファレンスマニュアル