From 6111316eb609bd71589b963cf6fc56b18ba3d241 Mon Sep 17 00:00:00 2001 From: Sadik Armagan Date: Thu, 25 Jul 2019 09:09:40 +0100 Subject: IVGCVSW-3530 Fix DynamicOutput Tests for Android Q NeuralNetworks 1.0 & 1.1 * Fixed for failing Conv2d, DepthwiseConv2d, and Activation tests on Hal 1.0 and 1.1 in Q Signed-off-by: Sadik Armagan Signed-off-by: Aron Virginas-Tar Change-Id: I435338b90b6c501320083f2fd9372e3a4ac3c32c --- ConversionUtils.hpp | 95 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 71 insertions(+), 24 deletions(-) (limited to 'ConversionUtils.hpp') diff --git a/ConversionUtils.hpp b/ConversionUtils.hpp index f84dc108..790382d6 100644 --- a/ConversionUtils.hpp +++ b/ConversionUtils.hpp @@ -194,6 +194,11 @@ inline bool IsBool(V1_0::Operand) return false; } +inline bool Is12Operand(V1_0::Operand) +{ + return false; +} + #ifdef ARMNN_ANDROID_NN_V1_2 inline bool IsBool(V1_2::Operand operand) @@ -201,6 +206,12 @@ inline bool IsBool(V1_2::Operand operand) return operand.type == V1_2::OperandType::BOOL; } +/// Checks if a operand is 1_2 Operand +inline bool Is12Operand(V1_2::Operand) +{ + return true; +} + #endif template @@ -1161,8 +1172,15 @@ bool ConvertToActivation(const HalOperation& operation, armnn::TensorInfo outInfo = GetTensorInfoForOperand(*outputOperand); if (IsDynamicTensor(outInfo)) { - ALOGD("Output shape not set, will infer from input"); - outInfo.SetShape(input.GetTensorInfo().GetShape()); + if (Is12Operand(*outputOperand)) + { + ALOGD("Output shape not set, will infer from input"); + outInfo.SetShape(input.GetTensorInfo().GetShape()); + } + else + { + return Fail("%s: Dynamic OutputShapes are not supported in this HAL version", __func__); + } } bool isSupported = false; @@ -1189,6 +1207,55 @@ bool ConvertToActivation(const HalOperation& operation, data,armnn::Optional(outInfo)); } +template +bool ConvertReLu(const HalOperation& operation, const HalModel& model, ConversionData& data) +{ + armnn::ActivationDescriptor desc; + desc.m_Function = armnn::ActivationFunction::ReLu; + + return ConvertToActivation(operation, __func__, desc, model, data); +} + +template +bool ConvertReLu1(const HalOperation& operation, const HalModel& model, ConversionData& data) +{ + armnn::ActivationDescriptor desc; + desc.m_Function = armnn::ActivationFunction::BoundedReLu; + desc.m_A = 1.0f; + desc.m_B = -1.0f; + + return ConvertToActivation(operation, __func__, desc, model, data); +} + +template +bool ConvertReLu6(const HalOperation& operation, const HalModel& model, ConversionData& data) +{ + armnn::ActivationDescriptor desc; + desc.m_Function = armnn::ActivationFunction::BoundedReLu; + desc.m_A = 6.0f; + + return ConvertToActivation(operation, __func__, desc, model, data); +} + +template +bool ConvertTanH(const HalOperation& operation, const HalModel& model, ConversionData& data) +{ + armnn::ActivationDescriptor desc; + desc.m_Function = armnn::ActivationFunction::TanH; + desc.m_A = 1.0f; // android nn does not support tanH parameters + desc.m_B = 1.0f; // set to 1.0f for unity scaling + + return ConvertToActivation(operation, __func__, desc, model, data); +} + template @@ -1420,17 +1487,7 @@ bool ConvertConv2d(const HalOperation& operation, const HalModel& model, Convers if (IsDynamicTensor(outputInfo)) { - try - { - ALOGD("Output shape not set, will infer from inputs"); - outputInfo.SetShape(InferConvolution2dOutputShape(inputInfo.GetShape(), - weights.GetInfo().GetShape(), - desc)); - } - catch (armnn::Exception& e) - { - return Fail("%s: Could not infer dynamic output shape: %s", __func__, e.what()); - } + return Fail("%s: Dynamic OutputShapes are not supported", __func__); } bool isSupported = false; @@ -1600,17 +1657,7 @@ bool ConvertDepthwiseConv2d(const HalOperation& operation, const HalModel& model if (IsDynamicTensor(outputInfo)) { - try - { - ALOGD("Output shape not set, will infer from inputs"); - outputInfo.SetShape(InferDepthwiseConvolution2dOutputShape(inputInfo.GetShape(), - weights.GetInfo().GetShape(), - desc)); - } - catch (armnn::Exception& e) - { - return Fail("%s: Could not infer dynamic output shape: %s", __func__, e.what()); - } + return Fail("%s: Dynamic OutputShapes are not supported", __func__); } bool isSupported = false; -- cgit v1.2.1