From a20d2b8756fb0dea15b1f7620072e510f4977aeb Mon Sep 17 00:00:00 2001 From: Jan Eilers Date: Tue, 27 Apr 2021 09:21:08 +0100 Subject: IVGCVSW-5826 Change weights layout for depthwise to [1,H,W,I*M] !armnn:5552 Signed-off-by: Jan Eilers Change-Id: I5bbc998f1a29030f718d85b646907c5a314ceecf --- ConversionUtils.hpp | 21 ++++++--------------- ConversionUtils_1_2.hpp | 18 ++++-------------- 2 files changed, 10 insertions(+), 29 deletions(-) diff --git a/ConversionUtils.hpp b/ConversionUtils.hpp index 0f6b783d..f48d58ed 100644 --- a/ConversionUtils.hpp +++ b/ConversionUtils.hpp @@ -472,7 +472,8 @@ void SanitizeBiasQuantizationScale(armnn::TensorInfo& biasInfo, std::transform(biasScales.begin(), biasScales.end(), biasScales.begin(), UpdateBiasScaleValue); biasInfo.SetQuantizationScales(biasScales); - biasInfo.SetQuantizationDim(weightInfo.GetQuantizationDim()); + // bias is expected to be a 1d tensor, set qdim=0 + biasInfo.SetQuantizationDim(0); ALOGV("Bias quantization params have been updated for per-axis quantization"); } @@ -2564,22 +2565,12 @@ bool ConvertDepthwiseConv2d(const HalOperation& operation, const HalModel& model armnn::DepthwiseConvolution2dDescriptor desc; desc.m_DataLayout = armnn::DataLayout::NHWC; - // Reinterpret weight data as [ H, W, I, M ] - armnn::TensorShape weightsShape({ weightsOperand->dimensions[1], - weightsOperand->dimensions[2], - inputInfo.GetShape()[3], - weightsOperand->dimensions[3] / inputInfo.GetShape()[3] }); - - // Swizzle weight data [ H, W, I, M ] -> [ M, I, H, W ] - const armnn::PermutationVector HWIMToMIHW = { 2U, 3U, 1U, 0U }; - + // The layout for weights in depthwise is [ 1, H, W, O] and it's the same in ArmNN. No need to permute anything. const ConstTensorPin weightsPin = ConvertOperationInputToConstTensorPin(operation, 1, model, - data, - HWIMToMIHW, - &weightsShape); + data); // Bias is a 1D tensor const ConstTensorPin biasPin = ConvertOperationInputToConstTensorPin(operation, 2, model, data); @@ -2619,8 +2610,8 @@ bool ConvertDepthwiseConv2d(const HalOperation& operation, const HalModel& model return Fail("%s: Operation has invalid inputs", __func__); } - const uint32_t kernelX = weights.GetShape()[3]; - const uint32_t kernelY = weights.GetShape()[2]; + const uint32_t kernelX = weights.GetShape()[2]; + const uint32_t kernelY = weights.GetShape()[1]; const uint32_t inputX = inputInfo.GetShape()[2]; const uint32_t inputY = inputInfo.GetShape()[1]; diff --git a/ConversionUtils_1_2.hpp b/ConversionUtils_1_2.hpp index eec87bf5..f884f7c0 100644 --- a/ConversionUtils_1_2.hpp +++ b/ConversionUtils_1_2.hpp @@ -467,22 +467,12 @@ bool ConvertDepthwiseConv2d_1_2(const HalOperation& operation, const HalModel& m unsigned int widthIndex = dataLayoutIndexed.GetWidthIndex(); unsigned int heightIndex = dataLayoutIndexed.GetHeightIndex(); - // Reinterpret weight data as [ H, W, I, M ] - TensorShape weightsShape({ weightsOperand->dimensions[1], - weightsOperand->dimensions[2], - inputInfo.GetShape()[channelsIndex], - weightsOperand->dimensions[3] / inputInfo.GetShape()[channelsIndex] }); - - // Swizzle weight data [ H, W, I, M ] -> [ M, I, H, W ] - const PermutationVector HWIMToMIHW = { 2U, 3U, 1U, 0U }; - + // The layout for weights in depthwise is [ 1, H, W, O] and it's the same in ArmNN. No need to permute anything. const ConstTensorPin weightsPin = ConvertOperationInputToConstTensorPin(operation, 1, model, - data, - HWIMToMIHW, - &weightsShape); + data); // Bias is a 1D tensor const ConstTensorPin biasPin = @@ -516,8 +506,8 @@ bool ConvertDepthwiseConv2d_1_2(const HalOperation& operation, const HalModel& m return Fail("%s: Operation has invalid inputs (implicit padding)", __func__); } - const uint32_t kernelX = weights.GetShape()[3]; - const uint32_t kernelY = weights.GetShape()[2]; + const uint32_t kernelX = weights.GetShape()[2]; + const uint32_t kernelY = weights.GetShape()[1]; const uint32_t inputX = inputInfo.GetShape()[widthIndex]; const uint32_t inputY = inputInfo.GetShape()[heightIndex]; -- cgit v1.2.1