From e242f2dc646f41e9162aaaf74e057ce39fcb92df Mon Sep 17 00:00:00 2001 From: Jim Flynn Date: Wed, 22 May 2019 14:24:13 +0100 Subject: IVGCVSW-3119 Rename MergerLayer to ConcatLayer !android-nn-driver:1210 Change-Id: I940b3b9e421c92bfd55ae996f7bc54ac077f2604 Signed-off-by: Jim Flynn --- .../backendsCommon/test/ConcatTestImpl.hpp | 307 +++++++++++++++++++++ 1 file changed, 307 insertions(+) create mode 100644 src/backends/backendsCommon/test/ConcatTestImpl.hpp (limited to 'src/backends/backendsCommon/test/ConcatTestImpl.hpp') diff --git a/src/backends/backendsCommon/test/ConcatTestImpl.hpp b/src/backends/backendsCommon/test/ConcatTestImpl.hpp new file mode 100644 index 0000000000..ded3857282 --- /dev/null +++ b/src/backends/backendsCommon/test/ConcatTestImpl.hpp @@ -0,0 +1,307 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// +#pragma once + +#include "CommonTestUtils.hpp" + +#include + +#include + +#include + +#include + +namespace +{ + +template +INetworkPtr CreateConcatNetwork(const std::vector& inputShapes, + const TensorShape &outputShape, + unsigned int concatAxis, + const float qScale = 1.0f, + const int32_t qOffset = 0) +{ + using namespace armnn; + // Builds up the structure of the network. + INetworkPtr net(INetwork::Create()); + + OriginsDescriptor descriptor; + + descriptor = CreateDescriptorForConcatenation(inputShapes.begin(), + inputShapes.end(), + concatAxis); + IConnectableLayer* concat = net->AddConcatLayer(descriptor, "concat"); + + 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, concat, inputTensorInfo, 0, i); + } + + TensorInfo outputTensorInfo(outputShape, DataType, qScale, qOffset); + IConnectableLayer* output = net->AddOutputLayer(0, "output"); + Connect(concat, output, outputTensorInfo, 0, 0); + + return net; +} + +template +void ConcatDim0EndToEnd(const std::vector& backends) +{ + using namespace armnn; + using T = ResolveType; + + unsigned int concatAxis = 0; + const std::vector inputShapes{{ 2, 3, 2, 2 }, { 2, 3, 2, 2 }}; + const TensorShape& outputShape = { 4, 3, 2, 2 }; + + // Builds up the structure of the network + INetworkPtr net = CreateConcatNetwork(inputShapes, outputShape, concatAxis); + + BOOST_TEST_CHECKPOINT("create a network"); + + // Creates structures for input & output. + std::vector inputData{ + 1, 2, + 3, 4, + 5, 6, + 7, 8, + 9, 10, + 11, 12, + 1, 2, + 3, 4, + 5, 6, + 7, 8, + 9, 10, + 11, 12 + }; + + std::vector expectedOutput{ + 1, 2, + 3, 4, + 5, 6, + 7, 8, + 9, 10, + 11, 12, + 1, 2, + 3, 4, + 5, 6, + 7, 8, + 9, 10, + 11, 12, + 1, 2, + 3, 4, + 5, 6, + 7, 8, + 9, 10, + 11, 12, + 1, 2, + 3, 4, + 5, 6, + 7, 8, + 9, 10, + 11, 12 + }; + + std::map> inputTensorData = {{ 0,inputData }, { 1,inputData }}; + std::map> expectedOutputData = {{ 0,expectedOutput }}; + + EndToEndLayerTestImpl(move(net), inputTensorData, expectedOutputData, backends); +} + +template +void ConcatDim1EndToEnd(const std::vector& backends) +{ + using namespace armnn; + using T = ResolveType; + + unsigned int concatAxis = 1; + const std::vector inputShapes{{ 2, 3, 2, 2 }, { 2, 3, 2, 2 }}; + const TensorShape& outputShape = { 2, 6, 2, 2 }; + + // Builds up the structure of the network + INetworkPtr net = CreateConcatNetwork(inputShapes, outputShape, concatAxis); + + BOOST_TEST_CHECKPOINT("create a network"); + + // Creates structures for input & output. + std::vector inputData{ + 1, 2, + 3, 4, + 5, 6, + 7, 8, + 9, 10, + 11, 12, + 1, 2, + 3, 4, + 5, 6, + 7, 8, + 9, 10, + 11, 12 + }; + + std::vector expectedOutput{ + 1, 2, + 3, 4, + 5, 6, + 7, 8, + 9, 10, + 11, 12, + 1, 2, + 3, 4, + 5, 6, + 7, 8, + 9, 10, + 11, 12, + 1, 2, + 3, 4, + 5, 6, + 7, 8, + 9, 10, + 11, 12, + 1, 2, + 3, 4, + 5, 6, + 7, 8, + 9, 10, + 11, 12 + }; + + std::map> inputTensorData = {{ 0,inputData }, { 1,inputData }}; + std::map> expectedOutputData = {{ 0,expectedOutput }}; + + EndToEndLayerTestImpl(move(net), inputTensorData, expectedOutputData, backends); +} + +template +void ConcatDim2EndToEnd(const std::vector& backends) +{ + using namespace armnn; + using T = ResolveType; + + unsigned int concatAxis = 2; + const std::vector inputShapes{{ 2, 3, 2, 2 }, { 2, 3, 2, 2 }}; + const TensorShape& outputShape = { 2, 3, 4, 2 }; + + // Builds up the structure of the network + INetworkPtr net = CreateConcatNetwork(inputShapes, outputShape, concatAxis); + + BOOST_TEST_CHECKPOINT("create a network"); + + // Creates structures for input & output. + std::vector inputData{ + 1, 2, + 3, 4, + 5, 6, + 7, 8, + 9, 10, + 11, 12, + 1, 2, + 3, 4, + 5, 6, + 7, 8, + 9, 10, + 11, 12 + }; + + std::vector expectedOutput{ + 1, 2, + 3, 4, + 1, 2, + 3, 4, + 5, 6, + 7, 8, + 5, 6, + 7, 8, + 9, 10, + 11, 12, + 9, 10, + 11, 12, + 1, 2, + 3, 4, + 1, 2, + 3, 4, + 5, 6, + 7, 8, + 5, 6, + 7, 8, + 9, 10, + 11, 12, + 9, 10, + 11, 12 + }; + + std::map> inputTensorData = {{ 0,inputData }, { 1,inputData }}; + std::map> expectedOutputData = {{ 0,expectedOutput }}; + + EndToEndLayerTestImpl(move(net), inputTensorData, expectedOutputData, backends); +} + +template> +void ConcatDim3EndToEnd(const std::vector& backends) +{ + using namespace armnn; + + unsigned int concatAxis = 3; + const std::vector inputShapes{{ 2, 3, 2, 2 }, { 2, 3, 2, 2 }}; + const TensorShape& outputShape = { 2, 3, 2, 4 }; + + // Builds up the structure of the network + INetworkPtr net = CreateConcatNetwork(inputShapes, outputShape, concatAxis); + + BOOST_TEST_CHECKPOINT("create a network"); + + // Creates structures for input & output. + std::vector inputData{ + 1, 2, + 3, 4, + 5, 6, + 7, 8, + 9, 10, + 11, 12, + 1, 2, + 3, 4, + 5, 6, + 7, 8, + 9, 10, + 11, 12 + }; + + std::vector expectedOutput{ + 1, 2, + 1, 2, + 3, 4, + 3, 4, + 5, 6, + 5, 6, + 7, 8, + 7, 8, + 9, 10, + 9, 10, + 11, 12, + 11, 12, + 1, 2, + 1, 2, + 3, 4, + 3, 4, + 5, 6, + 5, 6, + 7, 8, + 7, 8, + 9, 10, + 9, 10, + 11, 12, + 11, 12 + }; + + std::map> inputTensorData = {{ 0,inputData }, { 1,inputData }}; + std::map> expectedOutputData = {{ 0,expectedOutput }}; + + EndToEndLayerTestImpl(move(net), inputTensorData, expectedOutputData, backends); +} + +} // anonymous namespace -- cgit v1.2.1