29 #include <schema_generated.h> 31 #include <flatbuffers/flexbuffers.h> 33 #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);
312 ::memcpy(buffer.data(), bufferPtr->data.data(), bufferPtr->data.size());
317 ::memcpy(uint64Buffer.data(), bufferPtr->data.data(), bufferPtr->data.size());
318 buffer.assign(std::begin(uint64Buffer), std::end(uint64Buffer));
323 #define CHECK_BUFFER_SIZE(BUFFER_PTR, TENSOR_INFO, BUFFER_ID) \ 324 CheckBufferSize(BUFFER_PTR, TENSOR_INFO, BUFFER_ID, CHECK_LOCATION()) 328 switch(activationType)
330 case tflite::ActivationFunctionType_NONE:
331 case tflite::ActivationFunctionType_RELU:
332 case tflite::ActivationFunctionType_RELU6:
333 case tflite::ActivationFunctionType_TANH:
344 #define CHECK_SUPPORTED_FUSED_ACTIVATION(OPTION, SUBGRAPH_INDEX, OPERATOR_INDEX) \ 346 if (IsActivationSupported(OPTION->fused_activation_function) == false) \ 348 throw ParseException( \ 349 fmt::format("TfLite parser doesn't suppport fused activation: " \ 350 "{}/{} in {} subgraph:{} operator:{} at {}", \ 351 OPTION->fused_activation_function, \ 352 tflite::EnumNameActivationFunctionType(\ 353 OPTION->fused_activation_function), \ 357 CHECK_LOCATION().FileLine())); \ 362 std::vector<unsigned int> AsUnsignedVector(
const std::vector<int32_t>& in)
364 std::vector<unsigned int> result;
365 result.reserve(in.size());
378 void CalcPadding(uint32_t inputSize,
382 uint32_t& paddingFront,
383 uint32_t& paddingBack,
384 tflite::Padding padding)
388 if (padding == tflite::Padding_SAME)
390 uint32_t outputSize = (inputSize + stride - 1) / stride;
391 uint32_t dilatedSize = filterSize + (dilation - 1) * (filterSize - 1);
392 uint32_t temp = (outputSize - 1) * stride + dilatedSize;
393 if (temp > inputSize)
395 paddingFront = (temp - inputSize) / 2;
396 paddingBack = (temp - inputSize) - paddingFront;
402 const std::vector<unsigned int>& shape,
403 const bool outputTensor =
false)
408 switch (tensorPtr->type)
410 case tflite::TensorType_UINT8:
413 case tflite::TensorType_FLOAT32:
416 case tflite::TensorType_INT8:
417 if (tensorPtr->quantization->zero_point.size() == 1)
428 case tflite::TensorType_INT16:
431 case tflite::TensorType_INT32:
434 case tflite::TensorType_INT64:
437 case tflite::TensorType_BOOL:
444 fmt::format(
"Unsupported data type {} = {} for tensor: {}. {}",
446 tflite::EnumNameTensorType(tensorPtr->type),
453 std::vector<unsigned int> safeShape = shape;
454 if (shape.size() == 0)
456 safeShape.push_back(1);
461 tensorShape =
TensorShape(armnn::numeric_cast<unsigned int>(safeShape.size()), safeShape.data());
465 size_t shapeSignatureSize = tensorPtr->shape_signature.size();
468 if (shapeSignatureSize != 0)
471 if (shapeSignatureSize != shape.size())
475 for (
unsigned int i = 0; i < shapeSignatureSize; ++i)
477 unsigned int dim = tensorPtr->shape_signature[i] > -1 ?
478 static_cast<unsigned int>(tensorPtr->shape_signature[i]) : 0;
479 safeShape.push_back(dim);
483 std::unique_ptr<bool[]> dimMask = std::make_unique<bool[]>(tensorPtr->shape_signature.size());
484 for (
unsigned int i = 0; i < tensorPtr->shape_signature.size(); ++i)
486 dimMask[i] = tensorPtr->shape_signature[i] == -1 ? false :
true;
488 tensorShape =
TensorShape(static_cast<unsigned int>(safeShape.size()), safeShape.data(), dimMask.get());
491 else if (shape.size() == 0)
497 tensorShape =
TensorShape(armnn::numeric_cast<unsigned int>(shape.size()), shape.data());
501 float quantizationScale = 0.0f;
502 int32_t quantizationOffset = 0;
504 if (tensorPtr->quantization.get())
506 if (tensorPtr->quantization->scale.size() <= 1)
511 if (tensorPtr->quantization->scale.size() == 1)
513 quantizationScale = tensorPtr->quantization->scale[0];
515 if (tensorPtr->quantization->zero_point.size() == 1)
530 std::vector<float> quantizationScales;
531 std::vector<int32_t> quantizationOffsets;
534 std::copy(tensorPtr->quantization->scale.begin(),
535 tensorPtr->quantization->scale.end(),
536 std::back_inserter(quantizationScales));
542 armnn::numeric_cast<unsigned int>(tensorPtr->quantization->quantized_dimension));
558 auto const& dimensions = AsUnsignedVector(tensorPtr->shape);
563 const bool outputTensor)
565 auto const& dimensions = AsUnsignedVector(tensorPtr->shape);
566 return ToTensorInfo(tensorPtr, dimensions, outputTensor);
570 std::pair<armnn::ConstTensor, std::unique_ptr<T[]>>
579 fmt::format(
"Buffer for buffer:{} is null", tensorPtr->buffer).c_str());
587 reinterpret_cast<const T*
>(bufferPtr->data.data()), data.get(),
sizeof(T));
591 ::memcpy(data.get(), bufferPtr->data.data(), tensorInfo.
GetNumBytes());
597 return std::make_pair(
ConstTensor(tensorInfo, data.get()), std::move(data));
610 if (actualSize != expected.size())
615 for (
unsigned int i = 0u; i < actualSize; i++)
617 if (expected[i] < 0 ||
618 actual[i] != static_cast<unsigned int>(expected[i]))
627 void CheckMatchingQuantization(
const TensorInfo& first,
629 const std::string& descName,
630 std::string
const& firstName,
631 std::string
const& secondName)
643 if (firstDataType != secondDataType)
646 " must be of the same quantized type, " +
654 " must have the same quantization space, " +
666 , m_Network(nullptr, nullptr)
670 m_ParserFunctions[tflite::BuiltinOperator_ABS] = &TfLiteParserImpl::ParseAbs;
671 m_ParserFunctions[tflite::BuiltinOperator_ADD] = &TfLiteParserImpl::ParseAdd;
672 m_ParserFunctions[tflite::BuiltinOperator_ARG_MIN] = &TfLiteParserImpl::ParseArgMin;
673 m_ParserFunctions[tflite::BuiltinOperator_ARG_MAX] = &TfLiteParserImpl::ParseArgMax;
674 m_ParserFunctions[tflite::BuiltinOperator_AVERAGE_POOL_2D] = &TfLiteParserImpl::ParseAveragePool2D;
675 m_ParserFunctions[tflite::BuiltinOperator_BATCH_TO_SPACE_ND] = &TfLiteParserImpl::ParseBatchToSpaceND;
676 m_ParserFunctions[tflite::BuiltinOperator_CAST] = &TfLiteParserImpl::ParseCast;
677 m_ParserFunctions[tflite::BuiltinOperator_CONCATENATION] = &TfLiteParserImpl::ParseConcatenation;
678 m_ParserFunctions[tflite::BuiltinOperator_CONV_2D] = &TfLiteParserImpl::ParseConv2D;
680 #if defined(ARMNN_POST_TFLITE_2_3) 681 m_ParserFunctions[tflite::BuiltinOperator_CONV_3D] = &TfLiteParserImpl::ParseConv3D;
683 m_ParserFunctions[tflite::BuiltinOperator_CUSTOM] = &TfLiteParserImpl::ParseCustomOperator;
684 m_ParserFunctions[tflite::BuiltinOperator_DEPTH_TO_SPACE] = &TfLiteParserImpl::ParseDepthToSpace;
685 m_ParserFunctions[tflite::BuiltinOperator_DEPTHWISE_CONV_2D] = &TfLiteParserImpl::ParseDepthwiseConv2D;
686 m_ParserFunctions[tflite::BuiltinOperator_DEQUANTIZE] = &TfLiteParserImpl::ParseDequantize;
687 m_ParserFunctions[tflite::BuiltinOperator_DIV] = &TfLiteParserImpl::ParseDiv;
688 m_ParserFunctions[tflite::BuiltinOperator_ELU] = &TfLiteParserImpl::ParseElu;
689 m_ParserFunctions[tflite::BuiltinOperator_EQUAL] = &TfLiteParserImpl::ParseEqual;
690 m_ParserFunctions[tflite::BuiltinOperator_EXP] = &TfLiteParserImpl::ParseExp;
691 m_ParserFunctions[tflite::BuiltinOperator_EXPAND_DIMS] = &TfLiteParserImpl::ParseExpandDims;
692 m_ParserFunctions[tflite::BuiltinOperator_FULLY_CONNECTED] = &TfLiteParserImpl::ParseFullyConnected;
693 m_ParserFunctions[tflite::BuiltinOperator_GATHER] = &TfLiteParserImpl::ParseGather;
694 m_ParserFunctions[tflite::BuiltinOperator_GREATER] = &TfLiteParserImpl::ParseGreater;
695 m_ParserFunctions[tflite::BuiltinOperator_GREATER_EQUAL] = &TfLiteParserImpl::ParseGreaterOrEqual;
696 m_ParserFunctions[tflite::BuiltinOperator_HARD_SWISH] = &TfLiteParserImpl::ParseHardSwish;
697 m_ParserFunctions[tflite::BuiltinOperator_LEAKY_RELU] = &TfLiteParserImpl::ParseLeakyRelu;
698 m_ParserFunctions[tflite::BuiltinOperator_LESS] = &TfLiteParserImpl::ParseLess;
699 m_ParserFunctions[tflite::BuiltinOperator_LESS_EQUAL] = &TfLiteParserImpl::ParseLessOrEqual;
700 m_ParserFunctions[tflite::BuiltinOperator_LOCAL_RESPONSE_NORMALIZATION]
701 = &TfLiteParserImpl::ParseLocalResponseNormalization;
702 m_ParserFunctions[tflite::BuiltinOperator_LOGICAL_NOT] = &TfLiteParserImpl::ParseLogicalNot;
703 m_ParserFunctions[tflite::BuiltinOperator_LOGISTIC] = &TfLiteParserImpl::ParseLogistic;
704 m_ParserFunctions[tflite::BuiltinOperator_L2_NORMALIZATION] = &TfLiteParserImpl::ParseL2Normalization;
705 m_ParserFunctions[tflite::BuiltinOperator_MAX_POOL_2D] = &TfLiteParserImpl::ParseMaxPool2D;
706 m_ParserFunctions[tflite::BuiltinOperator_MAXIMUM] = &TfLiteParserImpl::ParseMaximum;
707 m_ParserFunctions[tflite::BuiltinOperator_MEAN] = &TfLiteParserImpl::ParseMean;
708 m_ParserFunctions[tflite::BuiltinOperator_MINIMUM] = &TfLiteParserImpl::ParseMinimum;
709 m_ParserFunctions[tflite::BuiltinOperator_MIRROR_PAD] = &TfLiteParserImpl::ParseMirrorPad;
710 m_ParserFunctions[tflite::BuiltinOperator_MUL] = &TfLiteParserImpl::ParseMul;
711 m_ParserFunctions[tflite::BuiltinOperator_NEG] = &TfLiteParserImpl::ParseNeg;
712 m_ParserFunctions[tflite::BuiltinOperator_NOT_EQUAL] = &TfLiteParserImpl::ParseNotEqual;
713 m_ParserFunctions[tflite::BuiltinOperator_PACK] = &TfLiteParserImpl::ParsePack;
714 m_ParserFunctions[tflite::BuiltinOperator_PAD] = &TfLiteParserImpl::ParsePad;
715 m_ParserFunctions[tflite::BuiltinOperator_PADV2] = &TfLiteParserImpl::ParsePad;
716 m_ParserFunctions[tflite::BuiltinOperator_PRELU] = &TfLiteParserImpl::ParsePrelu;
717 m_ParserFunctions[tflite::BuiltinOperator_QUANTIZE] = &TfLiteParserImpl::ParseQuantize;
718 m_ParserFunctions[tflite::BuiltinOperator_RELU] = &TfLiteParserImpl::ParseRelu;
719 m_ParserFunctions[tflite::BuiltinOperator_RELU6] = &TfLiteParserImpl::ParseRelu6;
720 m_ParserFunctions[tflite::BuiltinOperator_REDUCE_MAX] = &TfLiteParserImpl::ParseReduceMax;
721 m_ParserFunctions[tflite::BuiltinOperator_REDUCE_MIN] = &TfLiteParserImpl::ParseReduceMin;
722 m_ParserFunctions[tflite::BuiltinOperator_REDUCE_PROD] = &TfLiteParserImpl::ParseReduceProd;
723 m_ParserFunctions[tflite::BuiltinOperator_RESHAPE] = &TfLiteParserImpl::ParseReshape;
724 m_ParserFunctions[tflite::BuiltinOperator_RESIZE_BILINEAR] = &TfLiteParserImpl::ParseResizeBilinear;
725 m_ParserFunctions[tflite::BuiltinOperator_RESIZE_NEAREST_NEIGHBOR] = &TfLiteParserImpl::ParseResizeNearestNeighbor;
726 m_ParserFunctions[tflite::BuiltinOperator_RSQRT] = &TfLiteParserImpl::ParseRsqrt;
727 m_ParserFunctions[tflite::BuiltinOperator_SHAPE] = &TfLiteParserImpl::ParseShape;
728 m_ParserFunctions[tflite::BuiltinOperator_SLICE] = &TfLiteParserImpl::ParseSlice;
729 m_ParserFunctions[tflite::BuiltinOperator_SOFTMAX] = &TfLiteParserImpl::ParseSoftmax;
730 m_ParserFunctions[tflite::BuiltinOperator_SPACE_TO_BATCH_ND] = &TfLiteParserImpl::ParseSpaceToBatchND;
731 m_ParserFunctions[tflite::BuiltinOperator_SPLIT] = &TfLiteParserImpl::ParseSplit;
732 m_ParserFunctions[tflite::BuiltinOperator_SPLIT_V] = &TfLiteParserImpl::ParseSplitV;
733 m_ParserFunctions[tflite::BuiltinOperator_SQUEEZE] = &TfLiteParserImpl::ParseSqueeze;
734 m_ParserFunctions[tflite::BuiltinOperator_STRIDED_SLICE] = &TfLiteParserImpl::ParseStridedSlice;
735 m_ParserFunctions[tflite::BuiltinOperator_SUB] = &TfLiteParserImpl::ParseSub;
736 m_ParserFunctions[tflite::BuiltinOperator_SUM] = &TfLiteParserImpl::ParseSum;
737 m_ParserFunctions[tflite::BuiltinOperator_TANH] = &TfLiteParserImpl::ParseTanH;
738 m_ParserFunctions[tflite::BuiltinOperator_TRANSPOSE] = &TfLiteParserImpl::ParseTranspose;
739 m_ParserFunctions[tflite::BuiltinOperator_TRANSPOSE_CONV] = &TfLiteParserImpl::ParseTransposeConv;
740 m_ParserFunctions[tflite::BuiltinOperator_UNPACK] = &TfLiteParserImpl::ParseUnpack;
743 m_CustomParserFunctions[
"TFLite_Detection_PostProcess"] = &TfLiteParserImpl::ParseDetectionPostProcess;
746 void TfLiteParserImpl::ResetParser()
750 m_SubgraphConnections.clear();
757 return CreateNetworkFromModel();
764 return CreateNetworkFromModel();
771 m_Model = std::move(model);
773 return CreateNetworkFromModel();
776 INetworkPtr TfLiteParserImpl::CreateNetworkFromModel()
781 if (m_Options && m_Options.value().m_InferAndValidate)
785 {
"InferAndValidate",
true }
788 networkOptions.push_back(shapeInferenceMethodOption);
791 m_Network = INetwork::Create(networkOptions);
794 if (m_Model->subgraphs.size() != 1)
797 fmt::format(
"Current TfLite parser only supports 1 subgraph. Current one has: {} {}",
798 m_Model->subgraphs.size(),
802 size_t subgraphIndex = 0;
803 size_t operatorIndex = 0;
806 for (
SubgraphPtr const& subgraph : m_Model->subgraphs)
808 m_SubgraphConnections.emplace_back(subgraph->tensors.size());
811 auto const& opCodePtr = m_Model->operator_codes[op->opcode_index];
814 #if defined(ARMNN_POST_TFLITE_2_3) 815 auto builtinCode = std::max(opCodePtr->builtin_code,
816 static_cast<tflite::BuiltinOperator>(opCodePtr->deprecated_builtin_code));
818 auto builtinCode = opCodePtr->builtin_code;
821 if (builtinCode > tflite::BuiltinOperator_MAX)
823 throw ParseException(fmt::format(
"Operator code {} is out of range 0-{}. " 824 "subgraph:{} operator idx:{}. {}",
825 builtinCode, tflite::BuiltinOperator_MAX, subgraphIndex,
830 auto& parserFunction = m_ParserFunctions[builtinCode];
831 (this->*parserFunction)(subgraphIndex, operatorIndex);
835 SetupInputLayers(subgraphIndex);
836 SetupOutputLayers(subgraphIndex);
837 SetupConstantLayers(subgraphIndex);
845 std::stringstream errorString;
846 errorString <<
"Failed to parse operator #" << operatorIndex <<
" within subgraph #" 847 << subgraphIndex <<
" error: " << e.
what();
849 std::stringstream errors;
850 errors << errorString.str() <<
"\n";
855 for (subgraphIndex = 0; subgraphIndex < m_SubgraphConnections.size(); ++subgraphIndex)
857 for (
size_t tensorIndex = 0; tensorIndex < m_SubgraphConnections[subgraphIndex].size(); ++tensorIndex)
859 if (m_SubgraphConnections[subgraphIndex][tensorIndex].outputSlot !=
nullptr)
861 for (
size_t inputSlotIdx = 0;
862 inputSlotIdx < m_SubgraphConnections[subgraphIndex][tensorIndex].inputSlots.size();
865 m_SubgraphConnections[subgraphIndex][tensorIndex].outputSlot->Connect(
866 *(m_SubgraphConnections[subgraphIndex][tensorIndex].inputSlots[inputSlotIdx]));
872 return std::move(m_Network);
875 void TfLiteParserImpl::RegisterProducerOfTensor(
size_t subgraphIndex,
880 ARMNN_ASSERT(m_SubgraphConnections.size() > subgraphIndex);
881 ARMNN_ASSERT(m_SubgraphConnections[subgraphIndex].size() > tensorIndex);
883 TensorSlots & tensorSlots = m_SubgraphConnections[subgraphIndex][tensorIndex];
886 if (tensorSlots.outputSlot !=
nullptr)
888 throw ParseException(fmt::format(
"Another layer has already registered itself as the producer of " 889 "subgraph:{} tensor:{} {}",
895 tensorSlots.outputSlot = slot;
898 void TfLiteParserImpl::RegisterConsumerOfTensor(
size_t subgraphIndex,
903 ARMNN_ASSERT(m_SubgraphConnections.size() > subgraphIndex);
904 ARMNN_ASSERT(m_SubgraphConnections[subgraphIndex].size() > tensorIndex);
906 TensorSlots& tensorSlots = m_SubgraphConnections[subgraphIndex][tensorIndex];
907 tensorSlots.inputSlots.push_back(slot);
910 void TfLiteParserImpl::ParseCustomOperator(
size_t subgraphIndex,
size_t operatorIndex)
912 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
915 auto customParserFunction = &TfLiteParserImpl::ParseUnsupportedOperator;
918 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
919 const auto& customCode = m_Model->operator_codes[operatorPtr->opcode_index]->custom_code;
922 auto iterator = m_CustomParserFunctions.find(customCode);
923 if (iterator != m_CustomParserFunctions.end())
925 customParserFunction = iterator->second;
929 (this->*customParserFunction)(subgraphIndex, operatorIndex);
932 void TfLiteParserImpl::ParseUnsupportedOperator(
size_t subgraphIndex,
size_t operatorIndex)
934 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
936 const auto & operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
938 auto opcodeIndex = operatorPtr->opcode_index;
941 #if defined(ARMNN_POST_TFLITE_2_3) 942 auto opcode = std::max(m_Model->operator_codes[opcodeIndex]->builtin_code,
943 static_cast<tflite::BuiltinOperator>(m_Model->operator_codes[opcodeIndex]->deprecated_builtin_code));
945 auto opcode = m_Model->operator_codes[opcodeIndex]->builtin_code;
948 if (!m_Options || !m_Options.value().m_StandInLayerForUnsupported)
952 fmt::format(
"Operator not supported. " 953 "subgraph:{} operator:{} " 954 "opcode_index:{} opcode:{} / {} {}",
959 tflite::EnumNameBuiltinOperator(opcode),
963 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
964 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
970 auto layerName = fmt::format(
"StandIn:{}:{}:{}", subgraphIndex, operatorIndex, opcode);
973 IConnectableLayer* layer = m_Network->AddStandInLayer(descriptor, layerName.c_str());
976 for (
unsigned int i = 0u; i < numOutputs; ++i)
981 auto inputTensorIds = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
982 auto outputTensorIds = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
984 RegisterInputSlots(subgraphIndex, operatorIndex, layer, inputTensorIds);
985 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, outputTensorIds);
988 void TfLiteParserImpl::ParseCast(
size_t subgraphIndex,
size_t operatorIndex)
990 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
992 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
994 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
997 auto layerName = fmt::format(
"Cast:{}:{}", subgraphIndex, operatorIndex);
1005 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1006 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
1008 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1009 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, outputTensorIndexes);
1012 void TfLiteParserImpl::ParseConv2D(
size_t subgraphIndex,
size_t operatorIndex)
1014 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1016 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
1017 const auto* options = operatorPtr->builtin_options.AsConv2DOptions();
1029 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1032 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1039 unsigned int inputHeight = inputTensorInfo.GetShape()[1];
1040 unsigned int inputWidth = inputTensorInfo.GetShape()[2];
1044 unsigned int filterHeight = filterTensorInfo.
GetShape()[1];
1045 unsigned int filterWidth = filterTensorInfo.
GetShape()[2];
1047 CalcPadding(inputHeight, filterHeight, desc.
m_StrideY,
1049 CalcPadding(inputWidth, filterWidth, desc.
m_StrideX,
1052 auto filterTensorAndData = CreateConstTensorNonPermuted(inputs[1], filterTensorInfo);
1055 auto layerName = fmt::format(
"Conv2D:{}:{}", subgraphIndex, operatorIndex);
1057 if (inputs.size() == 3)
1061 auto biasTensorAndData = CreateConstTensorNonPermuted(inputs[2], biasTensorInfo);
1062 layer = m_Network->AddConvolution2dLayer(desc,
1063 filterTensorAndData,
1069 layer = m_Network->AddConvolution2dLayer(desc,
1070 filterTensorAndData,
1082 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1083 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
1085 layer = AddFusedActivationLayer(layer, 0, options->fused_activation_function);
1087 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1088 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1092 #if defined(ARMNN_POST_TFLITE_2_3) 1093 void TfLiteParserImpl::ParseConv3D(
size_t subgraphIndex,
size_t operatorIndex)
1095 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1097 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
1098 const auto* options = operatorPtr->builtin_options.AsConv3DOptions();
1112 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1115 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1122 unsigned int inputDepth = inputTensorInfo.GetShape()[1];
1123 unsigned int inputHeight = inputTensorInfo.GetShape()[2];
1124 unsigned int inputWidth = inputTensorInfo.GetShape()[3];
1127 unsigned int filterDepth = filterTensorInfo.
GetShape()[0];
1128 unsigned int filterHeight = filterTensorInfo.
GetShape()[1];
1129 unsigned int filterWidth = filterTensorInfo.
GetShape()[2];
1131 CalcPadding(inputDepth, filterDepth, desc.
m_StrideZ,
1133 CalcPadding(inputHeight, filterHeight, desc.
m_StrideY,
1135 CalcPadding(inputWidth, filterWidth, desc.
m_StrideX,
1138 auto filterTensorAndData = CreateConstTensorNonPermuted(inputs[1], filterTensorInfo);
1140 auto layerName = fmt::format(
"Conv3D:{}:{}", subgraphIndex, operatorIndex);
1142 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1145 std::vector<unsigned int> tensorIndexesToRegister = {inputTensorIndexes[0], inputTensorIndexes[1]};
1147 if (inputs.size() == 3)
1152 tensorIndexesToRegister.emplace_back(inputTensorIndexes[2]);
1162 RegisterInputSlots(subgraphIndex, operatorIndex, layer, tensorIndexesToRegister);
1164 layer = AddFusedActivationLayer(layer, 0, options->fused_activation_function);
1166 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1167 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1171 void TfLiteParserImpl::ParseDepthwiseConv2D(
size_t subgraphIndex,
size_t operatorIndex)
1173 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1175 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
1176 const auto* options = operatorPtr->builtin_options.AsDepthwiseConv2DOptions();
1187 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1189 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1198 unsigned int inputHeight = inputTensorInfo.
GetShape()[1];
1199 unsigned int inputWidth = inputTensorInfo.
GetShape()[2];
1202 unsigned int filterHeight = filterTensorInfo.
GetShape()[1];
1203 unsigned int filterWidth = filterTensorInfo.
GetShape()[2];
1205 CalcPadding(inputHeight, filterHeight, desc.
m_StrideY,
1207 CalcPadding(inputWidth, filterWidth, desc.
m_StrideX,
1211 auto filterTensor = CreateConstTensorNonPermuted(inputs[1], filterTensorInfo);
1213 auto layerName = fmt::format(
"DepthwiseConv2D:{}:{}", subgraphIndex, operatorIndex);
1215 if (inputs.size() == 3)
1219 auto biasTensorAndData = CreateConstTensorNonPermuted(inputs[2], biasTensorInfo);
1220 layer = m_Network->AddDepthwiseConvolution2dLayer(desc,
1227 layer = m_Network->AddDepthwiseConvolution2dLayer(desc,
1239 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1240 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
1242 layer = AddFusedActivationLayer(layer, 0, options->fused_activation_function);
1244 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1245 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1248 void TfLiteParserImpl::ParseDequantize(
size_t subgraphIndex,
size_t operatorIndex)
1250 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1252 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1255 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1258 auto layerName = fmt::format(
"Dequantize:{}:{}", subgraphIndex, operatorIndex);
1266 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1267 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
1269 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1270 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, outputTensorIndexes);
1273 void TfLiteParserImpl::ParseExpandDims(
size_t subgraphIndex,
size_t operatorIndex)
1275 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1277 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1280 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1283 auto layerName = fmt::format(
"ExpandDims:{}:{}", subgraphIndex, operatorIndex);
1288 CheckMatchingQuantization(inputTensorInfo, outputTensorInfo, layerName,
"Input 0",
"Output 0");
1298 int32_t axis = inputs[1]->shape[0];
1302 if (axis > inputDimSize || axis < 0 - (inputDimSize + 1))
1304 throw ParseException(
"axis must be in range [0 - (inputDimSize + 1), inputDimSize] inclusive");
1309 axis = inputDimSize + axis + 1;
1312 std::vector<unsigned int> shape(static_cast<unsigned int>(inputDimSize) + 1);
1313 unsigned int inputShapeIndex = 0;
1314 for (
unsigned int i = 0; i < static_cast<unsigned int>(inputDimSize + 1); ++i)
1316 if (i == static_cast<unsigned int>(axis))
1322 shape[i] = inputTensorInfo.
GetShape()[inputShapeIndex];
1330 IConnectableLayer* layer = m_Network->AddReshapeLayer(reshapeDesc, layerName.c_str());
1332 layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
1334 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1335 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
1337 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1338 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1341 void TfLiteParserImpl::ParseTranspose(
size_t subgraphIndex,
size_t operatorIndex)
1343 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1345 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1348 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1351 auto layerName = fmt::format(
"Transpose:{}:{}", subgraphIndex, operatorIndex);
1354 if (inputs.size() == 2)
1359 std::vector<unsigned int> permuteShape(numPermVecElements);
1360 ::memcpy(permuteShape.data(), permuteBufferPtr->data.data(), permuteTensorInfo.
GetNumBytes());
1368 CheckMatchingQuantization(inputTensorInfo, outputTensorInfo, layerName,
"Input 0",
"Output 0");
1370 IConnectableLayer* layer = m_Network->AddTransposeLayer(desc, layerName.c_str());
1374 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1375 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
1377 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1378 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1381 void TfLiteParserImpl::ParseTransposeConv(
size_t subgraphIndex,
size_t operatorIndex)
1383 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1385 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
1386 const auto* options = operatorPtr->builtin_options.AsTransposeConvOptions();
1394 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1395 if (inputs.size() == 4)
1404 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1411 if (tensorInfo.
GetDataType() == DataType::Signed32)
1413 ::memcpy(output_shape.data(),
GetBuffer(m_Model, inputs[0]->buffer)->data.data(), tensorInfo.
GetNumBytes());
1415 if (tensorInfo.
GetDataType() == DataType::QAsymmU8)
1419 output_shape[i] =
GetBuffer(m_Model, inputs[0]->buffer)->data.data()[i];
1423 for (
int dimension : output_shape)
1425 desc.
m_OutputShape.push_back(static_cast<unsigned int>(dimension));
1433 const unsigned int inputHeight = inputTensorInfo.
GetShape()[1];
1434 const unsigned int inputWidth = inputTensorInfo.
GetShape()[2];
1436 const unsigned int filterHeight = filterTensorInfo.
GetShape()[1];
1437 const unsigned int filterWidth = filterTensorInfo.
GetShape()[2];
1439 CalcPadding(inputHeight,
1447 CalcPadding(inputWidth,
1455 auto filterTensorAndData = CreateConstTensorNonPermuted(inputs[1], filterTensorInfo);
1458 auto layerName = fmt::format(
"TransposeConv:{}:{}", subgraphIndex, operatorIndex);
1463 auto biasConstTensor = CreateConstTensorNonPermuted(inputs[3], biasTensorInfo);
1464 layer = m_Network->AddTransposeConvolution2dLayer(desc,
1465 filterTensorAndData,
1471 layer = m_Network->AddTransposeConvolution2dLayer(desc,
1472 filterTensorAndData,
1483 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1484 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[2]});
1486 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1487 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1490 void TfLiteParserImpl::ParseAveragePool2D(
size_t subgraphIndex,
size_t operatorIndex)
1492 ParsePool(subgraphIndex, operatorIndex, PoolingAlgorithm::Average);
1495 void TfLiteParserImpl::ParseBatchToSpaceND(
size_t subgraphIndex,
size_t operatorIndex)
1497 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1499 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1502 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1511 std::vector<unsigned int> blockShape(blockShapeTensorInfo.GetNumElements());
1512 ::memcpy(blockShape.data(), blockShapeBufferPtr->data.data(), blockShapeTensorInfo.GetNumBytes());
1514 std::vector<unsigned int> cropsVector(cropsTensorInfo.
GetNumElements());
1515 ::memcpy(cropsVector.data(), cropsBufferPtr->data.data(), cropsTensorInfo.
GetNumBytes());
1518 std::vector<std::pair<unsigned int, unsigned int>> crops;
1519 for (
unsigned int i = 0; i < cropsTensorInfo.
GetNumElements() / step; ++i)
1521 crops.emplace_back(cropsVector[i * step], cropsVector[i * step + 1]);
1529 auto layerName = fmt::format(
"BatchToSpaceND:{}:{}", subgraphIndex, operatorIndex);
1533 CheckMatchingQuantization(inputTensorInfo, outputTensorInfo, layerName,
"Input 0",
"Output 0");
1535 IConnectableLayer* layer = m_Network->AddBatchToSpaceNdLayer(desc, layerName.c_str());
1539 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1540 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
1542 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1543 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1546 void TfLiteParserImpl::ParseL2Normalization(
size_t subgraphIndex,
size_t operatorIndex)
1548 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1550 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1553 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1558 auto layerName = fmt::format(
"L2Normalization:{}:{}", subgraphIndex, operatorIndex);
1559 IConnectableLayer* layer = m_Network->AddL2NormalizationLayer(desc, layerName.c_str());
1566 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1567 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
1569 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1570 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1573 void TfLiteParserImpl::ParseMaxPool2D(
size_t subgraphIndex,
size_t operatorIndex)
1575 ParsePool(subgraphIndex, operatorIndex, PoolingAlgorithm::Max);
1578 void TfLiteParserImpl::ParseMaximum(
size_t subgraphIndex,
size_t operatorIndex)
1580 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1582 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1585 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1588 auto layerName = fmt::format(
"Maximum:{}:{}", subgraphIndex, operatorIndex);
1592 CheckMatchingQuantization(inputTensorInfo, input1TensorInfo, layerName,
"Input 0",
"Input 1");
1595 CheckMatchingQuantization(inputTensorInfo, outputTensorInfo, layerName,
"Input 0",
"Output 0");
1601 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1602 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0], inputTensorIndexes[1]});
1604 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1605 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1608 void TfLiteParserImpl::ParseMinimum(
size_t subgraphIndex,
size_t operatorIndex)
1610 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1612 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1615 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1618 auto layerName = fmt::format(
"Minimum:{}:{}", subgraphIndex, operatorIndex);
1622 CheckMatchingQuantization(inputTensorInfo, input1TensorInfo, layerName,
"Input 0",
"Input 1");
1625 CheckMatchingQuantization(inputTensorInfo, outputTensorInfo, layerName,
"Input 0",
"Output 0");
1631 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1632 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0], inputTensorIndexes[1]});
1634 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1635 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1638 void TfLiteParserImpl::ParsePool(
size_t subgraphIndex,
1639 size_t operatorIndex,
1642 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1644 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
1645 const auto* options = operatorPtr->builtin_options.AsPool2DOptions();
1649 std::string layerName;
1653 case PoolingAlgorithm::Average:
1655 fmt::format(
"AveragePool2D:{}:{}", subgraphIndex, operatorIndex);
1657 case PoolingAlgorithm::Max:
1659 fmt::format(
"MaxPool2D:{}:{}", subgraphIndex, operatorIndex);
1676 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1681 unsigned int inputHeight = inputTensorInfo.GetShape()[1];
1682 unsigned int inputWidth = inputTensorInfo.GetShape()[2];
1689 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1693 CheckMatchingQuantization(inputTensorInfo, outputTensorInfo, layerName,
"Input 0",
"Output 0");
1695 IConnectableLayer* layer = m_Network->AddPooling2dLayer(desc, layerName.c_str());
1701 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1702 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
1704 layer = AddFusedActivationLayer(layer, 0, options->fused_activation_function);
1706 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1707 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1710 void TfLiteParserImpl::ParseSlice(
size_t subgraphIndex,
size_t operatorIndex)
1712 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1714 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1716 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1725 std::vector<unsigned int> begin(beginTensorInfo.
GetNumElements());
1726 ::memcpy(begin.data(), beginBufferPtr->data.data(), beginTensorInfo.
GetNumBytes());
1732 std::vector<int> signedSize(sizeTensorInfo.GetNumElements());
1733 ::memcpy(signedSize.data(), sizeBufferPtr->data.data(), sizeTensorInfo.GetNumBytes());
1734 std::vector<unsigned int> size(sizeTensorInfo.GetNumElements());
1737 for (
unsigned int i = 0; i < signedSize.size(); ++i)
1739 int signedValue = signedSize[i];
1741 if (signedValue < -1 || signedValue > static_cast<int>(inputTensorInfo.GetShape()[i] - begin[i]))
1743 throw ParseException(fmt::format(
"Invalid value for size {} size must be in range " 1744 "[-1, inputDimSize - begin] [-1, {}] inclusive {}",
1746 inputTensorInfo.GetShape()[i] - begin[i],
1750 if (signedValue == -1)
1752 size[i] = inputTensorInfo.GetShape()[i] - begin[i];
1756 size[i] =
static_cast<unsigned int>(signedValue);
1762 auto layerName = fmt::format(
"Slice:{}:{}", subgraphIndex, operatorIndex);
1765 CheckMatchingQuantization(inputTensorInfo, outputTensorInfo, layerName,
"Input 0",
"Output 0");
1767 IConnectableLayer*
const layer = m_Network->AddSliceLayer(desc, layerName.c_str());
1772 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1773 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
1776 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1777 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1780 void TfLiteParserImpl::ParseSoftmax(
size_t subgraphIndex,
size_t operatorIndex)
1782 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1783 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
1784 const auto* options = operatorPtr->builtin_options.AsSoftmaxOptions();
1787 desc.
m_Beta = options->beta;
1789 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1791 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1794 auto layerName = fmt::format(
"Softmax:{}:{}", subgraphIndex, operatorIndex);
1795 IConnectableLayer*
const layer = m_Network->AddSoftmaxLayer(desc, layerName.c_str());
1802 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1803 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
1806 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1807 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1810 void TfLiteParserImpl::ParseSpaceToBatchND(
size_t subgraphIndex,
size_t operatorIndex)
1812 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1814 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1817 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1826 std::vector<unsigned int> blockShape(blockShapeTensorInfo.GetNumElements());
1827 ::memcpy(blockShape.data(), blockShapeBufferPtr->data.data(), blockShapeTensorInfo.GetNumBytes());
1829 std::vector<unsigned int> padListVector(padListTensorInfo.
GetNumElements());
1830 ::memcpy(padListVector.data(), padListBufferPtr->data.data(), padListTensorInfo.
GetNumBytes());
1833 std::vector<std::pair<unsigned int, unsigned int>> padList;
1834 for (
unsigned int i = 0; i < padListTensorInfo.
GetNumElements() / step; ++i)
1836 padList.emplace_back(padListVector[i * step], padListVector[i * step + 1]);
1844 auto layerName = fmt::format(
"SpaceToBatchND:{}:{}", subgraphIndex, operatorIndex);
1848 CheckMatchingQuantization(inputTensorInfo, outputTensorInfo, layerName,
"Input 0",
"Output 0");
1850 IConnectableLayer* layer = m_Network->AddSpaceToBatchNdLayer(desc, layerName.c_str());
1854 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1855 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
1857 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1858 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1865 static const uint32_t dimensionSequence[] = { 0, 1, 2, 3 };
1869 std::stringstream ss;
1870 ss <<
"Input tensor has unexpected number of dimensions:" << inputTensorInfo.
GetNumDimensions()
1871 <<
" shape:" << inputTensorInfo.
GetShape() <<
" " 1876 if (squeezeDims.empty())
1878 squeezeDims.assign(dimensionSequence,
1882 std::vector<uint32_t> outputDims;
1885 bool skipSqueeze = (std::find(squeezeDims.begin(), squeezeDims.end(), i) == squeezeDims.end());
1886 auto currentDimension = inputTensorInfo.
GetShape()[i];
1887 if (skipSqueeze || currentDimension != 1)
1889 outputDims.push_back(currentDimension);
1893 if (outputDims.size() > 4)
1895 std::stringstream ss;
1896 ss <<
"Output tensor has unexpected number of dimensions:" << inputTensorInfo.
GetNumDimensions()
1897 <<
" shape:" << inputTensorInfo.
GetShape() <<
" " 1909 return outTensorInfo;
1912 void TfLiteParserImpl::ParseShape(
size_t subgraphIndex,
size_t operatorIndex)
1914 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1916 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1918 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1921 auto layerName = fmt::format(
"Shape:{}:{}", subgraphIndex, operatorIndex);
1936 "Output tensor data type is not supported. (Supported types: Signed32 & Signed64) {}",
1940 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1941 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
1943 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1944 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, outputTensorIndexes);
1947 void TfLiteParserImpl::ParseSqueeze(
size_t subgraphIndex,
size_t operatorIndex)
1949 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1951 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1954 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1957 const auto & operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
1958 const auto * options = operatorPtr->builtin_options.AsSqueezeOptions();
1959 auto layerName = fmt::format(
"Squeeze:{}:{}", subgraphIndex, operatorIndex);
1963 std::vector<uint32_t> squeezeDim;
1966 if (options->squeeze_dims.size() == 1 && options->squeeze_dims[0] < 0)
1969 squeezeDim.push_back(static_cast<uint32_t>(dim));
1973 squeezeDim = AsUnsignedVector(options->squeeze_dims);
1978 CheckMatchingQuantization(inputTensorInfo, outputTensorInfo, layerName,
"Input 0",
"Output 0");
1983 IConnectableLayer* layer = m_Network->AddReshapeLayer(reshapeDesc, layerName.c_str());
1987 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1988 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
1990 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1991 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1994 void TfLiteParserImpl::ParseStridedSlice(
size_t subgraphIndex,
size_t operatorIndex)
1996 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1998 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2001 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2004 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
2005 const auto* options = operatorPtr->builtin_options.AsStridedSliceOptions();
2019 ::memcpy(begin.data(), beginBufferPtr->data.data(), beginTensorInfo.
GetNumBytes());
2024 std::vector<int> end(endTensorInfo.GetNumElements());
2025 ::memcpy(end.data(), endBufferPtr->data.data(), endTensorInfo.GetNumBytes());
2030 std::vector<int> stride(strideTensorInfo.GetNumElements());
2031 ::memcpy(stride.data(), strideBufferPtr->data.data(), strideTensorInfo.GetNumBytes());
2037 auto layerName = fmt::format(
"StridedSlice:{}:{}", subgraphIndex, operatorIndex);
2038 IConnectableLayer* layer = m_Network->AddStridedSliceLayer(desc, layerName.c_str());
2044 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2045 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
2047 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2048 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
2051 void TfLiteParserImpl::ParseSub(
size_t subgraphIndex,
size_t operatorIndex)
2053 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2055 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
2056 const auto* options = operatorPtr->builtin_options.AsSubOptions();
2058 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2061 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2067 auto layerName = fmt::format(
"Sub:{}:{}", subgraphIndex, operatorIndex);
2074 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2075 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0], inputTensorIndexes[1]});
2077 layer = AddFusedActivationLayer(layer, 0, options->fused_activation_function);
2079 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2080 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
2083 void TfLiteParserImpl::ParseDiv(
size_t subgraphIndex,
size_t operatorIndex)
2085 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2087 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
2088 const auto* options = operatorPtr->builtin_options.AsDivOptions();
2090 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2093 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2099 auto layerName = fmt::format(
"Div:{}:{}", subgraphIndex, operatorIndex);
2106 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2107 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0], inputTensorIndexes[1]});
2108 layer = AddFusedActivationLayer(layer, 0, options->fused_activation_function);
2110 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2111 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
2114 void TfLiteParserImpl::ParseAdd(
size_t subgraphIndex,
size_t operatorIndex)
2116 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2118 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
2119 const auto* options = operatorPtr->builtin_options.AsAddOptions();
2121 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2124 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2130 auto layerName = fmt::format(
"Add:{}:{}", subgraphIndex, operatorIndex);
2137 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2138 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0], inputTensorIndexes[1]});
2139 layer = AddFusedActivationLayer(layer, 0, options->fused_activation_function);
2141 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2142 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
2145 void TfLiteParserImpl::ParseMul(
size_t subgraphIndex,
size_t operatorIndex)
2147 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2149 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
2150 const auto* options = operatorPtr->builtin_options.AsMulOptions();
2152 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2155 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2161 auto layerName = fmt::format(
"Mul:{}:{}", subgraphIndex, operatorIndex);
2162 IConnectableLayer* layer = m_Network->AddMultiplicationLayer(layerName.c_str());
2168 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2169 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0], inputTensorIndexes[1]});
2170 layer = AddFusedActivationLayer(layer, 0, options->fused_activation_function);
2172 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2173 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
2176 void TfLiteParserImpl::ParseMean(
size_t subgraphIndex,
size_t operatorIndex)
2178 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2180 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2182 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2189 std::vector<unsigned int> axis(dimTensorInfo.GetNumElements());
2190 ::memcpy(axis.data(), bufferPtr->data.data(), dimTensorInfo.GetNumBytes());
2200 auto layerName = fmt::format(
"Mean:{}:{}", subgraphIndex, operatorIndex);
2206 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2207 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
2209 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2210 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
2213 void TfLiteParserImpl::ParsePad(
size_t subgraphIndex,
size_t operatorIndex)
2215 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2225 std::vector<unsigned int> padBuffer = GetUIntBuffer(padTensorInfo, m_Model, inputs[1]->buffer);
2229 auto opcode = GetOpCode(m_Model, subgraphIndex, operatorIndex);
2231 if (opcode == tflite::BuiltinOperator_PAD)
2235 if (inputTensorInfo.IsQuantized())
2237 desc.
m_PadValue =
static_cast<float>(inputTensorInfo.GetQuantizationOffset());
2240 else if (opcode == tflite::BuiltinOperator_PADV2)
2246 if (padValueTensorInfo.GetNumElements() != 1)
2253 if (padValueBufferPtr->data.size() > 0)
2255 switch (padValueTensorInfo.GetDataType())
2259 std::vector<float> padValueBuffer(padValueTensorInfo.GetNumElements());
2260 ::memcpy(padValueBuffer.data(), padValueBufferPtr->data.data(), padValueBufferPtr->data.size());
2266 std::vector<uint8_t> padValueBuffer(padValueTensorInfo.GetNumElements());
2267 ::memcpy(padValueBuffer.data(), padValueBufferPtr->data.data(), padValueBufferPtr->data.size());
2268 desc.
m_PadValue = armnn::Dequantize<uint8_t>(padValueBuffer[0],
2269 padValueTensorInfo.GetQuantizationScale(),
2270 padValueTensorInfo.GetQuantizationOffset());
2276 std::vector<int8_t> padValueBuffer(padValueTensorInfo.GetNumElements());
2277 ::memcpy(padValueBuffer.data(), padValueBufferPtr->data.data(), padValueBufferPtr->data.size());
2278 desc.
m_PadValue = armnn::Dequantize<int8_t>(padValueBuffer[0],
2279 padValueTensorInfo.GetQuantizationScale(),
2280 padValueTensorInfo.GetQuantizationOffset());
2286 else if (inputTensorInfo.IsQuantized())
2288 desc.
m_PadValue =
static_cast<float>(inputTensorInfo.GetQuantizationOffset());
2292 for (
unsigned int i = 0; i < padTensorInfo.
GetNumElements() / step; ++i)
2294 desc.
m_PadList.emplace_back(padBuffer[i * step], padBuffer[i * step + 1]);
2297 auto layerName = (opcode == tflite::BuiltinOperator_PAD) ? fmt::format(
"Pad:{}:{}", subgraphIndex, operatorIndex)
2298 : fmt::format(
"PadV2:{}:{}", subgraphIndex, operatorIndex);
2305 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2306 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
2308 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2309 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
2312 void TfLiteParserImpl::ParseMirrorPad(
size_t subgraphIndex,
size_t operatorIndex)
2314 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2327 std::vector<unsigned int> padBuffer(padTensorInfo.
GetNumElements());
2328 ::memcpy(padBuffer.data(), bufferPtr->data.data(), padTensorInfo.
GetNumBytes());
2332 for (
unsigned int i = 0; i < padTensorInfo.
GetNumElements() / step; ++i)
2334 desc.
m_PadList.emplace_back(padBuffer[i * step], padBuffer[i * step + 1]);
2337 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
2338 const auto* options = operatorPtr->builtin_options.AsMirrorPadOptions();
2340 if (options->mode == tflite::MirrorPadMode_REFLECT)
2344 else if (options->mode == tflite::MirrorPadMode_SYMMETRIC)
2355 auto inputShape = inputTensorInfo.GetShape();
2358 const unsigned int isReflect =
static_cast<unsigned int>(desc.
m_PaddingMode == PaddingMode::Reflect);
2359 for(
unsigned int i = 0; i < padList.size(); ++i)
2361 if(padList.at(i).first > (inputShape[i] - isReflect) ||
2362 padList.at(i).second > (inputShape[i] - isReflect))
2365 "equal (Symmetric) to the dimension size.");
2369 auto layerName = fmt::format(
"MirrorPad:{}:{}", subgraphIndex, operatorIndex);
2376 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2377 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
2379 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2380 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
2383 void TfLiteParserImpl::ParsePrelu(
size_t subgraphIndex,
size_t operatorIndex)
2385 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2387 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2390 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2393 auto layerName = fmt::format(
"Prelu:{}:{}", subgraphIndex, operatorIndex);
2398 CheckMatchingQuantization(inputTensorInfo, outputTensorInfo, layerName,
"Input 0",
"Output 0");
2404 if (IsConstTensor(inputs[1]))
2406 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2408 RegisterConsumerOfTensor(subgraphIndex, inputTensorIndexes[0], slot);
2410 auto alphaTensorAndData = CreateConstTensorNonPermuted(inputs[1], alphaTensorInfo);
2411 std::string constLayerName = fmt::format(
"Constant:{}", inputs[1]->name);
2413 m_Network->AddConstantLayer(alphaTensorAndData, constLayerName.c_str());
2418 RegisterOutputSlots(subgraphIndex,
2419 VIRTUAL_OPERATOR_ID,
2421 { inputTensorIndexes[1] });
2425 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2426 RegisterInputSlots(subgraphIndex, operatorIndex, layer, inputTensorIndexes);
2429 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2430 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, outputTensorIndexes);
2433 void TfLiteParserImpl::ParseQuantize(
size_t subgraphIndex,
size_t operatorIndex)
2435 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2437 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2440 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2443 auto layerName = fmt::format(
"Quantize:{}:{}", subgraphIndex, operatorIndex);
2451 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2452 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
2454 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2455 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, outputTensorIndexes);
2458 void TfLiteParserImpl::ParseRelu(
size_t subgraphIndex,
size_t operatorIndex)
2460 ParseActivation(subgraphIndex,operatorIndex, ActivationFunction::ReLu);
2463 void TfLiteParserImpl::ParseRelu6(
size_t subgraphIndex,
size_t operatorIndex)
2465 ParseActivation(subgraphIndex,operatorIndex, ActivationFunction::BoundedReLu);
2468 void TfLiteParserImpl::ParseLeakyRelu(
size_t subgraphIndex,
size_t operatorIndex)
2470 ParseActivation(subgraphIndex, operatorIndex, ActivationFunction::LeakyReLu);
2473 void TfLiteParserImpl::ParseLogistic(
size_t subgraphIndex,
size_t operatorIndex)
2475 ParseActivation(subgraphIndex,operatorIndex,ActivationFunction::Sigmoid);
2478 void TfLiteParserImpl::ParseTanH(
size_t subgraphIndex,
size_t operatorIndex)
2480 ParseActivation(subgraphIndex,operatorIndex,ActivationFunction::TanH);
2483 void TfLiteParserImpl::ParseElu(
size_t subgraphIndex,
size_t operatorIndex)
2485 ParseActivation(subgraphIndex, operatorIndex, ActivationFunction::Elu);
2488 void TfLiteParserImpl::ParseHardSwish(
size_t subgraphIndex,
size_t operatorIndex)
2490 ParseActivation(subgraphIndex, operatorIndex, ActivationFunction::HardSwish);
2493 void TfLiteParserImpl::ParseActivation(
size_t subgraphIndex,
size_t operatorIndex,
ActivationFunction activationType)
2495 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2496 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
2499 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2502 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2505 auto layerName = fmt::format(
"Activation:");
2509 switch (activationType)
2511 case ActivationFunction::ReLu:
2513 layerName += fmt::format(
"RELU:{}:{}", subgraphIndex, operatorIndex);
2516 case ActivationFunction::BoundedReLu:
2518 layerName += fmt::format(
"RELU6:{}:{}", subgraphIndex, operatorIndex);
2519 activationDesc.
m_A = 6.0f;
2520 activationDesc.
m_B = 0.0f;
2523 case ActivationFunction::Sigmoid:
2525 layerName += fmt::format(
"SIGMOID:{}:{}", subgraphIndex, operatorIndex);
2528 case ActivationFunction::TanH:
2530 layerName += fmt::format(
"TANH:{}:{}", subgraphIndex, operatorIndex);
2531 activationDesc.
m_A = 1.0f;
2532 activationDesc.
m_B = 1.0f;
2535 case ActivationFunction::LeakyReLu:
2537 layerName += fmt::format(
"LEAKYRELU:{}:{}", subgraphIndex, operatorIndex);
2538 const auto* options = operatorPtr->builtin_options.AsLeakyReluOptions();
2539 activationDesc.
m_A = options->alpha;
2542 case ActivationFunction::Elu:
2544 layerName += fmt::format(
"ELU:{}:{}", subgraphIndex, operatorIndex);
2545 activationDesc.
m_A = 1.0f;
2548 case ActivationFunction::HardSwish:
2550 layerName += fmt::format(
"HARDSWISH:{}:{}", subgraphIndex, operatorIndex);
2556 fmt::format(
"Unexpected ActivationFunction[{}] when creating layerName {} ",
2561 IConnectableLayer*
const layer = m_Network->AddActivationLayer(activationDesc, layerName.c_str());
2568 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2569 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
2572 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2573 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
2576 const std::vector<int32_t>& targetDimsIn)
2578 std::vector<unsigned int> outputDims(targetDimsIn.begin(), targetDimsIn.end());
2579 const auto stretchDim = std::find(targetDimsIn.begin(), targetDimsIn.end(), -1);
2581 if (stretchDim != targetDimsIn.end())
2583 if (std::find(std::next(stretchDim), targetDimsIn.end(), -1) != targetDimsIn.end())
2586 fmt::format(
"At most one component of shape can be -1 {}",
CHECK_LOCATION().AsString()));
2589 auto targetNumElements =
2591 std::accumulate(targetDimsIn.begin(), targetDimsIn.end(), -1, std::multiplies<int32_t>()));
2593 auto stretchIndex =
static_cast<size_t>(std::distance(targetDimsIn.begin(), stretchDim));
2594 outputDims[stretchIndex] = inputTensorInfo.
GetNumElements() / targetNumElements;
2605 void TfLiteParserImpl::ParseReshape(
size_t subgraphIndex,
size_t operatorIndex)
2607 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2609 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2611 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2614 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
2615 const auto* options = operatorPtr->builtin_options.AsReshapeOptions();
2616 auto layerName = fmt::format(
"Reshape:{}:{}", subgraphIndex, operatorIndex);
2620 CheckMatchingQuantization(inputTensorInfo, actualOutputTensorInfo, layerName,
"Input 0",
"Output 0");
2626 std::vector<int32_t> targetShape;
2627 bool targetShapeFound =
false;
2629 if (options !=
nullptr)
2632 if (options->new_shape.empty() ==
false)
2634 targetShape = options->new_shape;
2635 targetShapeFound =
true;
2640 if (!targetShapeFound)
2643 if (inputs.size() > 1 && inputs[1] !=
nullptr)
2645 if (inputs[1]->is_variable)
2650 if (inputs[1]->shape.size() != 1)
2655 if (inputs[1]->type != tflite::TensorType_INT32)
2661 auto bufferPtr =
GetBuffer(m_Model, inputs[1]->buffer);
2662 auto values =
reinterpret_cast<const int32_t*
>(bufferPtr->data.data());
2665 for (
int i = 0; i < inputs[1]->shape[0]; ++i)
2667 targetShape.push_back(values[i]);
2677 if (reshapeShapes[0] > 2)
2679 throw ParseException(fmt::format(
"Invalid input shape '{}' in Reshape layer '{}' {}. " 2680 "When inferring during runtime, the parser only supports " 2681 "shape (batch, -1) or (-1) for target shape input.",
2687 const int32_t numInputElements = inputTensorInfo.
GetNumElements();
2688 const int32_t inputTensorShape = inputTensorInfo.
GetShape()[0];
2689 if (reshapeShapes[0] == 1)
2691 targetShape = {numInputElements};
2693 else if (reshapeShapes[0] == 2)
2695 targetShape = {inputTensorShape, numInputElements / inputTensorShape};
2698 catch (
const std::exception& exc)
2701 "Reshape operation. Reshape operator target shape input buffer data " 2702 "is null. " << exc.what());
2709 "At least one method required");
2718 if (inputs.size() > 1 && !
CheckShape(reshapeOutputTensorShape, outputs[0]->shape))
2720 std::stringstream ss;
2721 ss <<
"New shape defined in reshape parameters " 2722 << reshapeOutputTensorShape
2723 <<
" does not equal output shape " 2724 << actualOutputTensorInfo.
GetShape()
2733 IConnectableLayer* layer = m_Network->AddReshapeLayer(reshapeDesc, layerName.c_str());
2737 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2738 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
2740 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2741 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
2744 void TfLiteParserImpl::ParseResizeBilinear(
size_t subgraphIndex,
size_t operatorIndex)
2746 ParseResize(subgraphIndex, operatorIndex, ResizeMethod::Bilinear);
2749 void TfLiteParserImpl::ParseResizeNearestNeighbor(
size_t subgraphIndex,
size_t operatorIndex)
2751 ParseResize(subgraphIndex, operatorIndex, ResizeMethod::NearestNeighbor);
2754 void TfLiteParserImpl::ParseResize(
size_t subgraphIndex,
size_t operatorIndex,
ResizeMethod resizeMethod)
2756 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2758 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2761 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2767 std::vector<int32_t> sizeTensorData(sizeTensorInfo.GetNumElements());
2770 ::memcpy(sizeTensorData.data(), sizeBufferPtr->data.data(), sizeTensorInfo.GetNumBytes());
2774 desc.m_TargetHeight =
static_cast<uint32_t
> (sizeTensorData[0]);
2775 desc.m_TargetWidth =
static_cast<uint32_t
> (sizeTensorData[1]);
2778 auto layerName = fmt::format(
"Resize:");
2780 switch (resizeMethod)
2782 case ResizeMethod::Bilinear:
2784 layerName += fmt::format(
"BILINEAR:{}:{}", subgraphIndex, operatorIndex);
2786 const auto & operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
2787 const auto * options = operatorPtr->builtin_options.AsResizeBilinearOptions();
2789 desc.m_AlignCorners = options->align_corners;
2792 case ResizeMethod::NearestNeighbor:
2794 layerName += fmt::format(
"NEARESTNEIGHBOR:{}:{}", subgraphIndex, operatorIndex);
2800 fmt::format(
"Unexpected ResizeMethod[{}] when creating layerName {} ",
2807 CheckMatchingQuantization(inputTensorInfo, outputTensorInfo, layerName,
"Input 0",
"Output 0");
2813 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2814 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
2816 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2817 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, outputTensorIndexes);
2820 void TfLiteParserImpl::ParseConcatenation(
size_t subgraphIndex,
size_t operatorIndex)
2822 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2824 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
2825 const auto* options = operatorPtr->builtin_options.AsConcatenationOptions();
2829 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2830 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2833 unsigned int numConcatView =
static_cast<unsigned int>(inputs.size());
2836 const unsigned int concatDimInput =
static_cast<unsigned int>(
2837 (
static_cast<int>(inputRank) + options->axis) %
static_cast<int>(inputRank));
2839 OriginsDescriptor concatDescriptor(static_cast<uint32_t>(numConcatView), inputRank);
2842 unsigned int mergeDimOrigin = 0;
2844 for (
unsigned int viewIndex = 0; viewIndex < numConcatView; ++viewIndex)
2850 inputTensorInfo, concatDescriptor, concatDimInput, viewIndex, mergeDimOrigin);
2853 auto layerName = fmt::format(
"Concatenation:{}:{}", subgraphIndex, operatorIndex);
2856 IConnectableLayer* layer = m_Network->AddConcatLayer(concatDescriptor, layerName.c_str());
2860 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2861 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes});
2864 layer = AddFusedActivationLayer(layer, 0, options->fused_activation_function);
2866 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2867 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
2870 void TfLiteParserImpl::ParseFullyConnected(
size_t subgraphIndex,
size_t operatorIndex)
2872 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2874 const auto& operatorRfr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
2875 const auto options = operatorRfr->builtin_options.AsFullyConnectedOptions();
2883 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2884 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2890 int32_t weightsDimension =
static_cast<int32_t
>(filterTensorInfo.GetNumDimensions());
2891 if (weightsDimension != 2)
2894 fmt::format(
"Dimension {} for Fully Connected weights is not supported by Armnn. " 2901 auto layerName = fmt::format(
"FullyConnected:{}:{}", subgraphIndex, operatorIndex);
2903 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2905 std::vector<unsigned int> tensorIndexesToRegister = {inputTensorIndexes[0]};
2906 std::vector<unsigned int> ignoreInputWhenRegister = {};
2911 tensorIndexesToRegister.emplace_back(inputTensorIndexes[1]);
2913 if (inputs.size() == 3)
2918 tensorIndexesToRegister.emplace_back(inputTensorIndexes[2]);
2922 layer = m_Network->AddFullyConnectedLayer(desc, layerName.c_str());
2927 unsigned int startingSlotIndex = 0;
2934 std::vector<unsigned int> reshapedDimensions(2);
2935 reshapedDimensions[1] = filterTensorInfo.GetShape()[1];
2936 reshapedDimensions[0] = inputTensorInfo.
GetNumElements() / reshapedDimensions[1];
2938 if (inputTensorInfo.
GetNumElements() % reshapedDimensions[1] != 0)
2941 fmt::format(
"Failed to deduce input tensor shape from filter size {} {}",
2942 reshapedDimensions[1],
2949 std::string reshapeLayerName = fmt::format(
"Reshape_for:{}", layer->
GetName());
2957 RegisterInputSlots(subgraphIndex, operatorIndex, reshapeLayer, {inputTensorIndexes[0]});
2959 tensorIndexesToRegister.erase(tensorIndexesToRegister.begin());
2960 startingSlotIndex = 1;
2963 RegisterInputSlots(subgraphIndex, operatorIndex, layer, tensorIndexesToRegister, startingSlotIndex);
2970 options->fused_activation_function);
2973 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2974 RegisterOutputSlots(subgraphIndex, operatorIndex, fusedActivationLayer, {outputTensorIndexes[0]});
2977 void TfLiteParserImpl::ParseDetectionPostProcess(
size_t subgraphIndex,
size_t operatorIndex)
2979 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2981 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
2983 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2984 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2988 auto custom_options = operatorPtr->custom_options;
2989 const flexbuffers::Map& m = flexbuffers::GetRoot(custom_options.data(), custom_options.size()).AsMap();
2998 desc.
m_ScaleH = m[
"h_scale"].AsFloat();
2999 desc.
m_ScaleW = m[
"w_scale"].AsFloat();
3000 desc.
m_ScaleX = m[
"x_scale"].AsFloat();
3001 desc.
m_ScaleY = m[
"y_scale"].AsFloat();
3003 if (!(m[
"use_regular_nms"].IsNull()))
3007 if (!(m[
"detections_per_class"].IsNull()))
3015 "must be positive and less than or equal to 1.");
3019 auto anchorTensorAndData = CreateConstTensorNonPermuted(inputs[2], anchorTensorInfo);
3021 auto layerName = fmt::format(
"DetectionPostProcess:{}:{}", subgraphIndex, operatorIndex);
3022 IConnectableLayer* layer = m_Network->AddDetectionPostProcessLayer(desc, anchorTensorAndData,
3030 m_OverridenOutputShapes.push_back({ 1, numDetectedBox, 4 });
3031 m_OverridenOutputShapes.push_back({ 1, numDetectedBox });
3032 m_OverridenOutputShapes.push_back({ 1, numDetectedBox });
3033 m_OverridenOutputShapes.push_back({ 1 });
3035 for (
unsigned int i = 0 ; i < outputs.size() ; ++i)
3043 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
3044 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0], inputTensorIndexes[1]});
3047 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
3048 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0],
3049 outputTensorIndexes[1],
3050 outputTensorIndexes[2],
3051 outputTensorIndexes[3]});
3055 void TfLiteParserImpl::ParsePack(
size_t subgraphIndex,
size_t operatorIndex)
3057 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
3059 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
3060 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
3063 if (inputs.size() < 1)
3068 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
3069 const auto* options = operatorPtr->builtin_options.AsPackOptions();
3072 desc.
m_Axis =
static_cast<uint32_t
>(options->axis);
3073 desc.
m_NumInputs =
static_cast<uint32_t
>(inputs.size());
3079 auto layerName = fmt::format(
"Pack:{}:{}", subgraphIndex, operatorIndex);
3087 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
3088 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes});
3090 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
3091 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
3094 void TfLiteParserImpl::ParseUnpack(
size_t subgraphIndex,
size_t operatorIndex)
3096 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
3098 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
3099 const auto* options = operatorPtr->builtin_options.AsUnpackOptions();
3104 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
3109 if (unpackAxis >= inputTensorInfo.GetNumDimensions())
3112 fmt::format(
"The unpack axis: {} cannot be greater than or equal to " 3113 "the number of input dimension {} {}",
3115 inputTensorInfo.GetNumDimensions(),
3123 unpackNum = inputTensorInfo.GetShape()[unpackAxis];
3129 throw ParseException(
"Number to unpack must greater than zero.");
3132 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
3135 auto inputDimSize = inputTensorInfo.GetNumDimensions();
3136 std::vector<unsigned int> unpackDimSizes(inputDimSize);
3139 for (
unsigned int i = 0; i < inputDimSize; ++i)
3141 unpackDimSizes[i] = inputTensorInfo.GetShape()[i];
3144 if (unpackDimSizes[unpackAxis] != unpackNum)
3146 throw ParseException(
"Number to unpack must be the same as length of the dimension to " 3150 unpackDimSizes[unpackAxis] /= unpackNum;
3152 SplitterDescriptor splitDesc(unpackNum, static_cast<unsigned int>(unpackDimSizes.size()));
3153 for (
unsigned int j = 0; j < unpackNum; ++j)
3156 for (
unsigned int dimIdx = 0; dimIdx < unpackDimSizes.size(); ++dimIdx)
3158 splitDesc.
SetViewSize(j, dimIdx, unpackDimSizes[dimIdx]);
3163 auto layerName = fmt::format(
"Unpack:{}:{}", subgraphIndex, operatorIndex);
3164 IConnectableLayer* layer = m_Network->AddSplitterLayer(splitDesc, layerName.c_str());
3168 unpackDimSizes.data());
3170 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
3171 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
3173 std::vector<unsigned int> reshapeDims;
3174 for (
unsigned int axis = 0; axis < splitOutShape.
GetNumDimensions(); ++axis)
3176 if (axis != unpackAxis)
3178 reshapeDims.push_back(splitOutShape[axis]);
3188 std::string reshapeLayerName = fmt::format(
"Reshape_for:{}", layer->
GetName());
3203 RegisterProducerOfTensor(subgraphIndex, reshapedOutputId, slot);
3207 void TfLiteParserImpl::ParseSplit(
size_t subgraphIndex,
size_t operatorIndex)
3209 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
3211 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
3212 const auto* options = operatorPtr->builtin_options.AsSplitOptions();
3219 throw ParseException(
"Number to splits must greater than zero.");
3222 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
3224 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
3232 if (axisBufferPtr ==
nullptr)
3235 fmt::format(
"Operation has invalid inputs. Failed to read axis. {}",
3240 ::memcpy(axisData.data(), axisBufferPtr->data.data(), axisTensorInfo.
GetNumBytes());
3241 int32_t axis = axisData[0];
3243 auto inputDimensions =
static_cast<int32_t
>(inputTensorInfo.GetNumDimensions());
3244 if (((axis < -inputDimensions) && (axis < 0)) || ((axis >= inputDimensions) && (axis > 0)))
3250 fmt::format(
"Operation has invalid axis: {}. Axis must be in range [-n, n) {}",
3257 auto inputDimSize = inputTensorInfo.GetNumDimensions();
3261 fmt::format(
"The number of dimensions: {} for input tensors of the split op cannot be greater than {} {}",
3262 inputTensorInfo.GetNumDimensions(),
3267 std::vector<unsigned int> splitterDimSizes(inputDimSize);
3270 for (
unsigned int i = 0; i < inputDimSize; ++i)
3272 splitterDimSizes[i] = inputTensorInfo.GetShape()[i];
3275 if (splitterDimSizes[splitDim] % numSplits != 0)
3277 throw ParseException(
"Number of splits must evenly divide the dimension");
3279 splitterDimSizes[splitDim] /= numSplits;
3282 for (
unsigned int j = 0; j < numSplits; ++j)
3285 for (
unsigned int dimIdx = 0; dimIdx < splitterDimSizes.size(); ++dimIdx)
3287 splitDesc.
SetViewSize(j, dimIdx, splitterDimSizes[dimIdx]);
3292 auto layerName = fmt::format(
"Split:{}:{}", subgraphIndex, operatorIndex);
3293 IConnectableLayer* layer = m_Network->AddSplitterLayer(splitDesc, layerName.c_str());
3296 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
3297 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[1]});
3305 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
3306 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, outputTensorIndexes);
3312 int v = idx < 0 ? numDims + idx : idx;
3316 return static_cast<unsigned int>(v);
3319 void TfLiteParserImpl::ParseSplitV(
size_t subgraphIndex,
size_t operatorIndex)
3321 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
3323 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
3324 const auto* options = operatorPtr->builtin_options.AsSplitVOptions();
3326 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
3329 auto& inputTensor = inputs[0];
3330 auto& splitsTensor = inputs[1];
3331 auto& axisTensor = inputs[2];
3343 fmt::format(
"The number of dimensions: {} for input tensors of the " 3344 "SplitV op cannot be greater than {} {}",
3352 if (axisBufferPtr ==
nullptr)
3355 fmt::format(
"Operation has invalid inputs. Failed to read axis. {}",
3360 ::memcpy(axisData.data(), axisBufferPtr->data.data(), axisTensorInfo.
GetNumBytes());
3361 int32_t axis = axisData[0];
3363 auto inputDimensions =
static_cast<int32_t
>(inputTensorInfo.
GetNumDimensions());
3364 if (((axis < -inputDimensions) && (axis < 0)) || ((axis >= inputDimensions) && (axis > 0)))
3370 fmt::format(
"Operation has invalid axis: {}. Axis must be in range [-n, n) {}",
3378 unsigned int numSplits{0};
3394 std::vector<int> splitsData(numSplits);
3396 ::memcpy(splitsData.data(), splitsBufferPtr->data.data(), splitsInfo.
GetNumBytes());
3398 unsigned int idx = 0;
3400 unsigned int inferIdx{0};
3402 for (
auto split : splitsData)
3416 if (numInferred == 0)
3418 if (splitSum != armnn::numeric_cast<int>(inputTensorInfo.
GetShape()[splitDim]))
3420 throw ParseException(
"SplitV split_sizes does not sum to the dimension of value along split_dim.");
3423 else if (numInferred == 1)
3429 throw ParseException(
"Cannot infer split size for more than one split");
3433 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
3438 unsigned int accumSplit = 0;
3439 for (
unsigned int j = 0; j < numSplits; ++j)
3444 for (
unsigned int dimIdx = 0; dimIdx < inputTensorInfo.
GetNumDimensions(); ++dimIdx)
3446 unsigned int dimSize = inputTensorInfo.
GetShape()[dimIdx];
3447 if (dimIdx == splitDim)
3449 dimSize = splitSize;
3451 splitDesc.SetViewSize(j, dimIdx, dimSize);
3454 splitDesc.SetViewOriginCoord(j, splitDim, accumSplit);
3455 accumSplit += splitSize;
3458 auto layerName = fmt::format(
"SplitV:{}:{}", subgraphIndex, operatorIndex);
3459 IConnectableLayer* layer = m_Network->AddSplitterLayer(splitDesc, layerName.c_str());
3462 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
3463 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
3471 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
3472 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, outputTensorIndexes);
3475 void TfLiteParserImpl::ParseArgMin(
size_t subgraphIndex,
size_t operatorIndex)
3480 void TfLiteParserImpl::ParseArgMax(
size_t subgraphIndex,
size_t operatorIndex)
3485 void TfLiteParserImpl::ParseArgMinMax(
size_t subgraphIndex,
size_t operatorIndex,
ArgMinMaxFunction argMinMaxFunction)
3487 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
3488 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
3491 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
3505 "Output tensor data type is not supported. (Supported types: Signed32 & Signed64) {}",
3511 if (axisBufferPtr ==
nullptr)
3514 fmt::format(
"Operation has invalid inputs. Failed to read axis. {}",
3519 ::memcpy(axisData.data(), axisBufferPtr->data.data(), axisTensorInfo.
GetNumBytes());
3520 int32_t axis = axisData.front();
3522 auto inputDimensions =
static_cast<int32_t
>(inputTensorInfo.GetNumDimensions());
3523 if (((axis < -inputDimensions) && (axis < 0)) || ((axis >= inputDimensions) && (axis > 0)))
3529 fmt::format(
"Operation has invalid axis: {}. Axis must be in range [-n, n) {}",
3539 auto layerName = argMinMaxFunction == ArgMinMaxFunction::Max ?
"ArgMax:{}:{}" :
"ArgMin:{}:{}";
3540 auto layerNameFormatted = fmt::format(layerName, subgraphIndex, operatorIndex);
3541 IConnectableLayer *layer = m_Network->AddArgMinMaxLayer(desc, layerNameFormatted.c_str());
3546 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
3547 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
3550 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
3551 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, outputTensorIndexes);
3554 void TfLiteParserImpl::ParseGather(
size_t subgraphIndex,
size_t operatorIndex)
3556 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
3569 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
3570 const auto* options = operatorPtr->builtin_options.AsGatherOptions();
3571 auto axis = options->axis;
3573 auto inputDimensions =
static_cast<int32_t
>(inputTensorInfo.GetNumDimensions());
3576 if (((axis < -inputDimensions) && (axis < 0)) || ((axis >= inputDimensions) && (axis > 0)))
3579 fmt::format(
"Operation has invalid axis: {} It is out of bounds [ -{}, {} ) {}",
3581 inputDimensions, inputDimensions,
3584 if (outputDimensions != static_cast<unsigned int>(inputDimensions) + indicesDimensions - 1)
3587 fmt::format(
"Operation has invalid output dimensions: {} Output must be an ({} + {} - 1) -D tensor {}",
3589 inputDimensions, indicesDimensions,
3593 gatherDescriptor.
m_Axis = axis;
3595 auto layerName = fmt::format(
"Gather:{}:{}", subgraphIndex, operatorIndex);
3596 IConnectableLayer* layer = m_Network->AddGatherLayer(gatherDescriptor, layerName.c_str());
3600 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
3601 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0], inputTensorIndexes[1]});
3603 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
3604 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
3607 void TfLiteParserImpl::ParseDepthToSpace(
size_t subgraphIndex,
size_t operatorIndex)
3609 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
3618 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
3619 const auto* options = operatorPtr->builtin_options.AsDepthToSpaceOptions();
3620 auto blockSize = options->block_size;
3624 fmt::format(
"Operation has invalid block size: {} Block size should be >= 2 {}",
3630 auto layerName = fmt::format(
"DepthToSpace:{}:{}", subgraphIndex, operatorIndex);
3631 IConnectableLayer* layer = m_Network->AddDepthToSpaceLayer(descriptor, layerName.c_str());
3636 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
3637 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
3639 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
3640 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
3643 void TfLiteParserImpl::ParseSum(
size_t subgraphIndex,
size_t operatorIndex)
3648 void TfLiteParserImpl::ParseReduceProd(
size_t subgraphIndex,
size_t operatorIndex)
3653 void TfLiteParserImpl::ParseReduceMax(
size_t subgraphIndex,
size_t operatorIndex)
3658 void TfLiteParserImpl::ParseReduceMin(
size_t subgraphIndex,
size_t operatorIndex)
3663 void TfLiteParserImpl::ParseReduce(
size_t subgraphIndex,
size_t operatorIndex,
ReduceOperation reduceOperation)
3665 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
3667 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
3668 const auto* options = operatorPtr->builtin_options.AsReducerOptions();
3670 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
3673 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
3676 auto layerName = fmt::format(
"Reduce:{}:{}", subgraphIndex, operatorIndex);
3684 if (axisBufferPtr !=
nullptr)
3686 std::vector<int32_t> axisData(inputTensorInfo1.
GetNumElements());
3687 ::memcpy(axisData.data(), axisBufferPtr->data.data(), inputTensorInfo1.
GetNumBytes());
3691 std::set<unsigned int> uniqueAxis;
3692 std::transform(axisData.begin(),
3694 std::inserter(uniqueAxis, uniqueAxis.begin()),
3695 [rank](
int i)->unsigned
int{
3696 return static_cast<uint32_t
>(((i + rank) % rank)); });
3697 desc.
m_vAxis.assign(uniqueAxis.begin(), uniqueAxis.end());
3717 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
3718 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
3721 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
3722 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, outputTensorIndexes);
3725 void TfLiteParserImpl::ParseAbs(
size_t subgraphIndex,
size_t operatorIndex)
3730 void TfLiteParserImpl::ParseExp(
size_t subgraphIndex,
size_t operatorIndex)
3735 void TfLiteParserImpl::ParseLocalResponseNormalization(
size_t subgraphIndex,
size_t operatorIndex)
3737 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
3739 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
3742 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
3745 auto layerName = fmt::format(
"LRN:{}:{}", subgraphIndex, operatorIndex);
3746 std::string layerNameFormatted = fmt::format(layerName, subgraphIndex, operatorIndex);
3750 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
3751 const auto* options = operatorPtr->builtin_options.AsLocalResponseNormalizationOptions();
3757 descriptor.
m_NormSize =
static_cast<uint32_t
>(options->radius);
3758 descriptor.
m_K = options->bias;
3759 descriptor.
m_Alpha = options->alpha;
3760 descriptor.
m_Beta = options->beta;
3766 IConnectableLayer* layer = m_Network->AddNormalizationLayer(descriptor, layerNameFormatted.c_str());
3772 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
3773 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
3775 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
3776 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
3779 void TfLiteParserImpl::ParseLogicalNot(
size_t subgraphIndex,
size_t operatorIndex)
3784 void TfLiteParserImpl::ParseNeg(
size_t subgraphIndex,
size_t operatorIndex)
3789 void TfLiteParserImpl::ParseRsqrt(
size_t subgraphIndex,
size_t operatorIndex)
3794 void TfLiteParserImpl::ParseElementwiseUnary(
size_t subgraphIndex,
size_t operatorIndex,
UnaryOperation unaryOperation)
3796 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
3798 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
3801 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
3805 std::string layerNameFormatted = fmt::format(layerName, subgraphIndex, operatorIndex);
3809 IConnectableLayer* layer = m_Network->AddElementwiseUnaryLayer(desc, layerNameFormatted.c_str());
3815 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
3816 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
3818 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
3819 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, outputTensorIndexes);
3822 void TfLiteParserImpl::ParseEqual(
size_t subgraphIndex,
size_t operatorIndex)
3827 void TfLiteParserImpl::ParseNotEqual(
size_t subgraphIndex,
size_t operatorIndex)
3832 void TfLiteParserImpl::ParseGreater(
size_t subgraphIndex,
size_t operatorIndex)
3837 void TfLiteParserImpl::ParseGreaterOrEqual(
size_t subgraphIndex,
size_t operatorIndex)
3842 void TfLiteParserImpl::ParseLess(
size_t subgraphIndex,
size_t operatorIndex)
3847 void TfLiteParserImpl::ParseLessOrEqual(
size_t subgraphIndex,
size_t operatorIndex)
3852 void TfLiteParserImpl::ParseComparison(
size_t subgraphIndex,
size_t operatorIndex,
3855 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
3857 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
3860 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
3864 std::string layerNameFormatted = fmt::format(layerName, subgraphIndex, operatorIndex);
3868 CheckMatchingQuantization(inputTensorInfo, input1TensorInfo, layerNameFormatted,
"Input 0",
"Input 1");
3872 IConnectableLayer* layer = m_Network->AddComparisonLayer(desc, layerNameFormatted.c_str());
3878 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
3879 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0], inputTensorIndexes[1]});
3881 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
3882 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
3886 unsigned int outputSlot,
3887 tflite::ActivationFunctionType activationType)
3890 std::string layerName = prevLayer->
GetName();
3892 switch(activationType)
3894 case tflite::ActivationFunctionType_NONE:
3899 case tflite::ActivationFunctionType_RELU:
3901 activationDesc.
m_Function = ActivationFunction::ReLu;
3902 layerName +=
":RELU";
3905 case tflite::ActivationFunctionType_RELU6:
3907 activationDesc.
m_Function = ActivationFunction::BoundedReLu;
3908 activationDesc.
m_A = 6.0f;
3909 activationDesc.
m_B = 0.0f;
3910 layerName +=
":RELU6";
3913 case tflite::ActivationFunctionType_TANH:
3915 activationDesc.
m_Function = ActivationFunction::TanH;
3916 activationDesc.
m_A = 1.0f;
3917 activationDesc.
m_B = 1.0f;
3918 layerName +=
":TANH";
3923 case tflite::ActivationFunctionType_RELU_N1_TO_1:
3924 case tflite::ActivationFunctionType_SIGN_BIT:
3928 fmt::format(
"TfLite parser doesn't suppport fused activation: " 3931 tflite::EnumNameActivationFunctionType(activationType),
3938 m_Network->AddActivationLayer(activationDesc, layerName.c_str());
3940 auto & prevOutputSlot = prevLayer->
GetOutputSlot(outputSlot);
3943 return activationLayer;
3948 if (fileName ==
nullptr)
3953 std::error_code errorCode;
3954 fs::path pathToFile(fileName);
3955 if (!fs::exists(pathToFile, errorCode))
3958 std::stringstream msg;
3959 msg <<
"Cannot find the file (" << fileName <<
") errorCode: " << errorCode
3964 std::ifstream file(fileName, std::ios::binary);
3965 std::string fileContent((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
3967 fileContent.size());
3972 if (binaryContent ==
nullptr)
3977 flatbuffers::Verifier verifier(binaryContent, len);
3978 if (verifier.VerifyBuffer<tflite::Model>() ==
false)
3981 fmt::format(
"Buffer doesn't conform to the expected Tensorflow Lite " 3982 "flatbuffers format. size:{} {}",
3986 return tflite::UnPackModel(binaryContent);
3990 size_t subgraphIndex,
3991 size_t operatorIndex)
3995 const auto& subgraphPtr = model->subgraphs[subgraphIndex];
3996 const auto& operatorPtr = subgraphPtr->operators[operatorIndex];
3998 size_t inputCount = operatorPtr->inputs.size();
4000 for (
size_t i = 0; i < inputCount; ++i)
4003 if (operatorPtr->inputs[i] == -1)
4010 result.push_back(subgraphPtr->tensors[inputId].get());
4017 size_t subgraphIndex,
4018 size_t operatorIndex)
4022 const auto& subgraphPtr = model->subgraphs[subgraphIndex];
4023 const auto& operatorPtr = subgraphPtr->operators[operatorIndex];
4025 size_t outputCount = operatorPtr->outputs.size();
4027 for (
size_t i = 0; i < outputCount; ++i)
4031 result[i] = subgraphPtr->tensors[outputId].get();
4037 size_t subgraphIndex)
4040 const auto& subgraphPtr = model->subgraphs[subgraphIndex];
4042 size_t inputCount = subgraphPtr->inputs.size();
4044 for (
size_t i = 0; i < inputCount; ++i)
4048 result[i] = std::make_pair(inputId, subgraphPtr->tensors[inputId].get());
4054 size_t subgraphIndex)
4057 const auto& subgraphPtr = model->subgraphs[subgraphIndex];
4059 size_t outputCount = subgraphPtr->outputs.size();
4061 for (
size_t i = 0; i < outputCount; ++i)
4064 result[i] = std::make_pair(outputId, subgraphPtr->tensors[outputId].get());
4070 size_t subgraphIndex,
4071 size_t operatorIndex)
4074 const auto& subgraphPtr = model->subgraphs[subgraphIndex];
4075 const auto& operatorPtr = subgraphPtr->operators[operatorIndex];
4076 return operatorPtr->inputs;
4080 size_t subgraphIndex,
4081 size_t operatorIndex)
4084 const auto& subgraphPtr = model->subgraphs[subgraphIndex];
4085 const auto& operatorPtr = subgraphPtr->operators[operatorIndex];
4086 return operatorPtr->outputs;
4089 void TfLiteParserImpl::RegisterInputSlots(
size_t subgraphIndex,
4090 size_t operatorIndex,
4092 const std::vector<unsigned int>& tensorIndexes,
4093 unsigned int startingSlotIndex)
4095 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
4101 fmt::format(
"The number of tensor inputs ({}) does not match the number expected ({})" 4102 " for subgraph:{} operator index:{} {}",
4103 tensorIndexes.size(),
4110 for (
unsigned int index = 0; index < tensorIndexes.size() ; ++index)
4112 unsigned int tensorIndex = tensorIndexes[index];
4114 RegisterConsumerOfTensor(subgraphIndex, tensorIndex, slot);
4118 void TfLiteParserImpl::RegisterOutputSlots(
size_t subgraphIndex,
4119 size_t operatorIndex,
4121 const std::vector<unsigned int>& tensorIndexes)
4123 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
4128 fmt::format(
"The number of tensor outputs ({}) does not match the number expected ({})" 4129 " for subgraph:{} operator index:{} {}",
4130 tensorIndexes.size(),
4137 for (
unsigned int slotIndex = 0; slotIndex < layer->
GetNumOutputSlots(); ++slotIndex)
4139 unsigned int tensorIndex = tensorIndexes[slotIndex];
4141 RegisterProducerOfTensor(subgraphIndex, tensorIndex, slot);
4145 void TfLiteParserImpl::SetupInputLayers(
size_t subgraphIndex)
4150 for (
auto const& tensorIdAndPtr : inputs)
4152 auto bindingId = GenerateLayerBindingId(subgraphIndex, tensorIdAndPtr.first);
4154 m_Network->AddInputLayer(bindingId, tensorIdAndPtr.second->name.c_str());
4159 RegisterOutputSlots(subgraphIndex,
4160 VIRTUAL_OPERATOR_ID,
4162 {
static_cast<uint32_t
>(tensorIdAndPtr.first) });
4166 void TfLiteParserImpl::SetupOutputLayers(
size_t subgraphIndex)
4171 for (
auto const& tensorIdAndPtr : outputs)
4173 auto bindingId = GenerateLayerBindingId(subgraphIndex, tensorIdAndPtr.first);
4175 m_Network->AddOutputLayer(bindingId, tensorIdAndPtr.second->name.c_str());
4177 RegisterInputSlots(subgraphIndex,
4178 VIRTUAL_OPERATOR_ID,
4180 {
static_cast<uint32_t
>(tensorIdAndPtr.first) });
4184 void TfLiteParserImpl::SetupConstantLayers(
size_t subgraphIndex)
4188 const auto& subgraphPtr = m_Model->subgraphs[subgraphIndex];
4189 for (
unsigned int subgraphIndex = 0; subgraphIndex < m_SubgraphConnections.size(); ++subgraphIndex)
4191 for (
unsigned int tensorIndex = 0; tensorIndex < m_SubgraphConnections[subgraphIndex].size(); ++tensorIndex)
4193 if (m_SubgraphConnections[subgraphIndex][tensorIndex].outputSlot ==
nullptr &&
4194 m_SubgraphConnections[subgraphIndex][tensorIndex].inputSlots.size() > 0)
4196 TensorRawPtr tensorPtr = subgraphPtr->tensors[tensorIndex].get();
4198 if(IsConstTensor(tensorPtr))
4201 auto tensorAndData = CreateConstTensorNonPermuted(tensorPtr, tensorInfo);
4203 std::string layerName = fmt::format(
"Constant:{}", tensorPtr->name);
4204 IConnectableLayer* layer = m_Network->AddConstantLayer(tensorAndData, layerName.c_str());
4207 RegisterOutputSlots(subgraphIndex,
4208 VIRTUAL_OPERATOR_ID,
4215 fmt::format(
"Invalid Tensor: Tensor should be constant. {}",
4227 return model->buffers[bufferIndex].get();
4230 template<
typename T>
4231 std::pair<armnn::ConstTensor, TfLiteParserImpl::SupportedDataStorage>
4240 auto constData = CreateConstTensorImpl<T>(bufferPtr,
4244 TfLiteParserImpl::SupportedDataStorage storage(std::move(constData.second));
4245 return std::make_pair(constData.first, std::move(storage));
4248 bool TfLiteParserImpl::IsConstTensor(
TensorRawPtr tensorPtr)
4251 bool isConst =
true;
4253 auto buffer =
GetBuffer(m_Model, tensorPtr->buffer);
4254 if (buffer->data.size() == 0)
4262 std::pair<armnn::ConstTensor, TfLiteParserImpl::SupportedDataStorage>
4263 TfLiteParserImpl::CreateConstTensorPermuted(
TensorRawPtr tensorPtr,
4268 auto bufferPtr =
GetBuffer(m_Model, tensorPtr->buffer);
4277 return CreateConstTensorAndStoreData<float>(bufferPtr,
4282 return CreateConstTensorAndStoreData<uint8_t>(bufferPtr,
4287 return CreateConstTensorAndStoreData<int8_t>(bufferPtr,
4292 return CreateConstTensorAndStoreData<int8_t>(bufferPtr,
4297 return CreateConstTensorAndStoreData<int32_t>(bufferPtr,
4303 std::stringstream errString;
4304 errString <<
"Unexpected datatype when creating const tensor: " 4306 <<
" shape:" << tensorInfo.GetShape()
4317 auto bufferPtr =
GetBuffer(m_Model, tensorPtr->buffer);
4323 return ConstTensor(tensorInfo, bufferPtr->data.data());
4327 const std::string& name)
const 4331 for (
auto const& input : inputs)
4333 if (input.second->name == name)
4335 auto bindingId = GenerateLayerBindingId(subgraphId, input.first);
4338 inputTensorInfo.SetConstant(
true);
4339 return std::make_pair(bindingId, inputTensorInfo);
4343 std::stringstream bindings;
4344 for (
auto const& input : inputs)
4346 bindings <<
"'" << input.second->name <<
"' ";
4350 fmt::format(
"No input binding found for subgraph:{} and name:{}. " 4351 "Possible inputs are: [{}] {}",
4359 const std::string& name)
const 4363 for (
unsigned int i = 0; i < outputs.size(); ++i)
4365 auto const output = outputs[i];
4366 if (output.second->name == name)
4368 auto bindingId = GenerateLayerBindingId(subgraphId, output.first);
4369 std::vector<unsigned int> shape = m_OverridenOutputShapes.size() > 0 ?
4370 m_OverridenOutputShapes[i] : AsUnsignedVector(output.second->shape);
4371 return std::make_pair(bindingId,
ToTensorInfo(output.second, shape));
4375 std::stringstream bindings;
4376 for (
auto const& output : outputs)
4378 bindings <<
"'" << output.second->name <<
"' ";
4382 fmt::format(
"No output binding found for subgraph:{} and name:{}. " 4383 "Possible outputs are: [{}] {}",
4392 return m_Model->subgraphs.size();
4399 std::vector<std::string> result;
4400 result.reserve(inputs.size());
4401 for (
auto const& input : inputs)
4403 result.push_back(input.second->name);
4412 std::vector<std::string> result;
4413 result.reserve(outputs.size());
4414 for (
auto const& output : outputs)
4416 result.push_back(output.second->name);
4426 TfLiteParserImpl::SupportedDataStorage::SupportedDataStorage(std::unique_ptr<
float[]>&& data)
4427 : m_FloatData(std::move(data))
4428 , m_Uint8Data(
nullptr)
4429 , m_Int8Data(
nullptr)
4430 , m_Int32Data(
nullptr)
4434 TfLiteParserImpl::SupportedDataStorage::SupportedDataStorage(std::unique_ptr<uint8_t[]>&& data)
4435 : m_FloatData(
nullptr)
4436 , m_Uint8Data(std::move(data))
4437 , m_Int8Data(
nullptr)
4438 , m_Int32Data(
nullptr)
4442 TfLiteParserImpl::SupportedDataStorage::SupportedDataStorage(std::unique_ptr<int8_t[]>&& data)
4443 : m_FloatData(
nullptr)
4444 , m_Uint8Data(
nullptr)
4445 , m_Int8Data(std::move(data))
4446 , m_Int32Data(
nullptr)
4450 TfLiteParserImpl::SupportedDataStorage::SupportedDataStorage(std::unique_ptr<int32_t[]>&& data)
4451 : m_FloatData(
nullptr)
4452 , m_Uint8Data(
nullptr)
4453 , m_Int8Data(
nullptr)
4454 , m_Int32Data(std::move(data))
uint32_t m_PadBottom
Padding bottom value in the height dimension.
bool m_BiasEnabled
Enable/disable bias.
#define CHECK_MODEL(MODEL, SUBGRAPH_INDEX, OPERATOR_INDEX)
std::unique_ptr< tflite::ModelT > ModelPtr
static TensorIdRawPtrVector GetSubgraphOutputs(const ModelPtr &model, size_t subgraphIndex)
virtual unsigned int GetNumOutputSlots() const =0
Returns the number of connectable output slots.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
UnaryOperation m_Operation
Specifies the elementwiseUnary operation to execute.
uint32_t m_Axis
0-based axis along which to stack the input tensors.
A ViewsDescriptor for the SplitterLayer.
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
float m_ScaleW
Center size encoding scale weight.
bool IsTypeSpaceMatch(const TensorInfo &other) const
Check that the types are the same and, if quantize, that the quantization parameters are the same...
uint32_t m_PadBottom
Padding bottom value in the height dimension.
bool m_BiasEnabled
Enable/disable bias.
virtual unsigned int GetNumInputSlots() const =0
Returns the number of connectable input slots.
float m_K
Kappa value used for the across channel normalization equation.
A TransposeConvolution2dDescriptor for the TransposeConvolution2dLayer.
#define ARMNN_THROW_PARSE_EXCEPTION(msg)
const TensorShape & GetShape() const
uint32_t m_PadBottom
Padding bottom value in the height dimension.
uint32_t m_PadLeft
Padding left value in the width dimension.
const tflite::TensorT * TensorRawPtr
std::string AsString() const
int32_t m_ShrinkAxisMask
Shrink axis mask value. If set, the nth specification shrinks the dimensionality by 1...
A ReshapeDescriptor for the ReshapeLayer.
bool AreAllDimensionsSpecified() const
Checks if there is at least one dimension not specified.
std::vector< int > m_Begin
Begin values for the input that will be sliced.
const tflite::BufferT * BufferRawPtr
uint32_t m_PadBack
Padding back value in the depth dimension.
float m_PadValue
Optional value to use for padding, defaults to 0.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
A ComparisonDescriptor for the ComparisonLayer.
float m_ScaleX
Center size encoding scale x.
TensorShape m_InputShape
Required shape of all input tensors.
bool m_TransposeWeightMatrix
Enable/disable transpose weight matrix.
uint32_t m_PoolWidth
Pooling width value.
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
A Convolution2dDescriptor for the Convolution2dLayer.
float m_Alpha
Alpha value for the normalization equation.
uint32_t m_PadLeft
Padding left value in the width dimension.
bool m_KeepDims
if true then output shape has no change.
bool m_BiasEnabled
Enable/disable bias.
std::vector< unsigned int > m_OutputShape
unsigned int GetNumBytes() const
ResizeMethod m_Method
The Interpolation method to use (Bilinear, NearestNeighbor).
float m_Beta
Exponentiation value.
armnn::INetworkPtr CreateNetworkFromBinaryFile(const char *graphFile)
Create the network from a flatbuffers binary file on disk.
PaddingMethod m_PaddingMethod
The padding method to be used. (Exclude, IgnoreValue).
BindingPointInfo GetNetworkOutputBindingInfo(size_t subgraphId, const std::string &name) const
Retrieve binding info (layer id and tensor info) for the network output identified by the given layer...
ArgMinMaxFunction m_Function
Specify if the function is to find Min or Max.
uint32_t m_DetectionsPerClass
Detections per classes, used in Regular NMS.
bool m_OutputShapeEnabled
Output shape if it has been specified.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
#define CHECK_BUFFER(MODEL, BUFFER_INDEX)
virtual const char * what() const noexcept override
#define ARMNN_LOG(severity)
uint32_t m_PadTop
Padding top value in the height dimension.
std::vector< BackendOptions > NetworkOptions
uint32_t m_PadBottom
Padding bottom value in the height dimension.
std::vector< std::string > GetSubgraphOutputTensorNames(size_t subgraphId) const
Return the output tensor names for a given subgraph.
bool m_BiasEnabled
Enable/disable bias.
void ProcessConcatInputTensorInfo(armnn::TensorInfo &inputTensorInfo, armnn::OriginsDescriptor &concatDescriptor, const unsigned int &concatAxis, unsigned int inputIndex, unsigned int &mergeDimOrigin)
uint32_t m_PadRight
Padding right value in the width dimension.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
std::vector< std::pair< unsigned int, unsigned int > > m_PadList
Specifies the padding for input dimension.
ReduceOperation m_ReduceOperation
Specifies the reduction operation to execute.
std::unique_ptr< ITfLiteParser, void(*)(ITfLiteParser *parser)> ITfLiteParserPtr
std::unique_ptr< tflite::OperatorT > OperatorPtr
unsigned int ComputeWrappedIndex(int idx, unsigned int numDimsIn)
Copyright (c) 2021 ARM Limited and Contributors.
void IgnoreUnused(Ts &&...)
uint32_t m_PadBottom
Padding bottom value in the height dimension.
int32_t m_BeginMask
Begin mask value.
static armnn::TensorInfo OutputShapeOfReshape(const armnn::TensorInfo &inputTensorInfo, const std::vector< int32_t > &targetDimsIn)
uint32_t m_DilationY
Dilation along y axis.
int32_t m_EndMask
End mask value.
A SpaceToDepthDescriptor for the SpaceToDepthLayer.
std::vector< std::pair< unsigned int, unsigned int > > m_PadList
Specifies the padding values for the input dimension: heightPad{top, bottom} widthPad{left, right}.
uint32_t m_DilationX
Dilation along x axis.
uint32_t m_DilationY
Dilation factor value for height dimension.
A BatchToSpaceNdDescriptor for the BatchToSpaceNdLayer.
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
int LayerBindingId
Type of identifiers for bindable layers (inputs, outputs).
#define TFLITE_PARSER_VERSION
TFLITE_PARSER_VERSION: "X.Y.Z" where: X = Major version number Y = Minor version number Z = Patch ver...
virtual void SetTensorInfo(const TensorInfo &tensorInfo)=0
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
NormalizationAlgorithmMethod m_NormMethodType
Normalization method algorithm to use (LocalBrightness, LocalContrast).
#define CHECK_TENSOR(MODEL, SUBGRAPH_INDEX, TENSOR_INDEX)
constexpr const char * GetDataTypeName(DataType dataType)
void SetShape(const TensorShape &newShape)
armnn::INetworkPtr CreateNetworkFromBinary(const std::vector< uint8_t > &binaryContent)
Create the network from a flatbuffers binary.
A ResizeBilinearDescriptor for the ResizeBilinearLayer.
static BufferRawPtr GetBuffer(const ModelPtr &model, size_t bufferIndex)
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
uint32_t m_MaxClassesPerDetection
Maximum numbers of classes per detection, used in Fast NMS.
std::vector< unsigned int > m_Axis
Values for the dimensions to reduce.
A StackDescriptor for the StackLayer.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
constexpr char const * GetUnaryOperationAsCString(UnaryOperation operation)
TensorShape m_TargetShape
Target shape value.
armnn::INetworkPtr CreateNetworkFromBinaryFile(const char *graphFile)
Create the network from a flatbuffers binary file on disk.
uint32_t m_PoolHeight
Pooling height value.
uint32_t m_PadTop
Padding top value in the height dimension.
uint32_t m_MaxDetections
Maximum numbers of detections.
A PadDescriptor for the PadLayer.
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
std::unique_ptr< onnx::ModelProto > ModelPtr
#define CHECK_SUBGRAPH(MODEL, SUBGRAPH_INDEX)
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
BindingPointInfo GetNetworkInputBindingInfo(size_t subgraphId, const std::string &name) const
Retrieve binding info (layer id and tensor info) for the network input identified by the given layer ...
bool CheckShape(const armnn::TensorShape &actual, const std::vector< uint32_t > &expected)
static ModelPtr LoadModelFromBinary(const uint8_t *binaryContent, size_t len)
float m_NmsIouThreshold
Intersection over union threshold.
uint32_t m_PadRight
Padding right value in the width dimension.
std::vector< TensorIdRawPtr > TensorIdRawPtrVector
uint32_t m_DilationX
Dilation factor value for width dimension.
uint32_t m_PadTop
Padding top value in the height dimension.
std::string FileLine() const
Status SetViewSize(uint32_t view, uint32_t coord, uint32_t value)
Set the size of the views.
#define ARMNN_ASSERT_MSG(COND, MSG)
int32_t m_NewAxisMask
New axis mask value.
bool m_KeepDims
Enable/disable keep dimensions. If true, then the reduced dimensions that are of length 1 are kept...
static std::vector< int32_t > & GetInputTensorIds(const ModelPtr &model, size_t subgraphIndex, size_t operatorIndex)
std::vector< unsigned int > m_BlockShape
Block shape values.
An output connection slot for a layer.
A L2NormalizationDescriptor for the L2NormalizationLayer.
int32_t GetQuantizationOffset() const
An ArgMinMaxDescriptor for ArgMinMaxLayer.
static const std::string GetVersion()
Retrieve version in X.Y.Z form.
float GetQuantizationScale() const
DataType GetDataType() const
An OriginsDescriptor for the ConcatLayer.
A ReduceDescriptor for the REDUCE operators.
bool has_value() const noexcept
A FullyConnectedDescriptor for the FullyConnectedLayer.
int32_t m_EllipsisMask
Ellipsis mask value.
bool m_BiasEnabled
Enable/disable bias.
static ModelPtr LoadModelFromFile(const char *fileName)
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
unsigned int GetUnsignedAxis(const unsigned int inputDimension, const int axis)
A GatherDescriptor for the GatherLayer.
#define CHECK_VALID_SIZE(ACTUAL,...)
uint32_t m_NumClasses
Number of classes.
#define CHECKED_NON_NEGATIVE(VALUE)
std::vector< TensorRawPtr > TensorRawPtrVector
size_t GetSubgraphCount() const
Return the number of subgraphs in the parsed model.
uint32_t m_PadTop
Padding top value in the height dimension.
#define ARMNN_ASSERT(COND)
A StandInDescriptor for the StandIn layer.
bool m_UseRegularNms
Use Regular NMS.
uint32_t m_PadFront
Padding front value in the depth dimension.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
std::vector< unsigned int > m_BlockShape
Block shape value.
std::vector< int > m_Stride
Stride values for the input that will be sliced.
An ActivationDescriptor for the ActivationLayer.
uint32_t m_NumInputs
Number of input tensors.
uint32_t m_PadLeft
Padding left value in the width dimension.
A SliceDescriptor for the SliceLayer.
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
armnn::INetworkPtr LoadModel(std::unique_ptr< tflite::ModelT > model)
A Convolution3dDescriptor for the Convolution3dLayer.
std::unique_ptr< tflite::SubGraphT > SubgraphPtr
uint32_t m_PadRight
Padding right value in the width dimension.
PaddingMode m_PaddingMode
Specifies the Padding mode (Constant, Reflect or Symmetric)
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
#define CHECK_TENSOR_PTR(TENSOR_PTR)
std::vector< uint32_t > m_vAxis
The indices of the dimensions to reduce.
float m_ScaleH
Center size encoding scale height.
ComparisonOperation m_Operation
Specifies the comparison operation to execute.
std::vector< int > m_End
End values for the input that will be sliced.
A SpaceToBatchNdDescriptor for the SpaceToBatchNdLayer.
static TensorIdRawPtrVector GetSubgraphInputs(const ModelPtr &model, size_t subgraphIndex)
DataLayout m_DataLayout
The data layout to be used (NDHWC, NCDHW).
Struct for the users to pass backend specific options.
NormalizationAlgorithmChannel m_NormChannelType
Normalization channel algorithm to use (Across, Within).
float m_A
Alpha upper bound value used by the activation functions. (BoundedReLu, Linear, TanH, Elu).
static TensorRawPtrVector GetInputs(const ModelPtr &model, size_t subgraphIndex, size_t operatorIndex)
uint32_t m_DilationX
Dilation along x axis.
const armnnSerializer::TensorInfo * TensorRawPtr
static TensorRawPtrVector GetOutputs(const ModelPtr &model, size_t subgraphIndex, size_t operatorIndex)
std::pair< armnn::ConstTensor, std::unique_ptr< T[]> > CreateConstTensorImpl(const T *bufferPtr, armnn::TensorInfo &tensorInfo, const armnn::Optional< armnn::PermutationVector &> permutationVector)
uint32_t m_PadLeft
Padding left value in the width dimension.
EmptyOptional is used to initialize the Optional class in case we want to have default value for an O...
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
static std::vector< int32_t > & GetOutputTensorIds(const ModelPtr &model, size_t subgraphIndex, size_t operatorIndex)
#define CHECK_SUPPORTED_FUSED_ACTIVATION(OPTION, SUBGRAPH_INDEX, OPERATOR_INDEX)
int32_t m_Axis
The axis in params to gather indices from.
A ElementwiseUnaryDescriptor for the ElementwiseUnaryLayer.
PoolingAlgorithm m_PoolType
The pooling algorithm to use (Max. Average, L2).
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
std::vector< std::pair< unsigned int, unsigned int > > m_Crops
The values to crop from the input dimension.
uint32_t m_PadTop
Padding top value in the height dimension.
unsigned int GetNumDimensions() const
Function that returns the tensor rank.
OutputShapeRounding m_OutputShapeRounding
The rounding method for the output shape. (Floor, Ceiling).
constexpr char const * GetComparisonOperationAsCString(ComparisonOperation operation)
void SetConcatAxis(unsigned int concatAxis)
Set the concatenation axis value.
virtual const IInputSlot & GetInputSlot(unsigned int index) const =0
Get a const input slot handle by slot index.
A MeanDescriptor for the MeanLayer.
void SetConstant(const bool IsConstant=true)
Marks the data corresponding to this tensor info as constant.
armnn::BindingPointInfo BindingPointInfo
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
armnn::TensorInfo ToTensorInfo(TensorRawPtr tensorPtr)
uint32_t m_PadRight
Padding right value in the width dimension.
A TransposeDescriptor for the TransposeLayer.
A StridedSliceDescriptor for the StridedSliceLayer.
virtual const IOutputSlot & GetOutputSlot(unsigned int index) const =0
Get the const output slot handle by slot index.
int m_Axis
Axis to reduce across the input tensor.
virtual const char * GetName() const =0
Returns the name of the layer.
float m_ScaleY
Center size encoding scale y.
float m_NmsScoreThreshold
NMS score threshold.
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
virtual int Connect(IInputSlot &destination)=0
Krichevsky 2012: Local Brightness Normalization.
A Pooling2dDescriptor for the Pooling2dLayer.
A NormalizationDescriptor for the NormalizationLayer.
static armnn::TensorInfo OutputShapeOfSqueeze(std::vector< uint32_t > squeezeDims, const armnn::TensorInfo &inputTensorInfo)
std::vector< std::string > GetSubgraphInputTensorNames(size_t subgraphId) const
Return the input tensor names for a given subgraph.
unsigned int GetNumDimensions() const
#define CHECK_BUFFER_SIZE(BUFFER_PTR, TENSOR_INFO, BUFFER_ID)
uint32_t m_DilationZ
Dilation along z axis.
float m_B
Beta lower bound value used by the activation functions. (BoundedReLu, Linear, TanH).
armnn::TensorShape Permuted(const armnn::TensorShape &srcShape, const armnn::PermutationVector &mappings)
A SoftmaxDescriptor for the SoftmaxLayer.
float m_Beta
Beta value for the normalization equation.
uint32_t m_StrideZ
Stride value when proceeding through input for the depth dimension.
bool IsActivationSupported(const BackendId &backend, const TensorInfo &input, const TensorInfo &output, const ActivationDescriptor &descriptor, char *reasonIfUnsupported=nullptr, size_t reasonIfUnsupportedMaxLength=1024)
Deprecated in favor of IBackend and ILayerSupport interfaces.
uint32_t m_NormSize
Depth radius value.
Status SetViewOriginCoord(uint32_t view, uint32_t coord, uint32_t value)
Set the view origin coordinates.
ActivationFunction m_Function
The activation function to use (Sigmoid, TanH, Linear, ReLu, BoundedReLu, SoftReLu, LeakyReLu, Abs, Sqrt, Square, Elu).
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
A DepthwiseConvolution2dDescriptor for the DepthwiseConvolution2dLayer.
constexpr unsigned int MaxNumOfTensorDimensions
uint32_t m_DilationY
Dilation along y axis.
uint32_t m_PadLeft
Padding left value in the width dimension.
unsigned int GetNumElements() const
uint32_t m_PadRight
Padding right value in the width dimension.
bool m_ConstantWeights
Enable/disable constant weights and biases.