Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ParseConv.cxx
Go to the documentation of this file.
3#include "onnx_proto3.pb.h"
4
5namespace TMVA {
6namespace Experimental {
7namespace SOFIE {
8
9ParserFuncSignature ParseConv = [](RModelParser_ONNX &parser, const onnx::NodeProto &nodeproto) {
10 ETensorType input_type;
11
12 auto input_name = nodeproto.input(0);
13 if (parser.IsRegisteredTensorType(input_name)) {
14 input_type = parser.GetTensorType(input_name);
15 } else {
16 throw std::runtime_error("TMVA::SOFIE ONNX Parser Conv op has input tensor " + input_name +
17 " but its type is not yet registered");
18 }
19
20 std::unique_ptr<ROperator> op;
21
22 std::string attr_auto_pad = "NOTSET";
23 std::vector<size_t> attr_dilations;
24 size_t attr_group = 0;
25 std::vector<size_t> attr_kernel_shape;
26 std::vector<size_t> attr_pads;
27 std::vector<size_t> attr_strides;
28
29 for (int_t i = 0; i < nodeproto.attribute_size(); i++) {
30 std::string attribute_name = nodeproto.attribute(i).name();
31 if (attribute_name == "auto_pad") {
32 attr_auto_pad = nodeproto.attribute(i).s();
33 } else if (attribute_name == "dilations") {
34 attr_dilations =
35 std::vector<size_t>({nodeproto.attribute(i).ints().begin(), nodeproto.attribute(i).ints().end()});
36 } else if (attribute_name == "group") {
37 attr_group = nodeproto.attribute(i).i();
38 } else if (attribute_name == "kernel_shape") {
39 attr_kernel_shape =
40 std::vector<size_t>({nodeproto.attribute(i).ints().begin(), nodeproto.attribute(i).ints().end()});
41 } else if (attribute_name == "pads") {
42 attr_pads = std::vector<size_t>({nodeproto.attribute(i).ints().begin(), nodeproto.attribute(i).ints().end()});
43 } else if (attribute_name == "strides") {
44 attr_strides =
45 std::vector<size_t>({nodeproto.attribute(i).ints().begin(), nodeproto.attribute(i).ints().end()});
46 } else {
47 std::cout << "TMVA::SOFIE Warning - Model Loading - Attribute " << attribute_name << " in OperatorNode "
48 << nodeproto.name() << " is not defined in ONNX IR and not applied!\n";
49 }
50 }
51
52 std::string name_b = "";
53 if (nodeproto.input_size() > 2) {
54 name_b = nodeproto.input(2);
55 }
56 std::string output_name = nodeproto.output(0);
57
58 switch (input_type) {
60 op.reset(new ROperator_Conv<float>(attr_auto_pad, attr_dilations, attr_group, attr_kernel_shape, attr_pads,
61 attr_strides, nodeproto.input(0), nodeproto.input(1), name_b, output_name));
62 break;
63 default:
64 throw std::runtime_error("TMVA::SOFIE - Unsupported - Operator Conv does not yet support input type " +
65 std::to_string(static_cast<int>(input_type)));
66 }
67
68 if (!parser.IsRegisteredTensorType(output_name)) {
69 parser.RegisterTensorType(output_name, input_type);
70 }
71
72 return op;
73};
74
75} // namespace SOFIE
76} // namespace Experimental
77} // namespace TMVA
void RegisterTensorType(const std::string &, ETensorType)
ETensorType GetTensorType(const std::string &name)
std::function< std::unique_ptr< ROperator >(RModelParser_ONNX &, const onnx::NodeProto &)> ParserFuncSignature
ParserFuncSignature ParseConv
Definition ParseConv.cxx:9
create variable transformations