Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ParseReshape.cxx
Go to the documentation of this file.
3#include "onnx_proto3.pb.h"
4
5namespace TMVA {
6namespace Experimental {
7namespace SOFIE {
8
9ParserFuncSignature ParseReshape = [](RModelParser_ONNX &parser, const onnx::NodeProto &nodeproto) {
10 // make Reshape operator
12
14 if (nodeproto.op_type() == "Flatten")
16 else if (nodeproto.op_type() == "Squeeze")
18 else if (nodeproto.op_type() == "Unsqueeze")
20
21 // reshape has as extra input shape tensor (int64) but
22 // it is not present for Flatten, Squeeze and Unsquueze
23 auto input_name = nodeproto.input(0);
24 // for squeeze is optional ?
25 auto shape_name = ((nodeproto.input_size() > 1) && ( opMode == Reshape || opMode == Unsqueeze || opMode == Squeeze) )
26 ? nodeproto.input(1) : "";
29 } else {
30 throw std::runtime_error("TMVA::SOFIE ONNX Parser Reshape op has input tensor" + input_name +
31 " but its type is not yet registered");
32 }
33
34 // Reshape is having one attribute: allowzero (int) (default = 0)
35 // Flatten is having one attribute: axis (int) (default=1)
36 // old version of reshape and squeeze have axes as attributes
37 std::unique_ptr<ROperator> op;
38 int attr_value = (opMode == Reshape) ? 0 : 1;
39 if (opMode == Reshape && nodeproto.attribute_size() > 0)
40 attr_value = nodeproto.attribute(0).i();
41
42 std::vector<int64_t> attr_axes = {};
43 // this is for older ONNX versions ( <= 11)
44 if (nodeproto.input_size() == 1 && nodeproto.attribute_size() > 0 && (opMode == Squeeze || opMode == Unsqueeze)) {
45 std::string attribute_name = nodeproto.attribute(0).name();
46 if (attribute_name == "axes")
47 attr_axes = {nodeproto.attribute(0).ints().begin(), nodeproto.attribute(0).ints().end()};
48 }
49
50 std::string output_name = nodeproto.output(0);
51
52 if (attr_axes.empty())
54 else // for old Squeeze and Unsqueeze
56
59 }
60
61 return op;
62};
63
64} // namespace SOFIE
65} // namespace Experimental
66} // namespace TMVA
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
const_iterator begin() const
const_iterator end() const
void RegisterTensorType(const std::string &, ETensorType)
ETensorType GetTensorType(const std::string &name)
ParserFuncSignature ParseReshape
std::function< std::unique_ptr< ROperator >(RModelParser_ONNX &, const onnx::NodeProto &)> ParserFuncSignature
create variable transformations