From f762b8391cdb6064fcca4c269fb582e5534bbc7f Mon Sep 17 00:00:00 2001 From: Kevin May Date: Fri, 18 Aug 2023 14:01:51 +0100 Subject: IVGCVSW-7957 Fix weights checking when converting Conv2d/DepthwiseConv2d * An Operand can only have NO_VALUE if it is an optional argument of an operation * Add a check to see if the operand is optional to IsWeightsValid Signed-off-by: Kevin May Change-Id: I6321934dbfa41dd2bd28d8871c135f3694d9674d --- ConversionUtils_1_2.hpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/ConversionUtils_1_2.hpp b/ConversionUtils_1_2.hpp index 7a629e5a..e5840468 100644 --- a/ConversionUtils_1_2.hpp +++ b/ConversionUtils_1_2.hpp @@ -27,7 +27,8 @@ template bool IsWeightsValid(const HalOperation& operation, uint32_t inputIndex, - const HalModel& model) + const HalModel& model, + const bool isOptional = true) { using HalOperand = typename HalPolicy::Operand; using HalOperandLifeTime = typename HalPolicy::OperandLifeTime; @@ -38,12 +39,19 @@ bool IsWeightsValid(const HalOperation& operation, return false; } + // If the operand is not an optional operand it cannot have a NO_VALUE lifetime + if (!isOptional && operand->lifetime == HalOperandLifeTime::NO_VALUE) + { + return false; + } + if (operand->lifetime != HalOperandLifeTime::CONSTANT_COPY && operand->lifetime != HalOperandLifeTime::CONSTANT_REFERENCE && operand->lifetime != HalOperandLifeTime::NO_VALUE) { return false; } + return true; } @@ -415,11 +423,10 @@ bool ConvertConv2d_1_2(const HalOperation& operation, const HalModel& model, Con // the DataLayout is NCHW - if (!IsWeightsValid(operation, 1, model) && desc.m_DataLayout == DataLayout::NCHW) + if (!IsWeightsValid(operation, 1, model, false) && desc.m_DataLayout == DataLayout::NCHW) { return Fail("%s: Operation has unsupported weights HalOperandLifeTime", __func__); } - LayerInputHandle weightsInput = (desc.m_DataLayout == DataLayout::NCHW) ? ConvertToLayerInputHandle(operation, 1, model, data, OHWIToOIHW) : ConvertToLayerInputHandle(operation, 1, model, data); @@ -562,12 +569,14 @@ bool ConvertDepthwiseConv2d_1_2(const HalOperation& operation, const HalModel& m const TensorInfo& outputInfo = GetTensorInfoForOperand(*output); // ArmNN does not currently support non-fixed weights or bias - // Find the shape of the weights tensor. In AndroidNN this will be [ 1, H, W, I * M ] - const HalOperand* weightsOperand = GetInputOperand(operation, 1, model); - if (!weightsOperand) + if (!IsWeightsValid(operation, 1, model, false)) { - return Fail("%s: Could not read weights", __func__); + return Fail("%s: This Operation has unsupported weights HalOperandLifeTime", __func__); } + + // Find the shape of the weights tensor. In AndroidNN this will be [ 1, H, W, I * M ] + const HalOperand* weightsOperand = GetInputOperand(operation, 1, model); + if (weightsOperand->dimensions[0] != 1) { return Fail("%s: Invalid weights; for depthwise convolution, dimension 0 must be 1 but it is %i", -- cgit v1.2.1