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 0000000..bacb19d Binary files /dev/null and b/core/test/input_models/MaxPool2d_AsymPad.onnx differ diff --git a/core/test/input_models/references/MaxPool2d_AsymPad.ref.hxx b/core/test/input_models/references/MaxPool2d_AsymPad.ref.hxx new file mode 100644 index 0000000..73fc4d5 --- /dev/null +++ b/core/test/input_models/references/MaxPool2d_AsymPad.ref.hxx @@ -0,0 +1,3 @@ +namespace MaxPool2d_AsymPad_ExpectedOutput { +float output[] = {4, 5, 6, 7, 7, 8, 9, 10, 11, 11, 12, 13, 14, 15, 15}; +} // namespace MaxPool2d_AsymPad_ExpectedOutput