11 #include <schema_generated.h> 13 #include <unordered_map> 23 using ModelPtr = std::unique_ptr<tflite::ModelT>;
46 const std::string& name)
const;
51 const std::string& name)
const;
80 const std::vector<int32_t> & targetDimsIn);
94 using OperatorParsingFunction = void(
TfLiteParserImpl::*)(
size_t subgraphIndex,
size_t operatorIndex);
96 void ParseCustomOperator(
size_t subgraphIndex,
size_t operatorIndex);
97 void ParseUnsupportedOperator(
size_t subgraphIndex,
size_t operatorIndex);
100 void ParseAdd(
size_t subgraphIndex,
size_t operatorIndex);
101 void ParseAveragePool2D(
size_t subgraphIndex,
size_t operatorIndex);
102 void ParseBatchToSpaceND(
size_t subgraphIndex,
size_t operatorIndex);
103 void ParseConcatenation(
size_t subgraphIndex,
size_t operatorIndex);
104 void ParseConv2D(
size_t subgraphIndex,
size_t operatorIndex);
105 void ParseDepthToSpace(
size_t subgraphIndex,
size_t operatorIndex);
106 void ParseDepthwiseConv2D(
size_t subgraphIndex,
size_t operatorIndex);
107 void ParseDequantize(
size_t subgraphIndex,
size_t operatorIndex);
108 void ParseDetectionPostProcess(
size_t subgraphIndex,
size_t operatorIndex);
109 void ParseElu(
size_t subgraphIndex,
size_t operatorIndex);
110 void ParseExp(
size_t subgraphIndex,
size_t operatorIndex);
111 void ParseFullyConnected(
size_t subgraphIndex,
size_t operatorIndex);
112 void ParseGather(
size_t subgraphIndex,
size_t operatorIndex);
113 void ParseHardSwish(
size_t subgraphIndex,
size_t operatorIndex);
114 void ParseLeakyRelu(
size_t subgraphIndex,
size_t operatorIndex);
115 void ParseLogistic(
size_t subgraphIndex,
size_t operatorIndex);
116 void ParseL2Normalization(
size_t subgraphIndex,
size_t operatorIndex);
117 void ParseMaxPool2D(
size_t subgraphIndex,
size_t operatorIndex);
118 void ParseMaximum(
size_t subgraphIndex,
size_t operatorIndex);
119 void ParseMean(
size_t subgraphIndex,
size_t operatorIndex);
120 void ParseMinimum(
size_t subgraphIndex,
size_t operatorIndex);
121 void ParseMul(
size_t subgraphIndex,
size_t operatorIndex);
122 void ParseNeg(
size_t subgraphIndex,
size_t operatorIndex);
123 void ParsePack(
size_t subgraphIndex,
size_t operatorIndex);
124 void ParsePad(
size_t subgraphIndex,
size_t operatorIndex);
126 void ParseQuantize(
size_t subgraphIndex,
size_t operatorIndex);
128 void ParseReduceMax(
size_t subgraphIndex,
size_t operatorIndex);
129 void ParseReduceMin(
size_t subgraphIndex,
size_t operatorIndex);
130 void ParseRelu(
size_t subgraphIndex,
size_t operatorIndex);
131 void ParseRelu6(
size_t subgraphIndex,
size_t operatorIndex);
132 void ParseReshape(
size_t subgraphIndex,
size_t operatorIndex);
133 void ParseResize(
size_t subgraphIndex,
size_t operatorIndex,
armnn::ResizeMethod resizeMethod);
134 void ParseResizeBilinear(
size_t subgraphIndex,
size_t operatorIndex);
135 void ParseResizeNearestNeighbor(
size_t subgraphIndex,
size_t operatorIndex);
136 void ParseSlice(
size_t subgraphIndex,
size_t operatorIndex);
137 void ParseSoftmax(
size_t subgraphIndex,
size_t operatorIndex);
138 void ParseSpaceToBatchND(
size_t subgraphIndex,
size_t operatorIndex);
139 void ParseSplit(
size_t subgraphIndex,
size_t operatorIndex);
140 void ParseSplitV(
size_t subgraphIndex,
size_t operatorIndex);
141 void ParseSqueeze(
size_t subgraphIndex,
size_t operatorIndex);
142 void ParseStridedSlice(
size_t subgraphIndex,
size_t operatorIndex);
143 void ParseSub(
size_t subgraphIndex,
size_t operatorIndex);
144 void ParseSum(
size_t subgraphIndex,
size_t operatorIndex);
145 void ParseDiv(
size_t subgraphIndex,
size_t operatorIndex);
146 void ParseTanH(
size_t subgraphIndex,
size_t operatorIndex);
147 void ParseTranspose(
size_t subgraphIndex,
size_t operatorIndex);
148 void ParseTransposeConv(
size_t subgraphIndex,
size_t operatorIndex);
149 void ParseUnpack(
size_t subgraphIndex,
size_t operatorIndex);
150 void ParseArgMax(
size_t subgraphIndex,
size_t operatorIndex);
152 void RegisterProducerOfTensor(
size_t subgraphIndex,
size_t tensorIndex,
armnn::IOutputSlot* slot);
153 void RegisterConsumerOfTensor(
size_t subgraphIndex,
size_t tensorIndex,
armnn::IInputSlot* slot);
154 void RegisterInputSlots(
size_t subgraphIndex,
155 size_t operatorIndex,
157 const std::vector<unsigned int>& tensorIndexes);
158 void RegisterOutputSlots(
size_t subgraphIndex,
159 size_t operatorIndex,
161 const std::vector<unsigned int>& tensorIndexes);
163 void SetupInputLayers(
size_t subgraphIndex);
164 void SetupOutputLayers(
size_t subgraphIndex);
165 void SetupConstantLayers(
size_t subgraphIndex);
169 void AddBroadcastReshapeLayer(
size_t subgraphIndex,
170 size_t operatorIndex,
175 unsigned int outputSlot,
176 tflite::ActivationFunctionType activationType);
180 struct SupportedDataStorage
184 SupportedDataStorage(std::unique_ptr<
float[]>&& data);
185 SupportedDataStorage(std::unique_ptr<uint8_t[]>&& data);
186 SupportedDataStorage(std::unique_ptr<int8_t[]>&& data);
187 SupportedDataStorage(std::unique_ptr<int32_t[]>&& data);
191 std::unique_ptr<float[]> m_FloatData;
192 std::unique_ptr<uint8_t[]> m_Uint8Data;
193 std::unique_ptr<int8_t[]> m_Int8Data;
194 std::unique_ptr<int32_t[]> m_Int32Data;
199 std::pair<armnn::ConstTensor, TfLiteParserImpl::SupportedDataStorage>
205 std::pair<armnn::ConstTensor, SupportedDataStorage>
217 std::vector<OperatorParsingFunction> m_ParserFunctions;
218 std::unordered_map<std::string, OperatorParsingFunction> m_CustomParserFunctions;
226 std::vector<armnn::IInputSlot*> inputSlots;
228 TensorSlots() : outputSlot(nullptr) { }
230 typedef std::vector<TensorSlots> TensorConnections;
233 std::vector<TensorConnections> m_SubgraphConnections;
237 std::vector<std::vector<unsigned int>> m_OverridenOutputShapes;
std::unique_ptr< tflite::TensorT > TensorPtr
std::unique_ptr< tflite::ModelT > ModelPtr
static TensorIdRawPtrVector GetSubgraphOutputs(const ModelPtr &model, size_t subgraphIndex)
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
const tflite::TensorT * TensorRawPtr
const tflite::BufferT * BufferRawPtr
BindingPointInfo GetNetworkOutputBindingInfo(size_t subgraphId, const std::string &name) const
Retrieve binding info (layer id and tensor info) for the network output identified by the given layer...
std::vector< std::string > GetSubgraphOutputTensorNames(size_t subgraphId) const
Return the output tensor names for a given subgraph.
~TfLiteParserImpl()=default
std::unique_ptr< tflite::OperatorT > OperatorPtr
static armnn::TensorInfo OutputShapeOfReshape(const armnn::TensorInfo &inputTensorInfo, const std::vector< int32_t > &targetDimsIn)
TfLiteParserImpl(const armnn::Optional< ITfLiteParser::TfLiteParserOptions > &options=armnn::EmptyOptional())
std::unique_ptr< tflite::BufferT > BufferPtr
armnn::INetworkPtr CreateNetworkFromBinary(const std::vector< uint8_t > &binaryContent)
Create the network from a flatbuffers binary.
static BufferRawPtr GetBuffer(const ModelPtr &model, size_t bufferIndex)
armnn::INetworkPtr CreateNetworkFromBinaryFile(const char *graphFile)
Create the network from a flatbuffers binary file on disk.
std::unique_ptr< tflite::OperatorCodeT > OperatorCodePtr
BindingPointInfo GetNetworkInputBindingInfo(size_t subgraphId, const std::string &name) const
Retrieve binding info (layer id and tensor info) for the network input identified by the given layer ...
static ModelPtr LoadModelFromBinary(const uint8_t *binaryContent, size_t len)
static armnn::TensorInfo OutputShapeOfSqueeze(const std::vector< uint32_t > &squeezeDims, const armnn::TensorInfo &inputTensorInfo)
std::vector< TensorIdRawPtr > TensorIdRawPtrVector
static std::vector< int32_t > & GetInputTensorIds(const ModelPtr &model, size_t subgraphIndex, size_t operatorIndex)
An output connection slot for a layer.
static const std::string GetVersion()
Retrieve version in X.Y.Z form.
static ModelPtr LoadModelFromFile(const char *fileName)
std::vector< TensorRawPtr > TensorRawPtrVector
size_t GetSubgraphCount() const
Return the number of subgraphs in the parsed model.
std::pair< size_t, TensorRawPtr > TensorIdRawPtr
std::unique_ptr< tflite::SubGraphT > SubgraphPtr
static TensorIdRawPtrVector GetSubgraphInputs(const ModelPtr &model, size_t subgraphIndex)
static TensorRawPtrVector GetInputs(const ModelPtr &model, size_t subgraphIndex, size_t operatorIndex)
static TensorRawPtrVector GetOutputs(const ModelPtr &model, size_t subgraphIndex, size_t operatorIndex)
EmptyOptional is used to initialize the Optional class in case we want to have default value for an O...
static std::vector< int32_t > & GetOutputTensorIds(const ModelPtr &model, size_t subgraphIndex, size_t operatorIndex)
armnn::BindingPointInfo BindingPointInfo
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
std::vector< std::string > GetSubgraphInputTensorNames(size_t subgraphId) const
Return the input tensor names for a given subgraph.