diff options
author | Mike Kelly <mike.kelly@arm.com> | 2021-09-01 21:22:37 +0100 |
---|---|---|
committer | Jim Flynn <jim.flynn@arm.com> | 2021-09-02 08:37:02 +0000 |
commit | 31dce2b3fa19781836a9a295b514b2ab37f5d928 (patch) | |
tree | 852770e21c4251c91ed80eddc49d2dcbc6047d61 /src/armnnTfLiteParser/TfLiteParser.cpp | |
parent | 00e9ebf026b1e2f6dbbed201ce1abe0091d6453b (diff) | |
download | armnn-31dce2b3fa19781836a9a295b514b2ab37f5d928.tar.gz |
IVGCVSW-6294 Added support for LRN to TfLiteParser
* Added support for LRN to TfLiteParser
Signed-off-by: Mike Kelly <mike.kelly@arm.com>
Change-Id: Ia34441a4adeecd1f17c65af047d6c207729703ec
Diffstat (limited to 'src/armnnTfLiteParser/TfLiteParser.cpp')
-rw-r--r-- | src/armnnTfLiteParser/TfLiteParser.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/armnnTfLiteParser/TfLiteParser.cpp b/src/armnnTfLiteParser/TfLiteParser.cpp index 2ac325c08c..5c7cb9b0b8 100644 --- a/src/armnnTfLiteParser/TfLiteParser.cpp +++ b/src/armnnTfLiteParser/TfLiteParser.cpp @@ -657,6 +657,8 @@ TfLiteParserImpl::TfLiteParserImpl(const Optional<ITfLiteParser::TfLiteParserOpt m_ParserFunctions[tflite::BuiltinOperator_LEAKY_RELU] = &TfLiteParserImpl::ParseLeakyRelu; m_ParserFunctions[tflite::BuiltinOperator_LESS] = &TfLiteParserImpl::ParseLess; m_ParserFunctions[tflite::BuiltinOperator_LESS_EQUAL] = &TfLiteParserImpl::ParseLessOrEqual; + m_ParserFunctions[tflite::BuiltinOperator_LOCAL_RESPONSE_NORMALIZATION] + = &TfLiteParserImpl::ParseLocalResponseNormalization; m_ParserFunctions[tflite::BuiltinOperator_LOGICAL_NOT] = &TfLiteParserImpl::ParseLogicalNot; m_ParserFunctions[tflite::BuiltinOperator_LOGISTIC] = &TfLiteParserImpl::ParseLogistic; m_ParserFunctions[tflite::BuiltinOperator_L2_NORMALIZATION] = &TfLiteParserImpl::ParseL2Normalization; @@ -3401,6 +3403,50 @@ void TfLiteParserImpl::ParseExp(size_t subgraphIndex, size_t operatorIndex) ParseElementwiseUnary(subgraphIndex, operatorIndex, armnn::UnaryOperation::Exp); } +void TfLiteParserImpl::ParseLocalResponseNormalization(size_t subgraphIndex, size_t operatorIndex) +{ + CHECK_MODEL(m_Model, subgraphIndex, operatorIndex); + + auto inputs = GetInputs(m_Model, subgraphIndex, operatorIndex); + CHECK_VALID_SIZE(inputs.size(), 1); + + auto outputs = GetOutputs(m_Model, subgraphIndex, operatorIndex); + CHECK_VALID_SIZE(outputs.size(), 1); + + auto layerName = fmt::format("LRN:{}:{}", subgraphIndex, operatorIndex); + std::string layerNameFormatted = fmt::format(layerName, subgraphIndex, operatorIndex); + + armnn::TensorInfo inputTensorInfo = ToTensorInfo(inputs[0]); + + const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex]; + const auto* options = operatorPtr->builtin_options.AsLocalResponseNormalizationOptions(); + + armnn::NormalizationDescriptor descriptor; + descriptor.m_DataLayout = armnn::DataLayout::NHWC; + descriptor.m_NormChannelType = armnn::NormalizationAlgorithmChannel::Across; + descriptor.m_NormMethodType = armnn::NormalizationAlgorithmMethod::LocalBrightness; + descriptor.m_NormSize = static_cast<uint32_t>(options->radius); + descriptor.m_K = options->bias; + descriptor.m_Alpha = options->alpha; + descriptor.m_Beta = options->beta; + + // ArmNN expects normSize to be the full size of the normalization + // window rather than the radius as in TfLite. + descriptor.m_NormSize = 1 + (2 * descriptor.m_NormSize); + + IConnectableLayer* layer = m_Network->AddNormalizationLayer(descriptor, layerNameFormatted.c_str()); + ARMNN_ASSERT(layer != nullptr); + + TensorInfo outputTensorInfo = ToTensorInfo(outputs[0], true); + layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); + + auto inputTensorIndexes = AsUnsignedVector(GetInputTensorIds(m_Model, subgraphIndex, operatorIndex)); + RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]}); + + auto outputTensorIndexes = AsUnsignedVector(GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex)); + RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]}); +} + void TfLiteParserImpl::ParseLogicalNot(size_t subgraphIndex, size_t operatorIndex) { ParseElementwiseUnary(subgraphIndex, operatorIndex, armnn::UnaryOperation::LogicalNot); |