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