From 382a91d5029e83002bda4ab006f9c73340d679fe Mon Sep 17 00:00:00 2001 From: jimfly01 Date: Fri, 26 Oct 2018 15:55:50 +0100 Subject: IVGCVSW-2074: Updated DepthwiseConvolution2dAsymmetricTest for NHWC Change-Id: I1bc8d2f270d4abfaa62e4843b8d96bcf462c6b09 --- src/backends/cl/test/ClLayerTests.cpp | 10 ++++-- src/backends/neon/test/NeonLayerTests.cpp | 10 ++++-- src/backends/reference/test/RefLayerTests.cpp | 10 ++++-- src/backends/test/Conv2dTestImpl.hpp | 46 +++++++++++++++++++++------ src/backends/test/LayerTests.cpp | 13 +++++--- src/backends/test/LayerTests.hpp | 3 +- 6 files changed, 71 insertions(+), 21 deletions(-) diff --git a/src/backends/cl/test/ClLayerTests.cpp b/src/backends/cl/test/ClLayerTests.cpp index 057b5d84b2..beb523f84e 100755 --- a/src/backends/cl/test/ClLayerTests.cpp +++ b/src/backends/cl/test/ClLayerTests.cpp @@ -75,8 +75,14 @@ ARMNN_AUTO_TEST_CASE(UnbiasedDepthwiseConvolution2dDepthMul1, DepthwiseConvoluti ARMNN_AUTO_TEST_CASE(DepthwiseConvolution2dDepthMul1Uint8, DepthwiseConvolution2dDepthMul1Uint8Test, true) ARMNN_AUTO_TEST_CASE(UnbiasedDepthwiseConvolution2dDepthMul1Uint8, DepthwiseConvolution2dDepthMul1Uint8Test, false) -ARMNN_AUTO_TEST_CASE(DepthwiseConvolution2dAsymmetric, DepthwiseConvolution2dAsymmetricTest, true) -ARMNN_AUTO_TEST_CASE(UnbiasedDepthwiseConvolution2dAsymmetric, DepthwiseConvolution2dAsymmetricTest, false) +ARMNN_AUTO_TEST_CASE(DepthwiseConvolution2dAsymmetric, + DepthwiseConvolution2dAsymmetricTest, true, armnn::DataLayout::NCHW) +ARMNN_AUTO_TEST_CASE(UnbiasedDepthwiseConvolution2dAsymmetric, + DepthwiseConvolution2dAsymmetricTest, false, armnn::DataLayout::NCHW) +ARMNN_AUTO_TEST_CASE(DepthwiseConvolution2dAsymmetricNhwc, + DepthwiseConvolution2dAsymmetricTest, true, armnn::DataLayout::NHWC) +ARMNN_AUTO_TEST_CASE(UnbiasedDepthwiseConvolution2dAsymmetricNhwc, + DepthwiseConvolution2dAsymmetricTest, false, armnn::DataLayout::NHWC) // Softmax BOOST_AUTO_TEST_CASE(Softmax4dSupport) diff --git a/src/backends/neon/test/NeonLayerTests.cpp b/src/backends/neon/test/NeonLayerTests.cpp index 349dbf8fb3..c7b0050311 100644 --- a/src/backends/neon/test/NeonLayerTests.cpp +++ b/src/backends/neon/test/NeonLayerTests.cpp @@ -98,8 +98,14 @@ ARMNN_AUTO_TEST_CASE(UnbiasedDepthwiseConvolution2dDepthMul1, DepthwiseConvoluti ARMNN_AUTO_TEST_CASE(DepthwiseConvolution2dDepthMul1Uint8, DepthwiseConvolution2dDepthMul1Uint8Test, true) ARMNN_AUTO_TEST_CASE(UnbiasedDepthwiseConvolution2dDepthMul1Uint8, DepthwiseConvolution2dDepthMul1Uint8Test, false) -ARMNN_AUTO_TEST_CASE(DepthwiseConvolution2dAsymmetric, DepthwiseConvolution2dAsymmetricTest, true) -ARMNN_AUTO_TEST_CASE(UnbiasedDepthwiseConvolution2dAsymmetric, DepthwiseConvolution2dAsymmetricTest, false) +ARMNN_AUTO_TEST_CASE(DepthwiseConvolution2dAsymmetric, + DepthwiseConvolution2dAsymmetricTest, true, armnn::DataLayout::NCHW) +ARMNN_AUTO_TEST_CASE(UnbiasedDepthwiseConvolution2dAsymmetric, + DepthwiseConvolution2dAsymmetricTest, false, armnn::DataLayout::NCHW) +ARMNN_AUTO_TEST_CASE(DepthwiseConvolution2dAsymmetricNhwc, + DepthwiseConvolution2dAsymmetricTest, true, armnn::DataLayout::NHWC) +ARMNN_AUTO_TEST_CASE(UnbiasedDepthwiseConvolution2dAsymmetricNhwc, + DepthwiseConvolution2dAsymmetricTest, false, armnn::DataLayout::NHWC) namespace { diff --git a/src/backends/reference/test/RefLayerTests.cpp b/src/backends/reference/test/RefLayerTests.cpp index cb5a1c4158..6a92b67e57 100644 --- a/src/backends/reference/test/RefLayerTests.cpp +++ b/src/backends/reference/test/RefLayerTests.cpp @@ -67,8 +67,14 @@ ARMNN_AUTO_TEST_CASE(DepthwiseConvolution2dDepthMul1Uint8, DepthwiseConvolution2 ARMNN_AUTO_TEST_CASE(UnbiasedDepthwiseConvolution2dDepthMul1, DepthwiseConvolution2dDepthMul1Test, false) ARMNN_AUTO_TEST_CASE(UnbiasedDepthwiseConvolution2dDepthMul1Uint8, DepthwiseConvolution2dDepthMul1Uint8Test, false) -ARMNN_AUTO_TEST_CASE(DepthwiseConvolution2dAsymmetric, DepthwiseConvolution2dAsymmetricTest, true) -ARMNN_AUTO_TEST_CASE(UnbiasedDepthwiseConvolution2dAsymmetric, DepthwiseConvolution2dAsymmetricTest, false) +ARMNN_AUTO_TEST_CASE(DepthwiseConvolution2dAsymmetric, + DepthwiseConvolution2dAsymmetricTest, true, armnn::DataLayout::NCHW) +ARMNN_AUTO_TEST_CASE(UnbiasedDepthwiseConvolution2dAsymmetric, + DepthwiseConvolution2dAsymmetricTest, false, armnn::DataLayout::NCHW) +ARMNN_AUTO_TEST_CASE(DepthwiseConvolution2dAsymmetricNhwc, + DepthwiseConvolution2dAsymmetricTest, true, armnn::DataLayout::NHWC) +ARMNN_AUTO_TEST_CASE(UnbiasedDepthwiseConvolution2dAsymmetricNhwc, + DepthwiseConvolution2dAsymmetricTest, false, armnn::DataLayout::NHWC) // Pooling ARMNN_AUTO_TEST_CASE(SimpleMaxPooling2dSize2x2Stride2x2, SimpleMaxPooling2dSize2x2Stride2x2Test, false) diff --git a/src/backends/test/Conv2dTestImpl.hpp b/src/backends/test/Conv2dTestImpl.hpp index 41a0d1b095..993794e325 100755 --- a/src/backends/test/Conv2dTestImpl.hpp +++ b/src/backends/test/Conv2dTestImpl.hpp @@ -337,11 +337,12 @@ LayerTestResult SimpleConvolution2dNhwcTestImpl(armnn::IWorkloadFactory& w template LayerTestResult DepthwiseConvolution2dAsymmetricTestImpl(armnn::IWorkloadFactory& workloadFactory, const boost::multi_array& input, - const boost::multi_array& kernel, + const boost::multi_array& originalKernel, const boost::multi_array& bias, const boost::multi_array& outputExpected, float qScale, int32_t qOffset, + const armnn::DataLayoutIndexed& layout, uint32_t padLeft = 0, uint32_t padTop = 0, uint32_t padRight = 0, @@ -353,10 +354,10 @@ LayerTestResult DepthwiseConvolution2dAsymmetricTestImpl(armnn::IWorkloadF unsigned int inputChannels = boost::numeric_cast(input.shape()[1]); unsigned int inputHeight = boost::numeric_cast(input.shape()[2]); unsigned int inputWidth = boost::numeric_cast(input.shape()[3]); - unsigned int kernelChanMul = boost::numeric_cast(kernel.shape()[0]); - unsigned int kernelChannels = boost::numeric_cast(kernel.shape()[1]); - unsigned int kernelHeight = boost::numeric_cast(kernel.shape()[2]); - unsigned int kernelWidth = boost::numeric_cast(kernel.shape()[3]); + unsigned int kernelChanMul = boost::numeric_cast(originalKernel.shape()[0]); + unsigned int kernelChannels = boost::numeric_cast(originalKernel.shape()[1]); + unsigned int kernelHeight = boost::numeric_cast(originalKernel.shape()[2]); + unsigned int kernelWidth = boost::numeric_cast(originalKernel.shape()[3]); unsigned int outputNum = boost::numeric_cast(outputExpected.shape()[0]); unsigned int outputChannels = boost::numeric_cast(outputExpected.shape()[1]); unsigned int outputHeight = boost::numeric_cast(outputExpected.shape()[2]); @@ -367,10 +368,9 @@ LayerTestResult DepthwiseConvolution2dAsymmetricTestImpl(armnn::IWorkloadF BOOST_ASSERT(!biasEnabled || bias.size() == outputChannels); // Creates the tensors. - armnn::TensorInfo inputTensorInfo({inputNum, inputChannels, inputHeight, inputWidth}, armnn::GetDataType()); - armnn::TensorInfo outputTensorInfo({outputNum, outputChannels, outputHeight, outputWidth}, - armnn::GetDataType()); - armnn::TensorInfo kernelDesc({kernelChanMul, kernelChannels, kernelHeight, kernelWidth}, armnn::GetDataType()); + armnn::TensorInfo inputTensorInfo = GetTensorInfo(inputNum, inputChannels, inputHeight, inputWidth, layout); + armnn::TensorInfo outputTensorInfo = GetTensorInfo(outputNum, outputChannels, outputHeight, outputWidth, layout); + armnn::TensorInfo kernelDesc = GetTensorInfo(kernelChanMul, kernelChannels, kernelHeight, kernelWidth, layout); armnn::TensorInfo biasDesc({static_cast(bias.size())}, armnn::GetDataType()); // Set quantization parameters if the requested type is a quantized type. @@ -389,6 +389,16 @@ LayerTestResult DepthwiseConvolution2dAsymmetricTestImpl(armnn::IWorkloadF // Construct the input data. std::vector inputData; inputData.assign(input.data(), input.data() + inputChannels*inputHeight*inputWidth); + + // At this point if we require it permute the input data + const armnn::PermutationVector NCHWToNHWC = { 0, 3, 1, 2 }; + if (layout.GetDataLayout() == armnn::DataLayout::NHWC) + { + std::vector tmp(inputData.size()); + armnnUtils::Permute(inputTensorInfo.GetShape(), NCHWToNHWC, inputData.data(), tmp.data()); + inputData = tmp; + } + auto batchedInput = MakeTensor(inputTensorInfo, inputData); // Construct the output data, with bias applied, as appropriate. @@ -404,12 +414,29 @@ LayerTestResult DepthwiseConvolution2dAsymmetricTestImpl(armnn::IWorkloadF } LayerTestResult ret(outputTensorInfo); + + // At this point if we require it permute the expected output + if (layout.GetDataLayout() == armnn::DataLayout::NHWC) + { + std::vector tmp(outputData.size()); + armnnUtils::Permute(outputTensorInfo.GetShape(), NCHWToNHWC, outputData.data(), tmp.data()); + outputData = tmp; + } + ret.outputExpected = MakeTensor(outputTensorInfo, outputData); std::unique_ptr inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo); std::unique_ptr outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo); armnn::ScopedCpuTensorHandle weightsTensor(kernelDesc); + + // Permute the kernel if necessary + boost::multi_array kernel = boost::multi_array(originalKernel); + if (layout.GetDataLayout() == armnn::DataLayout::NHWC) + { + armnnUtils::Permute(kernelDesc.GetShape(), NCHWToNHWC, originalKernel.data(), kernel.data()); + } + AllocateAndCopyDataToITensorHandle(&weightsTensor, &kernel[0][0][0][0]); armnn::ScopedCpuTensorHandle biasTensor(biasDesc); @@ -428,6 +455,7 @@ LayerTestResult DepthwiseConvolution2dAsymmetricTestImpl(armnn::IWorkloadF data.m_Parameters.m_PadTop = padTop; data.m_Parameters.m_PadBottom = padBottom; data.m_Parameters.m_BiasEnabled = biasEnabled; + data.m_Parameters.m_DataLayout = layout.GetDataLayout(); armnn::WorkloadInfo info; AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get()); diff --git a/src/backends/test/LayerTests.cpp b/src/backends/test/LayerTests.cpp index bc9e116f92..43a42f305c 100755 --- a/src/backends/test/LayerTests.cpp +++ b/src/backends/test/LayerTests.cpp @@ -432,7 +432,8 @@ template LayerTestResult DepthwiseConvolution2dAsymmetricTestCommon(armnn::IWorkloadFactory& workloadFactory, float qScale, int32_t qOffset, - bool biasEnabled) + bool biasEnabled, + const armnn::DataLayoutIndexed& layout) { // Use a single-batch 2-channel 5x5 image as input. armnn::TensorInfo inputTensorInfo({ 1, 2, 5, 5 }, armnn::GetDataType()); @@ -490,6 +491,7 @@ LayerTestResult DepthwiseConvolution2dAsymmetricTestCommon(armnn::IWorkloa expectedOutput, qScale, qOffset, + layout, 1, // Padding left. 1, // Padding top. 2, // Padding right. @@ -643,13 +645,14 @@ LayerTestResult DepthwiseConvolution2dDepthMul1Test(armnn::IWorkloadFa } LayerTestResult DepthwiseConvolution2dAsymmetricTest(armnn::IWorkloadFactory& workloadFactory, - bool biasEnabled) + bool biasEnabled, + const armnn::DataLayoutIndexed& layout) { - return DepthwiseConvolution2dAsymmetricTestCommon(workloadFactory, 0.0f, 0, biasEnabled); + return DepthwiseConvolution2dAsymmetricTestCommon(workloadFactory, 0.0f, 0, biasEnabled, layout); } LayerTestResult DepthwiseConvolution2dUint8Test(armnn::IWorkloadFactory& workloadFactory, - bool biasEnabled) + bool biasEnabled) { return DepthwiseConvolution2dTestImpl(workloadFactory, 0.5f, 50, biasEnabled); } @@ -671,7 +674,7 @@ LayerTestResult Convolution1dUint8Test(armnn::IWorkloadFactory& work } LayerTestResult CompareConvolution2dTest(armnn::IWorkloadFactory& workloadFactory, - armnn::IWorkloadFactory& refWorkloadFactory) + armnn::IWorkloadFactory& refWorkloadFactory) { return CompareConvolution2dTestImpl(workloadFactory, refWorkloadFactory); } diff --git a/src/backends/test/LayerTests.hpp b/src/backends/test/LayerTests.hpp index 8846297ff1..fec73d08f4 100644 --- a/src/backends/test/LayerTests.hpp +++ b/src/backends/test/LayerTests.hpp @@ -81,7 +81,8 @@ LayerTestResult DepthwiseConvolution2dDepthMul1Test(armnn::IWorkloadFa bool biasEnabled); LayerTestResult DepthwiseConvolution2dAsymmetricTest(armnn::IWorkloadFactory& workloadFactory, - bool biasEnabled); + bool biasEnabled, + const armnn::DataLayoutIndexed& layout); LayerTestResult SimpleMaxPooling2dSize2x2Stride2x2Test(armnn::IWorkloadFactory& workloadFactory, bool forceNoPadding); -- cgit v1.2.1