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
4 changes: 2 additions & 2 deletions tmva/sofie/inc/TMVA/ROperator_Conv.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ public:
}
} else { // general case (stride not 1)
int64_t v = pad - kernel;
std::string outStr = "((" + inputDim.param + "+" + std::to_string(v) + ")/"
+ std::to_string(stride) + "1)";
std::string outStr =
"((" + inputDim.param + "+" + std::to_string(v) + ")/" + std::to_string(stride) + "+1)";
return Dim{ outStr, static_cast<size_t>(-1)};
}
}
Expand Down
23 changes: 23 additions & 0 deletions tmva/sofie/test/TestCustomModelsFromONNX.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,29 @@ TEST(ONNX, ConvWithStridesNoPadding)
}


TEST(ONNX, ConvWithDynShapeStride)
{
// Conv1d with dynamic spatial dimension W and stride=2.
// Verifies fix for output dimension formula: ((W+pad-kernel)/stride+1)
// was incorrectly generated as ((W+pad-kernel)/stride1) before the fix.
//
// Model: kernel=3, stride=2, pad=0, weight=all-ones, input shape (1,1,W)
// With W=7: output shape (1,1,3), output = [0+1+2, 2+3+4, 4+5+6] = [3, 9, 15]

std::vector<float> input = {0, 1, 2, 3, 4, 5, 6}; // shape (1,1,7)
std::vector<float> correct_output = {3, 9, 15};

// model is dynamic in spatial dim W, use W = 7
ASSERT_INCLUDE_AND_RUN_SESSION_ARGS(std::vector<float>, "ConvWithDynShapeStride",
"\"ConvWithDynShapeStride_FromONNX.dat\", 7", 7, input);

EXPECT_EQ(output.size(), correct_output.size());
for (size_t i = 0; i < output.size(); ++i) {
EXPECT_LE(std::abs(output[i] - correct_output[i]), DEFAULT_TOLERANCE);
}
}


// Disables test (asymmetric padding not supported)
TEST(DISABLED_ONNX, ConvWithAsymmetricPadding)
{
Expand Down
Binary file not shown.