8 #include "google/protobuf/repeated_field.h" 9 #include <unordered_map> 11 #include <onnx/onnx.pb.h> 23 using ModelPtr = std::unique_ptr<onnx::ModelProto>;
28 using OperationParsingFunction = void(
OnnxParser::*)(
const onnx::NodeProto& NodeProto);
32 using GraphPtr = std::unique_ptr<onnx::GraphProto>;
35 virtual armnn::INetworkPtr CreateNetworkFromBinaryFile(
const char* graphFile)
override;
41 virtual armnn::INetworkPtr CreateNetworkFromString(
const std::string& protoText)
override;
44 virtual BindingPointInfo GetNetworkInputBindingInfo(
const std::string& name)
const override;
47 virtual BindingPointInfo GetNetworkOutputBindingInfo(
const std::string& name)
const override;
53 static ModelPtr LoadModelFromBinaryFile(
const char * fileName);
54 static ModelPtr LoadModelFromTextFile(
const char * fileName);
55 static ModelPtr LoadModelFromString(
const std::string& inputString);
58 static std::vector<std::string> GetInputs(
ModelPtr& model);
61 static std::vector<std::string> GetOutputs(
ModelPtr& model);
71 void SetupInfo(
const google::protobuf::RepeatedPtrField<onnx::ValueInfoProto >* list);
73 std::vector<armnn::TensorInfo> ComputeOutputInfo(std::vector<std::string> outNames,
75 std::vector<armnn::TensorShape> inputShapes);
77 void DetectFullyConnected();
79 template <
typename Location>
80 void GetInputAndParam(
const onnx::NodeProto& node,
81 std::string* inputName,
82 std::string* constName,
83 const Location& location);
85 template <
typename Location>
86 void To1DTensor(
const std::string &name,
const Location& location);
89 std::pair<std::string, std::string> AddPrepareBroadcast(
const std::string& input0,
const std::string& input1);
90 void PrependForBroadcast(
const std::string& outputName,
const std::string& input0,
const std::string& input1);
92 void CreateConstantLayer(
const std::string& tensorName,
const std::string& layerName);
93 void CreateReshapeLayer(
const std::string& inputName,
94 const std::string& outputName,
95 const std::string& layerName);
97 void ParseBatchNormalization(
const onnx::NodeProto& node);
98 void ParseConstant(
const onnx::NodeProto& nodeProto);
100 void ParseMaxPool(
const onnx::NodeProto& nodeProto);
101 void ParseAveragePool(
const onnx::NodeProto& nodeProto);
102 void ParseGlobalAveragePool(
const onnx::NodeProto& node);
106 void ParseReshape(
const onnx::NodeProto& nodeProto);
109 void ParseSigmoid(
const onnx::NodeProto& nodeProto);
110 void ParseTanh(
const onnx::NodeProto& nodeProto);
111 void ParseRelu(
const onnx::NodeProto& nodeProto);
112 void ParseLeakyRelu(
const onnx::NodeProto& nodeProto);
115 void ParseConv(
const onnx::NodeProto& nodeProto);
117 void ParseAdd(
const onnx::NodeProto& nodeProto);
118 void AddFullyConnected(
const onnx::NodeProto& matmulNode,
const onnx::NodeProto* addNode =
nullptr);
123 void SetupInputLayers();
124 void SetupOutputLayers();
129 std::pair<armnn::ConstTensor, std::unique_ptr<float[]>> CreateConstTensor(
const std::string name);
131 template <
typename TypeList,
typename Location>
132 void ValidateInputs(
const onnx::NodeProto& node,
133 TypeList validInputs,
134 const Location& location);
145 std::unique_ptr<armnn::TensorInfo> m_info;
146 std::unique_ptr<const onnx::TensorProto> m_tensor;
149 OnnxTensor() : m_info(nullptr), m_tensor(nullptr), m_dtype(onnx::TensorProto::FLOAT) { }
150 bool isConstant() {
return m_tensor !=
nullptr; }
153 std::unordered_map<std::string, OnnxTensor> m_TensorsInfo;
156 static const std::map<std::string, OperationParsingFunction> m_ParserFunctions;
164 std::vector<armnn::IInputSlot*> inputSlots;
166 TensorSlots() : outputSlot(nullptr) { }
169 std::unordered_map<std::string, TensorSlots> m_TensorConnections;
172 std::unordered_map<std::string, std::pair<const onnx::NodeProto*, int>> m_OutputsMap;
178 std::vector<size_t> fusedWithNodes;
179 size_t inputForNodes;
181 UsageSummary() : fusedWithNodes({}), inputForNodes(0) { }
185 std::vector<UsageSummary> m_OutputsFusedAndUsed;
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
A Convolution2dDescriptor for the Convolution2dLayer.
Copyright (c) 2020 ARM Limited.
std::unique_ptr< onnx::ModelProto > ModelPtr
std::unique_ptr< onnx::GraphProto > GraphPtr
An output connection slot for a layer.
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
armnn::BindingPointInfo BindingPointInfo
A Pooling2dDescriptor for the Pooling2dLayer.