From 2050c23fb3c2f7b867033fd842ec6f4767449008 Mon Sep 17 00:00:00 2001 From: Sadik Armagan Date: Tue, 23 Jul 2019 16:59:58 +0100 Subject: IVGCVSW-3530 Fix DynamicOutput Tests for Android Q NeuralNetworks 1.0 & 1.1 * Updated ConvertToActivation, ConvertConv2d, and ConvertDepthwiseConv2d functions to infer output shape from input if it is dynamic Signed-off-by: Sadik Armagan Change-Id: Ie24fbfd87c6186c69c3ecba5c68a6866507fb449 --- ConversionUtils.hpp | 62 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 6 deletions(-) diff --git a/ConversionUtils.hpp b/ConversionUtils.hpp index 755e3bef..5ebec6b3 100644 --- a/ConversionUtils.hpp +++ b/ConversionUtils.hpp @@ -5,6 +5,7 @@ #pragma once +#include "OutputShapeUtils.hpp" #include "Utils.hpp" #include @@ -1157,7 +1158,12 @@ bool ConvertToActivation(const HalOperation& operation, { return false; } - const armnn::TensorInfo outInfo = GetTensorInfoForOperand(*outputOperand); + armnn::TensorInfo outInfo = GetTensorInfoForOperand(*outputOperand); + if (IsDynamicTensor(outInfo)) + { + ALOGD("Output shape not set, will infer from input"); + outInfo.SetShape(input.GetTensorInfo().GetShape()); + } bool isSupported = false; FORWARD_LAYER_SUPPORT_FUNC(__func__, @@ -1176,7 +1182,11 @@ bool ConvertToActivation(const HalOperation& operation, BOOST_ASSERT(layer != nullptr); input.Connect(layer->GetInputSlot(0)); - return SetupAndTrackLayerOutputSlot(operation, 0, *layer, model, data); + return SetupAndTrackLayerOutputSlot(operation, + 0, + *layer, + model, + data,armnn::Optional(outInfo)); } template(operation, 1, model, data); @@ -1408,6 +1418,21 @@ bool ConvertConv2d(const HalOperation& operation, const HalModel& model, Convers desc.m_BiasEnabled = true; armnn::Optional biases(bias.GetInfo()); + 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()); + } + } + bool isSupported = false; FORWARD_LAYER_SUPPORT_FUNC(__func__, IsConvolution2dSupported, @@ -1440,7 +1465,12 @@ bool ConvertConv2d(const HalOperation& operation, const HalModel& model, Convers input.Connect(startLayer->GetInputSlot(0)); - return SetupAndTrackLayerOutputSlot(operation, 0, *endLayer, model, data); + return SetupAndTrackLayerOutputSlot(operation, + 0, + *endLayer, + model, + data, + armnn::Optional(outputInfo)); } template biases(bias.GetInfo()); + 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()); + } + } + bool isSupported = false; FORWARD_LAYER_SUPPORT_FUNC(__func__, IsDepthwiseConvolutionSupported, @@ -1598,7 +1643,12 @@ bool ConvertDepthwiseConv2d(const HalOperation& operation, const HalModel& model input.Connect(startLayer->GetInputSlot(0)); - return SetupAndTrackLayerOutputSlot(operation, 0, *endLayer, model, data); + return SetupAndTrackLayerOutputSlot(operation, + 0, + *endLayer, + model, + data, + armnn::Optional(outputInfo)); } } // namespace armnn_driver -- cgit v1.2.1