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 " 287 #define CHECK_BUFFER_SIZE(BUFFER_PTR, TENSOR_INFO, BUFFER_ID) \ 288 CheckBufferSize(BUFFER_PTR, TENSOR_INFO, BUFFER_ID, CHECK_LOCATION()) 292 switch(activationType)
294 case tflite::ActivationFunctionType_NONE:
295 case tflite::ActivationFunctionType_RELU:
296 case tflite::ActivationFunctionType_RELU6:
297 case tflite::ActivationFunctionType_TANH:
308 #define CHECK_SUPPORTED_FUSED_ACTIVATION(OPTION, SUBGRAPH_INDEX, OPERATOR_INDEX) \ 310 if (IsActivationSupported(OPTION->fused_activation_function) == false) \ 312 throw ParseException( \ 313 fmt::format("TfLite parser doesn't suppport fused activation: " \ 314 "{}/{} in {} subgraph:{} operator:{} at {}", \ 315 OPTION->fused_activation_function, \ 316 tflite::EnumNameActivationFunctionType(\ 317 OPTION->fused_activation_function), \ 321 CHECK_LOCATION().FileLine())); \ 326 std::vector<unsigned int> AsUnsignedVector(
const std::vector<int32_t> & in)
328 std::vector<unsigned int> result;
329 result.reserve(in.size());
342 void CalcPadding(uint32_t inputSize,
346 uint32_t& paddingFront,
347 uint32_t& paddingBack,
348 tflite::Padding padding)
352 if (padding == tflite::Padding_SAME)
354 uint32_t outputSize = (inputSize + stride - 1) / stride;
355 uint32_t dilatedSize = filterSize + (dilation - 1) * (filterSize - 1);
356 uint32_t temp = (outputSize - 1) * stride + dilatedSize;
357 if (temp > inputSize)
359 paddingFront = (temp - inputSize) / 2;
360 paddingBack = (temp - inputSize) - paddingFront;
366 const std::vector<unsigned int>& shapes,
367 const bool outputTensor =
false)
372 switch (tensorPtr->type)
374 case tflite::TensorType_UINT8:
377 case tflite::TensorType_FLOAT32:
380 case tflite::TensorType_INT8:
381 if (tensorPtr->quantization->zero_point.size() == 1)
392 case tflite::TensorType_INT16:
395 case tflite::TensorType_INT32:
398 case tflite::TensorType_INT64:
401 case tflite::TensorType_BOOL:
408 fmt::format(
"Unsupported data type {} = {} for tensor: {}. {}",
410 tflite::EnumNameTensorType(tensorPtr->type),
415 std::vector<unsigned int> safeShape = shapes;
416 bool isDynamic =
false;
417 if (safeShape.size() == 0)
419 safeShape.push_back(1);
426 float quantizationScale = 0.0f;
427 int32_t quantizationOffset = 0;
429 if (tensorPtr->quantization.get())
431 if (tensorPtr->quantization->scale.size() <= 1)
436 if (tensorPtr->quantization->scale.size() == 1)
438 quantizationScale = tensorPtr->quantization->scale[0];
440 if (tensorPtr->quantization->zero_point.size() == 1)
447 TensorShape tensorShape(armnn::numeric_cast<unsigned int>(safeShape.size()),
461 std::vector<float> quantizationScales;
462 std::vector<int32_t> quantizationOffsets;
465 std::copy(tensorPtr->quantization->scale.begin(),
466 tensorPtr->quantization->scale.end(),
467 std::back_inserter(quantizationScales));
470 TensorShape tensorShape(armnn::numeric_cast<unsigned int>(safeShape.size()),
479 armnn::numeric_cast<unsigned int>(tensorPtr->quantization->quantized_dimension));
485 TensorShape tensorShape(armnn::numeric_cast<unsigned int>(safeShape.size()),
501 auto const & dimensions = AsUnsignedVector(tensorPtr->shape);
506 const bool outputTensor)
508 auto const & dimensions = AsUnsignedVector(tensorPtr->shape);
509 return ToTensorInfo(tensorPtr, dimensions, outputTensor);
513 std::pair<armnn::ConstTensor, std::unique_ptr<T[]>>
514 CreateConstTensorImpl(TfLiteParserImpl::BufferRawPtr bufferPtr,
522 fmt::format(
"Buffer for buffer:{} is null", tensorPtr->buffer).c_str());
530 reinterpret_cast<const T*
>(bufferPtr->data.data()), data.get(),
sizeof(T));
534 ::memcpy(data.get(), bufferPtr->data.data(), tensorInfo.
GetNumBytes());
537 return std::make_pair(
ConstTensor(tensorInfo, data.get()), std::move(data));
550 if (actualSize != expected.size())
555 for (
unsigned int i = 0u; i < actualSize; i++)
557 if (expected[i] < 0 ||
558 actual[i] != static_cast<unsigned int>(expected[i]))
567 void CheckMatchingQuantization(
const TensorInfo& first,
569 const std::string& descName,
570 std::string
const& firstName,
571 std::string
const& secondName)
583 if (firstDataType != secondDataType)
586 " must be of the same quantized type, " +
594 " must have the same quantization space, " +
606 , m_Network(nullptr, nullptr)
610 m_ParserFunctions[tflite::BuiltinOperator_ABS] = &TfLiteParserImpl::ParseAbs;
611 m_ParserFunctions[tflite::BuiltinOperator_ADD] = &TfLiteParserImpl::ParseAdd;
612 m_ParserFunctions[tflite::BuiltinOperator_ARG_MIN] = &TfLiteParserImpl::ParseArgMin;
613 m_ParserFunctions[tflite::BuiltinOperator_ARG_MAX] = &TfLiteParserImpl::ParseArgMax;
614 m_ParserFunctions[tflite::BuiltinOperator_AVERAGE_POOL_2D] = &TfLiteParserImpl::ParseAveragePool2D;
615 m_ParserFunctions[tflite::BuiltinOperator_BATCH_TO_SPACE_ND] = &TfLiteParserImpl::ParseBatchToSpaceND;
616 m_ParserFunctions[tflite::BuiltinOperator_CAST] = &TfLiteParserImpl::ParseCast;
617 m_ParserFunctions[tflite::BuiltinOperator_CONCATENATION] = &TfLiteParserImpl::ParseConcatenation;
618 m_ParserFunctions[tflite::BuiltinOperator_CONV_2D] = &TfLiteParserImpl::ParseConv2D;
619 m_ParserFunctions[tflite::BuiltinOperator_CUSTOM] = &TfLiteParserImpl::ParseCustomOperator;
620 m_ParserFunctions[tflite::BuiltinOperator_DEPTH_TO_SPACE] = &TfLiteParserImpl::ParseDepthToSpace;
621 m_ParserFunctions[tflite::BuiltinOperator_DEPTHWISE_CONV_2D] = &TfLiteParserImpl::ParseDepthwiseConv2D;
622 m_ParserFunctions[tflite::BuiltinOperator_DEQUANTIZE] = &TfLiteParserImpl::ParseDequantize;
623 m_ParserFunctions[tflite::BuiltinOperator_DIV] = &TfLiteParserImpl::ParseDiv;
624 m_ParserFunctions[tflite::BuiltinOperator_ELU] = &TfLiteParserImpl::ParseElu;
625 m_ParserFunctions[tflite::BuiltinOperator_EXP] = &TfLiteParserImpl::ParseExp;
626 m_ParserFunctions[tflite::BuiltinOperator_FULLY_CONNECTED] = &TfLiteParserImpl::ParseFullyConnected;
627 m_ParserFunctions[tflite::BuiltinOperator_GATHER] = &TfLiteParserImpl::ParseGather;
628 m_ParserFunctions[tflite::BuiltinOperator_HARD_SWISH] = &TfLiteParserImpl::ParseHardSwish;
629 m_ParserFunctions[tflite::BuiltinOperator_LEAKY_RELU] = &TfLiteParserImpl::ParseLeakyRelu;
630 m_ParserFunctions[tflite::BuiltinOperator_LOGICAL_NOT] = &TfLiteParserImpl::ParseLogicalNot;
631 m_ParserFunctions[tflite::BuiltinOperator_LOGISTIC] = &TfLiteParserImpl::ParseLogistic;
632 m_ParserFunctions[tflite::BuiltinOperator_L2_NORMALIZATION] = &TfLiteParserImpl::ParseL2Normalization;
633 m_ParserFunctions[tflite::BuiltinOperator_MAX_POOL_2D] = &TfLiteParserImpl::ParseMaxPool2D;
634 m_ParserFunctions[tflite::BuiltinOperator_MAXIMUM] = &TfLiteParserImpl::ParseMaximum;
635 m_ParserFunctions[tflite::BuiltinOperator_MEAN] = &TfLiteParserImpl::ParseMean;
636 m_ParserFunctions[tflite::BuiltinOperator_MINIMUM] = &TfLiteParserImpl::ParseMinimum;
637 m_ParserFunctions[tflite::BuiltinOperator_MUL] = &TfLiteParserImpl::ParseMul;
638 m_ParserFunctions[tflite::BuiltinOperator_NEG] = &TfLiteParserImpl::ParseNeg;
639 m_ParserFunctions[tflite::BuiltinOperator_PACK] = &TfLiteParserImpl::ParsePack;
640 m_ParserFunctions[tflite::BuiltinOperator_PAD] = &TfLiteParserImpl::ParsePad;
641 m_ParserFunctions[tflite::BuiltinOperator_QUANTIZE] = &TfLiteParserImpl::ParseQuantize;
642 m_ParserFunctions[tflite::BuiltinOperator_RELU] = &TfLiteParserImpl::ParseRelu;
643 m_ParserFunctions[tflite::BuiltinOperator_RELU6] = &TfLiteParserImpl::ParseRelu6;
644 m_ParserFunctions[tflite::BuiltinOperator_REDUCE_MAX] = &TfLiteParserImpl::ParseReduceMax;
645 m_ParserFunctions[tflite::BuiltinOperator_REDUCE_MIN] = &TfLiteParserImpl::ParseReduceMin;
646 m_ParserFunctions[tflite::BuiltinOperator_RESHAPE] = &TfLiteParserImpl::ParseReshape;
647 m_ParserFunctions[tflite::BuiltinOperator_RESIZE_BILINEAR] = &TfLiteParserImpl::ParseResizeBilinear;
648 m_ParserFunctions[tflite::BuiltinOperator_RESIZE_NEAREST_NEIGHBOR] = &TfLiteParserImpl::ParseResizeNearestNeighbor;
649 m_ParserFunctions[tflite::BuiltinOperator_RSQRT] = &TfLiteParserImpl::ParseRsqrt;
650 m_ParserFunctions[tflite::BuiltinOperator_SLICE] = &TfLiteParserImpl::ParseSlice;
651 m_ParserFunctions[tflite::BuiltinOperator_SOFTMAX] = &TfLiteParserImpl::ParseSoftmax;
652 m_ParserFunctions[tflite::BuiltinOperator_SPACE_TO_BATCH_ND] = &TfLiteParserImpl::ParseSpaceToBatchND;
653 m_ParserFunctions[tflite::BuiltinOperator_SPLIT] = &TfLiteParserImpl::ParseSplit;
654 m_ParserFunctions[tflite::BuiltinOperator_SPLIT_V] = &TfLiteParserImpl::ParseSplitV;
655 m_ParserFunctions[tflite::BuiltinOperator_SQUEEZE] = &TfLiteParserImpl::ParseSqueeze;
656 m_ParserFunctions[tflite::BuiltinOperator_STRIDED_SLICE] = &TfLiteParserImpl::ParseStridedSlice;
657 m_ParserFunctions[tflite::BuiltinOperator_SUB] = &TfLiteParserImpl::ParseSub;
658 m_ParserFunctions[tflite::BuiltinOperator_SUM] = &TfLiteParserImpl::ParseSum;
659 m_ParserFunctions[tflite::BuiltinOperator_TANH] = &TfLiteParserImpl::ParseTanH;
660 m_ParserFunctions[tflite::BuiltinOperator_TRANSPOSE] = &TfLiteParserImpl::ParseTranspose;
661 m_ParserFunctions[tflite::BuiltinOperator_TRANSPOSE_CONV] = &TfLiteParserImpl::ParseTransposeConv;
662 m_ParserFunctions[tflite::BuiltinOperator_UNPACK] = &TfLiteParserImpl::ParseUnpack;
665 m_CustomParserFunctions[
"TFLite_Detection_PostProcess"] = &TfLiteParserImpl::ParseDetectionPostProcess;
668 void TfLiteParserImpl::ResetParser()
672 m_SubgraphConnections.clear();
679 return CreateNetworkFromModel();
686 return CreateNetworkFromModel();
689 INetworkPtr TfLiteParserImpl::CreateNetworkFromModel()
694 if (m_Options && m_Options.value().m_InferAndValidate)
698 {
"InferAndValidate",
true }
701 networkOptions.push_back(shapeInferenceMethodOption);
704 m_Network = INetwork::Create(networkOptions);
707 if (m_Model->subgraphs.size() != 1)
710 fmt::format(
"Current TfLite parser only supports 1 subgraph. Current one has: {} {}",
711 m_Model->subgraphs.size(),
715 size_t subgraphIndex = 0;
716 size_t operatorIndex = 0;
719 for (
SubgraphPtr const& subgraph : m_Model->subgraphs)
721 m_SubgraphConnections.emplace_back(subgraph->tensors.size());
724 auto const& opCodePtr = m_Model->operator_codes[op->opcode_index];
725 auto builtinCode = opCodePtr->builtin_code;
727 if (builtinCode > tflite::BuiltinOperator_MAX)
729 throw ParseException(fmt::format(
"Operator code {} is out of range 0-{}. " 730 "subgraph:{} operator idx:{}. {}",
731 builtinCode, tflite::BuiltinOperator_MAX, subgraphIndex,
736 auto& parserFunction = m_ParserFunctions[builtinCode];
737 (this->*parserFunction)(subgraphIndex, operatorIndex);
741 SetupInputLayers(subgraphIndex);
742 SetupOutputLayers(subgraphIndex);
743 SetupConstantLayers(subgraphIndex);
751 std::stringstream errorString;
752 errorString <<
"Failed to parse operator #" << operatorIndex <<
" within subgraph #" 753 << subgraphIndex <<
" error: " << e.
what();
755 std::stringstream errors;
756 errors << errorString.str() <<
"\n";
761 for (subgraphIndex = 0; subgraphIndex < m_SubgraphConnections.size(); ++subgraphIndex)
763 for (
size_t tensorIndex = 0; tensorIndex < m_SubgraphConnections[subgraphIndex].size(); ++tensorIndex)
765 if (m_SubgraphConnections[subgraphIndex][tensorIndex].outputSlot !=
nullptr)
767 for (
size_t inputSlotIdx = 0;
768 inputSlotIdx < m_SubgraphConnections[subgraphIndex][tensorIndex].inputSlots.size();
771 m_SubgraphConnections[subgraphIndex][tensorIndex].outputSlot->Connect(
772 *(m_SubgraphConnections[subgraphIndex][tensorIndex].inputSlots[inputSlotIdx]));
778 return std::move(m_Network);
781 void TfLiteParserImpl::RegisterProducerOfTensor(
size_t subgraphIndex,
786 ARMNN_ASSERT(m_SubgraphConnections.size() > subgraphIndex);
787 ARMNN_ASSERT(m_SubgraphConnections[subgraphIndex].size() > tensorIndex);
789 TensorSlots & tensorSlots = m_SubgraphConnections[subgraphIndex][tensorIndex];
792 if (tensorSlots.outputSlot !=
nullptr)
794 throw ParseException(fmt::format(
"Another layer has already registered itself as the producer of " 795 "subgraph:{} tensor:{} {}",
801 tensorSlots.outputSlot = slot;
804 void TfLiteParserImpl::RegisterConsumerOfTensor(
size_t subgraphIndex,
809 ARMNN_ASSERT(m_SubgraphConnections.size() > subgraphIndex);
810 ARMNN_ASSERT(m_SubgraphConnections[subgraphIndex].size() > tensorIndex);
812 TensorSlots& tensorSlots = m_SubgraphConnections[subgraphIndex][tensorIndex];
813 tensorSlots.inputSlots.push_back(slot);
816 void TfLiteParserImpl::ParseCustomOperator(
size_t subgraphIndex,
size_t operatorIndex)
818 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
821 auto customParserFunction = &TfLiteParserImpl::ParseUnsupportedOperator;
824 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
825 const auto& customCode = m_Model->operator_codes[operatorPtr->opcode_index]->custom_code;
828 auto iterator = m_CustomParserFunctions.find(customCode);
829 if (iterator != m_CustomParserFunctions.end())
831 customParserFunction = iterator->second;
835 (this->*customParserFunction)(subgraphIndex, operatorIndex);
838 void TfLiteParserImpl::ParseUnsupportedOperator(
size_t subgraphIndex,
size_t operatorIndex)
840 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
842 const auto & operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
844 auto opcodeIndex = operatorPtr->opcode_index;
845 auto opcode = m_Model->operator_codes[opcodeIndex]->builtin_code;
847 if (!m_Options || !m_Options.value().m_StandInLayerForUnsupported)
851 fmt::format(
"Operator not supported. " 852 "subgraph:{} operator:{} " 853 "opcode_index:{} opcode:{} / {} {}",
858 tflite::EnumNameBuiltinOperator(opcode),
862 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
863 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
869 auto layerName = fmt::format(
"StandIn:{}:{}:{}", subgraphIndex, operatorIndex, opcode);
872 IConnectableLayer* layer = m_Network->AddStandInLayer(descriptor, layerName.c_str());
875 for (
unsigned int i = 0u; i < numOutputs; ++i)
880 auto inputTensorIds = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
881 auto outputTensorIds = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
883 RegisterInputSlots(subgraphIndex, operatorIndex, layer, inputTensorIds);
884 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, outputTensorIds);
887 void TfLiteParserImpl::ParseCast(
size_t subgraphIndex,
size_t operatorIndex)
889 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
891 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
893 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
896 auto layerName = fmt::format(
"Cast:{}:{}", subgraphIndex, operatorIndex);
904 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
905 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
907 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
908 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, outputTensorIndexes);
911 void TfLiteParserImpl::ParseConv2D(
size_t subgraphIndex,
size_t operatorIndex)
913 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
915 const auto & operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
916 const auto * options = operatorPtr->builtin_options.AsConv2DOptions();
928 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
931 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
938 unsigned int inputHeight = inputTensorInfo.GetShape()[1];
939 unsigned int inputWidth = inputTensorInfo.GetShape()[2];
943 unsigned int filterHeight = filterTensorInfo.
GetShape()[1];
944 unsigned int filterWidth = filterTensorInfo.
GetShape()[2];
946 CalcPadding(inputHeight, filterHeight, desc.
m_StrideY,
948 CalcPadding(inputWidth, filterWidth, desc.
m_StrideX,
951 auto filterTensorAndData = CreateConstTensorNonPermuted(inputs[1], filterTensorInfo);
954 auto layerName = fmt::format(
"Conv2D:{}:{}", subgraphIndex, operatorIndex);
956 if (inputs.size() == 3)
960 auto biasTensorAndData = CreateConstTensorNonPermuted(inputs[2], biasTensorInfo);
961 layer = m_Network->AddConvolution2dLayer(desc,
968 layer = m_Network->AddConvolution2dLayer(desc,
981 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
982 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
984 layer = AddFusedActivationLayer(layer, 0, options->fused_activation_function);
986 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
987 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
990 void TfLiteParserImpl::ParseDepthwiseConv2D(
size_t subgraphIndex,
size_t operatorIndex)
992 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
994 const auto & operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
995 const auto * options = operatorPtr->builtin_options.AsDepthwiseConv2DOptions();
1006 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1008 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1020 unsigned int inputHeight = inputTensorInfo.
GetShape()[1];
1021 unsigned int inputWidth = inputTensorInfo.
GetShape()[2];
1024 unsigned int filterHeight = filterTensorInfo.
GetShape()[1];
1025 unsigned int filterWidth = filterTensorInfo.
GetShape()[2];
1028 filterTensorInfo.
SetShape({ filterHeight,
1033 CalcPadding(inputHeight, filterHeight, desc.
m_StrideY,
1035 CalcPadding(inputWidth, filterWidth, desc.
m_StrideX,
1038 auto filterTensorAndData = CreateConstTensorPermuted(inputs[1], filterTensorInfo, permutationVector);
1040 auto layerName = fmt::format(
"DepthwiseConv2D:{}:{}", subgraphIndex, operatorIndex);
1042 if (inputs.size() == 3)
1046 auto biasTensorAndData = CreateConstTensorNonPermuted(inputs[2], biasTensorInfo);
1047 layer = m_Network->AddDepthwiseConvolution2dLayer(desc,
1048 filterTensorAndData.first,
1054 layer = m_Network->AddDepthwiseConvolution2dLayer(desc,
1055 filterTensorAndData.first,
1066 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1067 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
1069 layer = AddFusedActivationLayer(layer, 0, options->fused_activation_function);
1071 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1072 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1075 void TfLiteParserImpl::ParseDequantize(
size_t subgraphIndex,
size_t operatorIndex)
1077 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1079 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1082 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1085 auto layerName = fmt::format(
"Dequantize:{}:{}", subgraphIndex, operatorIndex);
1093 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1094 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
1096 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1097 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, outputTensorIndexes);
1100 void TfLiteParserImpl::ParseTranspose(
size_t subgraphIndex,
size_t operatorIndex)
1102 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1104 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1107 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1110 auto layerName = fmt::format(
"Transpose:{}:{}", subgraphIndex, operatorIndex);
1113 if (inputs.size() == 2)
1118 std::vector<unsigned int> permuteShape(numPermVecElements);
1119 ::memcpy(permuteShape.data(), permuteBufferPtr->data.data(), permuteTensorInfo.
GetNumBytes());
1127 CheckMatchingQuantization(inputTensorInfo, outputTensorInfo, layerName,
"Input 0",
"Output 0");
1129 IConnectableLayer* layer = m_Network->AddTransposeLayer(desc, layerName.c_str());
1133 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1134 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
1136 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1137 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1140 void TfLiteParserImpl::ParseTransposeConv(
size_t subgraphIndex,
size_t operatorIndex)
1142 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1144 const auto & operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
1145 const auto * options = operatorPtr->builtin_options.AsTransposeConvOptions();
1153 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1154 if (inputs.size() == 4)
1163 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1170 if (tensorInfo.
GetDataType() == DataType::Signed32)
1172 ::memcpy(output_shape.data(),
GetBuffer(m_Model, inputs[0]->buffer)->data.data(), tensorInfo.
GetNumBytes());
1174 if (tensorInfo.
GetDataType() == DataType::QAsymmU8)
1178 output_shape[i] =
GetBuffer(m_Model, inputs[0]->buffer)->data.data()[i];
1182 for (
int dimension : output_shape)
1184 desc.
m_OutputShape.push_back(static_cast<unsigned int>(dimension));
1192 const unsigned int inputHeight = inputTensorInfo.
GetShape()[1];
1193 const unsigned int inputWidth = inputTensorInfo.
GetShape()[2];
1195 const unsigned int filterHeight = filterTensorInfo.
GetShape()[1];
1196 const unsigned int filterWidth = filterTensorInfo.
GetShape()[2];
1198 CalcPadding(inputHeight,
1206 CalcPadding(inputWidth,
1214 auto filterTensorAndData = CreateConstTensorNonPermuted(inputs[1], filterTensorInfo);
1217 auto layerName = fmt::format(
"TransposeConv:{}:{}", subgraphIndex, operatorIndex);
1222 auto biasConstTensor = CreateConstTensorNonPermuted(inputs[3], biasTensorInfo);
1223 layer = m_Network->AddTransposeConvolution2dLayer(desc,
1224 filterTensorAndData,
1230 layer = m_Network->AddTransposeConvolution2dLayer(desc,
1231 filterTensorAndData,
1242 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1243 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[2]});
1245 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1246 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1249 void TfLiteParserImpl::ParseAveragePool2D(
size_t subgraphIndex,
size_t operatorIndex)
1251 ParsePool(subgraphIndex, operatorIndex, PoolingAlgorithm::Average);
1254 void TfLiteParserImpl::ParseBatchToSpaceND(
size_t subgraphIndex,
size_t operatorIndex)
1256 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1258 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1261 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1270 std::vector<unsigned int> blockShape(blockShapeTensorInfo.GetNumElements());
1271 ::memcpy(blockShape.data(), blockShapeBufferPtr->data.data(), blockShapeTensorInfo.GetNumBytes());
1273 std::vector<unsigned int> cropsVector(cropsTensorInfo.
GetNumElements());
1274 ::memcpy(cropsVector.data(), cropsBufferPtr->data.data(), cropsTensorInfo.
GetNumBytes());
1277 std::vector<std::pair<unsigned int, unsigned int>> crops;
1278 for (
unsigned int i = 0; i < cropsTensorInfo.
GetNumElements() / step; ++i)
1280 crops.emplace_back(cropsVector[i * step], cropsVector[i * step + 1]);
1288 auto layerName = fmt::format(
"BatchToSpaceND:{}:{}", subgraphIndex, operatorIndex);
1292 CheckMatchingQuantization(inputTensorInfo, outputTensorInfo, layerName,
"Input 0",
"Output 0");
1294 IConnectableLayer* layer = m_Network->AddBatchToSpaceNdLayer(desc, layerName.c_str());
1298 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1299 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
1301 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1302 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1305 void TfLiteParserImpl::ParseL2Normalization(
size_t subgraphIndex,
size_t operatorIndex)
1307 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1309 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1312 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1317 auto layerName = fmt::format(
"L2Normalization:{}:{}", subgraphIndex, operatorIndex);
1318 IConnectableLayer* layer = m_Network->AddL2NormalizationLayer(desc, layerName.c_str());
1325 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1326 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
1328 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1329 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1332 void TfLiteParserImpl::ParseMaxPool2D(
size_t subgraphIndex,
size_t operatorIndex)
1334 ParsePool(subgraphIndex, operatorIndex, PoolingAlgorithm::Max);
1337 void TfLiteParserImpl::ParseMaximum(
size_t subgraphIndex,
size_t operatorIndex)
1339 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1341 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1344 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1347 auto layerName = fmt::format(
"Maximum:{}:{}", subgraphIndex, operatorIndex);
1351 CheckMatchingQuantization(inputTensorInfo, input1TensorInfo, layerName,
"Input 0",
"Input 1");
1354 CheckMatchingQuantization(inputTensorInfo, outputTensorInfo, layerName,
"Input 0",
"Output 0");
1360 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1361 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0], inputTensorIndexes[1]});
1363 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1364 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1367 void TfLiteParserImpl::ParseMinimum(
size_t subgraphIndex,
size_t operatorIndex)
1369 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1371 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1374 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1377 auto layerName = fmt::format(
"Minimum:{}:{}", subgraphIndex, operatorIndex);
1381 CheckMatchingQuantization(inputTensorInfo, input1TensorInfo, layerName,
"Input 0",
"Input 1");
1384 CheckMatchingQuantization(inputTensorInfo, outputTensorInfo, layerName,
"Input 0",
"Output 0");
1390 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1391 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0], inputTensorIndexes[1]});
1393 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1394 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1397 void TfLiteParserImpl::ParsePool(
size_t subgraphIndex,
1398 size_t operatorIndex,
1401 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1403 const auto & operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
1404 const auto * options = operatorPtr->builtin_options.AsPool2DOptions();
1408 std::string layerName;
1412 case PoolingAlgorithm::Average:
1414 fmt::format(
"AveragePool2D:{}:{}", subgraphIndex, operatorIndex);
1416 case PoolingAlgorithm::Max:
1418 fmt::format(
"MaxPool2D:{}:{}", subgraphIndex, operatorIndex);
1435 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1440 unsigned int inputHeight = inputTensorInfo.GetShape()[1];
1441 unsigned int inputWidth = inputTensorInfo.GetShape()[2];
1448 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1452 CheckMatchingQuantization(inputTensorInfo, outputTensorInfo, layerName,
"Input 0",
"Output 0");
1454 IConnectableLayer* layer = m_Network->AddPooling2dLayer(desc, layerName.c_str());
1460 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1461 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
1463 layer = AddFusedActivationLayer(layer, 0, options->fused_activation_function);
1465 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1466 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1469 void TfLiteParserImpl::ParseSlice(
size_t subgraphIndex,
size_t operatorIndex)
1471 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1473 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1475 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1484 std::vector<unsigned int> begin(beginTensorInfo.
GetNumElements());
1485 ::memcpy(begin.data(), beginBufferPtr->data.data(), beginTensorInfo.
GetNumBytes());
1491 std::vector<unsigned int> size(sizeTensorInfo.GetNumElements());
1492 ::memcpy(size.data(), sizeBufferPtr->data.data(), sizeTensorInfo.GetNumBytes());
1495 auto layerName = fmt::format(
"Slice:{}:{}", subgraphIndex, operatorIndex);
1499 CheckMatchingQuantization(inputTensorInfo, outputTensorInfo, layerName,
"Input 0",
"Output 0");
1501 IConnectableLayer*
const layer = m_Network->AddSliceLayer(desc, layerName.c_str());
1506 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1507 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
1510 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1511 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1514 void TfLiteParserImpl::ParseSoftmax(
size_t subgraphIndex,
size_t operatorIndex)
1516 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1517 const auto & operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
1518 const auto * options = operatorPtr->builtin_options.AsSoftmaxOptions();
1521 desc.
m_Beta = options->beta;
1523 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1525 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1528 auto layerName = fmt::format(
"Softmax:{}:{}", subgraphIndex, operatorIndex);
1529 IConnectableLayer*
const layer = m_Network->AddSoftmaxLayer(desc, layerName.c_str());
1536 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1537 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
1540 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1541 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1544 void TfLiteParserImpl::ParseSpaceToBatchND(
size_t subgraphIndex,
size_t operatorIndex)
1546 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1548 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1551 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1560 std::vector<unsigned int> blockShape(blockShapeTensorInfo.GetNumElements());
1561 ::memcpy(blockShape.data(), blockShapeBufferPtr->data.data(), blockShapeTensorInfo.GetNumBytes());
1563 std::vector<unsigned int> padListVector(padListTensorInfo.
GetNumElements());
1564 ::memcpy(padListVector.data(), padListBufferPtr->data.data(), padListTensorInfo.
GetNumBytes());
1567 std::vector<std::pair<unsigned int, unsigned int>> padList;
1568 for (
unsigned int i = 0; i < padListTensorInfo.
GetNumElements() / step; ++i)
1570 padList.emplace_back(padListVector[i * step], padListVector[i * step + 1]);
1578 auto layerName = fmt::format(
"SpaceToBatchND:{}:{}", subgraphIndex, operatorIndex);
1582 CheckMatchingQuantization(inputTensorInfo, outputTensorInfo, layerName,
"Input 0",
"Output 0");
1584 IConnectableLayer* layer = m_Network->AddSpaceToBatchNdLayer(desc, layerName.c_str());
1588 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1589 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
1591 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1592 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1599 std::vector<uint32_t> squeezeDims = squeezeDimsIn;
1600 static const uint32_t dimensionSequence[] = { 0, 1, 2, 3 };
1604 std::stringstream ss;
1605 ss <<
"Input tensor has unexpected number of dimensions:" << inputTensorInfo.
GetNumDimensions()
1606 <<
" shape:" << inputTensorInfo.
GetShape() <<
" " 1611 if (squeezeDims.empty())
1613 squeezeDims.assign(dimensionSequence,
1617 std::vector<uint32_t> outputDims;
1620 bool skipSqueeze = (std::find(squeezeDims.begin(), squeezeDims.end(), i) == squeezeDims.end());
1621 auto currentDimension = inputTensorInfo.
GetShape()[i];
1622 if (skipSqueeze || currentDimension != 1)
1624 outputDims.push_back(currentDimension);
1628 if (outputDims.size() > 4)
1630 std::stringstream ss;
1631 ss <<
"Output tensor has unexpected number of dimensions:" << inputTensorInfo.
GetNumDimensions()
1632 <<
" shape:" << inputTensorInfo.
GetShape() <<
" " 1644 return outTensorInfo;
1647 void TfLiteParserImpl::ParseSqueeze(
size_t subgraphIndex,
size_t operatorIndex)
1649 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1651 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1654 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1657 const auto & operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
1658 const auto * options = operatorPtr->builtin_options.AsSqueezeOptions();
1659 auto layerName = fmt::format(
"Squeeze:{}:{}", subgraphIndex, operatorIndex);
1665 CheckMatchingQuantization(inputTensorInfo, outputTensorInfo, layerName,
"Input 0",
"Output 0");
1670 IConnectableLayer* layer = m_Network->AddReshapeLayer(reshapeDesc, layerName.c_str());
1674 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1675 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
1677 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1678 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1681 void TfLiteParserImpl::ParseStridedSlice(
size_t subgraphIndex,
size_t operatorIndex)
1683 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1685 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1688 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1691 const auto & operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
1692 const auto * options = operatorPtr->builtin_options.AsStridedSliceOptions();
1706 ::memcpy(begin.data(), beginBufferPtr->data.data(), beginTensorInfo.
GetNumBytes());
1711 std::vector<int> end(endTensorInfo.GetNumElements());
1712 ::memcpy(end.data(), endBufferPtr->data.data(), endTensorInfo.GetNumBytes());
1717 std::vector<int> stride(strideTensorInfo.GetNumElements());
1718 ::memcpy(stride.data(), strideBufferPtr->data.data(), strideTensorInfo.GetNumBytes());
1724 auto layerName = fmt::format(
"StridedSlice:{}:{}", subgraphIndex, operatorIndex);
1725 IConnectableLayer* layer = m_Network->AddStridedSliceLayer(desc, layerName.c_str());
1731 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1732 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
1734 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1735 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1738 void TfLiteParserImpl::ParseSub(
size_t subgraphIndex,
size_t operatorIndex)
1740 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1742 const auto & operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
1743 const auto * options = operatorPtr->builtin_options.AsSubOptions();
1745 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1748 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1754 auto layerName = fmt::format(
"Sub:{}:{}", subgraphIndex, operatorIndex);
1761 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1762 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0], inputTensorIndexes[1]});
1764 layer = AddFusedActivationLayer(layer, 0, options->fused_activation_function);
1766 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1767 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1770 void TfLiteParserImpl::ParseDiv(
size_t subgraphIndex,
size_t operatorIndex)
1772 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1774 const auto & operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
1775 const auto * options = operatorPtr->builtin_options.AsDivOptions();
1777 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1780 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1786 auto layerName = fmt::format(
"Div:{}:{}", subgraphIndex, operatorIndex);
1793 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1794 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0], inputTensorIndexes[1]});
1795 layer = AddFusedActivationLayer(layer, 0, options->fused_activation_function);
1797 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1798 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1801 void TfLiteParserImpl::ParseAdd(
size_t subgraphIndex,
size_t operatorIndex)
1803 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1805 const auto & operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
1806 const auto * options = operatorPtr->builtin_options.AsAddOptions();
1808 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1811 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1817 auto layerName = fmt::format(
"Add:{}:{}", subgraphIndex, operatorIndex);
1824 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1825 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0], inputTensorIndexes[1]});
1826 layer = AddFusedActivationLayer(layer, 0, options->fused_activation_function);
1828 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1829 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1832 void TfLiteParserImpl::ParseMul(
size_t subgraphIndex,
size_t operatorIndex)
1834 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1836 const auto & operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
1837 const auto * options = operatorPtr->builtin_options.AsMulOptions();
1839 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1842 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1848 auto layerName = fmt::format(
"Mul:{}:{}", subgraphIndex, operatorIndex);
1849 IConnectableLayer* layer = m_Network->AddMultiplicationLayer(layerName.c_str());
1855 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1856 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0], inputTensorIndexes[1]});
1857 layer = AddFusedActivationLayer(layer, 0, options->fused_activation_function);
1859 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1860 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1863 void TfLiteParserImpl::ParseMean(
size_t subgraphIndex,
size_t operatorIndex)
1865 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1867 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1869 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1876 std::vector<unsigned int> axis(dimTensorInfo.GetNumElements());
1877 ::memcpy(axis.data(), bufferPtr->data.data(), dimTensorInfo.GetNumBytes());
1887 auto layerName = fmt::format(
"Mean:{}:{}", subgraphIndex, operatorIndex);
1893 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1894 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
1896 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1897 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1900 void TfLiteParserImpl::ParsePad(
size_t subgraphIndex,
size_t operatorIndex)
1902 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1914 std::vector<unsigned int> padBuffer(padTensorInfo.
GetNumElements());
1915 ::memcpy(padBuffer.data(), bufferPtr->data.data(), padTensorInfo.
GetNumBytes());
1919 if (inputTensorInfo.IsQuantized())
1921 desc.
m_PadValue =
static_cast<float>(inputTensorInfo.GetQuantizationOffset());
1923 for (
unsigned int i = 0; i < padTensorInfo.
GetNumElements() / step; ++i)
1925 desc.
m_PadList.emplace_back(padBuffer[i * step], padBuffer[i * step + 1]);
1928 auto layerName = fmt::format(
"Pad:{}:{}", subgraphIndex, operatorIndex);
1935 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1936 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
1938 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1939 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
1942 void TfLiteParserImpl::ParseQuantize(
size_t subgraphIndex,
size_t operatorIndex)
1944 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
1946 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
1949 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
1952 auto layerName = fmt::format(
"Quantize:{}:{}", subgraphIndex, operatorIndex);
1960 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
1961 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
1963 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
1964 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, outputTensorIndexes);
1967 void TfLiteParserImpl::ParseRelu(
size_t subgraphIndex,
size_t operatorIndex)
1969 ParseActivation(subgraphIndex,operatorIndex, ActivationFunction::ReLu);
1972 void TfLiteParserImpl::ParseRelu6(
size_t subgraphIndex,
size_t operatorIndex)
1974 ParseActivation(subgraphIndex,operatorIndex, ActivationFunction::BoundedReLu);
1977 void TfLiteParserImpl::ParseLeakyRelu(
size_t subgraphIndex,
size_t operatorIndex)
1979 ParseActivation(subgraphIndex, operatorIndex, ActivationFunction::LeakyReLu);
1982 void TfLiteParserImpl::ParseLogistic(
size_t subgraphIndex,
size_t operatorIndex)
1984 ParseActivation(subgraphIndex,operatorIndex,ActivationFunction::Sigmoid);
1987 void TfLiteParserImpl::ParseTanH(
size_t subgraphIndex,
size_t operatorIndex)
1989 ParseActivation(subgraphIndex,operatorIndex,ActivationFunction::TanH);
1992 void TfLiteParserImpl::ParseElu(
size_t subgraphIndex,
size_t operatorIndex)
1994 ParseActivation(subgraphIndex, operatorIndex, ActivationFunction::Elu);
1997 void TfLiteParserImpl::ParseHardSwish(
size_t subgraphIndex,
size_t operatorIndex)
1999 ParseActivation(subgraphIndex, operatorIndex, ActivationFunction::HardSwish);
2002 void TfLiteParserImpl::ParseActivation(
size_t subgraphIndex,
size_t operatorIndex,
ActivationFunction activationType)
2004 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2005 const auto & operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
2008 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2011 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2014 auto layerName = fmt::format(
"Activation:");
2018 switch (activationType)
2020 case ActivationFunction::ReLu:
2022 layerName += fmt::format(
"RELU:{}:{}", subgraphIndex, operatorIndex);
2025 case ActivationFunction::BoundedReLu:
2027 layerName += fmt::format(
"RELU6:{}:{}", subgraphIndex, operatorIndex);
2028 activationDesc.
m_A = 6.0f;
2029 activationDesc.
m_B = 0.0f;
2032 case ActivationFunction::Sigmoid:
2034 layerName += fmt::format(
"SIGMOID:{}:{}", subgraphIndex, operatorIndex);
2037 case ActivationFunction::TanH:
2039 layerName += fmt::format(
"TANH:{}:{}", subgraphIndex, operatorIndex);
2040 activationDesc.
m_A = 1.0f;
2041 activationDesc.
m_B = 1.0f;
2044 case ActivationFunction::LeakyReLu:
2046 layerName += fmt::format(
"LEAKYRELU:{}:{}", subgraphIndex, operatorIndex);
2047 const auto * options = operatorPtr->builtin_options.AsLeakyReluOptions();
2048 activationDesc.
m_A = options->alpha;
2051 case ActivationFunction::Elu:
2053 layerName += fmt::format(
"ELU:{}:{}", subgraphIndex, operatorIndex);
2054 activationDesc.
m_A = 1.0f;
2057 case ActivationFunction::HardSwish:
2059 layerName += fmt::format(
"HARDSWISH:{}:{}", subgraphIndex, operatorIndex);
2065 fmt::format(
"Unexpected ActivationFunction[{}] when creating layerName {} ",
2070 IConnectableLayer*
const layer = m_Network->AddActivationLayer(activationDesc, layerName.c_str());
2077 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2078 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
2081 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2082 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
2085 const std::vector<int32_t> & targetDimsIn)
2087 std::vector<unsigned int> outputDims(targetDimsIn.begin(), targetDimsIn.end());
2088 const auto stretchDim = std::find(targetDimsIn.begin(), targetDimsIn.end(), -1);
2090 if (stretchDim != targetDimsIn.end())
2092 if (std::find(std::next(stretchDim), targetDimsIn.end(), -1) != targetDimsIn.end())
2095 fmt::format(
"At most one component of shape can be -1 {}",
CHECK_LOCATION().AsString()));
2098 auto targetNumElements =
2100 std::accumulate(targetDimsIn.begin(), targetDimsIn.end(), -1, std::multiplies<int32_t>()));
2102 auto stretchIndex =
static_cast<size_t>(std::distance(targetDimsIn.begin(), stretchDim));
2103 outputDims[stretchIndex] = inputTensorInfo.
GetNumElements() / targetNumElements;
2114 void TfLiteParserImpl::ParseReshape(
size_t subgraphIndex,
size_t operatorIndex)
2116 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2118 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2120 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2123 const auto & operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
2124 const auto * options = operatorPtr->builtin_options.AsReshapeOptions();
2125 auto layerName = fmt::format(
"Reshape:{}:{}", subgraphIndex, operatorIndex);
2129 CheckMatchingQuantization(inputTensorInfo, actualOutputTensorInfo, layerName,
"Input 0",
"Output 0");
2135 std::vector<int32_t> targetShape;
2136 bool targetShapeFound =
false;
2138 if (options !=
nullptr)
2141 if (options->new_shape.empty() ==
false)
2143 targetShape = options->new_shape;
2144 targetShapeFound =
true;
2149 if (!targetShapeFound)
2152 if (inputs.size() > 1 && inputs[1] !=
nullptr)
2154 if (inputs[1]->is_variable)
2159 if (inputs[1]->shape.size() != 1)
2164 if (inputs[1]->type != tflite::TensorType_INT32)
2170 auto bufferPtr =
GetBuffer(m_Model, inputs[1]->buffer);
2171 auto values =
reinterpret_cast<const int32_t*
>(bufferPtr->data.data());
2176 for (
int i=0; i < inputs[1]->shape[0]; ++i)
2178 targetShape.push_back(values[i]);
2184 "At least one method required");
2193 if (inputs.size() > 1 && !
CheckShape(reshapeOutputTensorShape, outputs[0]->shape))
2195 std::stringstream ss;
2196 ss <<
"New shape defined in reshape parameters " 2197 << reshapeOutputTensorShape
2198 <<
" does not equal output shape " 2199 << actualOutputTensorInfo.
GetShape()
2208 IConnectableLayer* layer = m_Network->AddReshapeLayer(reshapeDesc, layerName.c_str());
2212 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2213 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
2215 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2216 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
2219 void TfLiteParserImpl::ParseResizeBilinear(
size_t subgraphIndex,
size_t operatorIndex)
2221 ParseResize(subgraphIndex, operatorIndex, ResizeMethod::Bilinear);
2224 void TfLiteParserImpl::ParseResizeNearestNeighbor(
size_t subgraphIndex,
size_t operatorIndex)
2226 ParseResize(subgraphIndex, operatorIndex, ResizeMethod::NearestNeighbor);
2229 void TfLiteParserImpl::ParseResize(
size_t subgraphIndex,
size_t operatorIndex,
ResizeMethod resizeMethod)
2231 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2233 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2236 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2242 std::vector<int32_t> sizeTensorData(sizeTensorInfo.GetNumElements());
2245 ::memcpy(sizeTensorData.data(), sizeBufferPtr->data.data(), sizeTensorInfo.GetNumBytes());
2249 desc.m_TargetHeight =
static_cast<uint32_t
> (sizeTensorData[0]);
2250 desc.m_TargetWidth =
static_cast<uint32_t
> (sizeTensorData[1]);
2253 auto layerName = fmt::format(
"Resize:");
2255 switch (resizeMethod)
2257 case ResizeMethod::Bilinear:
2259 layerName += fmt::format(
"BILINEAR:{}:{}", subgraphIndex, operatorIndex);
2261 const auto & operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
2262 const auto * options = operatorPtr->builtin_options.AsResizeBilinearOptions();
2264 desc.m_AlignCorners = options->align_corners;
2267 case ResizeMethod::NearestNeighbor:
2269 layerName += fmt::format(
"NEARESTNEIGHBOR:{}:{}", subgraphIndex, operatorIndex);
2275 fmt::format(
"Unexpected ResizeMethod[{}] when creating layerName {} ",
2282 CheckMatchingQuantization(inputTensorInfo, outputTensorInfo, layerName,
"Input 0",
"Output 0");
2288 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2289 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
2291 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2292 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, outputTensorIndexes);
2295 void TfLiteParserImpl::ParseConcatenation(
size_t subgraphIndex,
size_t operatorIndex)
2297 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2299 const auto & operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
2300 const auto * options = operatorPtr->builtin_options.AsConcatenationOptions();
2304 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2305 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2308 unsigned int numConcatView =
static_cast<unsigned int>(inputs.size());
2311 const unsigned int concatDimInput =
static_cast<unsigned int>(
2312 (
static_cast<int>(inputRank) + options->axis) %
static_cast<int>(inputRank));
2314 OriginsDescriptor concatDescriptor(static_cast<uint32_t>(numConcatView), inputRank);
2317 unsigned int mergeDimOrigin = 0;
2319 for (
unsigned int viewIndex = 0; viewIndex < numConcatView; ++viewIndex)
2325 inputTensorInfo, concatDescriptor, concatDimInput, viewIndex, mergeDimOrigin);
2328 auto layerName = fmt::format(
"Concatenation:{}:{}", subgraphIndex, operatorIndex);
2331 IConnectableLayer* layer = m_Network->AddConcatLayer(concatDescriptor, layerName.c_str());
2335 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2336 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes});
2339 layer = AddFusedActivationLayer(layer, 0, options->fused_activation_function);
2341 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2342 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
2345 void TfLiteParserImpl::ParseFullyConnected(
size_t subgraphIndex,
size_t operatorIndex)
2347 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2349 const auto & operatorRfr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
2350 const auto options = operatorRfr->builtin_options.AsFullyConnectedOptions();
2358 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2359 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2365 int32_t weightsDimension =
static_cast<int32_t
>(filterTensorInfo.GetNumDimensions());
2366 if (weightsDimension != 2)
2369 fmt::format(
"Dimension {} for Fully Connected weights is not supported by Armnn. " 2376 auto layerName = fmt::format(
"FullyConnected:{}:{}", subgraphIndex, operatorIndex);
2382 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2383 std::vector<unsigned int> tensorIndexesToRegister = {inputTensorIndexes[0]};
2386 filterOptionalConstTensor =
Optional<ConstTensor>(CreateConstTensorNonPermuted(inputs[1], filterTensorInfo));
2391 tensorIndexesToRegister.emplace_back(inputTensorIndexes[1]);
2395 if (inputs.size() == 3)
2401 biasOptionalConstTensor =
Optional<ConstTensor>(CreateConstTensorNonPermuted(inputs[2], biasTensorInfo));
2406 tensorIndexesToRegister.emplace_back(inputTensorIndexes[2]);
2410 layer = m_Network->AddFullyConnectedLayer(desc,
2411 filterOptionalConstTensor,
2412 biasOptionalConstTensor,
2418 unsigned int startingSlotIndex = 0;
2425 std::vector<unsigned int> reshapedDimensions(2);
2426 reshapedDimensions[1] = filterTensorInfo.GetShape()[1];
2427 reshapedDimensions[0] = inputTensorInfo.
GetNumElements() / reshapedDimensions[1];
2429 if (inputTensorInfo.
GetNumElements() % reshapedDimensions[1] != 0)
2432 fmt::format(
"Failed to deduce input tensor shape from filter size {} {}",
2433 reshapedDimensions[1],
2440 std::string reshapeLayerName = fmt::format(
"Reshape_for:{}", layer->
GetName());
2448 RegisterInputSlots(subgraphIndex, operatorIndex, reshapeLayer, {inputTensorIndexes[0]});
2450 tensorIndexesToRegister.erase(tensorIndexesToRegister.begin());
2451 startingSlotIndex = 1;
2454 RegisterInputSlots(subgraphIndex, operatorIndex, layer, tensorIndexesToRegister, startingSlotIndex);
2461 options->fused_activation_function);
2464 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2465 RegisterOutputSlots(subgraphIndex, operatorIndex, fusedActivationLayer, {outputTensorIndexes[0]});
2468 void TfLiteParserImpl::ParseDetectionPostProcess(
size_t subgraphIndex,
size_t operatorIndex)
2470 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2472 const auto & operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
2474 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2475 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2479 auto custom_options = operatorPtr->custom_options;
2480 const flexbuffers::Map& m = flexbuffers::GetRoot(custom_options.data(), custom_options.size()).AsMap();
2489 desc.
m_ScaleH = m[
"h_scale"].AsFloat();
2490 desc.
m_ScaleW = m[
"w_scale"].AsFloat();
2491 desc.
m_ScaleX = m[
"x_scale"].AsFloat();
2492 desc.
m_ScaleY = m[
"y_scale"].AsFloat();
2494 if (!(m[
"use_regular_nms"].IsNull()))
2498 if (!(m[
"detections_per_class"].IsNull()))
2506 "must be positive and less than or equal to 1.");
2510 auto anchorTensorAndData = CreateConstTensorNonPermuted(inputs[2], anchorTensorInfo);
2512 auto layerName = fmt::format(
"DetectionPostProcess:{}:{}", subgraphIndex, operatorIndex);
2513 IConnectableLayer* layer = m_Network->AddDetectionPostProcessLayer(desc, anchorTensorAndData,
2521 m_OverridenOutputShapes.push_back({ 1, numDetectedBox, 4 });
2522 m_OverridenOutputShapes.push_back({ 1, numDetectedBox });
2523 m_OverridenOutputShapes.push_back({ 1, numDetectedBox });
2524 m_OverridenOutputShapes.push_back({ 1 });
2526 for (
unsigned int i = 0 ; i < outputs.size() ; ++i)
2534 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2535 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0], inputTensorIndexes[1]});
2538 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2539 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0],
2540 outputTensorIndexes[1],
2541 outputTensorIndexes[2],
2542 outputTensorIndexes[3]});
2546 void TfLiteParserImpl::ParsePack(
size_t subgraphIndex,
size_t operatorIndex)
2548 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2550 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2551 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2554 if (inputs.size() < 1)
2559 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
2560 const auto* options = operatorPtr->builtin_options.AsPackOptions();
2563 desc.
m_Axis =
static_cast<uint32_t
>(options->axis);
2564 desc.
m_NumInputs =
static_cast<uint32_t
>(inputs.size());
2570 auto layerName = fmt::format(
"Pack:{}:{}", subgraphIndex, operatorIndex);
2578 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2579 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes});
2581 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2582 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
2585 void TfLiteParserImpl::ParseUnpack(
size_t subgraphIndex,
size_t operatorIndex)
2587 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2589 const auto & operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
2590 const auto * options = operatorPtr->builtin_options.AsUnpackOptions();
2595 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2600 if (unpackAxis >= inputTensorInfo.GetNumDimensions())
2603 fmt::format(
"The unpack axis: {} cannot be greater than or equal to " 2604 "the number of input dimension {} {}",
2606 inputTensorInfo.GetNumDimensions(),
2614 unpackNum = inputTensorInfo.GetShape()[unpackAxis];
2620 throw ParseException(
"Number to unpack must greater than zero.");
2623 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2626 auto inputDimSize = inputTensorInfo.GetNumDimensions();
2627 std::vector<unsigned int> unpackDimSizes(inputDimSize);
2630 for (
unsigned int i = 0; i < inputDimSize; ++i)
2632 unpackDimSizes[i] = inputTensorInfo.GetShape()[i];
2635 if (unpackDimSizes[unpackAxis] != unpackNum)
2637 throw ParseException(
"Number to unpack must be the same as length of the dimension to " 2641 unpackDimSizes[unpackAxis] /= unpackNum;
2643 SplitterDescriptor splitDesc(unpackNum, static_cast<unsigned int>(unpackDimSizes.size()));
2644 for (
unsigned int j = 0; j < unpackNum; ++j)
2647 for (
unsigned int dimIdx = 0; dimIdx < unpackDimSizes.size(); ++dimIdx)
2649 splitDesc.
SetViewSize(j, dimIdx, unpackDimSizes[dimIdx]);
2654 auto layerName = fmt::format(
"Unpack:{}:{}", subgraphIndex, operatorIndex);
2655 IConnectableLayer* layer = m_Network->AddSplitterLayer(splitDesc, layerName.c_str());
2659 unpackDimSizes.data());
2661 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2662 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
2668 std::string reshapeLayerName = fmt::format(
"Reshape_for:{}", layer->
GetName());
2683 RegisterProducerOfTensor(subgraphIndex, reshapedOutputId, slot);
2687 void TfLiteParserImpl::ParseSplit(
size_t subgraphIndex,
size_t operatorIndex)
2689 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2691 const auto & operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
2692 const auto * options = operatorPtr->builtin_options.AsSplitOptions();
2699 throw ParseException(
"Number to splits must greater than zero.");
2702 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2704 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2712 if (axisBufferPtr ==
nullptr)
2715 fmt::format(
"Operation has invalid inputs. Failed to read axis. {}",
2720 ::memcpy(axisData.data(), axisBufferPtr->data.data(), axisTensorInfo.
GetNumBytes());
2721 int32_t axis = axisData[0];
2723 auto inputDimensions =
static_cast<int32_t
>(inputTensorInfo.GetNumDimensions());
2724 if (((axis < -inputDimensions) && (axis < 0)) || ((axis >= inputDimensions) && (axis > 0)))
2730 fmt::format(
"Operation has invalid axis: {}. Axis must be in range [-n, n) {}",
2737 auto inputDimSize = inputTensorInfo.GetNumDimensions();
2741 fmt::format(
"The number of dimensions: {} for input tensors of the split op cannot be greater than {} {}",
2742 inputTensorInfo.GetNumDimensions(),
2747 std::vector<unsigned int> splitterDimSizes(inputDimSize);
2750 for (
unsigned int i = 0; i < inputDimSize; ++i)
2752 splitterDimSizes[i] = inputTensorInfo.GetShape()[i];
2755 if (splitterDimSizes[splitDim] % numSplits != 0)
2757 throw ParseException(
"Number of splits must evenly divide the dimension");
2759 splitterDimSizes[splitDim] /= numSplits;
2762 for (
unsigned int j = 0; j < numSplits; ++j)
2765 for (
unsigned int dimIdx = 0; dimIdx < splitterDimSizes.size(); ++dimIdx)
2767 splitDesc.
SetViewSize(j, dimIdx, splitterDimSizes[dimIdx]);
2772 auto layerName = fmt::format(
"Split:{}:{}", subgraphIndex, operatorIndex);
2773 IConnectableLayer* layer = m_Network->AddSplitterLayer(splitDesc, layerName.c_str());
2776 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2777 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[1]});
2785 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2786 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, outputTensorIndexes);
2792 int v = idx < 0 ? numDims + idx : idx;
2796 return static_cast<unsigned int>(v);
2799 void TfLiteParserImpl::ParseSplitV(
size_t subgraphIndex,
size_t operatorIndex)
2801 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2803 const auto & operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
2804 const auto * options = operatorPtr->builtin_options.AsSplitVOptions();
2806 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2809 auto& inputTensor = inputs[0];
2810 auto& splitsTensor = inputs[1];
2811 auto& axisTensor = inputs[2];
2823 fmt::format(
"The number of dimensions: {} for input tensors of the " 2824 "SplitV op cannot be greater than {} {}",
2832 if (axisBufferPtr ==
nullptr)
2835 fmt::format(
"Operation has invalid inputs. Failed to read axis. {}",
2840 ::memcpy(axisData.data(), axisBufferPtr->data.data(), axisTensorInfo.
GetNumBytes());
2841 int32_t axis = axisData[0];
2843 auto inputDimensions =
static_cast<int32_t
>(inputTensorInfo.
GetNumDimensions());
2844 if (((axis < -inputDimensions) && (axis < 0)) || ((axis >= inputDimensions) && (axis > 0)))
2850 fmt::format(
"Operation has invalid axis: {}. Axis must be in range [-n, n) {}",
2858 unsigned int numSplits{0};
2874 std::vector<int> splitsData(numSplits);
2876 ::memcpy(splitsData.data(), splitsBufferPtr->data.data(), splitsInfo.
GetNumBytes());
2878 unsigned int idx = 0;
2880 unsigned int inferIdx{0};
2882 for (
auto split : splitsData)
2896 if (numInferred == 0)
2898 if (splitSum != armnn::numeric_cast<int>(inputTensorInfo.
GetShape()[splitDim]))
2900 throw ParseException(
"SplitV split_sizes does not sum to the dimension of value along split_dim.");
2903 else if (numInferred == 1)
2909 throw ParseException(
"Cannot infer split size for more than one split");
2913 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2918 unsigned int accumSplit = 0;
2919 for (
unsigned int j = 0; j < numSplits; ++j)
2924 for (
unsigned int dimIdx = 0; dimIdx < inputTensorInfo.
GetNumDimensions(); ++dimIdx)
2926 unsigned int dimSize = inputTensorInfo.
GetShape()[dimIdx];
2927 if (dimIdx == splitDim)
2929 dimSize = splitSize;
2931 splitDesc.SetViewSize(j, dimIdx, dimSize);
2934 splitDesc.SetViewOriginCoord(j, splitDim, accumSplit);
2935 accumSplit += splitSize;
2938 auto layerName = fmt::format(
"SplitV:{}:{}", subgraphIndex, operatorIndex);
2939 IConnectableLayer* layer = m_Network->AddSplitterLayer(splitDesc, layerName.c_str());
2942 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
2943 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
2951 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
2952 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, outputTensorIndexes);
2955 void TfLiteParserImpl::ParseArgMin(
size_t subgraphIndex,
size_t operatorIndex)
2960 void TfLiteParserImpl::ParseArgMax(
size_t subgraphIndex,
size_t operatorIndex)
2965 void TfLiteParserImpl::ParseArgMinMax(
size_t subgraphIndex,
size_t operatorIndex,
ArgMinMaxFunction argMinMaxFunction)
2967 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2968 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
2971 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
2985 "Output tensor data type is not supported. (Supported types: Signed32 & Signed64) {}",
2991 if (axisBufferPtr ==
nullptr)
2994 fmt::format(
"Operation has invalid inputs. Failed to read axis. {}",
2999 ::memcpy(axisData.data(), axisBufferPtr->data.data(), axisTensorInfo.
GetNumBytes());
3000 int32_t axis = axisData.front();
3002 auto inputDimensions =
static_cast<int32_t
>(inputTensorInfo.GetNumDimensions());
3003 if (((axis < -inputDimensions) && (axis < 0)) || ((axis >= inputDimensions) && (axis > 0)))
3009 fmt::format(
"Operation has invalid axis: {}. Axis must be in range [-n, n) {}",
3019 auto layerName = argMinMaxFunction == ArgMinMaxFunction::Max ?
"ArgMax:{}:{}" :
"ArgMin:{}:{}";
3020 auto layerNameFormatted = fmt::format(layerName, subgraphIndex, operatorIndex);
3021 IConnectableLayer *layer = m_Network->AddArgMinMaxLayer(desc, layerNameFormatted.c_str());
3026 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
3027 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
3030 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
3031 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, outputTensorIndexes);
3034 void TfLiteParserImpl::ParseGather(
size_t subgraphIndex,
size_t operatorIndex)
3036 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
3049 const auto & operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
3050 const auto * options = operatorPtr->builtin_options.AsGatherOptions();
3051 auto axis = options->axis;
3053 auto inputDimensions =
static_cast<int32_t
>(inputTensorInfo.GetNumDimensions());
3056 if (((axis < -inputDimensions) && (axis < 0)) || ((axis >= inputDimensions) && (axis > 0)))
3059 fmt::format(
"Operation has invalid axis: {} It is out of bounds [ -{}, {} ) {}",
3061 inputDimensions, inputDimensions,
3064 if (outputDimensions != static_cast<unsigned int>(inputDimensions) + indicesDimensions - 1)
3067 fmt::format(
"Operation has invalid output dimensions: {} Output must be an ({} + {} - 1) -D tensor {}",
3069 inputDimensions, indicesDimensions,
3073 gatherDescriptor.
m_Axis = axis;
3075 auto layerName = fmt::format(
"Gather:{}:{}", subgraphIndex, operatorIndex);
3076 IConnectableLayer* layer = m_Network->AddGatherLayer(gatherDescriptor, layerName.c_str());
3080 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
3081 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0], inputTensorIndexes[1]});
3083 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
3084 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
3087 void TfLiteParserImpl::ParseDepthToSpace(
size_t subgraphIndex,
size_t operatorIndex)
3089 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
3098 const auto & operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
3099 const auto * options = operatorPtr->builtin_options.AsDepthToSpaceOptions();
3100 auto blockSize = options->block_size;
3104 fmt::format(
"Operation has invalid block size: {} Block size should be >= 2 {}",
3110 auto layerName = fmt::format(
"DepthToSpace:{}:{}", subgraphIndex, operatorIndex);
3111 IConnectableLayer* layer = m_Network->AddDepthToSpaceLayer(descriptor, layerName.c_str());
3116 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
3117 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
3119 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
3120 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
3123 void TfLiteParserImpl::ParseSum(
size_t subgraphIndex,
size_t operatorIndex)
3128 void TfLiteParserImpl::ParseReduceMax(
size_t subgraphIndex,
size_t operatorIndex)
3133 void TfLiteParserImpl::ParseReduceMin(
size_t subgraphIndex,
size_t operatorIndex)
3138 void TfLiteParserImpl::ParseReduce(
size_t subgraphIndex,
size_t operatorIndex,
ReduceOperation reduceOperation)
3140 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
3142 const auto &operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
3143 const auto *options = operatorPtr->builtin_options.AsReducerOptions();
3145 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
3148 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
3151 auto layerName = fmt::format(
"Reduce:{}:{}", subgraphIndex, operatorIndex);
3159 if (axisBufferPtr !=
nullptr)
3161 std::vector<int32_t> axisData(inputTensorInfo1.
GetNumElements());
3162 ::memcpy(axisData.data(), axisBufferPtr->data.data(), inputTensorInfo1.
GetNumBytes());
3166 std::set<unsigned int> uniqueAxis;
3167 std::transform(axisData.begin(),
3169 std::inserter(uniqueAxis, uniqueAxis.begin()),
3170 [rank](
int i)->unsigned
int{
3171 return static_cast<uint32_t
>(((i + rank) % rank)); });
3172 desc.
m_vAxis.assign(uniqueAxis.begin(), uniqueAxis.end());
3192 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
3193 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
3196 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
3197 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, outputTensorIndexes);
3200 void TfLiteParserImpl::ParseAbs(
size_t subgraphIndex,
size_t operatorIndex)
3205 void TfLiteParserImpl::ParseExp(
size_t subgraphIndex,
size_t operatorIndex)
3210 void TfLiteParserImpl::ParseLogicalNot(
size_t subgraphIndex,
size_t operatorIndex)
3215 void TfLiteParserImpl::ParseNeg(
size_t subgraphIndex,
size_t operatorIndex)
3220 void TfLiteParserImpl::ParseRsqrt(
size_t subgraphIndex,
size_t operatorIndex)
3225 void TfLiteParserImpl::ParseElementwiseUnary(
size_t subgraphIndex,
size_t operatorIndex,
UnaryOperation unaryOperation)
3227 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
3229 auto inputs =
GetInputs(m_Model, subgraphIndex, operatorIndex);
3232 auto outputs =
GetOutputs(m_Model, subgraphIndex, operatorIndex);
3236 std::string layerNameFormatted = fmt::format(layerName, subgraphIndex, operatorIndex);
3240 IConnectableLayer* layer = m_Network->AddElementwiseUnaryLayer(desc, layerNameFormatted.c_str());
3246 auto inputTensorIndexes = AsUnsignedVector(
GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
3247 RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
3249 auto outputTensorIndexes = AsUnsignedVector(
GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
3250 RegisterOutputSlots(subgraphIndex, operatorIndex, layer, outputTensorIndexes);
3254 unsigned int outputSlot,
3255 tflite::ActivationFunctionType activationType)
3258 std::string layerName = prevLayer->
GetName();
3260 switch(activationType)
3262 case tflite::ActivationFunctionType_NONE:
3267 case tflite::ActivationFunctionType_RELU:
3269 activationDesc.
m_Function = ActivationFunction::ReLu;
3270 layerName +=
":RELU";
3273 case tflite::ActivationFunctionType_RELU6:
3275 activationDesc.
m_Function = ActivationFunction::BoundedReLu;
3276 activationDesc.
m_A = 6.0f;
3277 activationDesc.
m_B = 0.0f;
3278 layerName +=
":RELU6";
3281 case tflite::ActivationFunctionType_TANH:
3283 activationDesc.
m_Function = ActivationFunction::TanH;
3284 activationDesc.
m_A = 1.0f;
3285 activationDesc.
m_B = 1.0f;
3286 layerName +=
":TANH";
3291 case tflite::ActivationFunctionType_RELU_N1_TO_1:
3292 case tflite::ActivationFunctionType_SIGN_BIT:
3296 fmt::format(
"TfLite parser doesn't suppport fused activation: " 3299 tflite::EnumNameActivationFunctionType(activationType),
3306 m_Network->AddActivationLayer(activationDesc, layerName.c_str());
3308 auto & prevOutputSlot = prevLayer->
GetOutputSlot(outputSlot);
3311 return activationLayer;
3316 if (fileName ==
nullptr)
3321 std::error_code errorCode;
3322 fs::path pathToFile(fileName);
3323 if (!fs::exists(pathToFile, errorCode))
3326 std::stringstream msg;
3327 msg <<
"Cannot find the file (" << fileName <<
") errorCode: " << errorCode
3332 std::ifstream file(fileName, std::ios::binary);
3333 std::string fileContent((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
3335 fileContent.size());
3340 if (binaryContent ==
nullptr)
3345 flatbuffers::Verifier verifier(binaryContent, len);
3346 if (verifier.VerifyBuffer<tflite::Model>() ==
false)
3349 fmt::format(
"Buffer doesn't conform to the expected Tensorflow Lite " 3350 "flatbuffers format. size:{} {}",
3354 return tflite::UnPackModel(binaryContent);
3358 size_t subgraphIndex,
3359 size_t operatorIndex)
3363 const auto & subgraphPtr = model->subgraphs[subgraphIndex];
3364 const auto & operatorPtr = subgraphPtr->operators[operatorIndex];
3366 size_t inputCount = operatorPtr->inputs.size();
3368 for (
size_t i=0; i<inputCount; ++i)
3371 if (operatorPtr->inputs[i] == -1)
3378 result.push_back(subgraphPtr->tensors[inputId].get());
3385 size_t subgraphIndex,
3386 size_t operatorIndex)
3390 const auto & subgraphPtr = model->subgraphs[subgraphIndex];
3391 const auto & operatorPtr = subgraphPtr->operators[operatorIndex];
3393 size_t outputCount = operatorPtr->outputs.size();
3395 for (
size_t i=0; i<outputCount; ++i)
3399 result[i] = subgraphPtr->tensors[outputId].get();
3405 size_t subgraphIndex)
3408 const auto & subgraphPtr = model->subgraphs[subgraphIndex];
3410 size_t inputCount = subgraphPtr->inputs.size();
3412 for (
size_t i=0; i<inputCount; ++i)
3416 result[i] = std::make_pair(inputId, subgraphPtr->tensors[inputId].get());
3422 size_t subgraphIndex)
3425 const auto & subgraphPtr = model->subgraphs[subgraphIndex];
3427 size_t outputCount = subgraphPtr->outputs.size();
3429 for (
size_t i=0; i<outputCount; ++i)
3432 result[i] = std::make_pair(outputId, subgraphPtr->tensors[outputId].get());
3438 size_t subgraphIndex,
3439 size_t operatorIndex)
3442 const auto & subgraphPtr = model->subgraphs[subgraphIndex];
3443 const auto & operatorPtr = subgraphPtr->operators[operatorIndex];
3444 return operatorPtr->inputs;
3448 size_t subgraphIndex,
3449 size_t operatorIndex)
3452 const auto & subgraphPtr = model->subgraphs[subgraphIndex];
3453 const auto & operatorPtr = subgraphPtr->operators[operatorIndex];
3454 return operatorPtr->outputs;
3457 void TfLiteParserImpl::RegisterInputSlots(
size_t subgraphIndex,
3458 size_t operatorIndex,
3460 const std::vector<unsigned int>& tensorIndexes,
3461 unsigned int startingSlotIndex)
3463 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
3468 fmt::format(
"The number of tensor inputs ({}) does not match the number expected ({})" 3469 " for subgraph:{} operator index:{} {}",
3470 tensorIndexes.size(),
3477 for (
unsigned int index = 0; index < tensorIndexes.size() ; ++index)
3479 unsigned int tensorIndex = tensorIndexes[index];
3481 RegisterConsumerOfTensor(subgraphIndex, tensorIndex, slot);
3485 void TfLiteParserImpl::RegisterOutputSlots(
size_t subgraphIndex,
3486 size_t operatorIndex,
3488 const std::vector<unsigned int>& tensorIndexes)
3490 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
3495 fmt::format(
"The number of tensor outputs ({}) does not match the number expected ({})" 3496 " for subgraph:{} operator index:{} {}",
3497 tensorIndexes.size(),
3504 for (
unsigned int slotIndex = 0; slotIndex < layer->
GetNumOutputSlots(); ++slotIndex)
3506 unsigned int tensorIndex = tensorIndexes[slotIndex];
3508 RegisterProducerOfTensor(subgraphIndex, tensorIndex, slot);
3512 void TfLiteParserImpl::SetupInputLayers(
size_t subgraphIndex)
3517 for (
auto const & tensorIdAndPtr : inputs)
3519 auto bindingId = GenerateLayerBindingId(subgraphIndex, tensorIdAndPtr.first);
3521 m_Network->AddInputLayer(bindingId, tensorIdAndPtr.second->name.c_str());
3526 RegisterOutputSlots(subgraphIndex,
3527 VIRTUAL_OPERATOR_ID,
3529 {
static_cast<uint32_t
>(tensorIdAndPtr.first) });
3533 void TfLiteParserImpl::SetupOutputLayers(
size_t subgraphIndex)
3538 for (
auto const & tensorIdAndPtr : outputs)
3540 auto bindingId = GenerateLayerBindingId(subgraphIndex, tensorIdAndPtr.first);
3542 m_Network->AddOutputLayer(bindingId, tensorIdAndPtr.second->name.c_str());
3544 RegisterInputSlots(subgraphIndex,
3545 VIRTUAL_OPERATOR_ID,
3547 {
static_cast<uint32_t
>(tensorIdAndPtr.first) });
3551 void TfLiteParserImpl::SetupConstantLayers(
size_t subgraphIndex)
3555 const auto & subgraphPtr = m_Model->subgraphs[subgraphIndex];
3556 for (
unsigned int subgraphIndex = 0; subgraphIndex < m_SubgraphConnections.size(); ++subgraphIndex)
3558 for (
unsigned int tensorIndex = 0; tensorIndex < m_SubgraphConnections[subgraphIndex].size(); ++tensorIndex)
3560 if (m_SubgraphConnections[subgraphIndex][tensorIndex].outputSlot ==
nullptr &&
3561 m_SubgraphConnections[subgraphIndex][tensorIndex].inputSlots.size() > 0)
3563 TensorRawPtr tensorPtr = subgraphPtr->tensors[tensorIndex].get();
3565 auto tensorAndData = CreateConstTensorNonPermuted(tensorPtr, tensorInfo);
3567 std::string layerName = fmt::format(
"Constant:{}", tensorPtr->name);
3569 m_Network->AddConstantLayer(tensorAndData, layerName.c_str());
3572 RegisterOutputSlots(subgraphIndex,
3573 VIRTUAL_OPERATOR_ID,
3586 return model->buffers[bufferIndex].get();
3589 template<
typename T>
3590 std::pair<armnn::ConstTensor, TfLiteParserImpl::SupportedDataStorage>
3596 auto constData = CreateConstTensorImpl<T>(bufferPtr,
3600 TfLiteParserImpl::SupportedDataStorage storage(std::move(constData.second));
3601 return std::make_pair(constData.first, std::move(storage));
3604 bool TfLiteParserImpl::IsConstTensor(
TensorRawPtr tensorPtr)
3607 bool isConst =
true;
3609 auto buffer =
GetBuffer(m_Model, tensorPtr->buffer);
3610 if (buffer->data.size() == 0)
3619 std::pair<armnn::ConstTensor, TfLiteParserImpl::SupportedDataStorage>
3620 TfLiteParserImpl::CreateConstTensorPermuted(
TensorRawPtr tensorPtr,
3625 auto bufferPtr =
GetBuffer(m_Model, tensorPtr->buffer);
3631 return CreateConstTensorAndStoreData<float>(bufferPtr,
3636 return CreateConstTensorAndStoreData<uint8_t>(bufferPtr,
3641 return CreateConstTensorAndStoreData<int8_t>(bufferPtr,
3646 return CreateConstTensorAndStoreData<int8_t>(bufferPtr,
3651 return CreateConstTensorAndStoreData<int32_t>(bufferPtr,
3657 std::stringstream errString;
3658 errString <<
"Unexpected datatype when creating const tensor: " 3660 <<
" shape:" << tensorInfo.GetShape()
3671 auto bufferPtr =
GetBuffer(m_Model, tensorPtr->buffer);
3674 return ConstTensor(tensorInfo, bufferPtr->data.data());
3678 const std::string& name)
const 3682 for (
auto const & input : inputs)
3684 if (input.second->name == name)
3686 auto bindingId = GenerateLayerBindingId(subgraphId, input.first);
3687 return std::make_pair(bindingId,
ToTensorInfo(input.second));
3691 std::stringstream bindings;
3692 for (
auto const & input : inputs)
3694 bindings <<
"'" << input.second->name <<
"' ";
3698 fmt::format(
"No input binding found for subgraph:{} and name:{}. " 3699 "Possible inputs are: [{}] {}",
3707 const std::string& name)
const 3711 for (
unsigned int i = 0; i < outputs.size(); ++i)
3713 auto const output = outputs[i];
3714 if (output.second->name == name)
3716 auto bindingId = GenerateLayerBindingId(subgraphId, output.first);
3717 std::vector<unsigned int> shape = m_OverridenOutputShapes.size() > 0 ?
3718 m_OverridenOutputShapes[i] : AsUnsignedVector(output.second->shape);
3719 return std::make_pair(bindingId,
ToTensorInfo(output.second, shape));
3723 std::stringstream bindings;
3724 for (
auto const & output : outputs)
3726 bindings <<
"'" << output.second->name <<
"' ";
3730 fmt::format(
"No output binding found for subgraph:{} and name:{}. " 3731 "Possible outputs are: [{}] {}",
3740 return m_Model->subgraphs.size();
3747 std::vector<std::string> result;
3748 result.reserve(inputs.size());
3749 for (
auto const & input : inputs)
3751 result.push_back(input.second->name);
3760 std::vector<std::string> result;
3761 result.reserve(outputs.size());
3762 for (
auto const & output : outputs)
3764 result.push_back(output.second->name);
3774 TfLiteParserImpl::SupportedDataStorage::SupportedDataStorage(std::unique_ptr<
float[]> && data)
3775 : m_FloatData(std::move(data))
3776 , m_Uint8Data(
nullptr)
3777 , m_Int8Data(
nullptr)
3778 , m_Int32Data(
nullptr)
3782 TfLiteParserImpl::SupportedDataStorage::SupportedDataStorage(std::unique_ptr<uint8_t[]> && data)
3783 : m_FloatData(
nullptr)
3784 , m_Uint8Data(std::move(data))
3785 , m_Int8Data(
nullptr)
3786 , m_Int32Data(
nullptr)
3790 TfLiteParserImpl::SupportedDataStorage::SupportedDataStorage(std::unique_ptr<int8_t[]> && data)
3791 : m_FloatData(
nullptr)
3792 , m_Uint8Data(
nullptr)
3793 , m_Int8Data(std::move(data))
3794 , m_Int32Data(
nullptr)
3798 TfLiteParserImpl::SupportedDataStorage::SupportedDataStorage(std::unique_ptr<int32_t[]> && data)
3799 : m_FloatData(
nullptr)
3800 , m_Uint8Data(
nullptr)
3801 , m_Int8Data(
nullptr)
3802 , 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.
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.
std::vector< int > m_Begin
Begin values for the input that will be sliced.
const tflite::BufferT * BufferRawPtr
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).
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.
A Convolution2dDescriptor for the Convolution2dLayer.
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
std::vector< std::string > GetSubgraphOutputTensorNames(size_t subgraphId) const
Return the output tensor names for a given subgraph.
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.
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_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
#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 ResizeDescriptor for the ResizeLayer.
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.
void CheckTensor(const ConstTensor &t)
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)
static armnn::TensorInfo OutputShapeOfSqueeze(const std::vector< uint32_t > &squeezeDims, const armnn::TensorInfo &inputTensorInfo)
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.
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.
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.
An ActivationDescriptor for the ActivationLayer.
uint32_t m_NumInputs
Number of input tensors.
A SliceDescriptor for the SliceLayer.
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
std::unique_ptr< tflite::SubGraphT > SubgraphPtr
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.
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)
Struct for the users to pass backend specific options.
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)
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.
unsigned int GetNumDimensions() const
Function that returns the tensor rank.
OutputShapeRounding m_OutputShapeRounding
The rounding method for the output shape. (Floor, Ceiling).
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.
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
A Pooling2dDescriptor for the Pooling2dLayer.
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)
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.
DataLayout::NCHW DataLayout::NCHW DataLayout::NHWC DataLayout::NHWC true
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_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.