Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ParseFuseConvAdd.cxx
Go to the documentation of this file.
3#include "onnx_proto3.pb.h"
4
5namespace TMVA {
6namespace Experimental {
7namespace SOFIE {
8
10 const onnx::NodeProto &addnode) {
11 if (addnode.input_size() != 2) {
12 throw std::runtime_error("TMVA::SOFIE - Cannot fuse Conv and Add - Add input size is not 2");
13 }
14 std::string name_b;
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);
19 else
20 throw std::runtime_error("TMVA::SOFIE - Cannot fuse Conv and Add - output of Conv is not input to Add");
21
23 auto input_name = convnode.input(0);
26 } else {
27 throw std::runtime_error("TMVA::SOFIE ONNX Parser Conv op has input tensor " + input_name +
28 " but its type is not yet registered");
29 }
30
31 std::unique_ptr<ROperator> op;
32
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;
39
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()});
54 } else {
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";
57 }
58 }
59
60 std::string output_name = addnode.output(0);
61 switch (input_type) {
64 attr_strides, convnode.input(0), convnode.input(1), name_b, output_name));
65 break;
66 default:
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)));
69 }
70
73 }
74
75 return op;
76};
77
78} // namespace SOFIE
79} // namespace Experimental
80} // namespace TMVA
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
const_iterator end() const
void RegisterTensorType(const std::string &, ETensorType)
ETensorType GetTensorType(const std::string &name)
std::function< std::unique_ptr< ROperator >(RModelParser_ONNX &, const onnx::NodeProto &, const onnx::NodeProto &)> ParserFuseFuncSignature
ParserFuseFuncSignature ParseFuseConvAdd
create variable transformations