diff options
author | Francis Murtagh <francis.murtagh@arm.com> | 2021-02-15 18:23:17 +0000 |
---|---|---|
committer | Francis Murtagh <francis.murtagh@arm.com> | 2021-02-15 18:23:17 +0000 |
commit | 3d2b4b2bff3be27f12a99e0e01284078870ee954 (patch) | |
tree | 33a9ea2a3267707088fd0a4a727d73a4568bb0a6 /src/armnn/test/optimizations/PermuteAndBatchToSpaceAsDepthToSpaceTests.cpp | |
parent | 052fbe9c86628cfdc534c515d9b451aa8d3d1cb6 (diff) | |
download | armnn-3d2b4b2bff3be27f12a99e0e01284078870ee954.tar.gz |
IVGCVSW-4873 Implement Pimpl Idiom for INetwork and IOptimizedNetwork
!android-nn-driver:5042
Signed-off-by: Kevin May <kevin.may@arm.com>
Change-Id: Ia1ce8b839e81b46428ba0f78463e085e5906958d
Signed-off-by: Francis Murtagh <francis.murtagh@arm.com>
Signed-off-by: Finn Williams <Finn.Williams@arm.com>
Diffstat (limited to 'src/armnn/test/optimizations/PermuteAndBatchToSpaceAsDepthToSpaceTests.cpp')
-rw-r--r-- | src/armnn/test/optimizations/PermuteAndBatchToSpaceAsDepthToSpaceTests.cpp | 73 |
1 files changed, 67 insertions, 6 deletions
diff --git a/src/armnn/test/optimizations/PermuteAndBatchToSpaceAsDepthToSpaceTests.cpp b/src/armnn/test/optimizations/PermuteAndBatchToSpaceAsDepthToSpaceTests.cpp index 6bfd7e301f..b47e3c7296 100644 --- a/src/armnn/test/optimizations/PermuteAndBatchToSpaceAsDepthToSpaceTests.cpp +++ b/src/armnn/test/optimizations/PermuteAndBatchToSpaceAsDepthToSpaceTests.cpp @@ -50,6 +50,36 @@ INetworkPtr CreateTestNetwork() } /// Shared function for the below tests, so that we test the same network in both cases. +std::unique_ptr<NetworkImpl> CreateTestNetworkImpl() +{ + std::unique_ptr<NetworkImpl> network(new NetworkImpl()); + + auto input = network->AddInputLayer(0, "input"); + const TensorInfo inputInfo({ 1, 2, 3, 4 }, DataType::Float32); + input->GetOutputSlot(0).SetTensorInfo(inputInfo); + + // Insert Permute which swaps batches and channels dimensions + auto permute = network->AddPermuteLayer(PermuteDescriptor(PermutationVector{ 3, 1, 2, 0 }), "permute"); + const TensorInfo permuteInfo({ 4, 2, 3, 1 }, DataType::Float32); + permute->GetOutputSlot(0).SetTensorInfo(permuteInfo); + input->GetOutputSlot(0).Connect(permute->GetInputSlot(0)); + + // Insert BatchToSpace + BatchToSpaceNdDescriptor batchToSpaceDesc; + batchToSpaceDesc.m_BlockShape = { 2, 2 }; + batchToSpaceDesc.m_DataLayout = DataLayout::NHWC; + auto batchToSpace = network->AddBatchToSpaceNdLayer(batchToSpaceDesc, "batchToSpace"); + const TensorInfo batchToSpaceInfo({ 1, 4, 6, 1 }, DataType::Float32); + batchToSpace->GetOutputSlot(0).SetTensorInfo(batchToSpaceInfo); + permute->GetOutputSlot(0).Connect(batchToSpace->GetInputSlot(0)); + + auto output = network->AddOutputLayer(0, "output"); + batchToSpace->GetOutputSlot(0).Connect(output->GetInputSlot(0)); + + return network; +} + +/// Shared function for the below tests, so that we test the same network in both cases. INetworkPtr CreateTransposeTestNetwork() { // Create a network @@ -80,14 +110,45 @@ INetworkPtr CreateTransposeTestNetwork() return network; } +/// Shared function for the below tests, so that we test the same network in both cases. +std::unique_ptr<NetworkImpl> CreateTransposeTestNetworkImpl() +{ + // Create a network + std::unique_ptr<NetworkImpl> network(new NetworkImpl()); + + auto input = network->AddInputLayer(0, "input"); + const TensorInfo inputInfo({ 1, 2, 3, 4 }, DataType::Float32); + input->GetOutputSlot(0).SetTensorInfo(inputInfo); + + // Insert Permute which swaps batches and channels dimensions + auto permute = network->AddTransposeLayer(TransposeDescriptor(PermutationVector{ 3, 1, 2, 0 }), "permute"); + const TensorInfo permuteInfo({ 4, 2, 3, 1 }, DataType::Float32); + permute->GetOutputSlot(0).SetTensorInfo(permuteInfo); + input->GetOutputSlot(0).Connect(permute->GetInputSlot(0)); + + // Insert BatchToSpace + BatchToSpaceNdDescriptor batchToSpaceDesc; + batchToSpaceDesc.m_BlockShape = { 2, 2 }; + batchToSpaceDesc.m_DataLayout = DataLayout::NHWC; + auto batchToSpace = network->AddBatchToSpaceNdLayer(batchToSpaceDesc, "batchToSpace"); + const TensorInfo batchToSpaceInfo({ 1, 4, 6, 1 }, DataType::Float32); + batchToSpace->GetOutputSlot(0).SetTensorInfo(batchToSpaceInfo); + permute->GetOutputSlot(0).Connect(batchToSpace->GetInputSlot(0)); + + auto output = network->AddOutputLayer(0, "output"); + batchToSpace->GetOutputSlot(0).Connect(output->GetInputSlot(0)); + + return network; +} + } // namespace /// Tests that the optimization performed by PermuteAndBatchToSpaceAsDepthToSpace is as expected. /// Note this does not ensure the correctness of the optimization - that is done in the below test. BOOST_AUTO_TEST_CASE(PermuteAndBatchToSpaceAsDepthToSpaceOptimizerTest) { - INetworkPtr network = CreateTestNetwork(); - Graph graph = static_cast<Network*>(network.get())->GetGraph(); + std::unique_ptr<NetworkImpl> network = CreateTestNetworkImpl(); + Graph graph = network.get()->GetGraph(); // Confirm initial graph is as we expect BOOST_TEST(CheckSequence(graph.cbegin(), graph.cend(), &IsLayerOfType<InputLayer>, &IsLayerOfType<PermuteLayer>, @@ -116,8 +177,8 @@ BOOST_AUTO_TEST_CASE(PermuteAndBatchToSpaceAsDepthToSpaceOptimizerTest) /// Note this does not ensure the correctness of the optimization - that is done in the below test. BOOST_AUTO_TEST_CASE(TransposeAndBatchToSpaceAsDepthToSpaceOptimizerTest) { - INetworkPtr network = CreateTransposeTestNetwork(); - Graph graph = static_cast<Network*>(network.get())->GetGraph(); + std::unique_ptr<NetworkImpl> network = CreateTransposeTestNetworkImpl(); + Graph graph = network.get()->GetGraph(); // Confirm initial graph is as we expect BOOST_TEST(CheckSequence(graph.cbegin(), graph.cend(), &IsLayerOfType<InputLayer>, &IsLayerOfType<TransposeLayer>, @@ -155,7 +216,7 @@ BOOST_AUTO_TEST_CASE(PermuteAndBatchToSpaceAsDepthToSpaceCorrectnessTest) IOptimizedNetworkPtr optimizedNetwork = Optimize(*network, { Compute::CpuRef }, runtime->GetDeviceSpec()); // Confirm that the optimization has actually taken place - const Graph& optGraph = static_cast<OptimizedNetwork*>(optimizedNetwork.get())->GetGraph(); + const Graph& optGraph = GetGraphForTesting(optimizedNetwork.get()); BOOST_TEST(CheckSequence(optGraph.cbegin(), optGraph.cend(), &IsLayerOfType<InputLayer>, &IsLayerOfType<DepthToSpaceLayer>, &IsLayerOfType<OutputLayer>)); @@ -202,7 +263,7 @@ BOOST_AUTO_TEST_CASE(TransposeAndBatchToSpaceAsDepthToSpaceCorrectnessTest) IOptimizedNetworkPtr optimizedNetwork = Optimize(*network, { Compute::CpuRef }, runtime->GetDeviceSpec()); // Confirm that the optimization has actually taken place - const Graph& optGraph = static_cast<OptimizedNetwork*>(optimizedNetwork.get())->GetGraph(); + const Graph& optGraph = GetGraphForTesting(optimizedNetwork.get()); BOOST_TEST(CheckSequence(optGraph.cbegin(), optGraph.cend(), &IsLayerOfType<InputLayer>, &IsLayerOfType<DepthToSpaceLayer>, &IsLayerOfType<OutputLayer>)); |