Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ParseLeakyRelu.cxx
Go to the documentation of this file.
3#include "onnx_proto3.pb.h"
4
5namespace TMVA {
6namespace Experimental {
7namespace SOFIE {
8
9ParserFuncSignature ParseLeakyRelu = [](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 leaky relu op has input tensor" + input_name +
17 " but its type is not yet registered");
18 }
19
20 std::unique_ptr<ROperator> op;
21
22 float attr_alpha = 0.01;
23
24 for (int_t i = 0; i < nodeproto.attribute_size(); i++) {
25 std::string attribute_name = nodeproto.attribute(i).name();
26 if (attribute_name == "alpha")
27 attr_alpha = nodeproto.attribute(i).f();
28 }
29
30 std::string output_name = nodeproto.output(0);
31 switch (input_type) {
32 case ETensorType::FLOAT: op.reset(new ROperator_LeakyRelu<float>(attr_alpha, input_name, output_name)); break;
33 default:
34 throw std::runtime_error("TMVA::SOFIE - Unsupported - Operator Leaky Relu does not yet support input type " +
35 std::to_string(static_cast<int>(input_type)));
36 }
37
38 if (!parser.IsRegisteredTensorType(output_name)) {
39 parser.RegisterTensorType(output_name, input_type);
40 }
41
42 return op;
43};
44
45} // namespace SOFIE
46} // namespace Experimental
47} // namespace TMVA
void RegisterTensorType(const std::string &, ETensorType)
ETensorType GetTensorType(const std::string &name)
ParserFuncSignature ParseLeakyRelu
std::function< std::unique_ptr< ROperator >(RModelParser_ONNX &, const onnx::NodeProto &)> ParserFuncSignature
create variable transformations