11 if (addnode.input_size() != 2) {
12 throw std::runtime_error(
"TMVA::SOFIE - Cannot fuse Conv and Add - Add input size is not 2");
15 if (convnode.output(0) == addnode.input(0))
16 name_b = addnode.input(1);
17 else if (convnode.output(0) == addnode.input(1))
18 name_b = addnode.input(0);
20 throw std::runtime_error(
"TMVA::SOFIE - Cannot fuse Conv and Add - output of Conv is not input to Add");
23 auto input_name = convnode.input(0);
27 throw std::runtime_error(
"TMVA::SOFIE ONNX Parser Conv op has input tensor " + input_name +
28 " but its type is not yet registered");
31 std::unique_ptr<ROperator> op;
33 std::string attr_auto_pad =
"NOTSET";
34 std::vector<size_t> attr_dilations;
35 size_t attr_group = 0;
36 std::vector<size_t> attr_kernel_shape;
37 std::vector<size_t> attr_pads;
38 std::vector<size_t> attr_strides;
40 for (
int_t i = 0; i < convnode.attribute_size(); i++) {
41 std::string attribute_name = convnode.attribute(i).name();
42 if (attribute_name ==
"auto_pad") {
43 attr_auto_pad = convnode.attribute(i).s();
44 }
else if (attribute_name ==
"dilations") {
45 attr_dilations = std::vector<size_t>({convnode.attribute(i).ints().begin(), convnode.attribute(i).ints().end()});
46 }
else if (attribute_name ==
"group") {
47 attr_group = convnode.attribute(i).i();
48 }
else if (attribute_name ==
"kernel_shape") {
49 attr_kernel_shape = std::vector<size_t>({convnode.attribute(i).ints().begin(), convnode.attribute(i).ints().end()});
50 }
else if (attribute_name ==
"pads") {
51 attr_pads = std::vector<size_t>({convnode.attribute(i).ints().begin(), convnode.attribute(i).ints().end()});
52 }
else if (attribute_name ==
"strides") {
53 attr_strides = std::vector<size_t>({convnode.attribute(i).ints().begin(), convnode.attribute(i).ints().end()});
55 std::cout <<
"TMVA::SOFIE Warning - Model Loading - Attribute " << attribute_name <<
" in OperatorNode "
56 << convnode.name() <<
" is not defined in ONNX IR and not applied!\n";
60 std::string output_name = addnode.output(0);
63 op.reset(
new ROperator_Conv<float>(attr_auto_pad, attr_dilations, attr_group, attr_kernel_shape, attr_pads,
64 attr_strides, convnode.input(0), convnode.input(1), name_b, output_name));
67 throw std::runtime_error(
"TMVA::SOFIE - Unsupported - Operator Conv does not yet support input type " +
68 std::to_string(
static_cast<int>(input_type)));