Skip to content
Closed
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
16 changes: 7 additions & 9 deletions tmva/sofie/inc/TMVA/ROperator_Conv.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ public:
// trick for speed is using caffe im2col and output a matrix which contains filtered values as rows.
// By doing this one has consecutive memory reads and writes
// Resulting matrix op_xcol is (input channels * filter_h * filter_w , output_h * output_w)
// The generated filter tensor is already expanded for fAttrDilations, so Im2col scans it contiguously.
if (fDim ==1) {
if (fAttrPads[0] != fAttrPads[1] ) {
std::cout << "TMVA SOFIE Operator Conv: asymmetric padding not supported. Assume an average padding "
Expand Down Expand Up @@ -493,11 +494,10 @@ public:
<< fShapeW[1] << "," << iHeight << "," << iWidth << ",";
if (fDim == 1)
out << "1, " << fAttrKernelShape[0] << ",0," << fAttrPads[0] << ",1," << fAttrStrides[0] << ",1,"
<< fAttrDilations[0];
<< 1;
else // dim ==2
out << fAttrKernelShape[0] << "," << fAttrKernelShape[1] << "," << fAttrPads[0] << "," << fAttrPads[1]
<< "," << fAttrStrides[0] << "," << fAttrStrides[1] << "," << fAttrDilations[0] << ","
<< fAttrDilations[1];
<< "," << fAttrStrides[0] << "," << fAttrStrides[1] << ",1,1";
out << "," << "tensor_" <<fNX << "_xcol);\n\n ";
} else {
// 3d im2col
Expand All @@ -509,8 +509,7 @@ public:
<< fShapeW[1] << "," << iDepth << "," << iHeight << "," << iWidth << ","
<< fAttrKernelShape[0] << "," << fAttrKernelShape[1] << "," << fAttrKernelShape[2] << ","
<< fAttrPads[0] << "," << fAttrPads[1] << "," << fAttrPads[2] << ","
<< fAttrStrides[0] << "," << fAttrStrides[1] << "," << fAttrStrides[2] << ","
<< fAttrDilations[0] << "," << fAttrDilations[1] << "," << fAttrDilations[2] << ","
<< fAttrStrides[0] << "," << fAttrStrides[1] << "," << fAttrStrides[2] << ",1,1,1,"
<< "tensor_" << fNX << "_xcol);\n\n ";
}
// BLAS
Expand Down Expand Up @@ -551,11 +550,10 @@ public:
<< fShapeW[1] << "," << iHeight << "," << iWidth << ",";
if (fDim == 1)
out << "1, " << fAttrKernelShape[0] << ",0," << fAttrPads[0] << ",1," << fAttrStrides[0] << ",1,"
<< fAttrDilations[0];
<< 1;
else // dim ==2
out << fAttrKernelShape[0] << "," << fAttrKernelShape[1] << "," << fAttrPads[0] << "," << fAttrPads[1]
<< "," << fAttrStrides[0] << "," << fAttrStrides[1] << "," << fAttrDilations[0] << ","
<< fAttrDilations[1];
<< "," << fAttrStrides[0] << "," << fAttrStrides[1] << ",1,1";
out << ", tensor_" << fNX << "_xcol);\n\n ";
} else {
// 3d im2col
Expand All @@ -567,7 +565,7 @@ public:
<< fShapeW[1] << "," << iDepth << "," << iHeight << "," << iWidth << "," << fAttrKernelShape[0] << ","
<< fAttrKernelShape[1] << "," << fAttrKernelShape[2] << "," << fAttrPads[0] << "," << fAttrPads[1]
<< "," << fAttrPads[2] << "," << fAttrStrides[0] << "," << fAttrStrides[1] << "," << fAttrStrides[2]
<< "," << fAttrDilations[0] << "," << fAttrDilations[1] << "," << fAttrDilations[2] << ",tensor_" << fNX
<< ",1,1,1,tensor_" << fNX
<< "_xcol);\n\n ";
}

Expand Down
17 changes: 17 additions & 0 deletions tmva/sofie/test/TestCustomModelsFromONNX.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ constexpr auto modelDataSuffix = "_FromONNX.dat";
#include "input_models/references/ConvWithStridesPadding.ref.hxx"
#include "input_models/references/ConvWithStridesNoPadding.ref.hxx"
#include "input_models/references/ConvWithAsymmetricPadding.ref.hxx"
#include "input_models/references/ConvWithDilation.ref.hxx"
#include "input_models/references/MaxPool1d.ref.hxx"
#include "input_models/references/MaxPool2d.ref.hxx"
#include "input_models/references/MaxPool2d_CeilMode.ref.hxx"
Expand Down Expand Up @@ -663,6 +664,22 @@ TEST(ONNX, ConvWithoutPadding)
}
}

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

std::vector<float> input(49);
std::iota(input.begin(), input.end(), 0.0f);
ASSERT_INCLUDE_AND_RUN(std::vector<float>, "ConvWithDilation", input);

EXPECT_EQ(output.size(), std::size(ConvWithDilation_ExpectedOutput::outputs));

float *correct = ConvWithDilation_ExpectedOutput::outputs;

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

TEST(ONNX, ConvWithAutopadSameLower)
{
Expand Down
Binary file added tmva/sofie/test/input_models/ConvWithDilation.onnx
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace ConvWithDilation_ExpectedOutput {
float outputs[] = {98.4f, 102.9f, 107.4f, 129.9f, 134.4f, 138.9f, 161.4f, 165.9f, 170.4f};
} // namespace ConvWithDilation_ExpectedOutput