aboutsummaryrefslogtreecommitdiff
path: root/src/armnn/layers/MeanLayer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/armnn/layers/MeanLayer.cpp')
-rw-r--r--src/armnn/layers/MeanLayer.cpp22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/armnn/layers/MeanLayer.cpp b/src/armnn/layers/MeanLayer.cpp
index 49eac04a8e..a6f721b076 100644
--- a/src/armnn/layers/MeanLayer.cpp
+++ b/src/armnn/layers/MeanLayer.cpp
@@ -1,5 +1,5 @@
//
-// Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
+// Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved.
// SPDX-License-Identifier: MIT
//
@@ -49,7 +49,19 @@ void MeanLayer::ValidateTensorShapesFromInputs()
VerifyShapeInferenceType(outputShape, m_ShapeInferenceMethod);
- const TensorInfo& input = GetInputSlot(0).GetConnection()->GetTensorInfo();
+ std::vector<TensorShape> inferredShapes = InferOutputShapes(
+ { GetInputSlot(0).GetConnection()->GetTensorInfo().GetShape() });
+
+ ARMNN_ASSERT(inferredShapes.size() == 1);
+ ARMNN_ASSERT(inferredShapes[0].GetDimensionality() == Dimensionality::Specified);
+
+ ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "MeanLayer");
+}
+
+std::vector<TensorShape> MeanLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const
+{
+ ARMNN_ASSERT(inputShapes.size() == 1);
+ const TensorShape& input = inputShapes[0];
ARMNN_ASSERT_MSG(input.GetNumDimensions() > 0 && input.GetNumDimensions() <= 4,
"MeanLayer: Mean supports up to 4D input.");
@@ -88,7 +100,7 @@ void MeanLayer::ValidateTensorShapesFromInputs()
{
if (std::find(m_Param.m_Axis.begin(), m_Param.m_Axis.end(), i) == m_Param.m_Axis.end())
{
- dimSizes[outputIndex] = armnn::numeric_cast<unsigned int>(input.GetShape()[i]);
+ dimSizes[outputIndex] = armnn::numeric_cast<unsigned int>(input[i]);
++outputIndex;
}
else if (m_Param.m_KeepDims)
@@ -98,9 +110,7 @@ void MeanLayer::ValidateTensorShapesFromInputs()
}
}
}
- const TensorShape& inferredShape = TensorShape(outputRank, dimSizes.data());
-
- ValidateAndCopyShape(outputShape, inferredShape, m_ShapeInferenceMethod, "MeanLayer");
+ return std::vector<TensorShape>({ TensorShape(outputRank, dimSizes.data()) });
}
void MeanLayer::ExecuteStrategy(IStrategy& strategy) const