From be5d356c1663009c69c934fd860db1f91863e3d1 Mon Sep 17 00:00:00 2001 From: Aron Virginas-Tar Date: Tue, 16 Jul 2019 11:32:29 +0100 Subject: IVGCVSW-3522 Support dynamic output shape in hal_1_2::HalPolicy::ConvertResize Signed-off-by: Aron Virginas-Tar Change-Id: I962f9759679f539566f7bc3aa75ed3e0bffe7c9f --- 1.2/HalPolicy.cpp | 23 +++++++++++++++++++++-- OutputShapeUtils.cpp | 22 ++++++++++++++++++++++ OutputShapeUtils.hpp | 3 +++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/1.2/HalPolicy.cpp b/1.2/HalPolicy.cpp index 0c57636c..5b501dbc 100644 --- a/1.2/HalPolicy.cpp +++ b/1.2/HalPolicy.cpp @@ -727,7 +727,7 @@ bool HalPolicy::ConvertResize(const Operation& operation, } const armnn::TensorInfo& inputInfo = input.GetTensorInfo(); - const armnn::TensorInfo& outputInfo = GetTensorInfoForOperand(*output); + armnn::TensorInfo outputInfo = GetTensorInfoForOperand(*output); armnn::ResizeDescriptor descriptor; descriptor.m_Method = resizeMethod; @@ -795,6 +795,19 @@ bool HalPolicy::ConvertResize(const Operation& operation, return false; } + if (IsDynamicOutput(outputInfo)) + { + try + { + ALOGD("Output shape not set, will infer from inputs"); + outputInfo.SetShape(InferResizeOutputShape(inputInfo.GetShape(), descriptor)); + } + 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__, IsResizeSupported, @@ -803,6 +816,7 @@ bool HalPolicy::ConvertResize(const Operation& operation, inputInfo, outputInfo, descriptor); + if (!isSupported) { return false; @@ -815,7 +829,12 @@ bool HalPolicy::ConvertResize(const Operation& operation, layer->GetOutputSlot(0).SetTensorInfo(outputInfo); input.Connect(layer->GetInputSlot(0)); - return SetupAndTrackLayerOutputSlot(operation, 0, *layer, model, data); + return SetupAndTrackLayerOutputSlot(operation, + 0, + *layer, + model, + data, + armnn::Optional(outputInfo)); } bool HalPolicy::ConvertSpaceToDepth(const Operation& operation, const Model& model, ConversionData& data) diff --git a/OutputShapeUtils.cpp b/OutputShapeUtils.cpp index 285e25f4..6c936ee7 100644 --- a/OutputShapeUtils.cpp +++ b/OutputShapeUtils.cpp @@ -144,6 +144,28 @@ TensorShape InferPreluOutputShape(const TensorShape& inputShape, const TensorSha return CalculateMaxShape(inputShape, alphaShape); } +TensorShape InferResizeOutputShape(const TensorShape& inputShape, const ResizeDescriptor& descriptor) +{ + if (inputShape.GetNumDimensions() != 4) + { + throw InvalidArgumentException("Input shape for Resize must be 4D"); + } + + armnnUtils::DataLayoutIndexed dataLayoutIndexed(descriptor.m_DataLayout); + + const unsigned int cIndex = dataLayoutIndexed.GetChannelsIndex(); + const unsigned int wIndex = dataLayoutIndexed.GetWidthIndex(); + const unsigned int hIndex = dataLayoutIndexed.GetHeightIndex(); + + TensorShape outputShape(4); + outputShape[0] = inputShape[0]; + outputShape[cIndex] = inputShape[cIndex]; + outputShape[wIndex] = descriptor.m_TargetWidth; + outputShape[hIndex] = descriptor.m_TargetHeight; + + return outputShape; +} + TensorShape InferSubOutputShape(const TensorShape& input0Shape, const TensorShape& input1Shape) { return CalculateMaxShape(input0Shape, input1Shape); diff --git a/OutputShapeUtils.hpp b/OutputShapeUtils.hpp index bcb43475..2a832618 100644 --- a/OutputShapeUtils.hpp +++ b/OutputShapeUtils.hpp @@ -28,6 +28,9 @@ armnn::TensorShape InferPadOutputShape(const armnn::TensorShape& inputShape, armnn::TensorShape InferPreluOutputShape(const armnn::TensorShape& inputShape, const armnn::TensorShape& alphaShape); +armnn::TensorShape InferResizeOutputShape(const armnn::TensorShape& inputShape, + const armnn::ResizeDescriptor& descriptor); + armnn::TensorShape InferSubOutputShape(const armnn::TensorShape& input0Shape, const armnn::TensorShape& input1Shape); } // namespace armnn_driver -- cgit v1.2.1