aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSadik Armagan <sadik.armagan@arm.com>2020-05-27 11:06:17 +0100
committerSadik Armagan <sadik.armagan@arm.com>2020-05-27 11:22:09 +0000
commit12239e7291fb04b862e44045be0a4feb7751af62 (patch)
tree0dd982182e0ce34ca36e13bd5e631b62f86974d1 /src
parent0729b2febd3dfb13686b5aa43c5cea090af329f6 (diff)
downloadarmnn-12239e7291fb04b862e44045be0a4feb7751af62.tar.gz
IVGCVSW-4187 Add LEAKY_RELU to TFLite parser
Signed-off-by: Nikhil Raj <nikhil.raj@arm.com> Signed-off-by: Sadik Armagan <sadik.armagan@arm.com> Change-Id: I3e934142487b92897eb487099a22d032f80e8e07
Diffstat (limited to 'src')
-rw-r--r--src/armnnTfLiteParser/TensorFlowLiteSupport.md2
-rw-r--r--src/armnnTfLiteParser/TfLiteParser.cpp13
-rw-r--r--src/armnnTfLiteParser/TfLiteParser.hpp1
-rw-r--r--src/armnnTfLiteParser/test/LeakyRelu.cpp79
4 files changed, 95 insertions, 0 deletions
diff --git a/src/armnnTfLiteParser/TensorFlowLiteSupport.md b/src/armnnTfLiteParser/TensorFlowLiteSupport.md
index b69da0a824..ff80ffc13f 100644
--- a/src/armnnTfLiteParser/TensorFlowLiteSupport.md
+++ b/src/armnnTfLiteParser/TensorFlowLiteSupport.md
@@ -26,6 +26,8 @@ The Arm NN SDK TensorFlow Lite parser currently supports the following operators
* FULLY_CONNECTED, Supported Fused Activation: RELU , RELU6 , TANH, NONE
+* LEAKY_RELU
+
* LOGISTIC
* L2_NORMALIZATION
diff --git a/src/armnnTfLiteParser/TfLiteParser.cpp b/src/armnnTfLiteParser/TfLiteParser.cpp
index dcdae34872..f4f675ea98 100644
--- a/src/armnnTfLiteParser/TfLiteParser.cpp
+++ b/src/armnnTfLiteParser/TfLiteParser.cpp
@@ -502,6 +502,7 @@ TfLiteParser::TfLiteParser(const Optional<ITfLiteParser::TfLiteParserOptions>& o
m_ParserFunctions[tflite::BuiltinOperator_DEQUANTIZE] = &TfLiteParser::ParseDequantize;
m_ParserFunctions[tflite::BuiltinOperator_EXP] = &TfLiteParser::ParseExp;
m_ParserFunctions[tflite::BuiltinOperator_FULLY_CONNECTED] = &TfLiteParser::ParseFullyConnected;
+ m_ParserFunctions[tflite::BuiltinOperator_LEAKY_RELU] = &TfLiteParser::ParseLeakyRelu;
m_ParserFunctions[tflite::BuiltinOperator_LOGISTIC] = &TfLiteParser::ParseLogistic;
m_ParserFunctions[tflite::BuiltinOperator_L2_NORMALIZATION] = &TfLiteParser::ParseL2Normalization;
m_ParserFunctions[tflite::BuiltinOperator_MAX_POOL_2D] = &TfLiteParser::ParseMaxPool2D;
@@ -1888,6 +1889,11 @@ void TfLiteParser::ParseRelu6(size_t subgraphIndex, size_t operatorIndex)
ParseActivation(subgraphIndex,operatorIndex, ActivationFunction::BoundedReLu);
}
+void TfLiteParser::ParseLeakyRelu(size_t subgraphIndex, size_t operatorIndex)
+{
+ ParseActivation(subgraphIndex,operatorIndex, ActivationFunction::LeakyReLu);
+}
+
void TfLiteParser::ParseLogistic(size_t subgraphIndex, size_t operatorIndex)
{
ParseActivation(subgraphIndex,operatorIndex,ActivationFunction::Sigmoid);
@@ -1941,6 +1947,13 @@ void TfLiteParser::ParseActivation(size_t subgraphIndex, size_t operatorIndex, A
activationDesc.m_B = 1.0f;
break;
}
+ case ActivationFunction::LeakyReLu:
+ {
+ layerName += str(boost::format("LEAKYRELU:%1%:%2%") % subgraphIndex % operatorIndex);
+ const auto * options = operatorPtr->builtin_options.AsLeakyReluOptions();
+ activationDesc.m_A = options->alpha;
+ break;
+ }
default:
{
throw ParseException(
diff --git a/src/armnnTfLiteParser/TfLiteParser.hpp b/src/armnnTfLiteParser/TfLiteParser.hpp
index 6ed6d8399c..f0f75afabd 100644
--- a/src/armnnTfLiteParser/TfLiteParser.hpp
+++ b/src/armnnTfLiteParser/TfLiteParser.hpp
@@ -104,6 +104,7 @@ private:
void ParseDetectionPostProcess(size_t subgraphIndex, size_t operatorIndex);
void ParseExp(size_t subgraphIndex, size_t operatorIndex);
void ParseFullyConnected(size_t subgraphIndex, size_t operatorIndex);
+ void ParseLeakyRelu(size_t subgraphIndex, size_t operatorIndex);
void ParseLogistic(size_t subgraphIndex, size_t operatorIndex);
void ParseL2Normalization(size_t subgraphIndex, size_t operatorIndex);
void ParseMaxPool2D(size_t subgraphIndex, size_t operatorIndex);
diff --git a/src/armnnTfLiteParser/test/LeakyRelu.cpp b/src/armnnTfLiteParser/test/LeakyRelu.cpp
new file mode 100644
index 0000000000..471c01444c
--- /dev/null
+++ b/src/armnnTfLiteParser/test/LeakyRelu.cpp
@@ -0,0 +1,79 @@
+//
+// Copyright © 2020 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include <boost/test/unit_test.hpp>
+#include "ParserFlatbuffersFixture.hpp"
+#include "../TfLiteParser.hpp"
+
+#include <string>
+#include <iostream>
+
+BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
+
+struct LeakyReluFixture : public ParserFlatbuffersFixture
+{
+ explicit LeakyReluFixture()
+ {
+ m_JsonString = R"(
+ {
+ "version": 3,
+ "operator_codes": [ { "builtin_code": "LEAKY_RELU" } ],
+ "subgraphs": [ {
+ "tensors": [
+ {
+ "shape": [ 1, 7 ],
+ "type": "FLOAT32",
+ "buffer": 0,
+ "name": "inputTensor",
+ "quantization": {
+ "min": [ 0.0 ],
+ "max": [ 255.0 ],
+ "scale": [ 1.0 ],
+ "zero_point": [ 0 ],
+ }
+ },
+ {
+ "shape": [ 1, 7 ],
+ "type": "FLOAT32",
+ "buffer": 1,
+ "name": "outputTensor",
+ "quantization": {
+ "min": [ 0.0 ],
+ "max": [ 255.0 ],
+ "scale": [ 1.0 ],
+ "zero_point": [ 0 ],
+ }
+ }
+ ],
+ "inputs": [ 0 ],
+ "outputs": [ 1 ],
+ "operators": [
+ {
+ "opcode_index": 0,
+ "inputs": [ 0 ],
+ "outputs": [ 1 ],
+ "builtin_options_type": "LeakyReluOptions",
+ "builtin_options": {
+ "alpha": 0.01
+ },
+ "custom_options_format": "FLEXBUFFERS"
+ }
+ ],
+ } ],
+ "buffers" : [ {}, {} ]
+ }
+ )";
+ SetupSingleInputSingleOutput("inputTensor", "outputTensor");
+ }
+};
+
+BOOST_FIXTURE_TEST_CASE(ParseLeakyRelu, LeakyReluFixture)
+{
+ RunTest<2, armnn::DataType::Float32>(0,
+ {{ "inputTensor", { -0.1f, -0.2f, -0.3f, -0.4f, 0.1f, 0.2f, 0.3f }}},
+ {{ "outputTensor", { -0.001f, -0.002f, -0.003f, -0.004f, 0.1f, 0.2f, 0.3f }}});
+}
+
+BOOST_AUTO_TEST_SUITE_END()