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