aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAron Virginas-Tar <Aron.Virginas-Tar@arm.com>2019-07-16 11:32:29 +0100
committerÁron Virginás-Tar <aron.virginas-tar@arm.com>2019-07-16 13:31:47 +0000
commitbe5d356c1663009c69c934fd860db1f91863e3d1 (patch)
tree603c9b744147c6875998beadb931afec00e8d3a9
parent9fd373954d64fbae72d1726bbdfc57a18a3a2f6d (diff)
downloadandroid-nn-driver-be5d356c1663009c69c934fd860db1f91863e3d1.tar.gz
IVGCVSW-3522 Support dynamic output shape in hal_1_2::HalPolicy::ConvertResize
Signed-off-by: Aron Virginas-Tar <Aron.Virginas-Tar@arm.com> Change-Id: I962f9759679f539566f7bc3aa75ed3e0bffe7c9f
-rw-r--r--1.2/HalPolicy.cpp23
-rw-r--r--OutputShapeUtils.cpp22
-rw-r--r--OutputShapeUtils.hpp3
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<hal_1_2::HalPolicy>(operation, 0, *layer, model, data);
+ return SetupAndTrackLayerOutputSlot<hal_1_2::HalPolicy>(operation,
+ 0,
+ *layer,
+ model,
+ data,
+ armnn::Optional<armnn::TensorInfo>(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