From: FrancisMurtagh Date: Thu, 20 Dec 2018 16:09:45 +0000 (+0000) Subject: IVGCVSW-2401 & IVGCVSW-2402 Add end-to-end test for Greater/Equal Operator X-Git-Tag: submit/tizen/20200316.035456~983 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2262bbd746907b28f5a5c2f36c153503884a8b8f;p=platform%2Fupstream%2Farmnn.git IVGCVSW-2401 & IVGCVSW-2402 Add end-to-end test for Greater/Equal Operator * Add Arithmetic end-to-end test implementation * Enable tests for float, Uint8 and Broadcast Change-Id: I81c7096e9b6ad29eaa935b74ad5f30f823be2331 --- diff --git a/src/backends/backendsCommon/test/ArithmeticTestImpl.hpp b/src/backends/backendsCommon/test/ArithmeticTestImpl.hpp new file mode 100644 index 0000000..f70bf48 --- /dev/null +++ b/src/backends/backendsCommon/test/ArithmeticTestImpl.hpp @@ -0,0 +1,105 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// +#pragma once + +#include + +#include + +#include + +#include + +namespace +{ + +template +INetworkPtr CreateArithmeticNetwork(const std::vector& inputShapes, + const TensorShape& outputShape, + const LayerType type, + const float qScale = 1.0f, + const int32_t qOffset = 0) +{ + using namespace armnn; + + // Builds up the structure of the network. + INetworkPtr net(INetwork::Create()); + + IConnectableLayer* arithmeticLayer = nullptr; + + switch(type){ + case LayerType::Equal: arithmeticLayer = net->AddEqualLayer("equal"); break; + case LayerType::Greater: arithmeticLayer = net->AddGreaterLayer("greater"); break; + default: BOOST_TEST_FAIL("Non-Arithmetic layer type called."); + } + + for (unsigned int i = 0; i < inputShapes.size(); ++i) + { + TensorInfo inputTensorInfo(inputShapes[i], DataType, qScale, qOffset); + IConnectableLayer* input = net->AddInputLayer(boost::numeric_cast(i)); + Connect(input, arithmeticLayer, inputTensorInfo, 0, i); + } + + TensorInfo outputTensorInfo(outputShape, DataType, qScale, qOffset); + IConnectableLayer* output = net->AddOutputLayer(0, "output"); + Connect(arithmeticLayer, output, outputTensorInfo, 0, 0); + + return net; +} + +template +void ArithmeticSimpleEndToEnd(const std::vector& backends, + const LayerType type, + const std::vector expectedOutput) +{ + using namespace armnn; + + const std::vector inputShapes{{ 2, 2, 2, 2 }, { 2, 2, 2, 2 }}; + const TensorShape& outputShape = { 2, 2, 2, 2 }; + + // Builds up the structure of the network + INetworkPtr net = CreateArithmeticNetwork()>(inputShapes, outputShape, type); + + BOOST_TEST_CHECKPOINT("create a network"); + + const std::vector input0({ 1, 1, 1, 1, 5, 5, 5, 5, + 3, 3, 3, 3, 4, 4, 4, 4 }); + + const std::vector input1({ 1, 1, 1, 1, 3, 3, 3, 3, + 5, 5, 5, 5, 4, 4, 4, 4 }); + + std::map> inputTensorData = {{ 0, input0 }, { 1, input1 }}; + std::map> expectedOutputData = {{ 0, expectedOutput }}; + + EndToEndLayerTestImpl(move(net), inputTensorData, expectedOutputData, backends); +} + +template +void ArithmeticBroadcastEndToEnd(const std::vector& backends, + const LayerType type, + const std::vector expectedOutput) +{ + using namespace armnn; + + const std::vector inputShapes{{ 1, 2, 2, 3 }, { 1, 1, 1, 3 }}; + const TensorShape& outputShape = { 1, 2, 2, 3 }; + + // Builds up the structure of the network + INetworkPtr net = CreateArithmeticNetwork()>(inputShapes, outputShape, type); + + BOOST_TEST_CHECKPOINT("create a network"); + + const std::vector input0({ 1, 2, 3, 1, 0, 6, + 7, 8, 9, 10, 11, 12 }); + + const std::vector input1({ 1, 1, 3 }); + + std::map> inputTensorData = {{ 0, input0 }, { 1, input1 }}; + std::map> expectedOutputData = {{ 0, expectedOutput }}; + + EndToEndLayerTestImpl(move(net), inputTensorData, expectedOutputData, backends); +} + +} // anonymous namespace diff --git a/src/backends/reference/test/RefEndToEndTests.cpp b/src/backends/reference/test/RefEndToEndTests.cpp index 8ad6f5a..9a4e601 100644 --- a/src/backends/reference/test/RefEndToEndTests.cpp +++ b/src/backends/reference/test/RefEndToEndTests.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -311,6 +312,69 @@ BOOST_AUTO_TEST_CASE(TrivialMin) BOOST_TEST(outputData[3] == 2); } +BOOST_AUTO_TEST_CASE(RefEqualSimpleEndToEndTest) +{ + const std::vector expectedOutput({ 1, 1, 1, 1, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 1, 1, 1 }); + + ArithmeticSimpleEndToEnd(defaultBackends, LayerType::Equal, expectedOutput); +} + +BOOST_AUTO_TEST_CASE(RefGreaterSimpleEndToEndTest) +{ + const std::vector expectedOutput({ 0, 0, 0, 0, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0 }); + + ArithmeticSimpleEndToEnd(defaultBackends, LayerType::Greater, expectedOutput); +} + +BOOST_AUTO_TEST_CASE(RefEqualSimpleEndToEndUint8Test) +{ + const std::vector expectedOutput({ 1, 1, 1, 1, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 1, 1, 1 }); + + ArithmeticSimpleEndToEnd(defaultBackends, LayerType::Equal, expectedOutput); +} + +BOOST_AUTO_TEST_CASE(RefGreaterSimpleEndToEndUint8Test) +{ + const std::vector expectedOutput({ 0, 0, 0, 0, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0 }); + + ArithmeticSimpleEndToEnd(defaultBackends, LayerType::Greater, expectedOutput); +} + +BOOST_AUTO_TEST_CASE(RefEqualBroadcastEndToEndTest) +{ + const std::vector expectedOutput({ 1, 0, 1, 1, 0, 0, + 0, 0, 0, 0, 0, 0 }); + + ArithmeticBroadcastEndToEnd(defaultBackends, LayerType::Equal, expectedOutput); +} + +BOOST_AUTO_TEST_CASE(RefGreaterBroadcastEndToEndTest) +{ + const std::vector expectedOutput({ 0, 1, 0, 0, 0, 1, + 1, 1, 1, 1, 1, 1 }); + + ArithmeticBroadcastEndToEnd(defaultBackends, LayerType::Greater, expectedOutput); +} + +BOOST_AUTO_TEST_CASE(RefEqualBroadcastEndToEndUint8Test) +{ + const std::vector expectedOutput({ 1, 0, 1, 1, 0, 0, + 0, 0, 0, 0, 0, 0 }); + + ArithmeticBroadcastEndToEnd(defaultBackends, LayerType::Equal, expectedOutput); +} + +BOOST_AUTO_TEST_CASE(RefGreaterBroadcastEndToEndUint8Test) +{ + const std::vector expectedOutput({ 0, 1, 0, 0, 0, 1, + 1, 1, 1, 1, 1, 1 }); + + ArithmeticBroadcastEndToEnd(defaultBackends, LayerType::Greater, expectedOutput); +} BOOST_AUTO_TEST_CASE(RefMergerEndToEndDim0Test) {