From 903cc52c9e4621c2faf905d235f8ba5cc13ca7ce Mon Sep 17 00:00:00 2001 From: Harsh Chauhan Date: Mon, 1 Jun 2026 16:17:24 +0530 Subject: [PATCH] fix wrong pad indices in pool for asym padding --- core/inc/SOFIE/ROperator_Pool.hxx | 10 ++++---- core/test/TestCustomModelsFromONNX.cxx | 23 ++++++++++++++++++ core/test/input_models/MaxPool2d_AsymPad.onnx | Bin 0 -> 165 bytes .../references/MaxPool2d_AsymPad.ref.hxx | 3 +++ 4 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 core/test/input_models/MaxPool2d_AsymPad.onnx create mode 100644 core/test/input_models/references/MaxPool2d_AsymPad.ref.hxx diff --git a/core/inc/SOFIE/ROperator_Pool.hxx b/core/inc/SOFIE/ROperator_Pool.hxx index 8e11271..fb42871 100644 --- a/core/inc/SOFIE/ROperator_Pool.hxx +++ b/core/inc/SOFIE/ROperator_Pool.hxx @@ -281,20 +281,20 @@ public: assert(fAttrKernelShape.size() == 3); // find lower bounds of filtered area int hmin = - fAttrPads[0]; // minimum lower bound value of filter area - int hmax = fShapeX[2] + fAttrPads[1] - fAttrKernelShape[0] +1; // maximum lower bound value + 1 + int hmax = fShapeX[2] + fAttrPads[fDim] - fAttrKernelShape[0] +1; // maximum lower bound value + 1 int wmin,wmax,dmin,dmax; if(fDim >= 2){ - wmin = - fAttrPads[2]; // minimum lower bound value of filter area - wmax = fShapeX[3] + fAttrPads[3] - fAttrKernelShape[1] +1; // maximum lower bound value + 1 + wmin = - fAttrPads[1]; // minimum lower bound value of filter area + wmax = fShapeX[3] + fAttrPads[fDim + 1] - fAttrKernelShape[1] +1; // maximum lower bound value + 1 } else{ wmin=1; wmax=1; } if(fDim == 3){ - dmin = - fAttrPads[4]; // minimum lower bound value of filter area - dmax = fShapeX[4] + fAttrPads[5] - fAttrKernelShape[2] +1; // maximum lower bound value + 1 + dmin = - fAttrPads[2]; // minimum lower bound value of filter area + dmax = fShapeX[4] + fAttrPads[fDim + 2] - fAttrKernelShape[2] +1; // maximum lower bound value + 1 } else{ dmin=1; diff --git a/core/test/TestCustomModelsFromONNX.cxx b/core/test/TestCustomModelsFromONNX.cxx index 902cbcc..f6cd135 100644 --- a/core/test/TestCustomModelsFromONNX.cxx +++ b/core/test/TestCustomModelsFromONNX.cxx @@ -86,6 +86,9 @@ #include "MaxPool2d_FromONNX.hxx" #include "input_models/references/MaxPool2d.ref.hxx" +#include "MaxPool2d_AsymPad_FromONNX.hxx" +#include "input_models/references/MaxPool2d_AsymPad.ref.hxx" + #include "MaxPool3d_FromONNX.hxx" #include "input_models/references/MaxPool3d.ref.hxx" @@ -1051,6 +1054,26 @@ TEST(ONNX, MaxPool2d){ } +TEST(ONNX, MaxPool2d_AsymPad) +{ + constexpr float TOLERANCE = DEFAULT_TOLERANCE; + + // 1x1x4x4 input with values 0..15 + std::vector input({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}); + + SOFIE_MaxPool2d_AsymPad::Session s("MaxPool2d_AsymPad_FromONNX.dat"); + std::vector output = s.infer(input.data()); + + // pads=[0,1,0,1] (width padded, height not) gives a 1x1x3x5 output; + // the pre-fix code mis-read the pads and produced a 4x4 grid instead + EXPECT_EQ(output.size(), sizeof(MaxPool2d_AsymPad_ExpectedOutput::output) / sizeof(float)); + + float *correct = MaxPool2d_AsymPad_ExpectedOutput::output; + for (size_t i = 0; i < output.size(); ++i) { + EXPECT_LE(std::abs(output[i] - correct[i]), TOLERANCE); + } +} + TEST(ONNX, MaxPool3d){ constexpr float TOLERANCE = DEFAULT_TOLERANCE; diff --git a/core/test/input_models/MaxPool2d_AsymPad.onnx b/core/test/input_models/MaxPool2d_AsymPad.onnx new file mode 100644 index 0000000000000000000000000000000000000000..bacb19d2886a18ae643bca33d97a94f74d37e168 GIT binary patch literal 165 zcmdcHf{w1AOaOOT7D zATg!bfx&?hgh4_AT#%E5TlfM$KuM|fW(w2X^{D1Tp}EdLIPY& b9E?!R0;E}zfRd3|B$