diff options
author | Bruno Goncalves <bruno.slackware@gmail.com> | 2019-02-07 18:37:39 -0200 |
---|---|---|
committer | Les Bell <les.bell@arm.com> | 2019-02-22 13:03:09 +0000 |
commit | bbeae26a881af1e4f6690c45b2efbe2bef14c5cc (patch) | |
tree | 332404702537fd2858317fdee4dceea6afaec204 /src/armnnTfLiteParser/TfLiteParser.cpp | |
parent | 17cf71f7ca8e627d8ca7be0ba4e0a7ac6b6ccd0a (diff) | |
download | armnn-bbeae26a881af1e4f6690c45b2efbe2bef14c5cc.tar.gz |
Add sub parser to tf-lite
Change-Id: I0e63d81d95528e6c278dc5fa8b87ccc1f8798130
Signed-off-by: Bruno Goncalves <bruno.slackware@gmail.com>
Diffstat (limited to 'src/armnnTfLiteParser/TfLiteParser.cpp')
-rw-r--r-- | src/armnnTfLiteParser/TfLiteParser.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/armnnTfLiteParser/TfLiteParser.cpp b/src/armnnTfLiteParser/TfLiteParser.cpp index b45e5372ff..7ea85bb48e 100644 --- a/src/armnnTfLiteParser/TfLiteParser.cpp +++ b/src/armnnTfLiteParser/TfLiteParser.cpp @@ -431,6 +431,7 @@ TfLiteParser::TfLiteParser() m_ParserFunctions[tflite::BuiltinOperator_RESHAPE] = &TfLiteParser::ParseReshape; m_ParserFunctions[tflite::BuiltinOperator_SOFTMAX] = &TfLiteParser::ParseSoftmax; m_ParserFunctions[tflite::BuiltinOperator_SQUEEZE] = &TfLiteParser::ParseSqueeze; + m_ParserFunctions[tflite::BuiltinOperator_SUB] = &TfLiteParser::ParseSub; m_ParserFunctions[tflite::BuiltinOperator_ADD] = &TfLiteParser::ParseAdd; m_ParserFunctions[tflite::BuiltinOperator_MUL] = &TfLiteParser::ParseMul; m_ParserFunctions[tflite::BuiltinOperator_MEAN] = &TfLiteParser::ParseMean; @@ -1023,6 +1024,44 @@ void TfLiteParser::ParseSqueeze(size_t subgraphIndex, size_t operatorIndex) RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]}); } +void TfLiteParser::ParseSub(size_t subgraphIndex, size_t operatorIndex) +{ + CHECK_MODEL(m_Model, subgraphIndex, operatorIndex); + + const auto & operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex]; + const auto * options = operatorPtr->builtin_options.AsSubOptions(); + + auto inputs = GetInputs(m_Model, subgraphIndex, operatorIndex); + CHECK_VALID_SIZE(inputs.size(), 2); + + auto outputs = GetOutputs(m_Model, subgraphIndex, operatorIndex); + CHECK_VALID_SIZE(outputs.size(), 1); + + armnn::TensorInfo inputTensorInfo = ToTensorInfo(inputs[0]); + armnn::TensorInfo input1TensorInfo = ToTensorInfo(inputs[1]); + + auto layerName = boost::str(boost::format("Sub:%1%:%2%") % subgraphIndex % operatorIndex); + IConnectableLayer* layer = m_Network->AddSubtractionLayer(layerName.c_str()); + + TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); + layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); + + auto inputTensorIndexes = AsUnsignedVector(GetInputTensorIds(m_Model, subgraphIndex, operatorIndex)); + if (inputTensorInfo.GetNumDimensions() != input1TensorInfo.GetNumDimensions()) + { + AddBroadcastReshapeLayer(subgraphIndex, operatorIndex, layer); + } + else + { + RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0], inputTensorIndexes[1]}); + } + + layer = AddFusedActivationLayer(layer, 0, options->fused_activation_function); + + auto outputTensorIndexes = AsUnsignedVector(GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex)); + RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]}); +} + void TfLiteParser::ParseAdd(size_t subgraphIndex, size_t operatorIndex) { CHECK_MODEL(m_Model, subgraphIndex, operatorIndex); |