diff options
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | docs/01_parsers.dox | 1 | ||||
-rw-r--r-- | src/armnnTfLiteParser/TensorFlowLiteSupport.md | 2 | ||||
-rw-r--r-- | src/armnnTfLiteParser/TfLiteParser.cpp | 13 | ||||
-rw-r--r-- | src/armnnTfLiteParser/TfLiteParser.hpp | 1 | ||||
-rw-r--r-- | src/armnnTfLiteParser/test/LeakyRelu.cpp | 79 |
6 files changed, 97 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b9b19fc83..86fcf54636 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -775,6 +775,7 @@ if(BUILD_UNIT_TESTS) src/armnnTfLiteParser/test/Exp.cpp src/armnnTfLiteParser/test/FullyConnected.cpp src/armnnTfLiteParser/test/L2Normalization.cpp + src/armnnTfLiteParser/test/LeakyRelu.cpp src/armnnTfLiteParser/test/Maximum.cpp src/armnnTfLiteParser/test/MaxPool2D.cpp src/armnnTfLiteParser/test/Mean.cpp diff --git a/docs/01_parsers.dox b/docs/01_parsers.dox index 285641160c..ddd17eecfe 100644 --- a/docs/01_parsers.dox +++ b/docs/01_parsers.dox @@ -162,6 +162,7 @@ The Arm NN SDK TensorFlow Lite parser currently supports the following operators - FULLY_CONNECTED, Supported Fused Activation: RELU , RELU6 , TANH, NONE - LOGISTIC - L2_NORMALIZATION +- LEAKY_RELU - MAX_POOL_2D, Supported Fused Activation: RELU , RELU6 , TANH, NONE - MAXIMUM - MEAN 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() |