31 #include <schema_generated.h>
33 #include <flatbuffers/flexbuffers.h>
35 #include <fmt/format.h>
42 #define ARMNN_THROW_PARSE_EXCEPTION(msg) \
44 throw armnn::ParseException( static_cast<const std::stringstream&>( std::stringstream() << msg \
46 << CHECK_LOCATION().AsString()).str()); \
49 using namespace armnn;
55 pTfLiteParserImpl(
new TfLiteParserImpl(options)) {}
57 ITfLiteParser::~ITfLiteParser() =
default;
79 armnn::INetworkPtr ITfLiteParser::CreateNetworkFromBinary(
const std::vector<uint8_t>& binaryContent)
81 return pTfLiteParserImpl->CreateNetworkFromBinary(binaryContent);
85 const std::string& name)
const
87 return pTfLiteParserImpl->GetNetworkInputBindingInfo(subgraphId, name);
91 const std::string& name)
const
93 return pTfLiteParserImpl->GetNetworkOutputBindingInfo(subgraphId, name);
96 size_t ITfLiteParser::GetSubgraphCount()
const
98 return pTfLiteParserImpl->GetSubgraphCount();
101 std::vector<std::string> ITfLiteParser::GetSubgraphInputTensorNames(
size_t subgraphId)
const
103 return pTfLiteParserImpl->GetSubgraphInputTensorNames(subgraphId);
106 std::vector<std::string> ITfLiteParser::GetSubgraphOutputTensorNames(
size_t subgraphId)
const
108 return pTfLiteParserImpl->GetSubgraphOutputTensorNames(subgraphId);
114 const uint32_t VIRTUAL_OPERATOR_ID = std::numeric_limits<uint32_t>::max();
117 size_t subgraphIndex,
120 if (model.get() ==
nullptr)
123 fmt::format(
"{} was called with invalid (null) model. "
124 "Possible reason is that the model is not yet loaded and Unpack(ed). "
130 else if (subgraphIndex >= model->subgraphs.size())
133 fmt::format(
"{} was called with an invalid subgraph index. "
141 #define CHECK_SUBGRAPH(MODEL, SUBGRAPH_INDEX) \
142 CheckSubgraph(MODEL, SUBGRAPH_INDEX, CHECK_LOCATION())
145 size_t subgraphIndex,
146 size_t operatorIndex,
149 if (model.get() ==
nullptr)
152 fmt::format(
"{} was called with invalid (null) model. "
153 "Possible reason is that the model is not yet loaded and Unpack(ed). "
154 "subgraph:{} operator:{} at {}",
160 else if (subgraphIndex >= model->subgraphs.size())
163 fmt::format(
"{} was called with an invalid subgraph index. "
164 "subgraph:{} operator:{} at {}",
170 else if (operatorIndex >= model->subgraphs[subgraphIndex]->operators.size() &&
171 operatorIndex != VIRTUAL_OPERATOR_ID)
174 fmt::format(
"{} was called with an invalid operator index. "
175 "subgraph:{} operator:{} at {}",
183 #define CHECK_MODEL(MODEL, SUBGRAPH_INDEX, OPERATOR_INDEX) \
184 CheckModel(MODEL, SUBGRAPH_INDEX, OPERATOR_INDEX, CHECK_LOCATION())
187 size_t subgraphIndex,
193 ARMNN_ASSERT_MSG(model.get() !=
nullptr,
"Expecting a valid model in this function");
197 ARMNN_ASSERT_MSG(subgraphIndex < model->subgraphs.size(),
"Expecting a valid subgraph index");
200 if (tensorIndex >= model->subgraphs[subgraphIndex]->tensors.size())
203 fmt::format(
"{} was called with an invalid tensor index. "
204 "subgraph:{} tensor:{} at {}",
212 #define CHECK_TENSOR(MODEL, SUBGRAPH_INDEX, TENSOR_INDEX) \
213 CheckTensor(MODEL, SUBGRAPH_INDEX, TENSOR_INDEX, CHECK_LOCATION())
218 if (rawPtr ==
nullptr)
221 fmt::format(
"{} was called with a null tensor pointer at {}", location.
m_Function, location.
FileLine()));
225 #define CHECK_TENSOR_PTR(TENSOR_PTR) \
226 CheckTensorPtr(TENSOR_PTR, CHECK_LOCATION())
232 if (model.get() ==
nullptr)
235 fmt::format(
"{} was called with invalid (null) model. "
236 "Possible reason is that the model is not yet loaded and Unpack(ed). "
242 else if (bufferIndex >= model->buffers.size())
245 fmt::format(
"{} was called with an invalid buffer index. "
246 "buffer index:{} at {}",
251 else if (model->buffers[bufferIndex].get() ==
nullptr)
254 fmt::format(
"The buffer #{} is null. {}",
260 #define CHECK_BUFFER(MODEL, BUFFER_INDEX) \
261 CheckBuffer(MODEL, BUFFER_INDEX, CHECK_LOCATION())
263 void CheckBufferSize(TfLiteParserImpl::BufferRawPtr bufferPtr,
268 if (bufferPtr ==
nullptr)
271 fmt::format(
"BufferPtr is null for buffer:{}. {}",
278 std::stringstream ss;
279 ss <<
"Buffer #" << bufferId <<
" has " << bufferPtr->data.size() <<
" bytes. "
280 <<
"For tensor: " << tensorInfo.
GetShape()
281 <<
" expecting: " << tensorInfo.
GetNumBytes() <<
" bytes and "
290 const auto& operatorPtr = model->subgraphs[subgraphIndex]->operators[operatorIndex];
291 auto opcodeIndex = operatorPtr->opcode_index;
294 #if defined(ARMNN_POST_TFLITE_2_3)
295 auto opcode = std::max(model->operator_codes[opcodeIndex]->builtin_code,
296 static_cast<tflite::BuiltinOperator
>(model->operator_codes[opcodeIndex]->deprecated_builtin_code));
298 auto opcode = model->operator_codes[opcodeIndex]->builtin_code;
307 TfLiteParserImpl::BufferRawPtr bufferPtr = TfLiteParserImpl::GetBuffer(model, bufferIndex);
308 std::vector<unsigned int> buffer(
info.GetNumElements());
312 ::memcpy(buffer.data(), bufferPtr->data.data(), bufferPtr->data.size());
316 std::vector<uint64_t> uint64Buffer(
info.GetNumElements());
317 ::memcpy(uint64Buffer.data(), bufferPtr->data.data(), bufferPtr->data.size());
318 buffer.assign(std::begin(uint64Buffer), std::end(uint64Buffer));
324 fmt::format(
"Unsupported data type for uint buffer {}, only Signed 32 or Signed 64 are supported. {}",
331 #define CHECK_BUFFER_SIZE(BUFFER_PTR, TENSOR_INFO, BUFFER_ID) \
332 CheckBufferSize(BUFFER_PTR, TENSOR_INFO, BUFFER_ID, CHECK_LOCATION())
336 switch(activationType)
338 case tflite::ActivationFunctionType_NONE:
339 case tflite::ActivationFunctionType_RELU:
340 case tflite::ActivationFunctionType_RELU6:
341 case tflite::ActivationFunctionType_TANH:
352 #define CHECK_SUPPORTED_FUSED_ACTIVATION(OPTION, SUBGRAPH_INDEX, OPERATOR_INDEX) \
354 if (IsActivationSupported(OPTION->fused_activation_function) == false) \
356 throw ParseException( \
357 fmt::format("TfLite parser doesn't support fused activation: " \
358 "{}/{} in {} subgraph:{} operator:{} at {}", \
359 OPTION->fused_activation_function, \
360 tflite::EnumNameActivationFunctionType(\
361 OPTION->fused_activation_function), \
365 CHECK_LOCATION().FileLine())); \
370 std::vector<unsigned int> AsUnsignedVector(
const std::vector<int32_t>& in)
372 std::vector<unsigned int> result;
373 result.reserve(in.size());
386 bool IsOptionalOperandPresent(
int input)
391 void CalcPadding(uint32_t inputSize,
395 uint32_t& paddingFront,
396 uint32_t& paddingBack,
397 tflite::Padding padding)
401 if (padding == tflite::Padding_SAME)
403 uint32_t outputSize = (inputSize + stride - 1) / stride;
404 uint32_t dilatedSize = filterSize + (dilation - 1) * (filterSize - 1);
405 uint32_t temp = (outputSize - 1) * stride + dilatedSize;
406 if (temp > inputSize)
408 paddingFront = (temp - inputSize) / 2;
409 paddingBack = (temp - inputSize) - paddingFront;
417 void CalcPadding(uint32_t inputSize,
421 uint32_t& paddingFront,
422 uint32_t& paddingBack,
423 tflite::Padding padding,
429 if (padding == tflite::Padding_SAME)
431 uint32_t totalPadding = (inputSize - 1) * stride + filterSize - outputSize;
432 paddingFront = totalPadding / 2;
433 paddingBack = totalPadding - paddingFront;
438 const std::vector<unsigned int>& shape,
439 const bool outputTensor =
false)
444 switch (tensorPtr->type)
446 case tflite::TensorType_UINT8:
449 case tflite::TensorType_FLOAT32:
452 case tflite::TensorType_FLOAT16:
455 case tflite::TensorType_INT8:
456 if (tensorPtr->quantization->zero_point.size() == 1)
467 case tflite::TensorType_INT16:
470 case tflite::TensorType_INT32:
473 case tflite::TensorType_INT64:
476 case tflite::TensorType_BOOL:
483 fmt::format(
"Unsupported data type {} = {} for tensor: {}. {}",
485 tflite::EnumNameTensorType(tensorPtr->type),
492 std::vector<unsigned int> safeShape = shape;
493 if (shape.size() == 0)
495 safeShape.push_back(1);
500 tensorShape =
TensorShape(armnn::numeric_cast<unsigned int>(safeShape.size()), safeShape.data());
504 size_t shapeSignatureSize = tensorPtr->shape_signature.size();
507 if (shapeSignatureSize != 0)
510 if (shapeSignatureSize != shape.size())
514 for (
unsigned int i = 0; i < shapeSignatureSize; ++i)
516 unsigned int dim = tensorPtr->shape_signature[i] > -1 ?
517 static_cast<unsigned int>(tensorPtr->shape_signature[i]) : 0;
518 safeShape.push_back(dim);
522 std::unique_ptr<bool[]> dimMask = std::make_unique<bool[]>(tensorPtr->shape_signature.size());
523 bool batchOnly =
true;
524 for (
unsigned int i = 0; i < tensorPtr->shape_signature.size(); ++i)
526 dimMask[i] = tensorPtr->shape_signature[i] != -1;
528 if (i > 0 && !dimMask[i])
537 tensorShape =
TensorShape(
static_cast<unsigned int>(safeShape.size()), safeShape.data(), dimMask.get());
540 else if (shape.size() == 0)
546 tensorShape =
TensorShape(armnn::numeric_cast<unsigned int>(shape.size()), shape.data());
550 float quantizationScale = 1.0f;
551 int32_t quantizationOffset = 0;
553 if (tensorPtr->quantization.get())
555 if (tensorPtr->quantization->scale.size() <= 1)
560 if (tensorPtr->quantization->scale.size() == 1)
562 quantizationScale = tensorPtr->quantization->scale[0];
564 if (tensorPtr->quantization->zero_point.size() == 1)
568 quantizationOffset = armnn::numeric_cast<int32_t>(tensorPtr->quantization->zero_point[0]);
579 std::vector<float> quantizationScales;
580 std::vector<int32_t> quantizationOffsets;
583 std::copy(tensorPtr->quantization->scale.begin(),
584 tensorPtr->quantization->scale.end(),
585 std::back_inserter(quantizationScales));
591 armnn::numeric_cast<unsigned int>(tensorPtr->quantization->quantized_dimension));
606 const bool outputTensor =
false)
608 auto const& dimensions = AsUnsignedVector(tensorPtr->shape);
609 return ToTensorInfo(tensorPtr, dimensions, outputTensor);
613 std::pair<armnn::ConstTensor, std::unique_ptr<T[]>>
622 fmt::format(
"Buffer for buffer:{} is null", tensorPtr->buffer).c_str());
630 reinterpret_cast<const T*
>(bufferPtr->data.data()), data.get(),
sizeof(T));
634 ::memcpy(data.get(), bufferPtr->data.data(), tensorInfo.
GetNumBytes());
640 return std::make_pair(
ConstTensor(tensorInfo, data.get()), std::move(data));
653 if (actualSize != expected.size())
658 for (
unsigned int i = 0u; i < actualSize; i++)
660 if (expected[i] < 0 ||
661 actual[i] !=
static_cast<unsigned int>(expected[i]))
672 std::vector<int32_t> expectedVec;
675 expectedVec.push_back(expected[i]);
680 void CheckMatchingQuantization(
const TensorInfo& first,
682 const std::string& descName,
683 std::string
const& firstName,
684 std::string
const& secondName)
696 if (firstDataType != secondDataType)
699 " must be of the same quantized type, " +
707 " must have the same quantization space, " +
717 auto shape = tensorPtr->shape;
723 auto shapeSig = tensorPtr->shape_signature;
725 if (shapeSig.empty())
730 for (
unsigned int i = 0; i < shapeSig.size() ; ++i)
732 if (shapeSig[i] == -1)
744 , m_Network(nullptr, nullptr)
745 , m_ParserFunctions(tflite::BuiltinOperator_MAX+1, &
TfLiteParserImpl::ParseUnsupportedOperator)
748 m_ParserFunctions[tflite::BuiltinOperator_ABS] = &TfLiteParserImpl::ParseAbs;
749 m_ParserFunctions[tflite::BuiltinOperator_ADD] = &TfLiteParserImpl::ParseAdd;
750 m_ParserFunctions[tflite::BuiltinOperator_ARG_MIN] = &TfLiteParserImpl::ParseArgMin;
751 m_ParserFunctions[tflite::BuiltinOperator_ARG_MAX] = &TfLiteParserImpl::ParseArgMax;
752 m_ParserFunctions[tflite::BuiltinOperator_AVERAGE_POOL_2D] = &TfLiteParserImpl::ParseAveragePool2D;
753 m_ParserFunctions[tflite::BuiltinOperator_BATCH_TO_SPACE_ND] = &TfLiteParserImpl::ParseBatchToSpaceND;
754 m_ParserFunctions[tflite::BuiltinOperator_BATCH_MATMUL] = &TfLiteParserImpl::ParseBatchMatMul;
755 m_ParserFunctions[tflite::BuiltinOperator_CEIL] = &TfLiteParserImpl::ParseCeil;
756 m_ParserFunctions[tflite::BuiltinOperator_CAST] = &TfLiteParserImpl::ParseCast;
757 m_ParserFunctions[tflite::BuiltinOperator_CONCATENATION] = &TfLiteParserImpl::ParseConcatenation;
758 m_ParserFunctions[tflite::BuiltinOperator_CONV_2D] = &TfLiteParserImpl::ParseConv2D;
760 #if defined(ARMNN_POST_TFLITE_2_4)
761 m_ParserFunctions[tflite::BuiltinOperator_CONV_3D] = &TfLiteParserImpl::ParseConv3D;
763 m_ParserFunctions[tflite::BuiltinOperator_CUSTOM] = &TfLiteParserImpl::ParseCustomOperator;
764 m_ParserFunctions[tflite::BuiltinOperator_DEPTH_TO_SPACE] = &TfLiteParserImpl::ParseDepthToSpace;
765 m_ParserFunctions[tflite::BuiltinOperator_DEPTHWISE_CONV_2D] = &TfLiteParserImpl::ParseDepthwiseConv2D;
766 m_ParserFunctions[tflite::BuiltinOperator_DEQUANTIZE] = &TfLiteParserImpl::ParseDequantize;
767 m_ParserFunctions[tflite::BuiltinOperator_DIV] = &TfLiteParserImpl::ParseDiv;
768 m_ParserFunctions[tflite::BuiltinOperator_ELU] = &TfLiteParserImpl::ParseElu;
769 m_ParserFunctions[tflite::BuiltinOperator_EQUAL] = &TfLiteParserImpl::ParseEqual;
770 m_ParserFunctions[tflite::BuiltinOperator_EXP] = &TfLiteParserImpl::ParseExp;
771 m_ParserFunctions[tflite::BuiltinOperator_EXPAND_DIMS] = &TfLiteParserImpl::ParseExpandDims;
772 m_ParserFunctions[tflite::BuiltinOperator_FLOOR_DIV] = &TfLiteParserImpl::ParseFloorDiv;
773 m_ParserFunctions[tflite::BuiltinOperator_FULLY_CONNECTED] = &TfLiteParserImpl::ParseFullyConnected;
774 m_ParserFunctions[tflite::BuiltinOperator_GATHER] = &TfLiteParserImpl::ParseGather;
775 m_ParserFunctions[tflite::BuiltinOperator_GATHER_ND] = &TfLiteParserImpl::ParseGatherNd;
776 m_ParserFunctions[tflite::BuiltinOperator_GREATER] = &TfLiteParserImpl::ParseGreater;
777 m_ParserFunctions[tflite::BuiltinOperator_GREATER_EQUAL] = &TfLiteParserImpl::ParseGreaterOrEqual;
778 m_ParserFunctions[tflite::BuiltinOperator_HARD_SWISH] = &TfLiteParserImpl::ParseHardSwish;
779 m_ParserFunctions[tflite::BuiltinOperator_LEAKY_RELU] = &TfLiteParserImpl::ParseLeakyRelu;
780 m_ParserFunctions[tflite::BuiltinOperator_LESS] = &TfLiteParserImpl::ParseLess;
781 m_ParserFunctions[tflite::BuiltinOperator_LESS_EQUAL] = &TfLiteParserImpl::ParseLessOrEqual;
782 m_ParserFunctions[tflite::BuiltinOperator_LOCAL_RESPONSE_NORMALIZATION]
783 = &TfLiteParserImpl::ParseLocalResponseNormalization;
784 m_ParserFunctions[tflite::BuiltinOperator_LOG] = &TfLiteParserImpl::ParseLog;
785 m_ParserFunctions[tflite::BuiltinOperator_LOGICAL_NOT] = &TfLiteParserImpl::ParseLogicalNot;
786 m_ParserFunctions[tflite::BuiltinOperator_LOGISTIC] = &TfLiteParserImpl::ParseLogistic;
787 m_ParserFunctions[tflite::BuiltinOperator_LOG_SOFTMAX] = &TfLiteParserImpl::ParseLogSoftmax;
788 m_ParserFunctions[tflite::BuiltinOperator_L2_NORMALIZATION] = &TfLiteParserImpl::ParseL2Normalization;
789 m_ParserFunctions[tflite::BuiltinOperator_MAX_POOL_2D] = &TfLiteParserImpl::ParseMaxPool2D;
790 m_ParserFunctions[tflite::BuiltinOperator_MAXIMUM] = &TfLiteParserImpl::ParseMaximum;
791 m_ParserFunctions[tflite::BuiltinOperator_MEAN] = &TfLiteParserImpl::ParseMean;
792 m_ParserFunctions[tflite::BuiltinOperator_MINIMUM] = &TfLiteParserImpl::ParseMinimum;
793 m_ParserFunctions[tflite::BuiltinOperator_MIRROR_PAD] = &TfLiteParserImpl::ParseMirrorPad;
794 m_ParserFunctions[tflite::BuiltinOperator_MUL] = &TfLiteParserImpl::ParseMul;
795 m_ParserFunctions[tflite::BuiltinOperator_NEG] = &TfLiteParserImpl::ParseNeg;
796 m_ParserFunctions[tflite::BuiltinOperator_NOT_EQUAL] = &TfLiteParserImpl::ParseNotEqual;
797 m_ParserFunctions[tflite::BuiltinOperator_PACK] = &TfLiteParserImpl::ParsePack;
798 m_ParserFunctions[tflite::BuiltinOperator_PAD] = &TfLiteParserImpl::ParsePad;
799 m_ParserFunctions[tflite::BuiltinOperator_PADV2] = &TfLiteParserImpl::ParsePad;
800 m_ParserFunctions[tflite::BuiltinOperator_PRELU] = &TfLiteParserImpl::ParsePrelu;
801 m_ParserFunctions[tflite::BuiltinOperator_QUANTIZE] = &TfLiteParserImpl::ParseQuantize;
802 m_ParserFunctions[tflite::BuiltinOperator_RELU] = &TfLiteParserImpl::ParseRelu;
803 m_ParserFunctions[tflite::BuiltinOperator_RELU6] = &TfLiteParserImpl::ParseRelu6;
804 m_ParserFunctions[tflite::BuiltinOperator_REDUCE_MAX] = &TfLiteParserImpl::ParseReduceMax;
805 m_ParserFunctions[tflite::BuiltinOperator_REDUCE_MIN] = &TfLiteParserImpl::ParseReduceMin;
806 m_ParserFunctions[tflite::BuiltinOperator_REDUCE_PROD] = &TfLiteParserImpl::ParseReduceProd;
807 m_ParserFunctions[tflite::BuiltinOperator_RESHAPE] = &TfLiteParserImpl::ParseReshape;
808 m_ParserFunctions[tflite::BuiltinOperator_RESIZE_BILINEAR] = &TfLiteParserImpl::ParseResizeBilinear;
809 m_ParserFunctions[tflite::BuiltinOperator_RESIZE_NEAREST_NEIGHBOR] = &TfLiteParserImpl::ParseResizeNearestNeighbor;
810 m_ParserFunctions[tflite::BuiltinOperator_RSQRT] = &TfLiteParserImpl::ParseRsqrt;
811 m_ParserFunctions[tflite::BuiltinOperator_SQRT] = &TfLiteParserImpl::ParseSqrt;
812 m_ParserFunctions[tflite::BuiltinOperator_SHAPE] = &TfLiteParserImpl::ParseShape;
813 m_ParserFunctions[tflite::BuiltinOperator_SIN] = &TfLiteParserImpl::ParseSin;
814 m_ParserFunctions[tflite::BuiltinOperator_SLICE] = &TfLiteParserImpl::ParseSlice;
815 m_ParserFunctions[tflite::BuiltinOperator_SOFTMAX] = &TfLiteParserImpl::ParseSoftmax;
816 m_ParserFunctions[tflite::BuiltinOperator_SPACE_TO_BATCH_ND] = &TfLiteParserImpl::ParseSpaceToBatchND;
817 m_ParserFunctions[tflite::BuiltinOperator_SPACE_TO_DEPTH] = &TfLiteParserImpl::ParseSpaceToDepth;
818 m_ParserFunctions[tflite::BuiltinOperator_SPLIT] = &TfLiteParserImpl::ParseSplit;
819 m_ParserFunctions[tflite::BuiltinOperator_SPLIT_V] = &TfLiteParserImpl::ParseSplitV;
820 m_ParserFunctions[tflite::BuiltinOperator_SQUEEZE] = &TfLiteParserImpl::ParseSqueeze;
821 m_ParserFunctions[tflite::BuiltinOperator_STRIDED_SLICE] = &TfLiteParserImpl::ParseStridedSlice;
822 m_ParserFunctions[tflite::BuiltinOperator_SUB] = &TfLiteParserImpl::ParseSub;
823 m_ParserFunctions[tflite::BuiltinOperator_SUM] = &TfLiteParserImpl::ParseSum;
824 m_ParserFunctions[tflite::BuiltinOperator_TANH] = &TfLiteParserImpl::ParseTanH;
825 m_ParserFunctions[tflite::BuiltinOperator_TRANSPOSE] = &TfLiteParserImpl::ParseTranspose;
826 m_ParserFunctions[tflite::BuiltinOperator_TRANSPOSE_CONV] = &TfLiteParserImpl::ParseTransposeConv;
827 m_ParserFunctions[tflite::BuiltinOperator_UNIDIRECTIONAL_SEQUENCE_LSTM]
828 = &TfLiteParserImpl::ParseUnidirectionalSequenceLSTM;
829 m_ParserFunctions[tflite::BuiltinOperator_UNPACK] = &TfLiteParserImpl::ParseUnpack;
832 m_CustomParserFunctions[
"TFLite_Detection_PostProcess"] = &TfLiteParserImpl::ParseDetectionPostProcess;
836 size_t operatorIndex,
839 const auto& subgraphPtr = m_Model->subgraphs[subgraphIndex];
840 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
843 auto search = armnnTfLiteParser::TfLiteParserImpl::m_TensorInfos.find(inputId);
845 if (search != m_TensorInfos.end())
847 return m_TensorInfos[inputId];
852 m_TensorInfos.insert({ inputId, tensorInfo });
857 armnn::TensorInfo TfLiteParserImpl::OutputTensorInfoFromInputs(
size_t subgraphIndex,
858 size_t operatorIndex,
861 std::vector<int> inputs)
863 const auto& subgraphPtr = m_Model->subgraphs[subgraphIndex];
864 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
868 auto outputSearch = armnnTfLiteParser::TfLiteParserImpl::m_TensorInfos.find(outputId);
870 if (outputSearch != m_TensorInfos.end())
872 return m_TensorInfos[outputId];
875 const auto& outputTensorPtr = subgraphPtr->tensors[outputId].get();
878 if (IsDynamic(outputTensorPtr))
884 inputs.emplace_back(i);
888 std::vector<armnn::TensorShape> inputShapes;
890 for (
unsigned int i = 0; i < inputs.size(); ++i)
893 auto search = armnnTfLiteParser::TfLiteParserImpl::m_TensorInfos.find(inputId);
895 if (search != m_TensorInfos.end())
897 auto &inputTensorInfo = m_TensorInfos[inputId];
898 inputShapes.push_back(inputTensorInfo.GetShape());
902 m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
904 m_TensorInfos.insert({ inputId, inputTensorInfo});
905 inputShapes.push_back(inputTensorInfo.GetShape());
911 m_TensorInfos.insert({ outputId, tensor});
915 armnn::TensorInfo TfLiteParserImpl::OutputTensorInfoFromShapes(
size_t subgraphIndex,
916 size_t operatorIndex,
919 std::vector<armnn::TensorShape> inputShapes)
921 const auto& subgraphPtr = m_Model->subgraphs[subgraphIndex];
922 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
925 const auto& outputTensorPtr = subgraphPtr->tensors[outputId].get();
928 if (IsDynamic(outputTensorPtr))
933 m_TensorInfos.insert({ outputId, tensor});
937 void TfLiteParserImpl::ResetParser()
941 m_SubgraphConnections.clear();
942 m_OverriddenOutputShapes.clear();
943 m_ConstantsToDequantize.clear();
944 m_ConstantsToBeCreated.clear();
945 m_TensorInfos.clear();
952 return CreateNetworkFromModel();
959 return CreateNetworkFromModel();
966 m_Model = std::move(model);
968 return CreateNetworkFromModel();
971 INetworkPtr TfLiteParserImpl::CreateNetworkFromModel()
978 if (m_Options.value().m_InferAndValidate)
982 {
"InferAndValidate",
true }
985 networkOptions.push_back(shapeInferenceMethodOption);
987 if (m_Options.value().m_AllowExpandedDims)
991 {
"AllowExpandedDims",
true }
994 networkOptions.push_back(shapeInferenceMethodOption);
997 m_Network = INetwork::Create(networkOptions);
1000 if (m_Model->subgraphs.size() != 1)
1003 fmt::format(
"Current TfLite parser only supports 1 subgraph. Current one has: {} {}",
1004 m_Model->subgraphs.size(),
1008 size_t subgraphIndex = 0;
1009 size_t operatorIndex = 0;
1012 for (
SubgraphPtr const& subgraph : m_Model->subgraphs)
1014 SetupInputLayerTensorInfos(subgraphIndex);
1015 SetupConstantLayerTensorInfos(subgraphIndex);
1017 m_SubgraphConnections.emplace_back(subgraph->tensors.size());
1020 auto const& opCodePtr = m_Model->operator_codes[op->opcode_index];
1023 #if defined(ARMNN_POST_TFLITE_2_3)
1024 auto builtinCode = std::max(opCodePtr->builtin_code,
1025 static_cast<tflite::BuiltinOperator
>(opCodePtr->deprecated_builtin_code));
1027 auto builtinCode = opCodePtr->builtin_code;
1030 if (builtinCode > tflite::BuiltinOperator_MAX)
1032 throw ParseException(fmt::format(
"Operator code {} is out of range 0-{}. "
1033 "subgraph:{} operator idx:{}. {}",
1034 builtinCode, tflite::BuiltinOperator_MAX, subgraphIndex,
1039 auto& parserFunction = m_ParserFunctions[builtinCode];
1040 (this->*parserFunction)(subgraphIndex, operatorIndex);
1044 SetupInputLayers(subgraphIndex);
1045 SetupOutputLayers(subgraphIndex);
1046 SetupConstantLayers(subgraphIndex);
1054 std::stringstream errorString;
1055 errorString <<
"Failed to parse operator #" << operatorIndex <<
" within subgraph #"
1056 << subgraphIndex <<
" error: " << e.
what();
1058 std::stringstream errors;
1059 errors << errorString.str() <<
"\n";
1064 for (subgraphIndex = 0; subgraphIndex < m_SubgraphConnections.size(); ++subgraphIndex)
1066 for (
size_t tensorIndex = 0; tensorIndex < m_SubgraphConnections[subgraphIndex].size(); ++tensorIndex)
1068 if (m_SubgraphConnections[subgraphIndex][tensorIndex].outputSlot !=
nullptr)
1070 for (
size_t inputSlotIdx = 0;
1071 inputSlotIdx < m_SubgraphConnections[subgraphIndex][tensorIndex].inputSlots.size();
1074 m_SubgraphConnections[subgraphIndex][tensorIndex].outputSlot->Connect(
1075 *(m_SubgraphConnections[subgraphIndex][tensorIndex].inputSlots[inputSlotIdx]));
1080 return std::move(m_Network);
1087 return (TfLiteParserImpl::IsConstTensor(tensorPtr) && inputDataType == DataType::Float32 &&
1088 (tensorDataType == DataType::QAsymmU8 ||
1089 tensorDataType == DataType::QAsymmS8 ||
1090 tensorDataType == DataType::QSymmS8 ||
1091 tensorDataType == DataType::Signed32 ||
1092 tensorDataType == DataType::Signed64));
1095 void TfLiteParserImpl::RegisterProducerOfTensor(
size_t subgraphIndex,
1100 ARMNN_ASSERT(m_SubgraphConnections.size() > subgraphIndex);
1101 ARMNN_ASSERT(m_SubgraphConnections[subgraphIndex].size() > tensorIndex);
1103 TensorSlots & tensorSlots = m_SubgraphConnections[subgraphIndex][tensorIndex];
1109 if (tensorSlots.outputSlot !=
nullptr)
1111 throw ParseException(fmt::format(
"Another layer has already registered itself as the producer of "
1112 "subgraph:{} tensor:{} {}",
1118 tensorSlots.outputSlot = slot;
1121 void TfLiteParserImpl::RegisterConsumerOfTensor(
size_t subgraphIndex,
1126 ARMNN_ASSERT(m_SubgraphConnections.size() > subgraphIndex);
1127 ARMNN_ASSERT(m_SubgraphConnections[subgraphIndex].size() > tensorIndex);
1129 TensorSlots& tensorSlots = m_SubgraphConnections[subgraphIndex][tensorIndex];
1130 tensorSlots.inputSlots.push_back(slot);
1133 void TfLiteParserImpl::ParseCustomOperator(
size_t subgraphIndex,
size_t operatorIndex)
1135 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1138 auto customParserFunction = &TfLiteParserImpl::ParseUnsupportedOperator;
1141 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
1142 const auto& customCode = m_Model->operator_codes[operatorPtr->opcode_index]->custom_code;
1145 auto iterator = m_CustomParserFunctions.find(customCode);
1146 if (iterator != m_CustomParserFunctions.end())
1148 customParserFunction = iterator->second;
1152 (this->*customParserFunction)(subgraphIndex, operatorIndex);
1155 void TfLiteParserImpl::ParseUnsupportedOperator(
size_t subgraphIndex,
size_t operatorIndex)
1157 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1159 const auto & operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
1161 auto opcodeIndex = operatorPtr->opcode_index;
1164 #if defined(ARMNN_POST_TFLITE_2_3)
1165 auto opcode = std::max(m_Model->operator_codes[opcodeIndex]->builtin_code,
1166 static_cast<tflite::BuiltinOperator
>(m_Model->operator_codes[opcodeIndex]->deprecated_builtin_code));
1168 auto opcode = m_Model->operator_codes[opcodeIndex]->builtin_code;
1171 if (!m_Options || !m_Options.value().m_StandInLayerForUnsupported)
1175 fmt::format(
"Operator not supported. "
1176 "subgraph:{} operator:{} "
1177 "opcode_index:{} opcode:{} / {} {}",
1182 tflite::EnumNameBuiltinOperator(opcode),
1186 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1187 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1189 const unsigned int numInputs = armnn::numeric_cast<unsigned int>(inputs.size());
1190 const unsigned int numOutputs = armnn::numeric_cast<unsigned int>(outputs.size());
1193 auto layerName = fmt::format(
"StandIn:{}:{}:{}", subgraphIndex, operatorIndex, opcode);
1196 IConnectableLayer* layer = m_Network->AddStandInLayer(descriptor, layerName.c_str());
1199 for (
unsigned int i = 0u; i < numOutputs; ++i)
1204 auto inputTensorIds = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1205 auto outputTensorIds = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1207 RegisterInputSlots(subgraphIndex, operatorIndex, layer, inputTensorIds);
1208 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, outputTensorIds);
1211 void TfLiteParserImpl::ParseCast(
size_t subgraphIndex,
size_t operatorIndex)
1213 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1215 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1217 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1220 auto layerName = fmt::format(
"Cast:{}:{}", subgraphIndex, operatorIndex);
1225 TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0});
1228 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1229 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
1231 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1232 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, outputTensorIndexes);
1235 void TfLiteParserImpl::ParseConv2D(
size_t subgraphIndex,
size_t operatorIndex)
1237 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1239 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
1240 const auto* options = operatorPtr->builtin_options.AsConv2DOptions();
1244 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1245 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1249 inputs.size() == 3 ?
1257 armnn::TensorInfo inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
1258 armnn::TensorInfo filterTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 1);
1261 unsigned int inputHeight = inputTensorInfo.
GetShape()[1];
1262 unsigned int inputWidth = inputTensorInfo.
GetShape()[2];
1266 unsigned int filterHeight = filterTensorInfo.
GetShape()[1];
1267 unsigned int filterWidth = filterTensorInfo.
GetShape()[2];
1269 CalcPadding(inputHeight, filterHeight, desc.
m_StrideY,
1271 CalcPadding(inputWidth, filterWidth, desc.
m_StrideX,
1276 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1277 std::vector<unsigned int> tensorIndexesToRegister = { inputTensorIndexes[0], inputTensorIndexes[1] };
1279 auto layerName = fmt::format(
"Conv2D:{}:{}", subgraphIndex, operatorIndex);
1282 if (ShouldConstantTensorBeConverted(inputs[1], inputTensorInfo.
GetDataType(), filterTensorInfo.
GetDataType()))
1284 m_ConstantsToDequantize.emplace_back(inputs[1]->buffer);
1289 armnn::TensorInfo biasTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 2);
1292 tensorIndexesToRegister.emplace_back(inputTensorIndexes[2]);
1294 if (ShouldConstantTensorBeConverted(inputs[2], inputTensorInfo.
GetDataType(), biasTensorInfo.
GetDataType()))
1296 m_ConstantsToDequantize.emplace_back(inputs[2]->buffer);
1302 armnn::TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0, 1});
1307 RegisterInputSlots(subgraphIndex, operatorIndex, layer, tensorIndexesToRegister);
1309 layer = AddFusedActivationLayer(layer, 0, options->fused_activation_function);
1311 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1312 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, { outputTensorIndexes[0] });
1316 #if defined(ARMNN_POST_TFLITE_2_4)
1317 void TfLiteParserImpl::ParseConv3D(
size_t subgraphIndex,
size_t operatorIndex)
1319 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1321 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
1322 const auto* options = operatorPtr->builtin_options.AsConv3DOptions();
1336 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1339 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1342 armnn::TensorInfo inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
1343 armnn::TensorInfo filterTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 1);
1346 unsigned int inputDepth = inputTensorInfo.
GetShape()[1];
1347 unsigned int inputHeight = inputTensorInfo.
GetShape()[2];
1348 unsigned int inputWidth = inputTensorInfo.
GetShape()[3];
1351 unsigned int filterDepth = filterTensorInfo.
GetShape()[0];
1352 unsigned int filterHeight = filterTensorInfo.
GetShape()[1];
1353 unsigned int filterWidth = filterTensorInfo.
GetShape()[2];
1355 CalcPadding(inputDepth, filterDepth, desc.
m_StrideZ,
1357 CalcPadding(inputHeight, filterHeight, desc.
m_StrideY,
1359 CalcPadding(inputWidth, filterWidth, desc.
m_StrideX,
1362 auto filterTensorAndData = CreateConstTensorNonPermuted(inputs[1], filterTensorInfo, inputTensorInfo.
GetDataType());
1364 auto layerName = fmt::format(
"Conv3D:{}:{}", subgraphIndex, operatorIndex);
1366 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1369 std::vector<unsigned int> tensorIndexesToRegister = {inputTensorIndexes[0], inputTensorIndexes[1]};
1371 if (inputs.size() == 3)
1376 tensorIndexesToRegister.emplace_back(inputTensorIndexes[2]);
1382 armnn::TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0, 1});
1386 RegisterInputSlots(subgraphIndex, operatorIndex, layer, tensorIndexesToRegister);
1388 layer = AddFusedActivationLayer(layer, 0, options->fused_activation_function);
1390 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1391 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1395 void TfLiteParserImpl::ParseDepthwiseConv2D(
size_t subgraphIndex,
size_t operatorIndex)
1397 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1399 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
1400 const auto* options = operatorPtr->builtin_options.AsDepthwiseConv2DOptions();
1410 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1412 if (inputs.size() == 3)
1417 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1422 armnn::TensorInfo inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
1423 armnn::TensorInfo filterTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 1);
1426 unsigned int inputHeight = inputTensorInfo.
GetShape()[1];
1427 unsigned int inputWidth = inputTensorInfo.
GetShape()[2];
1430 unsigned int filterHeight = filterTensorInfo.
GetShape()[1];
1431 unsigned int filterWidth = filterTensorInfo.
GetShape()[2];
1433 CalcPadding(inputHeight, filterHeight, desc.
m_StrideY,
1435 CalcPadding(inputWidth, filterWidth, desc.
m_StrideX,
1439 auto layerName = fmt::format(
"DepthwiseConv2D:{}:{}", subgraphIndex, operatorIndex);
1441 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1444 std::vector<unsigned int> tensorIndexesToRegister = {inputTensorIndexes[0], inputTensorIndexes[1]};
1451 TensorInfo biasTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 2);
1454 tensorIndexesToRegister.emplace_back(inputTensorIndexes[2]);
1458 armnn::TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0, 1});
1463 RegisterInputSlots(subgraphIndex, operatorIndex, layer, tensorIndexesToRegister);
1465 layer = AddFusedActivationLayer(layer, 0, options->fused_activation_function);
1467 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1468 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1471 void TfLiteParserImpl::ParseDequantize(
size_t subgraphIndex,
size_t operatorIndex)
1473 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1475 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1478 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1481 auto layerName = fmt::format(
"Dequantize:{}:{}", subgraphIndex, operatorIndex);
1486 TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0});
1489 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1490 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
1492 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1493 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, outputTensorIndexes);
1496 void TfLiteParserImpl::ParseExpandDims(
size_t subgraphIndex,
size_t operatorIndex)
1498 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1500 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1503 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1506 auto layerName = fmt::format(
"ExpandDims:{}:{}", subgraphIndex, operatorIndex);
1508 armnn::TensorInfo inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
1511 CheckMatchingQuantization(inputTensorInfo, outputTensorInfo, layerName,
"Input 0",
"Output 0");
1521 int32_t axis = inputs[1]->shape[0];
1525 if (axis > inputDimSize || axis < 0 - (inputDimSize + 1))
1527 throw ParseException(
"axis must be in range [0 - (inputDimSize + 1), inputDimSize] inclusive");
1532 axis = inputDimSize + axis + 1;
1535 std::vector<unsigned int> shape(
static_cast<unsigned int>(inputDimSize) + 1);
1536 unsigned int inputShapeIndex = 0;
1537 for (
unsigned int i = 0; i < static_cast<unsigned int>(inputDimSize + 1); ++i)
1539 if (i ==
static_cast<unsigned int>(axis))
1545 shape[i] = inputTensorInfo.
GetShape()[inputShapeIndex];
1553 IConnectableLayer* layer = m_Network->AddReshapeLayer(reshapeDesc, layerName.c_str());
1556 reshapeDesc.
m_TargetShape = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0}).GetShape();
1561 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1562 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
1564 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1565 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1568 void TfLiteParserImpl::ParseTranspose(
size_t subgraphIndex,
size_t operatorIndex)
1570 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1572 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1575 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1578 auto layerName = fmt::format(
"Transpose:{}:{}", subgraphIndex, operatorIndex);
1581 if (inputs.size() == 2)
1583 armnn::TensorInfo permuteTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 1);
1586 std::vector<unsigned int> permuteShape(numPermVecElements);
1587 ::memcpy(permuteShape.data(), permuteBufferPtr->data.data(), permuteTensorInfo.
GetNumBytes());
1592 TensorInfo inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
1594 IConnectableLayer* layer = m_Network->AddTransposeLayer(desc, layerName.c_str());
1597 TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0});
1598 CheckMatchingQuantization(inputTensorInfo, outputTensorInfo, layerName,
"Input 0",
"Output 0");
1601 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1602 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
1604 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1605 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1608 void TfLiteParserImpl::ParseTransposeConv(
size_t subgraphIndex,
size_t operatorIndex)
1610 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1612 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
1613 const auto* options = operatorPtr->builtin_options.AsTransposeConvOptions();
1621 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1622 if (inputs.size() == 4)
1631 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1635 armnn::TensorInfo inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 2);
1636 armnn::TensorInfo filterTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 1);
1639 const unsigned int inputHeight = inputTensorInfo.
GetShape()[1];
1640 const unsigned int inputWidth = inputTensorInfo.
GetShape()[2];
1642 const unsigned int filterHeight = filterTensorInfo.
GetShape()[1];
1643 const unsigned int filterWidth = filterTensorInfo.
GetShape()[2];
1649 if (inputs[0] && IsConstTensor(inputs[0]))
1651 armnn::TensorInfo tensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
1654 if (tensorInfo.
GetDataType() == DataType::Signed32)
1656 ::memcpy(output_shape.data(),
GetBuffer(m_Model, inputs[0]->buffer)->data.data(), tensorInfo.
GetNumBytes());
1658 if (tensorInfo.
GetDataType() == DataType::QAsymmU8)
1662 output_shape[i] =
GetBuffer(m_Model, inputs[0]->buffer)->data.data()[i];
1666 for (
int dimension : output_shape)
1668 desc.
m_OutputShape.push_back(
static_cast<unsigned int>(dimension));
1676 CalcPadding(inputHeight,
1685 CalcPadding(inputWidth,
1696 CalcPadding(inputHeight,
1704 CalcPadding(inputWidth,
1713 auto filterTensorAndData = CreateConstTensorNonPermuted(inputs[1], filterTensorInfo, inputTensorInfo.
GetDataType());
1716 auto layerName = fmt::format(
"TransposeConv:{}:{}", subgraphIndex, operatorIndex);
1720 auto biasTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 3);
1721 auto biasConstTensor = CreateConstTensorNonPermuted(inputs[3], biasTensorInfo, inputTensorInfo.
GetDataType());
1722 layer = m_Network->AddTransposeConvolution2dLayer(desc,
1723 filterTensorAndData.first,
1724 biasConstTensor.first,
1729 layer = m_Network->AddTransposeConvolution2dLayer(desc,
1730 filterTensorAndData.first,
1737 armnn::TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0 , { 2, 1 });
1741 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1742 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[2]});
1744 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1745 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1748 void TfLiteParserImpl::ParseAveragePool2D(
size_t subgraphIndex,
size_t operatorIndex)
1750 ParsePool(subgraphIndex, operatorIndex, PoolingAlgorithm::Average);
1753 void TfLiteParserImpl::ParseBatchMatMul(
size_t subgraphIndex,
size_t operatorIndex)
1755 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1757 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1760 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1763 auto layerName = fmt::format(
"BatchMatMul:{}:{}", subgraphIndex, operatorIndex);
1765 TensorInfo inputXTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
1766 TensorInfo inputYTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 1);
1768 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
1769 const auto* options = operatorPtr->builtin_options.AsBatchMatMulOptions();
1778 IConnectableLayer* layer = m_Network->AddBatchMatMulLayer(descriptor, layerName.c_str());
1781 TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0, 1});
1784 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1785 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0], inputTensorIndexes[1]});
1787 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1788 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1791 void TfLiteParserImpl::ParseBatchToSpaceND(
size_t subgraphIndex,
size_t operatorIndex)
1793 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1795 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1798 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1801 armnn::TensorInfo blockShapeTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 1);
1804 armnn::TensorInfo cropsTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 2);
1807 std::vector<unsigned int> blockShape(blockShapeTensorInfo.
GetNumElements());
1808 ::memcpy(blockShape.data(), blockShapeBufferPtr->data.data(), blockShapeTensorInfo.
GetNumBytes());
1810 std::vector<unsigned int> cropsVector(cropsTensorInfo.
GetNumElements());
1811 ::memcpy(cropsVector.data(), cropsBufferPtr->data.data(), cropsTensorInfo.
GetNumBytes());
1814 std::vector<std::pair<unsigned int, unsigned int>> crops;
1815 for (
unsigned int i = 0; i < cropsTensorInfo.
GetNumElements() / step; ++i)
1817 crops.emplace_back(cropsVector[i * step], cropsVector[i * step + 1]);
1825 auto layerName = fmt::format(
"BatchToSpaceND:{}:{}", subgraphIndex, operatorIndex);
1827 TensorInfo inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
1829 IConnectableLayer* layer = m_Network->AddBatchToSpaceNdLayer(desc, layerName.c_str());
1832 TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0});
1833 CheckMatchingQuantization(inputTensorInfo, outputTensorInfo, layerName,
"Input 0",
"Output 0");
1836 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1837 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
1839 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1840 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1843 void TfLiteParserImpl::ParseL2Normalization(
size_t subgraphIndex,
size_t operatorIndex)
1845 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1847 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1850 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1855 auto layerName = fmt::format(
"L2Normalization:{}:{}", subgraphIndex, operatorIndex);
1856 IConnectableLayer* layer = m_Network->AddL2NormalizationLayer(desc, layerName.c_str());
1860 armnn::TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0});
1863 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1864 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
1866 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1867 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1870 void TfLiteParserImpl::ParseMaxPool2D(
size_t subgraphIndex,
size_t operatorIndex)
1872 ParsePool(subgraphIndex, operatorIndex, PoolingAlgorithm::Max);
1875 void TfLiteParserImpl::ParseMaximum(
size_t subgraphIndex,
size_t operatorIndex)
1877 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1879 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1882 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1885 auto layerName = fmt::format(
"Maximum:{}:{}", subgraphIndex, operatorIndex);
1887 TensorInfo inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
1888 TensorInfo input1TensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 1);
1889 CheckMatchingQuantization(inputTensorInfo, input1TensorInfo, layerName,
"Input 0",
"Input 1");
1891 IConnectableLayer* layer = m_Network->AddElementwiseBinaryLayer(BinaryOperation::Maximum, layerName.c_str());
1894 TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0, 1});
1895 CheckMatchingQuantization(inputTensorInfo, outputTensorInfo, layerName,
"Input 0",
"Output 0");
1898 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1899 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0], inputTensorIndexes[1]});
1901 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1902 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1905 void TfLiteParserImpl::ParseMinimum(
size_t subgraphIndex,
size_t operatorIndex)
1907 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1909 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1912 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1915 auto layerName = fmt::format(
"Minimum:{}:{}", subgraphIndex, operatorIndex);
1917 TensorInfo inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
1918 TensorInfo input1TensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 1);
1919 CheckMatchingQuantization(inputTensorInfo, input1TensorInfo, layerName,
"Input 0",
"Input 1");
1921 IConnectableLayer* layer = m_Network->AddElementwiseBinaryLayer(BinaryOperation::Minimum, layerName.c_str());
1924 TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0, 1});
1925 CheckMatchingQuantization(inputTensorInfo, outputTensorInfo, layerName,
"Input 0",
"Output 0");
1928 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1929 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0], inputTensorIndexes[1]});
1931 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1932 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1935 void TfLiteParserImpl::ParsePool(
size_t subgraphIndex,
1936 size_t operatorIndex,
1939 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1941 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
1942 const auto* options = operatorPtr->builtin_options.AsPool2DOptions();
1946 std::string layerName;
1950 case PoolingAlgorithm::Average:
1952 fmt::format(
"AveragePool2D:{}:{}", subgraphIndex, operatorIndex);
1954 case PoolingAlgorithm::Max:
1956 fmt::format(
"MaxPool2D:{}:{}", subgraphIndex, operatorIndex);
1973 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1975 armnn::TensorInfo inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
1978 unsigned int inputHeight = inputTensorInfo.
GetShape()[1];
1979 unsigned int inputWidth = inputTensorInfo.
GetShape()[2];
1986 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1989 IConnectableLayer* layer = m_Network->AddPooling2dLayer(desc, layerName.c_str());
1992 armnn::TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0});
1993 CheckMatchingQuantization(inputTensorInfo, outputTensorInfo, layerName,
"Input 0",
"Output 0");
1998 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1999 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
2001 layer = AddFusedActivationLayer(layer, 0, options->fused_activation_function);
2003 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2004 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
2007 void TfLiteParserImpl::ParseSlice(
size_t subgraphIndex,
size_t operatorIndex)
2009 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2011 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2013 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2019 armnn::TensorInfo beginTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 1);
2022 std::vector<unsigned int> begin(beginTensorInfo.
GetNumElements());
2023 ::memcpy(begin.data(), beginBufferPtr->data.data(), beginTensorInfo.
GetNumBytes());
2026 armnn::TensorInfo sizeTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 2);
2032 if (sizeBufferPtr->data.data())
2034 ::memcpy(signedSize.data(), sizeBufferPtr->data.data(), sizeTensorInfo.
GetNumBytes());
2038 TensorInfo inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
2040 for (
unsigned int i = 0; i < signedSize.size(); ++i)
2042 int signedValue = signedSize[i];
2044 if (signedValue < -1 || signedValue >
static_cast<int>(inputTensorInfo.
GetShape()[i] - begin[i]))
2046 throw ParseException(fmt::format(
"Invalid value for size {} size must be in range "
2047 "[-1, inputDimSize - begin] [-1, {}] inclusive {}",
2049 inputTensorInfo.
GetShape()[i] - begin[i],
2053 if (signedValue == -1)
2055 size[i] = inputTensorInfo.
GetShape()[i] - begin[i];
2059 size[i] =
static_cast<unsigned int>(signedValue);
2065 auto layerName = fmt::format(
"Slice:{}:{}", subgraphIndex, operatorIndex);
2067 IConnectableLayer*
const layer = m_Network->AddSliceLayer(desc, layerName.c_str());
2069 TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0});
2070 CheckMatchingQuantization(inputTensorInfo, outputTensorInfo, layerName,
"Input 0",
"Output 0");
2075 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2076 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
2079 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2080 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
2083 void TfLiteParserImpl::ParseSoftmax(
size_t subgraphIndex,
size_t operatorIndex)
2085 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2086 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
2087 const auto* options = operatorPtr->builtin_options.AsSoftmaxOptions();
2090 desc.
m_Beta = options->beta;
2092 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2094 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2097 auto layerName = fmt::format(
"Softmax:{}:{}", subgraphIndex, operatorIndex);
2098 IConnectableLayer*
const layer = m_Network->AddSoftmaxLayer(desc, layerName.c_str());
2100 armnn::TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0});
2105 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2106 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
2109 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2110 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
2113 void TfLiteParserImpl::ParseLogSoftmax(
size_t subgraphIndex,
size_t operatorIndex)
2115 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2119 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2121 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2124 auto layerName = fmt::format(
"LogSoftmax:{}:{}", subgraphIndex, operatorIndex);
2125 IConnectableLayer*
const layer = m_Network->AddLogSoftmaxLayer(desc, layerName.c_str());
2127 armnn::TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0});
2132 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2133 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
2136 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2137 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
2140 void TfLiteParserImpl::ParseSpaceToBatchND(
size_t subgraphIndex,
size_t operatorIndex)
2142 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2144 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2147 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2150 armnn::TensorInfo blockShapeTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 1);
2153 armnn::TensorInfo padListTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 2);
2156 std::vector<unsigned int> blockShape(blockShapeTensorInfo.
GetNumElements());
2157 ::memcpy(blockShape.data(), blockShapeBufferPtr->data.data(), blockShapeTensorInfo.
GetNumBytes());
2159 std::vector<unsigned int> padListVector(padListTensorInfo.
GetNumElements());
2160 ::memcpy(padListVector.data(), padListBufferPtr->data.data(), padListTensorInfo.
GetNumBytes());
2163 std::vector<std::pair<unsigned int, unsigned int>> padList;
2164 for (
unsigned int i = 0; i < padListTensorInfo.
GetNumElements() / step; ++i)
2166 padList.emplace_back(padListVector[i * step], padListVector[i * step + 1]);
2174 auto layerName = fmt::format(
"SpaceToBatchND:{}:{}", subgraphIndex, operatorIndex);
2176 TensorInfo inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
2178 IConnectableLayer* layer = m_Network->AddSpaceToBatchNdLayer(desc, layerName.c_str());
2181 TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0});
2182 CheckMatchingQuantization(inputTensorInfo, outputTensorInfo, layerName,
"Input 0",
"Output 0");
2185 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2186 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
2188 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2189 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
2192 void TfLiteParserImpl::ParseSpaceToDepth(
size_t subgraphIndex,
size_t operatorIndex)
2194 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2203 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
2204 const auto* options = operatorPtr->builtin_options.AsSpaceToDepthOptions();
2205 auto blockSize = options->block_size;
2209 fmt::format(
"Operation has invalid block size: {} Block size should be >= 2 {}",
2213 descriptor.
m_BlockSize = armnn::numeric_cast<uint32_t>(blockSize);
2215 auto layerName = fmt::format(
"SpaceToDepth:{}:{}", subgraphIndex, operatorIndex);
2216 IConnectableLayer* layer = m_Network->AddSpaceToDepthLayer(descriptor, layerName.c_str());
2218 TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0});
2221 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2222 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
2224 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2225 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
2232 static const uint32_t dimensionSequence[] = { 0, 1, 2, 3 };
2236 std::stringstream ss;
2237 ss <<
"Input tensor has unexpected number of dimensions:" << inputTensorInfo.
GetNumDimensions()
2238 <<
" shape:" << inputTensorInfo.
GetShape() <<
" "
2243 if (squeezeDims.empty())
2245 squeezeDims.assign(dimensionSequence,
2249 std::vector<uint32_t> outputDims;
2252 bool skipSqueeze = (std::find(squeezeDims.begin(), squeezeDims.end(), i) == squeezeDims.end());
2253 auto currentDimension = inputTensorInfo.
GetShape()[i];
2254 if (skipSqueeze || currentDimension != 1)
2256 outputDims.push_back(currentDimension);
2260 if (outputDims.size() > 4)
2262 std::stringstream ss;
2263 ss <<
"Output tensor has unexpected number of dimensions:" << inputTensorInfo.
GetNumDimensions()
2264 <<
" shape:" << inputTensorInfo.
GetShape() <<
" "
2276 return outTensorInfo;
2279 void TfLiteParserImpl::ParseShape(
size_t subgraphIndex,
size_t operatorIndex)
2281 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2283 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2285 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2288 auto layerName = fmt::format(
"Shape:{}:{}", subgraphIndex, operatorIndex);
2293 TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0});
2302 "Output tensor data type is not supported. (Supported types: Signed32 & Signed64) {}",
2306 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2307 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
2309 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2310 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, outputTensorIndexes);
2313 void TfLiteParserImpl::ParseSqueeze(
size_t subgraphIndex,
size_t operatorIndex)
2315 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2317 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2320 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2323 const auto & operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
2324 const auto * options = operatorPtr->builtin_options.AsSqueezeOptions();
2325 auto layerName = fmt::format(
"Squeeze:{}:{}", subgraphIndex, operatorIndex);
2327 armnn::TensorInfo inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
2329 std::vector<uint32_t> squeezeDim;
2332 if (options->squeeze_dims.size() == 1 && options->squeeze_dims[0] < 0)
2335 squeezeDim.push_back(
static_cast<uint32_t
>(dim));
2339 squeezeDim = AsUnsignedVector(options->squeeze_dims);
2344 CheckMatchingQuantization(inputTensorInfo, outputTensorInfo, layerName,
"Input 0",
"Output 0");
2350 m_TensorInfos[outputTensorIds[0]] = outputTensorInfo;
2352 IConnectableLayer* layer = m_Network->AddReshapeLayer(reshapeDesc, layerName.c_str());
2356 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2357 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
2359 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2360 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
2363 void TfLiteParserImpl::ParseStridedSlice(
size_t subgraphIndex,
size_t operatorIndex)
2365 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2367 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2370 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2373 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
2374 const auto* options = operatorPtr->builtin_options.AsStridedSliceOptions();
2384 armnn::TensorInfo beginTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 1);
2388 ::memcpy(begin.data(), beginBufferPtr->data.data(), beginTensorInfo.
GetNumBytes());
2390 armnn::TensorInfo endTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 2);
2394 ::memcpy(end.data(), endBufferPtr->data.data(), endTensorInfo.
GetNumBytes());
2396 armnn::TensorInfo strideTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 3);
2400 ::memcpy(stride.data(), strideBufferPtr->data.data(), strideTensorInfo.
GetNumBytes());
2406 auto layerName = fmt::format(
"StridedSlice:{}:{}", subgraphIndex, operatorIndex);
2407 IConnectableLayer* layer = m_Network->AddStridedSliceLayer(desc, layerName.c_str());
2410 armnn::TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0});
2413 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2414 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
2416 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2417 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
2420 void TfLiteParserImpl::ParseSub(
size_t subgraphIndex,
size_t operatorIndex)
2422 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2424 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
2425 const auto* options = operatorPtr->builtin_options.AsSubOptions();
2427 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2430 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2433 armnn::TensorInfo inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
2434 armnn::TensorInfo input1TensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 1);
2436 auto layerName = fmt::format(
"Sub:{}:{}", subgraphIndex, operatorIndex);
2437 IConnectableLayer* layer = m_Network->AddElementwiseBinaryLayer(BinaryOperation::Sub, layerName.c_str());
2440 TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0, 1});
2443 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2444 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0], inputTensorIndexes[1]});
2446 layer = AddFusedActivationLayer(layer, 0, options->fused_activation_function);
2448 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2449 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
2452 void TfLiteParserImpl::ParseDiv(
size_t subgraphIndex,
size_t operatorIndex)
2454 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2456 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
2457 const auto* options = operatorPtr->builtin_options.AsDivOptions();
2459 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2462 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2465 armnn::TensorInfo inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
2466 armnn::TensorInfo input1TensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 1);
2468 auto layerName = fmt::format(
"Div:{}:{}", subgraphIndex, operatorIndex);
2469 IConnectableLayer* layer = m_Network->AddElementwiseBinaryLayer(BinaryOperation::Div, layerName.c_str());
2472 TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0, 1});
2475 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2476 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0], inputTensorIndexes[1]});
2477 layer = AddFusedActivationLayer(layer, 0, options->fused_activation_function);
2479 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2480 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
2483 void TfLiteParserImpl::ParseFloorDiv(
size_t subgraphIndex,
size_t operatorIndex)
2485 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2487 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2490 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2493 armnn::TensorInfo inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
2494 armnn::TensorInfo input1TensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 1);
2496 auto layerName = fmt::format(
"Div:{}:{}", subgraphIndex, operatorIndex);
2497 IConnectableLayer* layer = m_Network->AddElementwiseBinaryLayer(BinaryOperation::Div, layerName.c_str());
2500 TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0, 1});
2503 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2504 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0], inputTensorIndexes[1]});
2505 layer = AddFusedFloorLayer(layer, 0);
2507 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2508 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
2511 void TfLiteParserImpl::ParseAdd(
size_t subgraphIndex,
size_t operatorIndex)
2513 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2515 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
2516 const auto* options = operatorPtr->builtin_options.AsAddOptions();
2518 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2521 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2524 armnn::TensorInfo inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
2525 armnn::TensorInfo input1TensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 1);
2527 auto layerName = fmt::format(
"Add:{}:{}", subgraphIndex, operatorIndex);
2528 IConnectableLayer* layer = m_Network->AddElementwiseBinaryLayer(BinaryOperation::Add, layerName.c_str());
2531 TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0, 1});
2534 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2535 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0], inputTensorIndexes[1]});
2536 layer = AddFusedActivationLayer(layer, 0, options->fused_activation_function);
2538 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2539 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
2542 void TfLiteParserImpl::ParseMul(
size_t subgraphIndex,
size_t operatorIndex)
2544 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2546 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
2547 const auto* options = operatorPtr->builtin_options.AsMulOptions();
2549 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2552 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2555 armnn::TensorInfo inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
2556 armnn::TensorInfo input1TensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 1);
2558 auto layerName = fmt::format(
"Mul:{}:{}", subgraphIndex, operatorIndex);
2559 IConnectableLayer* layer = m_Network->AddElementwiseBinaryLayer(BinaryOperation::Mul, layerName.c_str());
2562 TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0, 1});
2565 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2566 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0], inputTensorIndexes[1]});
2567 layer = AddFusedActivationLayer(layer, 0, options->fused_activation_function);
2569 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2570 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
2573 void TfLiteParserImpl::ParseMean(
size_t subgraphIndex,
size_t operatorIndex)
2575 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2577 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2579 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2582 TensorInfo inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
2583 TensorInfo dimTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 1);
2588 if (axisBufferPtr !=
nullptr)
2591 ::memcpy(axisData.data(), axisBufferPtr->data.data(), dimTensorInfo.
GetNumBytes());
2595 std::set<unsigned int> uniqueAxis;
2596 std::transform(axisData.begin(),
2598 std::inserter(uniqueAxis, uniqueAxis.begin()),
2599 [rank](
int i)->unsigned
int{
2600 return static_cast<uint32_t>(((i + rank) % rank)); });
2601 desc.
m_Axis.assign(uniqueAxis.begin(), uniqueAxis.end());
2607 desc.
m_Axis.push_back(i);
2615 auto layerName = fmt::format(
"Mean:{}:{}", subgraphIndex, operatorIndex);
2619 outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0});
2622 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2623 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
2625 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2626 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
2629 void TfLiteParserImpl::ParsePad(
size_t subgraphIndex,
size_t operatorIndex)
2631 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2638 armnn::TensorInfo inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
2639 armnn::TensorInfo padTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 1);
2641 std::vector<unsigned int> padBuffer = GetUIntBuffer(padTensorInfo, m_Model, inputs[1]->buffer);
2645 auto opcode = GetOpCode(m_Model, subgraphIndex, operatorIndex);
2647 if (opcode == tflite::BuiltinOperator_PAD)
2656 else if (opcode == tflite::BuiltinOperator_PADV2)
2660 armnn::TensorInfo padValueTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 2);
2669 if (padValueBufferPtr->data.size() > 0)
2675 std::vector<float> padValueBuffer(padValueTensorInfo.
GetNumElements());
2676 ::memcpy(padValueBuffer.data(), padValueBufferPtr->data.data(), padValueBufferPtr->data.size());
2682 std::vector<uint8_t> padValueBuffer(padValueTensorInfo.
GetNumElements());
2683 ::memcpy(padValueBuffer.data(), padValueBufferPtr->data.data(), padValueBufferPtr->data.size());
2684 desc.
m_PadValue = armnn::Dequantize<uint8_t>(padValueBuffer[0],
2692 std::vector<int8_t> padValueBuffer(padValueTensorInfo.
GetNumElements());
2693 ::memcpy(padValueBuffer.data(), padValueBufferPtr->data.data(), padValueBufferPtr->data.size());
2694 desc.
m_PadValue = armnn::Dequantize<int8_t>(padValueBuffer[0],
2708 for (
unsigned int i = 0; i < padTensorInfo.
GetNumElements() / step; ++i)
2710 desc.
m_PadList.emplace_back(padBuffer[i * step], padBuffer[i * step + 1]);
2713 auto layerName = (opcode == tflite::BuiltinOperator_PAD) ? fmt::format(
"Pad:{}:{}", subgraphIndex, operatorIndex)
2714 : fmt::format(
"PadV2:{}:{}", subgraphIndex, operatorIndex);
2718 TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0});
2721 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2722 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
2724 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2725 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
2728 void TfLiteParserImpl::ParseMirrorPad(
size_t subgraphIndex,
size_t operatorIndex)
2730 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2738 armnn::TensorInfo inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
2740 armnn::TensorInfo padTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 1);
2743 std::vector<unsigned int> padBuffer(padTensorInfo.
GetNumElements());
2744 ::memcpy(padBuffer.data(), bufferPtr->data.data(), padTensorInfo.
GetNumBytes());
2748 for (
unsigned int i = 0; i < padTensorInfo.
GetNumElements() / step; ++i)
2750 desc.
m_PadList.emplace_back(padBuffer[i * step], padBuffer[i * step + 1]);
2753 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
2754 const auto* options = operatorPtr->builtin_options.AsMirrorPadOptions();
2756 if (options->mode == tflite::MirrorPadMode_REFLECT)
2760 else if (options->mode == tflite::MirrorPadMode_SYMMETRIC)
2771 auto inputShape = inputTensorInfo.
GetShape();
2774 const unsigned int isReflect =
static_cast<unsigned int>(desc.
m_PaddingMode == PaddingMode::Reflect);
2775 for(
unsigned int i = 0; i < padList.size(); ++i)
2777 if(padList.at(i).first > (inputShape[i] - isReflect) ||
2778 padList.at(i).second > (inputShape[i] - isReflect))
2781 "equal (Symmetric) to the dimension size.");
2785 auto layerName = fmt::format(
"MirrorPad:{}:{}", subgraphIndex, operatorIndex);
2789 TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0});
2792 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2793 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
2795 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2796 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
2799 void TfLiteParserImpl::ParsePrelu(
size_t subgraphIndex,
size_t operatorIndex)
2801 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2803 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2806 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2809 auto layerName = fmt::format(
"Prelu:{}:{}", subgraphIndex, operatorIndex);
2811 armnn::TensorInfo inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
2812 armnn::TensorInfo alphaTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 1);
2818 if (IsConstTensor(inputs[1]))
2820 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2822 RegisterConsumerOfTensor(subgraphIndex, inputTensorIndexes[0], slot);
2824 auto alphaTensorAndData = CreateConstTensorNonPermuted(inputs[1], alphaTensorInfo,
2826 std::string constLayerName = fmt::format(
"Constant:{}", inputs[1]->name);
2828 m_Network->AddConstantLayer(alphaTensorAndData.first, constLayerName.c_str());
2833 RegisterOutputSlots(subgraphIndex,
2834 VIRTUAL_OPERATOR_ID,
2836 { inputTensorIndexes[1] });
2840 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2841 RegisterInputSlots(subgraphIndex, operatorIndex, layer, inputTensorIndexes);
2844 armnn::TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0, 1});
2845 CheckMatchingQuantization(inputTensorInfo, outputTensorInfo, layerName,
"Input 0",
"Output 0");
2848 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2849 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, outputTensorIndexes);
2852 void TfLiteParserImpl::ParseQuantize(
size_t subgraphIndex,
size_t operatorIndex)
2854 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2856 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2859 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2862 auto layerName = fmt::format(
"Quantize:{}:{}", subgraphIndex, operatorIndex);
2867 TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0});
2870 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2871 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
2873 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2874 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, outputTensorIndexes);
2877 void TfLiteParserImpl::ParseRelu(
size_t subgraphIndex,
size_t operatorIndex)
2879 ParseActivation(subgraphIndex,operatorIndex, ActivationFunction::ReLu);
2882 void TfLiteParserImpl::ParseRelu6(
size_t subgraphIndex,
size_t operatorIndex)
2884 ParseActivation(subgraphIndex,operatorIndex, ActivationFunction::BoundedReLu);
2887 void TfLiteParserImpl::ParseLeakyRelu(
size_t subgraphIndex,
size_t operatorIndex)
2889 ParseActivation(subgraphIndex, operatorIndex, ActivationFunction::LeakyReLu);
2892 void TfLiteParserImpl::ParseLogistic(
size_t subgraphIndex,
size_t operatorIndex)
2894 ParseActivation(subgraphIndex,operatorIndex,ActivationFunction::Sigmoid);
2897 void TfLiteParserImpl::ParseTanH(
size_t subgraphIndex,
size_t operatorIndex)
2899 ParseActivation(subgraphIndex,operatorIndex,ActivationFunction::TanH);
2902 void TfLiteParserImpl::ParseElu(
size_t subgraphIndex,
size_t operatorIndex)
2904 ParseActivation(subgraphIndex, operatorIndex, ActivationFunction::Elu);
2907 void TfLiteParserImpl::ParseHardSwish(
size_t subgraphIndex,
size_t operatorIndex)
2909 ParseActivation(subgraphIndex, operatorIndex, ActivationFunction::HardSwish);
2912 void TfLiteParserImpl::ParseActivation(
size_t subgraphIndex,
size_t operatorIndex,
ActivationFunction activationType)
2914 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2915 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
2918 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2921 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2924 auto layerName = fmt::format(
"Activation:");
2928 switch (activationType)
2930 case ActivationFunction::ReLu:
2932 layerName += fmt::format(
"RELU:{}:{}", subgraphIndex, operatorIndex);
2935 case ActivationFunction::BoundedReLu:
2937 layerName += fmt::format(
"RELU6:{}:{}", subgraphIndex, operatorIndex);
2938 activationDesc.
m_A = 6.0f;
2939 activationDesc.
m_B = 0.0f;
2942 case ActivationFunction::Sigmoid:
2944 layerName += fmt::format(
"SIGMOID:{}:{}", subgraphIndex, operatorIndex);
2947 case ActivationFunction::TanH:
2949 layerName += fmt::format(
"TANH:{}:{}", subgraphIndex, operatorIndex);
2950 activationDesc.
m_A = 1.0f;
2951 activationDesc.
m_B = 1.0f;
2954 case ActivationFunction::LeakyReLu:
2956 layerName += fmt::format(
"LEAKYRELU:{}:{}", subgraphIndex, operatorIndex);
2957 const auto* options = operatorPtr->builtin_options.AsLeakyReluOptions();
2958 activationDesc.
m_A = options->alpha;
2961 case ActivationFunction::Elu:
2963 layerName += fmt::format(
"ELU:{}:{}", subgraphIndex, operatorIndex);
2964 activationDesc.
m_A = 1.0f;
2967 case ActivationFunction::HardSwish:
2969 layerName += fmt::format(
"HARDSWISH:{}:{}", subgraphIndex, operatorIndex);
2975 fmt::format(
"Unexpected ActivationFunction[{}] when creating layerName {} ",
2980 IConnectableLayer*
const layer = m_Network->AddActivationLayer(activationDesc, layerName.c_str());
2982 TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0});
2987 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2988 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
2991 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2992 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
2995 const std::vector<int32_t>& targetDimsIn)
2997 std::vector<unsigned int> outputDims(targetDimsIn.begin(), targetDimsIn.end());
2998 const auto stretchDim = std::find(targetDimsIn.begin(), targetDimsIn.end(), -1);
3000 if (stretchDim != targetDimsIn.end())
3002 if (std::find(std::next(stretchDim), targetDimsIn.end(), -1) != targetDimsIn.end())
3005 fmt::format(
"At most one component of shape can be -1 {}",
CHECK_LOCATION().AsString()));
3008 auto targetNumElements =
3009 armnn::numeric_cast<unsigned int>(
3010 std::accumulate(targetDimsIn.begin(), targetDimsIn.end(), -1, std::multiplies<int32_t>()));
3012 auto stretchIndex =
static_cast<size_t>(std::distance(targetDimsIn.begin(), stretchDim));
3013 outputDims[stretchIndex] = inputTensorInfo.
GetNumElements() / targetNumElements;
3024 void TfLiteParserImpl::ParseReshape(
size_t subgraphIndex,
size_t operatorIndex)
3026 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
3028 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
3030 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
3033 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
3034 const auto* options = operatorPtr->builtin_options.AsReshapeOptions();
3035 auto layerName = fmt::format(
"Reshape:{}:{}", subgraphIndex, operatorIndex);
3037 armnn::TensorInfo inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
3039 CheckMatchingQuantization(inputTensorInfo, actualOutputTensorInfo, layerName,
"Input 0",
"Output 0");
3045 std::vector<int32_t> targetShape;
3046 bool targetShapeFound =
false;
3048 if (options !=
nullptr)
3051 if (options->new_shape.empty() ==
false)
3053 targetShape = options->new_shape;
3054 targetShapeFound =
true;
3059 if (!targetShapeFound)
3062 if (inputs.size() > 1 && inputs[1] !=
nullptr)
3064 if (inputs[1]->is_variable)
3069 if (inputs[1]->shape.size() != 1)
3074 if (inputs[1]->type != tflite::TensorType_INT32)
3080 auto bufferPtr =
GetBuffer(m_Model, inputs[1]->buffer);
3081 auto values =
reinterpret_cast<const int32_t*
>(bufferPtr->data.data());
3084 for (
int i = 0; i < inputs[1]->shape[0]; ++i)
3086 targetShape.push_back(values[i]);
3098 for (
unsigned int i = 0; i < actualOutputTensorInfo.
GetShape().GetNumDimensions(); ++i)
3100 targetShape.push_back(actualOutputTensorInfo.
GetShape()[i]);
3104 else if (reshapeShapes[0] > 2)
3106 throw ParseException(fmt::format(
"Invalid input shape '{}' in Reshape layer '{}' {}. "
3107 "When inferring during runtime, the parser only supports "
3108 "shape (batch, -1) or (-1) for target shape input.",
3115 const int32_t numInputElements = inputTensorInfo.
GetNumElements();
3116 const int32_t inputTensorShape = inputTensorInfo.
GetShape()[0];
3117 if (reshapeShapes[0] == 1)
3119 targetShape = {numInputElements};
3121 else if (reshapeShapes[0] == 2)
3123 targetShape = {inputTensorShape, numInputElements / inputTensorShape};
3127 catch (
const std::exception& exc)
3130 "Reshape operation. Reshape operator target shape input buffer data "
3131 "is null. " << exc.what());
3138 "At least one method required");
3151 if (inputs.size() > 1 && !
CheckShape(reshapeOutputTensorShape, outputs[0]->shape))
3155 std::vector<int32_t> secondaryOutputTargetShape = outputs[0]->shape_signature;
3162 if (!
CheckShape(reshapeOutputTensorShape, secondaryReshapeOutputTensorInfo.
GetShape()))
3164 std::stringstream ss;
3165 ss <<
"New shape defined in reshape parameters "
3166 << reshapeOutputTensorShape
3167 <<
" does not equal output shape "
3168 << actualOutputTensorInfo.
GetShape()
3178 m_TensorInfos[outputTensorIds[0]] = reshapeOutputTensorInfo;
3180 IConnectableLayer* layer = m_Network->AddReshapeLayer(reshapeDesc, layerName.c_str());
3184 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
3185 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
3187 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
3188 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
3191 void TfLiteParserImpl::ParseResizeBilinear(
size_t subgraphIndex,
size_t operatorIndex)
3193 ParseResize(subgraphIndex, operatorIndex, ResizeMethod::Bilinear);
3196 void TfLiteParserImpl::ParseResizeNearestNeighbor(
size_t subgraphIndex,
size_t operatorIndex)
3198 ParseResize(subgraphIndex, operatorIndex, ResizeMethod::NearestNeighbor);
3201 void TfLiteParserImpl::ParseResize(
size_t subgraphIndex,
size_t operatorIndex,
ResizeMethod resizeMethod)
3203 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
3205 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
3208 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
3211 armnn::TensorInfo sizeTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 1);
3214 std::vector<int32_t> sizeTensorData(sizeTensorInfo.
GetNumElements());
3217 ::memcpy(sizeTensorData.data(), sizeBufferPtr->data.data(), sizeTensorInfo.
GetNumBytes());
3222 desc.
m_TargetWidth =
static_cast<uint32_t
> (sizeTensorData[1]);
3225 auto layerName = fmt::format(
"Resize:");
3227 switch (resizeMethod)
3229 case ResizeMethod::Bilinear:
3231 layerName += fmt::format(
"BILINEAR:{}:{}", subgraphIndex, operatorIndex);
3233 const auto & operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
3234 const auto * options = operatorPtr->builtin_options.AsResizeBilinearOptions();
3239 case ResizeMethod::NearestNeighbor:
3241 layerName += fmt::format(
"NEARESTNEIGHBOR:{}:{}", subgraphIndex, operatorIndex);
3247 fmt::format(
"Unexpected ResizeMethod[{}] when creating layerName {} ",
3252 TensorInfo inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
3256 TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0});
3257 CheckMatchingQuantization(inputTensorInfo, outputTensorInfo, layerName,
"Input 0",
"Output 0");
3260 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
3261 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
3263 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
3264 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, outputTensorIndexes);
3267 void TfLiteParserImpl::ParseConcatenation(
size_t subgraphIndex,
size_t operatorIndex)
3269 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
3271 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
3272 const auto* options = operatorPtr->builtin_options.AsConcatenationOptions();
3276 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
3277 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
3282 unsigned int numConcatView =
static_cast<unsigned int>(inputs.size());
3283 uint32_t inputRank = InputTensorInfo(subgraphIndex, operatorIndex, 0).
GetNumDimensions();
3285 const unsigned int concatDimInput =
static_cast<unsigned int>(
3286 (
static_cast<int>(inputRank) + options->axis) %
static_cast<int>(inputRank));
3288 OriginsDescriptor concatDescriptor(
static_cast<uint32_t
>(numConcatView), inputRank);
3289 concatDescriptor.SetConcatAxis(concatDimInput);
3290 unsigned int mergeDimOrigin = 0;
3292 for (
unsigned int viewIndex = 0; viewIndex < numConcatView; ++viewIndex)
3294 TensorInfo inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, viewIndex);
3298 inputTensorInfo, concatDescriptor, concatDimInput, viewIndex, mergeDimOrigin);
3301 auto layerName = fmt::format(
"Concatenation:{}:{}", subgraphIndex, operatorIndex);
3303 IConnectableLayer* layer = m_Network->AddConcatLayer(concatDescriptor, layerName.c_str());
3305 TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {});
3308 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
3309 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes});
3312 layer = AddFusedActivationLayer(layer, 0, options->fused_activation_function);
3314 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
3315 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
3318 void TfLiteParserImpl::ParseFullyConnected(
size_t subgraphIndex,
size_t operatorIndex)
3320 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
3322 const auto& operatorRfr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
3323 const auto options = operatorRfr->builtin_options.AsFullyConnectedOptions();
3331 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
3332 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
3335 armnn::TensorInfo filterTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 1);
3338 int32_t weightsDimension =
static_cast<int32_t
>(filterTensorInfo.
GetNumDimensions());
3339 if (weightsDimension != 2)
3342 fmt::format(
"Dimension {} for Fully Connected weights is not supported by Armnn. "
3349 auto layerName = fmt::format(
"FullyConnected:{}:{}", subgraphIndex, operatorIndex);
3351 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
3353 std::vector<unsigned int> tensorIndexesToRegister = {inputTensorIndexes[0]};
3354 armnn::TensorInfo inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
3359 tensorIndexesToRegister.emplace_back(inputTensorIndexes[1]);
3361 if (ShouldConstantTensorBeConverted(inputs[1], inputTensorInfo.
GetDataType(), filterTensorInfo.
GetDataType()))
3363 m_ConstantsToDequantize.emplace_back(inputs[1]->buffer);
3366 if (inputs.size() == 3)
3369 armnn::TensorInfo biasTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 2);
3372 tensorIndexesToRegister.emplace_back(inputTensorIndexes[2]);
3374 if (ShouldConstantTensorBeConverted(inputs[2], inputTensorInfo.
GetDataType(), biasTensorInfo.
GetDataType()))
3376 m_ConstantsToDequantize.emplace_back(inputs[2]->buffer);
3381 layer = m_Network->AddFullyConnectedLayer(desc, layerName.c_str());
3385 unsigned int startingSlotIndex = 0;
3392 std::vector<unsigned int> reshapedDimensions(2);
3393 reshapedDimensions[1] = filterTensorInfo.
GetShape()[1];
3394 reshapedDimensions[0] = inputTensorInfo.
GetNumElements() / reshapedDimensions[1];
3396 if (inputTensorInfo.
GetNumElements() % reshapedDimensions[1] != 0)
3399 fmt::format(
"Failed to deduce input tensor shape from filter size {} {}",
3400 reshapedDimensions[1],
3404 armnn::TensorInfo reshapedTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
3406 inputTensorInfo = reshapedTensorInfo;
3408 std::string reshapeLayerName = fmt::format(
"Reshape_for:{}", layer->
GetName());
3412 reshapeLayerName.c_str());
3417 RegisterInputSlots(subgraphIndex, operatorIndex, reshapeLayer, {inputTensorIndexes[0]});
3419 tensorIndexesToRegister.erase(tensorIndexesToRegister.begin());
3420 startingSlotIndex = 1;
3423 RegisterInputSlots(subgraphIndex, operatorIndex, layer, tensorIndexesToRegister, startingSlotIndex);
3425 armnn::TensorInfo outputTensorInfo = OutputTensorInfoFromShapes(subgraphIndex, operatorIndex, layer, 0,
3434 std::vector<unsigned int> reshapedDimensions(2);
3435 reshapedDimensions[1] = filterTensorInfo.
GetShape()[0];
3436 reshapedDimensions[0] = outputTensorInfo.
GetNumElements() / reshapedDimensions[1];
3438 if (outputTensorInfo.
GetNumElements() % reshapedDimensions[1] != 0)
3441 fmt::format(
"Failed to deduce output tensor shape from filter size {} {}",
3442 reshapedDimensions[1],
3448 std::string reshapeLayerName = fmt::format(
"ExpandDims:{}:{}", subgraphIndex, operatorIndex);
3449 layer = AddReshapeLayer(layer, 0, reshapeLayerName, outputTensorInfo);
3454 options->fused_activation_function);
3457 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
3458 RegisterOutputSlots(subgraphIndex, operatorIndex, fusedActivationLayer, {outputTensorIndexes[0]});
3463 void TfLiteParserImpl::ParseDetectionPostProcess(
size_t subgraphIndex,
size_t operatorIndex)
3465 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
3467 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
3469 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
3470 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
3474 auto custom_options = operatorPtr->custom_options;
3475 const flexbuffers::Map& m = flexbuffers::GetRoot(custom_options.data(), custom_options.size()).AsMap();
3484 desc.
m_ScaleH = m[
"h_scale"].AsFloat();
3485 desc.
m_ScaleW = m[
"w_scale"].AsFloat();
3486 desc.
m_ScaleX = m[
"x_scale"].AsFloat();
3487 desc.
m_ScaleY = m[
"y_scale"].AsFloat();
3489 if (!(m[
"use_regular_nms"].IsNull()))
3493 if (!(m[
"detections_per_class"].IsNull()))
3501 "must be positive and less than or equal to 1.");
3504 armnn::TensorInfo anchorTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 2);
3505 auto anchorTensorAndData = CreateConstTensorNonPermuted(inputs[2], anchorTensorInfo);
3507 auto layerName = fmt::format(
"DetectionPostProcess:{}:{}", subgraphIndex, operatorIndex);
3508 IConnectableLayer* layer = m_Network->AddDetectionPostProcessLayer(desc, anchorTensorAndData,
3516 m_OverriddenOutputShapes.push_back({ 1, numDetectedBox, 4 });
3517 m_OverriddenOutputShapes.push_back({ 1, numDetectedBox });
3518 m_OverriddenOutputShapes.push_back({ 1, numDetectedBox });
3519 m_OverriddenOutputShapes.push_back({ 1 });
3521 for (
unsigned int i = 0 ; i < outputs.size() ; ++i)
3529 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
3530 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0], inputTensorIndexes[1]});
3533 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
3534 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0],
3535 outputTensorIndexes[1],
3536 outputTensorIndexes[2],
3537 outputTensorIndexes[3]});
3541 void TfLiteParserImpl::ParsePack(
size_t subgraphIndex,
size_t operatorIndex)
3543 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
3545 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
3546 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
3549 if (inputs.size() < 1)
3554 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
3555 const auto* options = operatorPtr->builtin_options.AsPackOptions();
3558 desc.
m_Axis =
static_cast<uint32_t
>(options->axis);
3559 desc.
m_NumInputs =
static_cast<uint32_t
>(inputs.size());
3562 armnn::TensorInfo inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
3565 auto layerName = fmt::format(
"Pack:{}:{}", subgraphIndex, operatorIndex);
3570 armnn::TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {});
3573 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
3574 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes});
3576 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
3577 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
3580 void TfLiteParserImpl::ParseUnidirectionalSequenceLSTM(
size_t subgraphIndex,
size_t operatorIndex)
3582 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
3584 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
3585 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
3587 if (inputs.size() < 2)
3589 throw ParseException(
"UnidirectionalSequenceLSTM must have at least 2 input.");
3592 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
3593 const auto& subgraphPtr = m_Model->subgraphs[subgraphIndex];
3594 const auto nodeParams = operatorPtr->builtin_options.AsUnidirectionalSequenceLSTMOptions();
3596 auto inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
3604 if (IsOptionalOperandPresent(operatorPtr->inputs[1]))
3606 params.
m_InputToInputWeights = CreateConstTensorPtr(subgraphPtr->tensors[operatorPtr->inputs[1]].get(),
3607 inputTensorInfo).first;
3611 inputTensorInfo).first;
3612 params.
m_InputToCellWeights = CreateConstTensorPtr(subgraphPtr->tensors[operatorPtr->inputs[3]].get(),
3613 inputTensorInfo).first;
3615 inputTensorInfo).first;
3618 if (IsOptionalOperandPresent(operatorPtr->inputs[5]))
3621 inputTensorInfo).first;
3625 inputTensorInfo).first;
3627 inputTensorInfo).first;
3629 inputTensorInfo).first;
3632 if (IsOptionalOperandPresent(operatorPtr->inputs[9]))
3634 params.
m_CellToInputWeights = CreateConstTensorPtr(subgraphPtr->tensors[operatorPtr->inputs[9]].get(),
3635 inputTensorInfo).first;
3638 if (IsOptionalOperandPresent(operatorPtr->inputs[10]))
3640 params.
m_CellToForgetWeights = CreateConstTensorPtr(subgraphPtr->tensors[operatorPtr->inputs[10]].get(),
3641 inputTensorInfo).first;
3644 if (IsOptionalOperandPresent(operatorPtr->inputs[11]))
3646 params.
m_CellToOutputWeights = CreateConstTensorPtr(subgraphPtr->tensors[operatorPtr->inputs[11]].get(),
3647 inputTensorInfo).first;
3651 if (IsOptionalOperandPresent(operatorPtr->inputs[12]))
3653 params.
m_InputGateBias = CreateConstTensorPtr(subgraphPtr->tensors[operatorPtr->inputs[12]].get(),
3654 inputTensorInfo).first;
3657 params.
m_ForgetGateBias = CreateConstTensorPtr(subgraphPtr->tensors[operatorPtr->inputs[13]].get(),
3658 inputTensorInfo).first;
3659 params.
m_CellBias = CreateConstTensorPtr(subgraphPtr->tensors[operatorPtr->inputs[14]].get(),
3660 inputTensorInfo).first;
3661 params.
m_OutputGateBias = CreateConstTensorPtr(subgraphPtr->tensors[operatorPtr->inputs[15]].get(),
3662 inputTensorInfo).first;
3665 if (IsOptionalOperandPresent(operatorPtr->inputs[16]))
3667 params.
m_ProjectionWeights = CreateConstTensorPtr(subgraphPtr->tensors[operatorPtr->inputs[16]].get(),
3668 inputTensorInfo).first;
3671 if (IsOptionalOperandPresent(operatorPtr->inputs[17]))
3673 params.
m_ProjectionBias = CreateConstTensorPtr(subgraphPtr->tensors[operatorPtr->inputs[17]].get(),
3674 inputTensorInfo).first;
3679 m_ConstantsToBeCreated.push_back(operatorPtr->inputs[18]);
3681 m_ConstantsToBeCreated.push_back(operatorPtr->inputs[19]);
3684 if (inputs.size() >= 21 && IsOptionalOperandPresent(operatorPtr->inputs[20]))
3687 inputTensorInfo).first;
3690 if (inputs.size() >= 22 && IsOptionalOperandPresent(operatorPtr->inputs[21]))
3693 inputTensorInfo).first;
3696 if (inputs.size() >= 23 && IsOptionalOperandPresent(operatorPtr->inputs[22]))
3698 params.
m_CellLayerNormWeights = CreateConstTensorPtr(subgraphPtr->tensors[operatorPtr->inputs[22]].get(),
3699 inputTensorInfo).first;
3702 if (inputs.size() >= 24 && IsOptionalOperandPresent(operatorPtr->inputs[23]))
3705 inputTensorInfo).first;
3726 auto inputIntermediate = CreateConstTensorPtr(subgraphPtr->tensors[operatorPtr->intermediates[0]].get(),
3727 inputTensorInfo).first;
3728 auto inputIntermediateTensorInfo = inputIntermediate->GetInfo();
3731 auto forgetIntermediate = CreateConstTensorPtr(subgraphPtr->tensors[operatorPtr->intermediates[1]].get(),
3732 inputTensorInfo).first;
3733 auto forgetIntermediateTensorInfo = forgetIntermediate->GetInfo();
3736 auto cellIntermediate = CreateConstTensorPtr(subgraphPtr->tensors[operatorPtr->intermediates[2]].get(),
3737 inputTensorInfo).first;
3738 auto cellIntermediateTensorInfo = cellIntermediate->GetInfo();
3741 auto outputIntermediate = CreateConstTensorPtr(subgraphPtr->tensors[operatorPtr->intermediates[3]].get(),
3742 inputTensorInfo).first;
3743 auto outputIntermediateTensorInfo = outputIntermediate->GetInfo();
3748 float defaultIntermediate = std::pow(2, -12);
3755 if (operatorPtr->intermediates.size() > 4)
3757 auto hiddentensor = CreateConstTensorPtr(subgraphPtr->tensors[operatorPtr->intermediates[4]].get(),
3758 inputTensorInfo).first;
3763 unsigned int batchSize = inputTensorInfo.
GetShape()[0];
3764 unsigned int outputSize = outputTensorInfo.
GetShape()[2];
3765 unsigned int numUnits = cellStateInInfo.
GetShape()[1];
3771 armnn::TensorInfo scratchBufferTensorInfo({batchSize, numUnits * 3}, dataType, qScale, qOffset);
3774 scratchBufferTensorInfo =
armnn::TensorInfo({batchSize, numUnits * 4}, dataType, qScale, qOffset);
3780 armnn::TensorInfo outputStateOutTensorInfo({batchSize, outputSize}, dataType, qScale, qOffset);
3830 auto layerName = fmt::format(
"UnidirectionalSequenceLSTM:{}:{}", subgraphIndex, operatorIndex);
3836 auto inputTensorIndexes = AsUnsignedVector({operatorPtr->inputs[0],
3837 operatorPtr->inputs[18],
3838 operatorPtr->inputs[19]});
3839 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0],
3840 inputTensorIndexes[1],
3841 inputTensorIndexes[2]});
3843 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
3849 unsigned int tensorIndex = outputTensorIndexes[0];
3851 RegisterProducerOfTensor(subgraphIndex, tensorIndex, slot);
3854 void TfLiteParserImpl::ParseUnpack(
size_t subgraphIndex,
size_t operatorIndex)
3856 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
3858 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
3859 const auto* options = operatorPtr->builtin_options.AsUnpackOptions();
3864 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
3867 armnn::TensorInfo inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
3872 fmt::format(
"The unpack axis: {} cannot be greater than or equal to "
3873 "the number of input dimension {} {}",
3883 unpackNum = inputTensorInfo.
GetShape()[unpackAxis];
3889 throw ParseException(
"Number to unpack must greater than zero.");
3892 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
3896 std::vector<unsigned int> unpackDimSizes(inputDimSize);
3899 for (
unsigned int i = 0; i < inputDimSize; ++i)
3901 unpackDimSizes[i] = inputTensorInfo.
GetShape()[i];
3904 if (unpackDimSizes[unpackAxis] != unpackNum)
3906 throw ParseException(
"Number to unpack must be the same as length of the dimension to "
3910 unpackDimSizes[unpackAxis] /= unpackNum;
3912 SplitterDescriptor splitDesc(unpackNum,
static_cast<unsigned int>(unpackDimSizes.size()));
3913 for (
unsigned int j = 0; j < unpackNum; ++j)
3916 for (
unsigned int dimIdx = 0; dimIdx < unpackDimSizes.size(); ++dimIdx)
3918 splitDesc.SetViewSize(j, dimIdx, unpackDimSizes[dimIdx]);
3920 splitDesc.SetViewOriginCoord(j, unpackAxis, unpackDimSizes[unpackAxis] * j);
3923 auto layerName = fmt::format(
"Unpack:{}:{}", subgraphIndex, operatorIndex);
3924 IConnectableLayer* layer = m_Network->AddSplitterLayer(splitDesc, layerName.c_str());
3928 unpackDimSizes.data());
3930 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
3931 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
3933 std::vector<unsigned int> reshapeDims;
3934 for (
unsigned int axis = 0; axis < splitOutShape.
GetNumDimensions(); ++axis)
3936 if (axis != unpackAxis)
3938 reshapeDims.push_back(splitOutShape[axis]);
3948 std::string reshapeLayerName = fmt::format(
"Reshape_for:{}", layer->
GetName());
3963 RegisterProducerOfTensor(subgraphIndex, reshapedOutputId, slot);
3967 void TfLiteParserImpl::ParseSplit(
size_t subgraphIndex,
size_t operatorIndex)
3969 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
3971 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
3972 const auto* options = operatorPtr->builtin_options.AsSplitOptions();
3979 throw ParseException(
"Number to splits must greater than zero.");
3982 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
3984 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
3987 armnn::TensorInfo inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 1);
3988 armnn::TensorInfo axisTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
3992 if (axisBufferPtr ==
nullptr)
3995 fmt::format(
"Operation has invalid inputs. Failed to read axis. {}",
4000 ::memcpy(axisData.data(), axisBufferPtr->data.data(), axisTensorInfo.
GetNumBytes());
4001 int32_t axis = axisData[0];
4003 auto inputDimensions =
static_cast<int32_t
>(inputTensorInfo.
GetNumDimensions());
4004 if (((axis < -inputDimensions) && (axis < 0)) || ((axis >= inputDimensions) && (axis > 0)))
4010 fmt::format(
"Operation has invalid axis: {}. Axis must be in range [-n, n) {}",
4021 fmt::format(
"The number of dimensions: {} for input tensors of the split op cannot be greater than {} {}",
4027 std::vector<unsigned int> splitterDimSizes(inputDimSize);
4030 for (
unsigned int i = 0; i < inputDimSize; ++i)
4032 splitterDimSizes[i] = inputTensorInfo.
GetShape()[i];
4035 if (splitterDimSizes[splitDim] % numSplits != 0)
4037 throw ParseException(
"Number of splits must evenly divide the dimension");
4039 splitterDimSizes[splitDim] /= numSplits;
4042 for (
unsigned int j = 0; j < numSplits; ++j)
4045 for (
unsigned int dimIdx = 0; dimIdx < splitterDimSizes.size(); ++dimIdx)
4047 splitDesc.SetViewSize(j, dimIdx, splitterDimSizes[dimIdx]);
4049 splitDesc.SetViewOriginCoord(j, splitDim, splitterDimSizes[splitDim] * j);
4052 auto layerName = fmt::format(
"Split:{}:{}", subgraphIndex, operatorIndex);
4053 IConnectableLayer* layer = m_Network->AddSplitterLayer(splitDesc, layerName.c_str());
4056 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
4057 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[1]});
4065 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
4066 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, outputTensorIndexes);
4071 int numDims = armnn::numeric_cast<int>(numDimsIn);
4072 int v = idx < 0 ? numDims + idx : idx;
4076 return static_cast<unsigned int>(v);
4079 void TfLiteParserImpl::ParseSplitV(
size_t subgraphIndex,
size_t operatorIndex)
4081 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
4083 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
4084 const auto* options = operatorPtr->builtin_options.AsSplitVOptions();
4086 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
4089 auto& inputTensor = inputs[0];
4090 auto& splitsTensor = inputs[1];
4091 auto& axisTensor = inputs[2];
4103 fmt::format(
"The number of dimensions: {} for input tensors of the "
4104 "SplitV op cannot be greater than {} {}",
4112 if (axisBufferPtr ==
nullptr)
4115 fmt::format(
"Operation has invalid inputs. Failed to read axis. {}",
4120 ::memcpy(axisData.data(), axisBufferPtr->data.data(), axisTensorInfo.
GetNumBytes());
4121 int32_t axis = axisData[0];
4123 auto inputDimensions =
static_cast<int32_t
>(inputTensorInfo.
GetNumDimensions());
4124 if (((axis < -inputDimensions) && (axis < 0)) || ((axis >= inputDimensions) && (axis > 0)))
4130 fmt::format(
"Operation has invalid axis: {}. Axis must be in range [-n, n) {}",
4138 unsigned int numSplits{0};
4154 std::vector<int> splitsData(numSplits);
4156 ::memcpy(splitsData.data(), splitsBufferPtr->data.data(), splitsInfo.
GetNumBytes());
4158 unsigned int idx = 0;
4160 unsigned int inferIdx{0};
4162 for (
auto split : splitsData)
4176 if (numInferred == 0)
4178 if (splitSum != armnn::numeric_cast<int>(inputTensorInfo.
GetShape()[splitDim]))
4180 throw ParseException(
"SplitV split_sizes does not sum to the dimension of value along split_dim.");
4183 else if (numInferred == 1)
4185 splitsData[inferIdx] = armnn::numeric_cast<int>(inputTensorInfo.
GetShape()[splitDim]) - splitSum;
4189 throw ParseException(
"Cannot infer split size for more than one split");
4193 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
4198 unsigned int accumSplit = 0;
4199 for (
unsigned int j = 0; j < numSplits; ++j)
4201 unsigned int splitSize = armnn::numeric_cast<unsigned int>(splitsData[j]);
4204 for (
unsigned int dimIdx = 0; dimIdx < inputTensorInfo.
GetNumDimensions(); ++dimIdx)
4206 unsigned int dimSize = inputTensorInfo.
GetShape()[dimIdx];
4207 if (dimIdx == splitDim)
4209 dimSize = splitSize;
4211 splitDesc.SetViewSize(j, dimIdx, dimSize);
4214 splitDesc.SetViewOriginCoord(j, splitDim, accumSplit);
4215 accumSplit += splitSize;
4218 auto layerName = fmt::format(
"SplitV:{}:{}", subgraphIndex, operatorIndex);
4219 IConnectableLayer* layer = m_Network->AddSplitterLayer(splitDesc, layerName.c_str());
4222 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
4223 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
4231 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
4232 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, outputTensorIndexes);
4235 void TfLiteParserImpl::ParseArgMin(
size_t subgraphIndex,
size_t operatorIndex)
4240 void TfLiteParserImpl::ParseArgMax(
size_t subgraphIndex,
size_t operatorIndex)
4245 void TfLiteParserImpl::ParseArgMinMax(
size_t subgraphIndex,
size_t operatorIndex,
ArgMinMaxFunction argMinMaxFunction)
4247 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
4248 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
4251 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
4254 armnn::TensorInfo inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
4255 armnn::TensorInfo axisTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 1);
4265 "Output tensor data type is not supported. (Supported types: Signed32 & Signed64) {}",
4271 if (axisBufferPtr ==
nullptr)
4274 fmt::format(
"Operation has invalid inputs. Failed to read axis. {}",
4279 ::memcpy(axisData.data(), axisBufferPtr->data.data(), axisTensorInfo.
GetNumBytes());
4280 int32_t axis = axisData.front();
4282 auto inputDimensions =
static_cast<int32_t
>(inputTensorInfo.
GetNumDimensions());
4283 if (((axis < -inputDimensions) && (axis < 0)) || ((axis >= inputDimensions) && (axis > 0)))
4289 fmt::format(
"Operation has invalid axis: {}. Axis must be in range [-n, n) {}",
4299 auto layerName = argMinMaxFunction == ArgMinMaxFunction::Max ?
"ArgMax:{}:{}" :
"ArgMin:{}:{}";
4300 auto layerNameFormatted = fmt::format(layerName, subgraphIndex, operatorIndex);
4301 IConnectableLayer *layer = m_Network->AddArgMinMaxLayer(desc, layerNameFormatted.c_str());
4303 outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0});
4307 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
4308 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
4311 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
4312 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, outputTensorIndexes);
4315 void TfLiteParserImpl::ParseGather(
size_t subgraphIndex,
size_t operatorIndex)
4317 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
4324 armnn::TensorInfo inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
4325 armnn::TensorInfo indicesTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 1);
4330 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
4331 const auto* options = operatorPtr->builtin_options.AsGatherOptions();
4332 auto axis = options->axis;
4334 auto layerName = fmt::format(
"Gather:{}:{}", subgraphIndex, operatorIndex);
4336 auto inputDimensions =
static_cast<int32_t
>(inputTensorInfo.
GetNumDimensions());
4339 if (((axis < -inputDimensions) && (axis < 0)) || ((axis >= inputDimensions) && (axis > 0)))
4342 fmt::format(
"Operation has invalid axis: {} It is out of bounds [ -{}, {} ) {}",
4344 inputDimensions, inputDimensions,
4347 if (outputDimensions !=
static_cast<unsigned int>(inputDimensions) + indicesDimensions - 1)
4350 fmt::format(
"Operation has invalid output dimensions: {} Output must be an ({} + {} - 1) -D tensor {}",
4352 inputDimensions, indicesDimensions,
4356 gatherDescriptor.
m_Axis = axis;
4358 IConnectableLayer* layer = m_Network->AddGatherLayer(gatherDescriptor, layerName.c_str());
4360 outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0, 1});
4363 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
4364 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0], inputTensorIndexes[1]});
4366 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
4367 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
4370 void TfLiteParserImpl::ParseGatherNd(
size_t subgraphIndex,
size_t operatorIndex)
4372 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
4379 armnn::TensorInfo inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
4380 armnn::TensorInfo indicesTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 1);
4382 auto layerName = fmt::format(
"GatherNd:{}:{}", subgraphIndex, operatorIndex);
4385 TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0, 1});
4388 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
4389 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0], inputTensorIndexes[1]});
4391 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
4392 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
4395 void TfLiteParserImpl::ParseDepthToSpace(
size_t subgraphIndex,
size_t operatorIndex)
4397 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
4406 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
4407 const auto* options = operatorPtr->builtin_options.AsDepthToSpaceOptions();
4408 auto blockSize = options->block_size;
4412 fmt::format(
"Operation has invalid block size: {} Block size should be >= 2 {}",
4416 descriptor.
m_BlockSize = armnn::numeric_cast<uint32_t>(blockSize);
4418 auto layerName = fmt::format(
"DepthToSpace:{}:{}", subgraphIndex, operatorIndex);
4419 IConnectableLayer* layer = m_Network->AddDepthToSpaceLayer(descriptor, layerName.c_str());
4421 TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0});
4424 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
4425 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
4427 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
4428 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
4431 void TfLiteParserImpl::ParseSum(
size_t subgraphIndex,
size_t operatorIndex)
4436 void TfLiteParserImpl::ParseReduceProd(
size_t subgraphIndex,
size_t operatorIndex)
4441 void TfLiteParserImpl::ParseReduceMax(
size_t subgraphIndex,
size_t operatorIndex)
4446 void TfLiteParserImpl::ParseReduceMin(
size_t subgraphIndex,
size_t operatorIndex)
4451 void TfLiteParserImpl::ParseReduce(
size_t subgraphIndex,
size_t operatorIndex,
ReduceOperation reduceOperation)
4453 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
4455 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
4456 const auto* options = operatorPtr->builtin_options.AsReducerOptions();
4458 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
4461 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
4464 auto layerName = fmt::format(
"Reduce:{}:{}", subgraphIndex, operatorIndex);
4466 armnn::TensorInfo inputTensorInfo0 = InputTensorInfo(subgraphIndex, operatorIndex, 0);
4467 armnn::TensorInfo inputTensorInfo1 = InputTensorInfo(subgraphIndex, operatorIndex, 1);
4472 if (axisBufferPtr !=
nullptr)
4474 std::vector<int32_t> axisData(inputTensorInfo1.
GetNumElements());
4475 ::memcpy(axisData.data(), axisBufferPtr->data.data(), inputTensorInfo1.
GetNumBytes());
4479 std::set<unsigned int> uniqueAxis;
4480 std::transform(axisData.begin(),
4482 std::inserter(uniqueAxis, uniqueAxis.begin()),
4483 [rank](
int i)->unsigned
int{
4484 return static_cast<uint32_t>(((i + rank) % rank)); });
4485 desc.
m_vAxis.assign(uniqueAxis.begin(), uniqueAxis.end());
4501 armnn::TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0});
4505 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
4506 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
4509 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
4510 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, outputTensorIndexes);
4513 void TfLiteParserImpl::ParseLocalResponseNormalization(
size_t subgraphIndex,
size_t operatorIndex)
4515 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
4517 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
4520 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
4523 auto layerName = fmt::format(
"LRN:{}:{}", subgraphIndex, operatorIndex);
4524 std::string layerNameFormatted = fmt::format(layerName, subgraphIndex, operatorIndex);
4526 armnn::TensorInfo inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
4528 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
4529 const auto* options = operatorPtr->builtin_options.AsLocalResponseNormalizationOptions();
4535 descriptor.
m_NormSize =
static_cast<uint32_t
>(options->radius);
4536 descriptor.
m_K = options->bias;
4537 descriptor.
m_Alpha = options->alpha;
4538 descriptor.
m_Beta = options->beta;
4544 IConnectableLayer* layer = m_Network->AddNormalizationLayer(descriptor, layerNameFormatted.c_str());
4547 TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0});
4550 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
4551 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
4553 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
4554 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
4557 void TfLiteParserImpl::ParseAbs(
size_t subgraphIndex,
size_t operatorIndex)
4562 void TfLiteParserImpl::ParseCeil(
size_t subgraphIndex,
size_t operatorIndex)
4567 void TfLiteParserImpl::ParseExp(
size_t subgraphIndex,
size_t operatorIndex)
4572 void TfLiteParserImpl::ParseLog(
size_t subgraphIndex,
size_t operatorIndex)
4577 void TfLiteParserImpl::ParseLogicalNot(
size_t subgraphIndex,
size_t operatorIndex)
4582 void TfLiteParserImpl::ParseNeg(
size_t subgraphIndex,
size_t operatorIndex)
4587 void TfLiteParserImpl::ParseRsqrt(
size_t subgraphIndex,
size_t operatorIndex)
4592 void TfLiteParserImpl::ParseSin(
size_t subgraphIndex,
size_t operatorIndex)
4597 void TfLiteParserImpl::ParseSqrt(
size_t subgraphIndex,
size_t operatorIndex)
4602 void TfLiteParserImpl::ParseElementwiseUnary(
size_t subgraphIndex,
size_t operatorIndex,
UnaryOperation unaryOperation)
4604 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
4606 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
4609 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
4613 std::string layerNameFormatted = fmt::format(layerName, subgraphIndex, operatorIndex);
4617 IConnectableLayer* layer = m_Network->AddElementwiseUnaryLayer(desc, layerNameFormatted.c_str());
4620 TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0});
4623 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
4624 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
4626 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
4627 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, outputTensorIndexes);
4630 void TfLiteParserImpl::ParseEqual(
size_t subgraphIndex,
size_t operatorIndex)
4635 void TfLiteParserImpl::ParseNotEqual(
size_t subgraphIndex,
size_t operatorIndex)
4640 void TfLiteParserImpl::ParseGreater(
size_t subgraphIndex,
size_t operatorIndex)
4645 void TfLiteParserImpl::ParseGreaterOrEqual(
size_t subgraphIndex,
size_t operatorIndex)
4650 void TfLiteParserImpl::ParseLess(
size_t subgraphIndex,
size_t operatorIndex)
4655 void TfLiteParserImpl::ParseLessOrEqual(
size_t subgraphIndex,
size_t operatorIndex)
4660 void TfLiteParserImpl::ParseComparison(
size_t subgraphIndex,
size_t operatorIndex,
4663 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
4665 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
4668 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
4672 std::string layerNameFormatted = fmt::format(layerName, subgraphIndex, operatorIndex);
4674 armnn::TensorInfo inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
4675 armnn::TensorInfo input1TensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 1);
4676 CheckMatchingQuantization(inputTensorInfo, input1TensorInfo, layerNameFormatted,
"Input 0",
"Input 1");
4680 IConnectableLayer* layer = m_Network->AddComparisonLayer(desc, layerNameFormatted.c_str());
4683 TensorInfo outputTensorInfo = OutputTensorInfoFromInputs(subgraphIndex, operatorIndex, layer, 0, {0, 1});
4686 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
4687 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0], inputTensorIndexes[1]});
4689 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
4690 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
4694 unsigned int outputSlot,
4695 std::string reshapeLayerName,
4702 m_Network->AddReshapeLayer(desc, reshapeLayerName.c_str());
4707 return reshapeLayer;
4711 unsigned int outputSlot,
4712 tflite::ActivationFunctionType activationType)
4715 std::string layerName = prevLayer->
GetName();
4717 switch(activationType)
4719 case tflite::ActivationFunctionType_NONE:
4724 case tflite::ActivationFunctionType_RELU:
4726 activationDesc.
m_Function = ActivationFunction::ReLu;
4727 layerName +=
":RELU";
4730 case tflite::ActivationFunctionType_RELU6:
4732 activationDesc.
m_Function = ActivationFunction::BoundedReLu;
4733 activationDesc.
m_A = 6.0f;
4734 activationDesc.
m_B = 0.0f;
4735 layerName +=
":RELU6";
4738 case tflite::ActivationFunctionType_TANH:
4740 activationDesc.
m_Function = ActivationFunction::TanH;
4741 activationDesc.
m_A = 1.0f;
4742 activationDesc.
m_B = 1.0f;
4743 layerName +=
":TANH";
4748 case tflite::ActivationFunctionType_RELU_N1_TO_1:
4749 case tflite::ActivationFunctionType_SIGN_BIT:
4753 fmt::format(
"TfLite parser doesn't support fused activation: "
4756 tflite::EnumNameActivationFunctionType(activationType),
4763 m_Network->AddActivationLayer(activationDesc, layerName.c_str());
4765 auto & prevOutputSlot = prevLayer->
GetOutputSlot(outputSlot);
4768 return activationLayer;
4772 unsigned int outputSlot)
4775 auto& prevOutputSlot = prevLayer->
GetOutputSlot(outputSlot);
4778 if (dataType == DataType::Signed32)
4783 std::string layerName = prevLayer->
GetName();
4794 if (fileName ==
nullptr)
4799 std::error_code errorCode;
4800 fs::path pathToFile(fileName);
4801 if (!fs::exists(pathToFile, errorCode))
4804 std::stringstream msg;
4805 msg <<
"Cannot find the file (" << fileName <<
") errorCode: " << errorCode
4810 std::ifstream file(fileName, std::ios::binary);
4811 std::string fileContent((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
4813 fileContent.size());
4818 if (binaryContent ==
nullptr)
4823 flatbuffers::Verifier verifier(binaryContent, len);
4827 fmt::format(
"Buffer doesn't conform to the expected Tensorflow Lite "
4828 "flatbuffers format. size:{} {}",
4832 return tflite::UnPackModel(binaryContent);
4836 size_t subgraphIndex,
4837 size_t operatorIndex)
4841 const auto& subgraphPtr = model->subgraphs[subgraphIndex];
4842 const auto& operatorPtr = subgraphPtr->operators[operatorIndex];
4844 size_t inputCount = operatorPtr->inputs.size();
4846 for (
size_t i = 0; i < inputCount; ++i)
4849 if (operatorPtr->inputs[i] == -1)
4856 result.push_back(subgraphPtr->tensors[inputId].get());
4863 size_t subgraphIndex,
4864 size_t operatorIndex)
4868 const auto& subgraphPtr = model->subgraphs[subgraphIndex];
4869 const auto& operatorPtr = subgraphPtr->operators[operatorIndex];
4871 size_t outputCount = operatorPtr->outputs.size();
4873 for (
size_t i = 0; i < outputCount; ++i)
4877 result[i] = subgraphPtr->tensors[outputId].get();
4883 size_t subgraphIndex)
4886 const auto& subgraphPtr = model->subgraphs[subgraphIndex];
4888 size_t inputCount = subgraphPtr->inputs.size();
4890 for (
size_t i = 0; i < inputCount; ++i)
4894 result[i] = std::make_pair(inputId, subgraphPtr->tensors[inputId].get());
4900 size_t subgraphIndex)
4903 const auto& subgraphPtr = model->subgraphs[subgraphIndex];
4905 size_t outputCount = subgraphPtr->outputs.size();
4907 for (
size_t i = 0; i < outputCount; ++i)
4910 result[i] = std::make_pair(outputId, subgraphPtr->tensors[outputId].get());
4916 size_t subgraphIndex,
4917 size_t operatorIndex)
4920 const auto& subgraphPtr = model->subgraphs[subgraphIndex];
4921 const auto& operatorPtr = subgraphPtr->operators[operatorIndex];
4922 return operatorPtr->inputs;
4926 size_t subgraphIndex,
4927 size_t operatorIndex)
4930 const auto& subgraphPtr = model->subgraphs[subgraphIndex];
4931 const auto& operatorPtr = subgraphPtr->operators[operatorIndex];
4932 return operatorPtr->outputs;
4935 void TfLiteParserImpl::RegisterInputSlots(
size_t subgraphIndex,
4936 size_t operatorIndex,
4938 const std::vector<unsigned int>& tensorIndexes,
4939 unsigned int startingSlotIndex)
4941 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
4947 fmt::format(
"The number of tensor inputs ({}) does not match the number expected ({})"
4948 " for subgraph:{} operator index:{} {}",
4949 tensorIndexes.size(),
4956 for (
unsigned int index = 0; index < tensorIndexes.size() ; ++index)
4958 unsigned int tensorIndex = tensorIndexes[index];
4960 RegisterConsumerOfTensor(subgraphIndex, tensorIndex, slot);
4964 void TfLiteParserImpl::RegisterOutputSlots(
size_t subgraphIndex,
4965 size_t operatorIndex,
4967 const std::vector<unsigned int>& tensorIndexes)
4969 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
4974 fmt::format(
"The number of tensor outputs ({}) does not match the number expected ({})"
4975 " for subgraph:{} operator index:{} {}",
4976 tensorIndexes.size(),
4983 for (
unsigned int slotIndex = 0; slotIndex < layer->
GetNumOutputSlots(); ++slotIndex)
4985 unsigned int tensorIndex = tensorIndexes[slotIndex];
4987 RegisterProducerOfTensor(subgraphIndex, tensorIndex, slot);
4991 void TfLiteParserImpl::SetupInputLayerTensorInfos(
size_t subgraphIndex)
4996 for (
auto const& tensorIdAndPtr : inputs)
4999 m_TensorInfos.insert({tensorIdAndPtr.first, tensorInfo});
5003 void TfLiteParserImpl::SetupInputLayers(
size_t subgraphIndex)
5008 for (
auto const& tensorIdAndPtr : inputs)
5010 auto bindingId = GenerateLayerBindingId(subgraphIndex, tensorIdAndPtr.first);
5012 m_Network->AddInputLayer(bindingId, tensorIdAndPtr.second->name.c_str());
5017 RegisterOutputSlots(subgraphIndex,
5018 VIRTUAL_OPERATOR_ID,
5020 {
static_cast<uint32_t
>(tensorIdAndPtr.first) });
5024 void TfLiteParserImpl::SetupOutputLayers(
size_t subgraphIndex)
5029 for (
auto const& tensorIdAndPtr : outputs)
5031 auto bindingId = GenerateLayerBindingId(subgraphIndex, tensorIdAndPtr.first);
5033 m_Network->AddOutputLayer(bindingId, tensorIdAndPtr.second->name.c_str());
5035 RegisterInputSlots(subgraphIndex,
5036 VIRTUAL_OPERATOR_ID,
5038 {
static_cast<uint32_t
>(tensorIdAndPtr.first) });
5042 void TfLiteParserImpl::SetupConstantLayerTensorInfos(
size_t subgraph)
5046 const auto & subgraphPtr = m_Model->subgraphs[subgraph];
5047 for (
unsigned int subgraphIndex = 0; subgraphIndex < m_SubgraphConnections.size(); ++subgraphIndex)
5049 for (
unsigned int tensorIndex = 0; tensorIndex < m_SubgraphConnections[subgraphIndex].size(); ++tensorIndex)
5051 if (m_SubgraphConnections[subgraphIndex][tensorIndex].outputSlot ==
nullptr &&
5052 m_SubgraphConnections[subgraphIndex][tensorIndex].inputSlots.size() > 0)
5054 TensorRawPtr tensorPtr = subgraphPtr->tensors[tensorIndex].get();
5058 m_TensorInfos.insert({tensorIndex, tensorInfo});
5064 void TfLiteParserImpl::SetupConstantLayers(
size_t subgraph)
5068 const auto & subgraphPtr = m_Model->subgraphs[subgraph];
5069 for (
unsigned int subgraphIndex = 0; subgraphIndex < m_SubgraphConnections.size(); ++subgraphIndex)
5071 for (
unsigned int tensorIndex = 0; tensorIndex < m_SubgraphConnections[subgraphIndex].size(); ++tensorIndex)
5073 if (m_SubgraphConnections[subgraphIndex][tensorIndex].outputSlot ==
nullptr &&
5074 m_SubgraphConnections[subgraphIndex][tensorIndex].inputSlots.size() > 0)
5076 TensorRawPtr tensorPtr = subgraphPtr->tensors[tensorIndex].get();
5078 if (IsConstTensor(tensorPtr))
5083 if (std::find(m_ConstantsToDequantize.begin(), m_ConstantsToDequantize.end(), tensorPtr->buffer)
5084 != m_ConstantsToDequantize.end())
5086 dataType = DataType::Float32;
5088 auto tensorAndData = CreateConstTensorNonPermuted(tensorPtr, tensorInfo, dataType);
5090 std::string layerName = fmt::format(
"Constant:{}", tensorPtr->name);
5091 IConnectableLayer *layer = m_Network->AddConstantLayer(tensorAndData.first, layerName.c_str());
5094 RegisterOutputSlots(subgraphIndex,
5095 VIRTUAL_OPERATOR_ID,
5099 else if (ShouldConstantTensorBeCreated(tensorIndex))
5104 if (std::find(m_ConstantsToDequantize.begin(), m_ConstantsToDequantize.end(), tensorPtr->buffer)
5105 != m_ConstantsToDequantize.end())
5107 dataType = DataType::Float32;
5115 std::string layerName = fmt::format(
"Constant:{}", tensorPtr->name);
5116 IConnectableLayer* layer = m_Network->AddConstantLayer(tensorAndData, layerName.c_str());
5119 RegisterOutputSlots(subgraphIndex,
5120 VIRTUAL_OPERATOR_ID,
5127 fmt::format(
"Invalid Tensor: Tensor should be constant. {}",
5139 return model->buffers[bufferIndex].get();
5142 template<
typename T>
5143 std::pair<armnn::ConstTensor, TfLiteParserImpl::SupportedDataStorage>
5152 auto constData = CreateConstTensorImpl<T>(bufferPtr,
5156 TfLiteParserImpl::SupportedDataStorage storage(std::move(constData.second));
5157 return std::make_pair(constData.first, std::move(storage));
5160 bool TfLiteParserImpl::ShouldConstantTensorBeCreated(
unsigned int tensorIndex)
5163 return (std::find(m_ConstantsToBeCreated.begin(), m_ConstantsToBeCreated.end(), tensorIndex)
5164 != m_ConstantsToBeCreated.end());
5167 bool TfLiteParserImpl::IsConstTensor(
TensorRawPtr tensorPtr)
5170 bool isConst =
true;
5172 auto buffer =
GetBuffer(m_Model, tensorPtr->buffer);
5173 if (buffer->data.size() == 0)
5181 std::pair<armnn::ConstTensor, TfLiteParserImpl::SupportedDataStorage>
5182 TfLiteParserImpl::CreateConstTensorPermuted(
TensorRawPtr tensorPtr,
5187 auto bufferPtr =
GetBuffer(m_Model, tensorPtr->buffer);
5196 return CreateConstTensorAndStoreData<float>(bufferPtr,
5201 return CreateConstTensorAndStoreData<uint8_t>(bufferPtr,
5206 return CreateConstTensorAndStoreData<int8_t>(bufferPtr,
5211 return CreateConstTensorAndStoreData<int8_t>(bufferPtr,
5216 return CreateConstTensorAndStoreData<int32_t>(bufferPtr,
5222 std::stringstream errString;
5223 errString <<
"Unexpected datatype when creating const tensor: "
5225 <<
" shape:" << tensorInfo.
GetShape()
5236 auto bufferPtr =
GetBuffer(m_Model, tensorPtr->buffer);
5242 return ConstTensor(tensorInfo, bufferPtr->data.data());
5245 std::pair<armnn::ConstTensor, std::unique_ptr<float[]>>
5246 TfLiteParserImpl::CreateConstTensorNonPermuted(
TensorRawPtr tensorPtr,
5251 auto bufferPtr =
GetBuffer(m_Model, tensorPtr->buffer);
5257 if (inputDataType == DataType::Float32 && tensorInfo.
GetDataType() != DataType::Float32)
5263 return std::make_pair(
ConstTensor(constTensorInfo, data.get()), std::move(data));
5268 fmt::format(
"Unsupported input/weights combination: Input {} not supported with Weights {}",
5276 return std::make_pair(
ConstTensor(tensorInfo, bufferPtr->data.data()), std::unique_ptr<
float[]>());
5280 std::pair<armnn::ConstTensor*, std::unique_ptr<float[]>>
5285 auto bufferPtr =
GetBuffer(m_Model, tensorPtr->buffer);
5297 return std::make_pair(
new ConstTensor(constTensorInfo, data.get()), std::move(data));
5302 fmt::format(
"Unsupported input/weights combination: Input {} not supported with Weights {}",
5310 return std::make_pair(
new ConstTensor(tensorInfo, bufferPtr->data.data()), std::unique_ptr<
float[]>());
5315 const std::string& name)
const
5319 for (
auto const& input : inputs)
5321 if (input.second->name == name)
5323 auto bindingId = GenerateLayerBindingId(subgraphId, input.first);
5327 return std::make_pair(bindingId, inputTensorInfo);
5331 std::stringstream bindings;
5332 for (
auto const& input : inputs)
5334 bindings <<
"'" << input.second->name <<
"' ";
5338 fmt::format(
"No input binding found for subgraph:{} and name:{}. "
5339 "Possible inputs are: [{}] {}",
5347 const std::string& name)
const
5351 for (
unsigned int i = 0; i < outputs.size(); ++i)
5353 auto const output = outputs[i];
5354 if (output.second->name == name)
5356 auto bindingId = GenerateLayerBindingId(subgraphId, output.first);
5357 std::vector<unsigned int> shape = m_OverriddenOutputShapes.size() > 0 ?
5358 m_OverriddenOutputShapes[i] : AsUnsignedVector(output.second->shape);
5359 return std::make_pair(bindingId,
ToTensorInfo(output.second, shape));
5363 std::stringstream bindings;
5364 for (
auto const& output : outputs)
5366 bindings <<
"'" << output.second->name <<
"' ";
5370 fmt::format(
"No output binding found for subgraph:{} and name:{}. "
5371 "Possible outputs are: [{}] {}",
5380 return m_Model->subgraphs.size();
5387 std::vector<std::string> result;
5388 result.reserve(inputs.size());
5389 for (
auto const& input : inputs)
5391 result.push_back(input.second->name);
5400 std::vector<std::string> result;
5401 result.reserve(outputs.size());
5402 for (
auto const& output : outputs)
5404 result.push_back(output.second->name);
5414 TfLiteParserImpl::SupportedDataStorage::SupportedDataStorage(std::unique_ptr<
float[]>&& data)
5415 : m_FloatData(
std::move(data))
5416 , m_Uint8Data(nullptr)
5417 , m_Int8Data(nullptr)
5418 , m_Int32Data(nullptr)
5422 TfLiteParserImpl::SupportedDataStorage::SupportedDataStorage(std::unique_ptr<uint8_t[]>&& data)
5423 : m_FloatData(nullptr)
5424 , m_Uint8Data(
std::move(data))
5425 , m_Int8Data(nullptr)
5426 , m_Int32Data(nullptr)
5430 TfLiteParserImpl::SupportedDataStorage::SupportedDataStorage(std::unique_ptr<int8_t[]>&& data)
5431 : m_FloatData(nullptr)
5432 , m_Uint8Data(nullptr)
5433 , m_Int8Data(
std::move(data))
5434 , m_Int32Data(nullptr)
5438 TfLiteParserImpl::SupportedDataStorage::SupportedDataStorage(std::unique_ptr<int32_t[]>&& data)
5439 : m_FloatData(nullptr)
5440 , m_Uint8Data(nullptr)
5441 , m_Int8Data(nullptr)
5442 , m_Int32Data(
std::move(data))