diff options
author | Matteo Martincigh <matteo.martincigh@arm.com> | 2018-12-18 09:26:39 +0000 |
---|---|---|
committer | Matteo Martincigh <matteo.martincigh@arm.com> | 2019-01-04 17:28:07 +0000 |
commit | 747ef82c88f9afe14a8b80b6b3b34118353e97f2 (patch) | |
tree | a29ac33b84fb96a41103a0a97327189495374cc9 /src/armnn/layers | |
parent | 760892724d131c7da4b9baad05cddd49276ad6bb (diff) | |
download | armnn-747ef82c88f9afe14a8b80b6b3b34118353e97f2.tar.gz |
MLCE-77 Depthwise Convolution with depth multiplier > 1 doesn't work
* Unified ArmNN's weight format to [ M, I, H, W ] for the depthwise convolution
* Added conversion utilities to permute/reshape the weights as appropriate
when using CL and Neon backends
* Updated the reference implementation of the convolution
* Updated the relevant unit tests accordingly
!android-nn-driver:459
Change-Id: I07d0818efa9d1ca1e5dad82983aac1fe78eadb18
Diffstat (limited to 'src/armnn/layers')
-rw-r--r-- | src/armnn/layers/DepthwiseConvolution2dLayer.cpp | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/src/armnn/layers/DepthwiseConvolution2dLayer.cpp b/src/armnn/layers/DepthwiseConvolution2dLayer.cpp index 95d4690d4f..c4edc2022f 100644 --- a/src/armnn/layers/DepthwiseConvolution2dLayer.cpp +++ b/src/armnn/layers/DepthwiseConvolution2dLayer.cpp @@ -24,7 +24,7 @@ DepthwiseConvolution2dLayer::DepthwiseConvolution2dLayer(const DepthwiseConvolut { } -std::unique_ptr<IWorkload> DepthwiseConvolution2dLayer::CreateWorkload(const Graph& graph, +std::unique_ptr<IWorkload> DepthwiseConvolution2dLayer::CreateWorkload(const Graph& graph, const IWorkloadFactory& factory) const { // on this level constant data should not be released.. @@ -59,34 +59,40 @@ std::vector<TensorShape> DepthwiseConvolution2dLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const { BOOST_ASSERT(inputShapes.size() == 2); - const TensorShape& inputShape = inputShapes[0]; - const TensorShape filterShape = inputShapes[1]; + const TensorShape& inputShape = inputShapes[0]; + const TensorShape& filterShape = inputShapes[1]; BOOST_ASSERT_MSG(inputShape.GetNumDimensions() == 4, "Convolutions will always have 4D input."); DataLayoutIndexed dataLayoutIndex(m_Param.m_DataLayout); - unsigned int inWidth = inputShape[dataLayoutIndex.GetWidthIndex()]; - unsigned int inHeight = inputShape[dataLayoutIndex.GetHeightIndex()]; - unsigned int inBatchSize = inputShape[0]; + unsigned int inputBatchSize = inputShape[0]; + unsigned int inputHeight = inputShape[dataLayoutIndex.GetHeightIndex()]; + unsigned int inputWidth = inputShape[dataLayoutIndex.GetWidthIndex()]; + unsigned int inputChannels = inputShape[dataLayoutIndex.GetChannelsIndex()]; - unsigned int filterWidth = filterShape[dataLayoutIndex.GetWidthIndex()]; - unsigned int readWidth = (inWidth + m_Param.m_PadLeft + m_Param.m_PadRight) - (filterWidth); - unsigned int outWidth = 1 + (readWidth / m_Param.m_StrideX); + // Expected filter shape: [ M, I, H, W ] - This shape does NOT depend on the data layout + // Namely: [ depth multiplier, input channels, filter height, filter width ] + // Output channels = input channels * depthMultiplier - unsigned int filterHeight = filterShape[dataLayoutIndex.GetHeightIndex()]; - unsigned int readHeight = (inHeight + m_Param.m_PadTop + m_Param.m_PadBottom) - (filterHeight); - unsigned int outHeight = 1 + (readHeight / m_Param.m_StrideY); unsigned int depthMultiplier = filterShape[0]; - unsigned int outChannels = filterShape[dataLayoutIndex.GetChannelsIndex()] * depthMultiplier; - unsigned int outBatchSize = inBatchSize; + unsigned int filterHeight = filterShape[2]; + unsigned int readHeight = (inputHeight + m_Param.m_PadTop + m_Param.m_PadBottom) - filterHeight; + unsigned int outputHeight = 1 + (readHeight / m_Param.m_StrideY); + + unsigned int filterWidth = filterShape[3]; + unsigned int readWidth = (inputWidth + m_Param.m_PadLeft + m_Param.m_PadRight) - filterWidth; + unsigned int outputWidth = 1 + (readWidth / m_Param.m_StrideX); + + unsigned int outputChannels = inputChannels * depthMultiplier; + unsigned int outputBatchSize = inputBatchSize; TensorShape tensorShape = m_Param.m_DataLayout == armnn::DataLayout::NHWC ? - TensorShape( { outBatchSize, outHeight, outWidth, outChannels } ) : - TensorShape( { outBatchSize, outChannels, outHeight, outWidth }); + TensorShape{ outputBatchSize, outputHeight, outputWidth, outputChannels } : + TensorShape{ outputBatchSize, outputChannels, outputHeight, outputWidth }; - return std::vector<TensorShape>({ tensorShape }); + return std::vector<TensorShape>{ tensorShape }; } void DepthwiseConvolution2dLayer::ValidateTensorShapesFromInputs() |