diff options
author | Tracy Narine <tracy.narine@arm.com> | 2023-07-13 16:50:54 +0100 |
---|---|---|
committer | Tracy Narine <tracy.narine@arm.com> | 2023-07-17 14:19:36 +0100 |
commit | bb8d7591a35bd95480b39001f8b7e41a6671f3a6 (patch) | |
tree | abf2871aa1bb86378f423df405164b0d4521db3f /src/armnnTfLiteParser | |
parent | 688268328c69e7d4181cdd31fe4717c80a6d1685 (diff) | |
download | armnn-bb8d7591a35bd95480b39001f8b7e41a6671f3a6.tar.gz |
IVGCVSW-7879 Change REVERSE_V2 from LayerWithParameters with 1 input, to Layer with 2 inputs
* Changing ReverseV2 to use two inputs
* This is required by the backends
* The ReverseV2Descriptor was removed
* Tests updated
* Added a Run<> templatefor inputs with different data types
Signed-off-by: Tracy Narine <tracy.narine@arm.com>
Change-Id: I22f947de829b4b3da6bda3a74f4ffdef4052cc25
Diffstat (limited to 'src/armnnTfLiteParser')
-rw-r--r-- | src/armnnTfLiteParser/TfLiteParser.cpp | 37 | ||||
-rw-r--r-- | src/armnnTfLiteParser/test/ReverseV2.cpp | 24 |
2 files changed, 21 insertions, 40 deletions
diff --git a/src/armnnTfLiteParser/TfLiteParser.cpp b/src/armnnTfLiteParser/TfLiteParser.cpp index 078786cb93..77ce565959 100644 --- a/src/armnnTfLiteParser/TfLiteParser.cpp +++ b/src/armnnTfLiteParser/TfLiteParser.cpp @@ -3294,46 +3294,13 @@ void TfLiteParserImpl::ParseReverseV2(size_t subgraphIndex, size_t operatorIndex TensorInfo axisTensorInfo = ToTensorInfo(inputs[1]); TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); - std::vector<int32_t> axisTensorData(axisTensorInfo.GetNumElements()); - - BufferRawPtr axisBufferPtr = GetBuffer(m_Model, inputs[1]->buffer); - ::memcpy(axisTensorData.data(), axisBufferPtr->data.data(), axisTensorInfo.GetNumBytes()); - - ReverseV2Descriptor descriptor(axisTensorData); - - auto inputRank = static_cast<int32_t>(inputTensorInfo.GetNumDimensions()); - std::vector<bool> dimFlag(inputRank, false); - - for (auto axis : axisTensorData) - { - if (axis < -inputRank || axis >= inputRank) - { - throw ParseException( - fmt::format("Operation has invalid axis: {} It is out of bounds [ -{}, {} ) {}", - axis, - inputRank, inputRank, - CHECK_LOCATION().AsString())); - } - - auto posAxis = axis < 0 ? axis + inputRank : axis; - - if (dimFlag[posAxis]) - { - throw ParseException( - fmt::format("Operation has repeated axis: {} {}", - axis, - CHECK_LOCATION().AsString())); - } - dimFlag[posAxis] = true; - } - - IConnectableLayer* layer = m_Network->AddReverseV2Layer(descriptor, layerName.c_str()); + IConnectableLayer* layer = m_Network->AddReverseV2Layer(layerName.c_str()); ARMNN_ASSERT(layer != nullptr); layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); auto inputTensorIndexes = AsUnsignedVector(GetInputTensorIds(m_Model, subgraphIndex, operatorIndex)); - RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]}); + RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0], inputTensorIndexes[1]}); auto outputTensorIndexes = AsUnsignedVector(GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex)); RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]}); diff --git a/src/armnnTfLiteParser/test/ReverseV2.cpp b/src/armnnTfLiteParser/test/ReverseV2.cpp index 9604a3a1de..7dad19a40d 100644 --- a/src/armnnTfLiteParser/test/ReverseV2.cpp +++ b/src/armnnTfLiteParser/test/ReverseV2.cpp @@ -12,7 +12,6 @@ struct ReverseV2Fixture : public ParserFlatbuffersFixture explicit ReverseV2Fixture(const std::string& inputShape, const std::string& outputShape, const std::string& axisShape, - const std::string& axisData, const std::string& dataType = "FLOAT32", const std::string& scale = "1.0", const std::string& offset = "0") @@ -75,8 +74,8 @@ struct ReverseV2Fixture : public ParserFlatbuffersFixture } ], "buffers" : [ { }, - { "data": )" + axisData + R"(, }, { }, + { } ] } )"; @@ -86,15 +85,30 @@ struct ReverseV2Fixture : public ParserFlatbuffersFixture struct SimpleReverseV2Fixture : public ReverseV2Fixture { - SimpleReverseV2Fixture() : ReverseV2Fixture("[ 2, 2, 2 ]", "[ 2, 2, 2 ]", "[ 2 ]", "[ 0,0,0,0, 1,0,0,0 ]") {} + SimpleReverseV2Fixture() : ReverseV2Fixture("[ 2, 2, 2 ]", "[ 2, 2, 2 ]", "[ 2 ]" ) {} }; TEST_CASE_FIXTURE(SimpleReverseV2Fixture, "ParseReverseV2") { - RunTest<3, armnn::DataType::Float32> + RunTest<3, armnn::DataType::Float32, armnn::DataType::Signed32, armnn::DataType::Float32> (0, {{ "inputTensor", { 1, 2, 3, 4, 5, 6, 7, 8 }}}, + {{ "axis", { 0, 1 }}}, {{ "outputTensor", { 7, 8, 5, 6, 3, 4, 1, 2 }}}); } -}
\ No newline at end of file +struct SimpleReverseV2FixtureNegativeAxis : public ReverseV2Fixture +{ + SimpleReverseV2FixtureNegativeAxis() : ReverseV2Fixture("[ 2, 2, 2 ]", "[ 2, 2, 2 ]", "[ 1 ]" ) {} +}; + +TEST_CASE_FIXTURE(SimpleReverseV2FixtureNegativeAxis, "ParseReverseV2") +{ + RunTest<3, armnn::DataType::Float32, armnn::DataType::Signed32, armnn::DataType::Float32> + (0, + {{ "inputTensor", { 1, 2, 3, 4, 5, 6, 7, 8 }}}, + {{ "axis", { -1 }}}, + {{ "outputTensor", { 2, 1, 4, 3, 6, 5, 8, 7 }}}); +} + +} |