Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions core/inc/SOFIE/ROperator_Pool.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
23 changes: 23 additions & 0 deletions core/test/TestCustomModelsFromONNX.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -1051,6 +1054,26 @@ TEST(ONNX, MaxPool2d){

}

TEST(ONNX, MaxPool2d_AsymPad)
{
constexpr float TOLERANCE = DEFAULT_TOLERANCE;

// 1x1x4x4 input with values 0..15
std::vector<float> 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<float> 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;

Expand Down
Binary file added core/test/input_models/MaxPool2d_AsymPad.onnx
Binary file not shown.
3 changes: 3 additions & 0 deletions core/test/input_models/references/MaxPool2d_AsymPad.ref.hxx
Original file line number Diff line number Diff line change
@@ -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