ROOT
master
Reference Guide
Loading...
Searching...
No Matches
ParseSwish.cxx
Go to the documentation of this file.
1
#include "
TMVA/RModelParser_ONNX.hxx
"
2
#include "
TMVA/ROperator_Swish.hxx
"
3
#include "onnx_proto3.pb.h"
4
5
namespace
TMVA
{
6
namespace
Experimental {
7
namespace
SOFIE {
8
9
ParserFuncSignature
ParseSwish
= [](
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 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;
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
// ROperator_Swish implements alpha = 1 (x * sigmoid(x)); reject other values
31
if
(
attr_alpha
!= 1.0) {
32
throw
std::runtime_error(
"TMVA::SOFIE - Unsupported - Operator Swish does not yet support alpha != 1"
);
33
}
34
35
std::string
output_name
=
nodeproto
.output(0);
36
37
op
.reset(
new
ROperator_Swish
(
input_name
,
output_name
));
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
RModelParser_ONNX.hxx
ROperator_Swish.hxx
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:359
ROOT::Detail::TRangeCast
Definition
TCollection.h:312
TMVA::Experimental::SOFIE::RModelParser_ONNX
Definition
RModelParser_ONNX.hxx:30
TMVA::Experimental::SOFIE::RModelParser_ONNX::IsRegisteredTensorType
bool IsRegisteredTensorType(const std::string &)
Definition
RModelParser_ONNX.cxx:419
TMVA::Experimental::SOFIE::RModelParser_ONNX::RegisterTensorType
void RegisterTensorType(const std::string &, ETensorType)
Definition
RModelParser_ONNX.cxx:414
TMVA::Experimental::SOFIE::RModelParser_ONNX::GetTensorType
ETensorType GetTensorType(const std::string &name)
Definition
RModelParser_ONNX.cxx:424
TMVA::Experimental::SOFIE::ROperator_Swish
Definition
ROperator_Swish.hxx:15
TMVA::Experimental::SOFIE::ETensorType
ETensorType
Definition
SOFIE_common.hxx:28
TMVA::Experimental::SOFIE::ParserFuncSignature
std::function< std::unique_ptr< ROperator >(RModelParser_ONNX &, const onnx::NodeProto &)> ParserFuncSignature
Definition
RModelParser_ONNX.hxx:25
TMVA::Experimental::SOFIE::int_t
std::int64_t int_t
Definition
SOFIE_common.hxx:55
TMVA::Experimental::SOFIE::ParseSwish
ParserFuncSignature ParseSwish
Definition
ParseSwish.cxx:9
TMVA
create variable transformations
Definition
GeneticMinimizer.h:22
tmva
sofie_parsers
src
ParseSwish.cxx
ROOTmaster - Reference Guide Generated on Sun Jul 12 2026 05:02:59 (GVA Time) using Doxygen 1.10.0