diff --git a/tmva/sofie/inc/TMVA/ROperator_Conv.hxx b/tmva/sofie/inc/TMVA/ROperator_Conv.hxx index 78c1dcebc8030..4e2e90cbc130c 100644 --- a/tmva/sofie/inc/TMVA/ROperator_Conv.hxx +++ b/tmva/sofie/inc/TMVA/ROperator_Conv.hxx @@ -429,6 +429,10 @@ public: out << SP << SP << "}\n"; out << SP << "}\n"; + // Dilation is already folded into the expanded kernel shape and the dilated tensor__f + // layout above, so the dense im2col below must use dilation 1 to avoid double-counting it. + fAttrDilations = std::vector(3, 1); + //out << SP << "char " << OpName << "_transA = 'T';\n"; out << SP << "char " << OpName << "_transA = 'N';\n"; out << SP << "char " << OpName << "_transB = 'N';\n"; diff --git a/tmva/sofie/test/TestCustomModelsFromONNX.cxx b/tmva/sofie/test/TestCustomModelsFromONNX.cxx index b9857830820ac..33eb135bcdbd7 100644 --- a/tmva/sofie/test/TestCustomModelsFromONNX.cxx +++ b/tmva/sofie/test/TestCustomModelsFromONNX.cxx @@ -22,6 +22,7 @@ constexpr auto modelDataSuffix = "_FromONNX.dat"; #include "input_models/references/Erf.ref.hxx" #include "input_models/references/LinearWithSigmoid.ref.hxx" #include "input_models/references/ConvWithPadding.ref.hxx" +#include "input_models/references/ConvWithDilation.ref.hxx" #include "input_models/references/ConvWithoutPadding.ref.hxx" #include "input_models/references/ConvWithAutopadSameLower.ref.hxx" #include "input_models/references/ConvWithAutopadSameUpper.ref.hxx" @@ -726,6 +727,27 @@ TEST(ONNX, ConvWithStridesPadding) } +TEST(ONNX, ConvWithDilation) +{ + constexpr float TOLERANCE = DEFAULT_TOLERANCE; + + // Preparing the standard all-ones input + std::vector input(49); + std::iota(input.begin(), input.end(), 0.0f); + ASSERT_INCLUDE_AND_RUN(std::vector, "ConvWithDilation", input); + + // Checking output size + EXPECT_EQ(output.size(), std::size(ConvWithDilation_ExpectedOutput::all_ones)); + + float *correct = ConvWithDilation_ExpectedOutput::all_ones; + + // Checking every output value, one by one + for (size_t i = 0; i < output.size(); ++i) { + EXPECT_LE(std::abs(output[i] - correct[i]), TOLERANCE); + } +} + + TEST(ONNX, ConvWithStridesNoPadding) { constexpr float TOLERANCE = DEFAULT_TOLERANCE; diff --git a/tmva/sofie/test/input_models/ConvWithDilation.onnx b/tmva/sofie/test/input_models/ConvWithDilation.onnx new file mode 100644 index 0000000000000..c49707afa5be0 Binary files /dev/null and b/tmva/sofie/test/input_models/ConvWithDilation.onnx differ diff --git a/tmva/sofie/test/input_models/references/ConvWithDilation.ref.hxx b/tmva/sofie/test/input_models/references/ConvWithDilation.ref.hxx new file mode 100644 index 0000000000000..76559a18954bc --- /dev/null +++ b/tmva/sofie/test/input_models/references/ConvWithDilation.ref.hxx @@ -0,0 +1,3 @@ +namespace ConvWithDilation_ExpectedOutput { +float all_ones[] = {98.400002f, 102.900009f, 107.400002f, 129.899994f, 134.399994f, 138.899994f, 161.399994f, 165.899994f, 170.399994f}; +} // namespace ConvWithDilation_ExpectedOutput