-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Closed as not planned
Closed as not planned
Copy link
Labels
Description
Ask a Question
Does the output generated by the last slide of window divided by remaining pixels or kernal size when ceil_mode
is True.
Question
I found in current ORT, when ceil mode is on, the last output from the last slide of window is divided by kernal size regardless the remaining pixels (including padding). I am wondering in ONNX spec, should it be divided by kernal size or remaining pixels?
Further information
In PyTorch, it is divided by the number of remaining pixels:
import torch
a = torch.tensor([[[ 2.0903, 4.6493, 1.6320, -3.2051, 4.6975, 4.7296, 3.3653,-1.5815, -2.3832],[ 0.9628, -1.5899, -2.6820, 5.7529, 7.7346, -0.8910, -2.0151,0.1313, -0.5374]]])
p = torch.nn.AvgPool1d((7,), (3,), (3,), ceil_mode=True, count_include_pad=True)
p(a)
# tensor([[[ 0.7381, 2.5656, 0.8032, -0.0999],
# [ 0.3491, 1.0389, 1.4536, -0.4035]]])
In ORT, it's divided by kernal size:
import numpy as np
import onnxscript
from onnxscript.onnx_opset import opset18 as op
x = np.array([[[ 2.0903, 4.6493, 1.6320, -3.2051, 4.6975, 4.7296, 3.3653,-1.5815, -2.3832],
[ 0.9628, -1.5899, -2.6820, 5.7529, 7.7346, -0.8910, -2.0151,0.1313, -0.5374]]]).astype(np.float32)
@onnxscript.script(default_opset=op)
def avg_pool(x):
result = op.AveragePool(x, kernel_shape=[7], strides=[3], pads=[3,3], ceil_mode=True, count_include_pad=True)
return result
print(avg_pool(x))
# [[[ 0.73807144 2.5655572 0.8032287 -0.08562858]
# [ 0.34911433 1.0389 1.4536142 -0.34588572]]]
Notes
The difference happens in the last outputs which is divided by different number.