From b9c8963c3d393baf27edf37ab732fa76ee53af50 Mon Sep 17 00:00:00 2001 From: jimfly01 Date: Fri, 26 Oct 2018 16:50:13 +0100 Subject: IVGCVSW-2074: Updated the DepthwiseConvolution2dDepthMul1 for NHWC Change-Id: Ibaa0b909680a6f2a155e4ca6fa24e1144d6e6e73 --- src/backends/cl/test/ClLayerTests.cpp | 24 +++++++-- src/backends/neon/test/NeonLayerTests.cpp | 24 +++++++-- src/backends/reference/test/RefLayerTests.cpp | 24 +++++++-- src/backends/test/Conv2dTestImpl.hpp | 71 ++++++++++++++++++--------- src/backends/test/LayerTests.cpp | 10 ++-- src/backends/test/LayerTests.hpp | 6 ++- 6 files changed, 117 insertions(+), 42 deletions(-) diff --git a/src/backends/cl/test/ClLayerTests.cpp b/src/backends/cl/test/ClLayerTests.cpp index f2a28ec06e..4e7f785bbb 100755 --- a/src/backends/cl/test/ClLayerTests.cpp +++ b/src/backends/cl/test/ClLayerTests.cpp @@ -69,11 +69,27 @@ ARMNN_AUTO_TEST_CASE(UnbiasedConvolution2dSquareNhwc, SimpleConvolution2d3x3Test ARMNN_AUTO_TEST_CASE(SimpleConvolution2dSquareNhwc, SimpleConvolution2d3x3NhwcTest, false) // Depthwise Convolution -ARMNN_AUTO_TEST_CASE(DepthwiseConvolution2dDepthMul1, DepthwiseConvolution2dDepthMul1Test, true) +ARMNN_AUTO_TEST_CASE(DepthwiseConvolution2dDepthMul1, + DepthwiseConvolution2dDepthMul1Test, true, armnn::DataLayout::NCHW) +ARMNN_AUTO_TEST_CASE(UnbiasedDepthwiseConvolution2dDepthMul1, + DepthwiseConvolution2dDepthMul1Test, false, armnn::DataLayout::NCHW) +ARMNN_AUTO_TEST_CASE(DepthwiseConvolution2dDepthMul1Uint8, + DepthwiseConvolution2dDepthMul1Uint8Test, true, armnn::DataLayout::NCHW) +ARMNN_AUTO_TEST_CASE(UnbiasedDepthwiseConvolution2dDepthMul1Uint8, + DepthwiseConvolution2dDepthMul1Uint8Test, false, armnn::DataLayout::NCHW) + +// NHWC Depthwise Convolution +ARMNN_AUTO_TEST_CASE(DepthwiseConvolution2dDepthMul1Nhwc, + DepthwiseConvolution2dDepthMul1Test, true, armnn::DataLayout::NHWC) +ARMNN_AUTO_TEST_CASE(UnbiasedDepthwiseConvolution2dDepthMul1Nhwc, + DepthwiseConvolution2dDepthMul1Test, false, armnn::DataLayout::NHWC) +ARMNN_AUTO_TEST_CASE(DepthwiseConvolution2dDepthMul1Uint8Nhwc, + DepthwiseConvolution2dDepthMul1Uint8Test, true, armnn::DataLayout::NHWC) +ARMNN_AUTO_TEST_CASE(UnbiasedDepthwiseConvolution2dDepthMul1Uint8Nhwc, + DepthwiseConvolution2dDepthMul1Uint8Test, false, armnn::DataLayout::NHWC) + + ARMNN_AUTO_TEST_CASE(DepthwiseConvolution2dDepthNhwc, DepthwiseConvolution2dDepthNhwcTest, false) -ARMNN_AUTO_TEST_CASE(UnbiasedDepthwiseConvolution2dDepthMul1, DepthwiseConvolution2dDepthMul1Test, false) -ARMNN_AUTO_TEST_CASE(DepthwiseConvolution2dDepthMul1Uint8, DepthwiseConvolution2dDepthMul1Uint8Test, true) -ARMNN_AUTO_TEST_CASE(UnbiasedDepthwiseConvolution2dDepthMul1Uint8, DepthwiseConvolution2dDepthMul1Uint8Test, false) ARMNN_AUTO_TEST_CASE(DepthwiseConvolution2dAsymmetric, DepthwiseConvolution2dAsymmetricTest, true, armnn::DataLayout::NCHW) diff --git a/src/backends/neon/test/NeonLayerTests.cpp b/src/backends/neon/test/NeonLayerTests.cpp index 8fda825618..53dad94099 100644 --- a/src/backends/neon/test/NeonLayerTests.cpp +++ b/src/backends/neon/test/NeonLayerTests.cpp @@ -92,11 +92,27 @@ BOOST_AUTO_TEST_CASE(Conv2dUtils) } // Depthwise Convolution -ARMNN_AUTO_TEST_CASE(DepthwiseConvolution2dDepthMul1, DepthwiseConvolution2dDepthMul1Test, true) +ARMNN_AUTO_TEST_CASE(DepthwiseConvolution2dDepthMul1, + DepthwiseConvolution2dDepthMul1Test, true, armnn::DataLayout::NCHW) +ARMNN_AUTO_TEST_CASE(UnbiasedDepthwiseConvolution2dDepthMul1, + DepthwiseConvolution2dDepthMul1Test, false, armnn::DataLayout::NCHW) +ARMNN_AUTO_TEST_CASE(DepthwiseConvolution2dDepthMul1Uint8, + DepthwiseConvolution2dDepthMul1Uint8Test, true, armnn::DataLayout::NCHW) +ARMNN_AUTO_TEST_CASE(UnbiasedDepthwiseConvolution2dDepthMul1Uint8, + DepthwiseConvolution2dDepthMul1Uint8Test, false, armnn::DataLayout::NCHW) + +// NHWC Depthwise Convolution +ARMNN_AUTO_TEST_CASE(DepthwiseConvolution2dDepthMul1NHhwc, + DepthwiseConvolution2dDepthMul1Test, true, armnn::DataLayout::NHWC) +ARMNN_AUTO_TEST_CASE(UnbiasedDepthwiseConvolution2dDepthMul1Nhwc, + DepthwiseConvolution2dDepthMul1Test, false, armnn::DataLayout::NHWC) +ARMNN_AUTO_TEST_CASE(DepthwiseConvolution2dDepthMul1Uint8Nhwc, + DepthwiseConvolution2dDepthMul1Uint8Test, true, armnn::DataLayout::NHWC) +ARMNN_AUTO_TEST_CASE(UnbiasedDepthwiseConvolution2dDepthMul1Uint8Nhwc, + DepthwiseConvolution2dDepthMul1Uint8Test, false, armnn::DataLayout::NHWC) + ARMNN_AUTO_TEST_CASE(DepthwiseConvolution2dDepthNhwc, DepthwiseConvolution2dDepthNhwcTest, false) -ARMNN_AUTO_TEST_CASE(UnbiasedDepthwiseConvolution2dDepthMul1, DepthwiseConvolution2dDepthMul1Test, false) -ARMNN_AUTO_TEST_CASE(DepthwiseConvolution2dDepthMul1Uint8, DepthwiseConvolution2dDepthMul1Uint8Test, true) -ARMNN_AUTO_TEST_CASE(UnbiasedDepthwiseConvolution2dDepthMul1Uint8, DepthwiseConvolution2dDepthMul1Uint8Test, false) + ARMNN_AUTO_TEST_CASE(DepthwiseConvolution2dAsymmetric, DepthwiseConvolution2dAsymmetricTest, true, armnn::DataLayout::NCHW) diff --git a/src/backends/reference/test/RefLayerTests.cpp b/src/backends/reference/test/RefLayerTests.cpp index f5884aee17..00fba20c5d 100644 --- a/src/backends/reference/test/RefLayerTests.cpp +++ b/src/backends/reference/test/RefLayerTests.cpp @@ -74,11 +74,26 @@ ARMNN_AUTO_TEST_CASE(UnbiasedDepthwiseConvolution2dUint8Nhwc, false, armnn::DataLayout::NHWC) -ARMNN_AUTO_TEST_CASE(DepthwiseConvolution2dDepthMul1, DepthwiseConvolution2dDepthMul1Test, true) -ARMNN_AUTO_TEST_CASE(DepthwiseConvolution2dDepthMul1Uint8, DepthwiseConvolution2dDepthMul1Uint8Test, true) -ARMNN_AUTO_TEST_CASE(UnbiasedDepthwiseConvolution2dDepthMul1, DepthwiseConvolution2dDepthMul1Test, false) -ARMNN_AUTO_TEST_CASE(UnbiasedDepthwiseConvolution2dDepthMul1Uint8, DepthwiseConvolution2dDepthMul1Uint8Test, false) +ARMNN_AUTO_TEST_CASE(DepthwiseConvolution2dDepthMul1, + DepthwiseConvolution2dDepthMul1Test, true, armnn::DataLayout::NCHW) +ARMNN_AUTO_TEST_CASE(DepthwiseConvolution2dDepthMul1Uint8, + DepthwiseConvolution2dDepthMul1Uint8Test, true, armnn::DataLayout::NCHW) + +ARMNN_AUTO_TEST_CASE(UnbiasedDepthwiseConvolution2dDepthMul1, + DepthwiseConvolution2dDepthMul1Test, false, armnn::DataLayout::NCHW) +ARMNN_AUTO_TEST_CASE(UnbiasedDepthwiseConvolution2dDepthMul1Uint8, + DepthwiseConvolution2dDepthMul1Uint8Test, false, armnn::DataLayout::NCHW) + +ARMNN_AUTO_TEST_CASE(DepthwiseConvolution2dDepthMul1Nhwc, + DepthwiseConvolution2dDepthMul1Test, true, armnn::DataLayout::NHWC) +ARMNN_AUTO_TEST_CASE(DepthwiseConvolution2dDepthMul1Uint8Nhwc, + DepthwiseConvolution2dDepthMul1Uint8Test, true, armnn::DataLayout::NHWC) + +ARMNN_AUTO_TEST_CASE(UnbiasedDepthwiseConvolution2dDepthMul1Nhwc, + DepthwiseConvolution2dDepthMul1Test, false, armnn::DataLayout::NHWC) +ARMNN_AUTO_TEST_CASE(UnbiasedDepthwiseConvolution2dDepthMul1Uint8Nhwc, + DepthwiseConvolution2dDepthMul1Uint8Test, false, armnn::DataLayout::NHWC) ARMNN_AUTO_TEST_CASE(DepthwiseConvolution2dAsymmetric, DepthwiseConvolution2dAsymmetricTest, true, armnn::DataLayout::NCHW) @@ -89,6 +104,7 @@ ARMNN_AUTO_TEST_CASE(DepthwiseConvolution2dAsymmetricNhwc, ARMNN_AUTO_TEST_CASE(UnbiasedDepthwiseConvolution2dAsymmetricNhwc, DepthwiseConvolution2dAsymmetricTest, false, armnn::DataLayout::NHWC) + // Pooling ARMNN_AUTO_TEST_CASE(SimpleMaxPooling2dSize2x2Stride2x2, SimpleMaxPooling2dSize2x2Stride2x2Test, false) ARMNN_AUTO_TEST_CASE(SimpleMaxPooling2dSize2x2Stride2x2Uint8, SimpleMaxPooling2dSize2x2Stride2x2Uint8Test, false) diff --git a/src/backends/test/Conv2dTestImpl.hpp b/src/backends/test/Conv2dTestImpl.hpp index 9bb36fb344..3791fb0a8e 100755 --- a/src/backends/test/Conv2dTestImpl.hpp +++ b/src/backends/test/Conv2dTestImpl.hpp @@ -457,7 +457,8 @@ template LayerTestResult DepthwiseConvolution2dDepthMul1TestImpl(armnn::IWorkloadFactory& workloadFactory, float qScale, int32_t qOffset, - bool biasEnabled) + bool biasEnabled, + const armnn::DataLayoutIndexed& layout) { unsigned int inputHeight = 3; unsigned int inputWidth = 3; @@ -473,10 +474,9 @@ LayerTestResult DepthwiseConvolution2dDepthMul1TestImpl(armnn::IWorkloadFa unsigned int outputChannels = kernelChannels; unsigned int outputNum = inputNum; - armnn::TensorInfo inputTensorInfo({ inputNum, inputChannels, inputHeight, inputWidth }, armnn::GetDataType()); - armnn::TensorInfo outputTensorInfo({ outputNum, outputChannels, outputHeight, outputWidth }, - armnn::GetDataType()); - armnn::TensorInfo kernelDesc({ 1, outputChannels, 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(1, outputChannels, kernelHeight, kernelWidth, layout); armnn::TensorInfo biasDesc({ outputChannels }, armnn::GetDataType()); // Set quantization parameters if the requested type is a quantized type. @@ -491,32 +491,47 @@ LayerTestResult DepthwiseConvolution2dDepthMul1TestImpl(armnn::IWorkloadFa biasDesc.SetQuantizationScale(qScale*qScale); biasDesc.SetQuantizationOffset(0); } + std::vector inputData = std::vector( + QuantizedVector(inputTensorInfo.GetQuantizationScale(), inputTensorInfo.GetQuantizationOffset(), { + 1.f, 2.f, 1.f, + 2.f, 1.f, 2.f, + 1.f, 2.f, 1.f, - auto input = MakeTensor(inputTensorInfo, std::vector( - QuantizedVector(inputTensorInfo.GetQuantizationScale(), inputTensorInfo.GetQuantizationOffset(), { - 1.f, 2.f, 1.f, - 2.f, 1.f, 2.f, - 1.f, 2.f, 1.f, - - 1.f, 2.f, 1.f, - 2.f, 1.f, 2.f, - 1.f, 2.f, 1.f, - }))); + 1.f, 2.f, 1.f, + 2.f, 1.f, 2.f, + 1.f, 2.f, 1.f, + })); + // 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 input = MakeTensor(inputTensorInfo, inputData); std::vector biasV(QuantizedVector(biasDesc.GetQuantizationScale(), biasDesc.GetQuantizationOffset(), {0, 2})); auto bias = MakeTensor(biasDesc, biasV); - auto kernel = MakeTensor(kernelDesc, std::vector( - QuantizedVector(kernelDesc.GetQuantizationScale(), kernelDesc.GetQuantizationOffset(), { - 1.f, 0.f, 1.f, - 0.f, 0.f, 0.f, - -1.f, 0.f, -1.f, + std::vector kernelData = std::vector( + QuantizedVector(kernelDesc.GetQuantizationScale(), kernelDesc.GetQuantizationOffset(), { + 1.f, 0.f, 1.f, + 0.f, 0.f, 0.f, + -1.f, 0.f, -1.f, - 1.f, 0.f, 1.f, - 0.f, 0.f, 0.f, - -1.f, 0.f, -1.f, - }))); + 1.f, 0.f, 1.f, + 0.f, 0.f, 0.f, + -1.f, 0.f, -1.f, + })); + if (layout.GetDataLayout() == armnn::DataLayout::NHWC) + { + std::vector tmp(kernelData.size()); + armnnUtils::Permute(kernelDesc.GetShape(), NCHWToNHWC, kernelData.data(), tmp.data()); + kernelData = tmp; + } + auto kernel = MakeTensor(kernelDesc, kernelData); // Manually calculated. std::vector outputImage( @@ -534,6 +549,13 @@ LayerTestResult DepthwiseConvolution2dDepthMul1TestImpl(armnn::IWorkloadFa } LayerTestResult ret(outputTensorInfo); + if (layout.GetDataLayout() == armnn::DataLayout::NHWC) + { + std::vector tmp(outputImage.size()); + armnnUtils::Permute(outputTensorInfo.GetShape(), NCHWToNHWC, outputImage.data(), tmp.data()); + outputImage = tmp; + } + ret.outputExpected = MakeTensor(outputTensorInfo, outputImage); std::unique_ptr inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo); @@ -559,6 +581,7 @@ LayerTestResult DepthwiseConvolution2dDepthMul1TestImpl(armnn::IWorkloadFa data.m_Parameters.m_PadTop = 0; data.m_Parameters.m_PadBottom = 0; data.m_Parameters.m_BiasEnabled = biasEnabled; + data.m_Parameters.m_DataLayout = layout.GetDataLayout(); std::unique_ptr workload = workloadFactory.CreateDepthwiseConvolution2d(data, info); inputHandle->Allocate(); diff --git a/src/backends/test/LayerTests.cpp b/src/backends/test/LayerTests.cpp index 49c6d30b6d..3a4e95ce94 100755 --- a/src/backends/test/LayerTests.cpp +++ b/src/backends/test/LayerTests.cpp @@ -640,9 +640,10 @@ LayerTestResult DepthwiseConvolution2dDepthNhwcTest(armnn::IWorkloadFa } LayerTestResult DepthwiseConvolution2dDepthMul1Test(armnn::IWorkloadFactory& workloadFactory, - bool biasEnabled) + bool biasEnabled, + const armnn::DataLayoutIndexed& layout) { - return DepthwiseConvolution2dDepthMul1TestImpl(workloadFactory, 0.0f, 0, biasEnabled); + return DepthwiseConvolution2dDepthMul1TestImpl(workloadFactory, 0.0f, 0, biasEnabled, layout); } LayerTestResult DepthwiseConvolution2dAsymmetricTest(armnn::IWorkloadFactory& workloadFactory, @@ -660,9 +661,10 @@ LayerTestResult DepthwiseConvolution2dUint8Test(armnn::IWorkloadFact } LayerTestResult DepthwiseConvolution2dDepthMul1Uint8Test(armnn::IWorkloadFactory& workloadFactory, - bool biasEnabled) + bool biasEnabled, + const armnn::DataLayoutIndexed& layout) { - return DepthwiseConvolution2dDepthMul1TestImpl(workloadFactory, 0.5f, 50, biasEnabled); + return DepthwiseConvolution2dDepthMul1TestImpl(workloadFactory, 0.5f, 50, biasEnabled, layout); } LayerTestResult Convolution1dTest(armnn::IWorkloadFactory& workloadFactory, bool biasEnabled) diff --git a/src/backends/test/LayerTests.hpp b/src/backends/test/LayerTests.hpp index 006425ae5f..39cd4c4a0b 100644 --- a/src/backends/test/LayerTests.hpp +++ b/src/backends/test/LayerTests.hpp @@ -80,7 +80,8 @@ LayerTestResult DepthwiseConvolution2dDepthNhwcTest(armnn::IWorkloadFa bool biasEnabled); LayerTestResult DepthwiseConvolution2dDepthMul1Test(armnn::IWorkloadFactory& workloadFactory, - bool biasEnabled); + bool biasEnabled, + const armnn::DataLayoutIndexed& layout); LayerTestResult DepthwiseConvolution2dAsymmetricTest(armnn::IWorkloadFactory& workloadFactory, bool biasEnabled, @@ -342,7 +343,8 @@ LayerTestResult DepthwiseConvolution2dUint8Test(armnn::IWorkloadFact const armnn::DataLayoutIndexed& layout); LayerTestResult DepthwiseConvolution2dDepthMul1Uint8Test(armnn::IWorkloadFactory& workloadFactory, - bool biasEnabled); + bool biasEnabled, + const armnn::DataLayoutIndexed& layout); LayerTestResult ConstantLinearActivationUint8Test(armnn::IWorkloadFactory& workloadFactory); -- cgit v1.2.1