diff options
author | Mike Kelly <mike.kelly@arm.com> | 2022-05-16 23:10:42 +0100 |
---|---|---|
committer | TeresaARM <teresa.charlinreyes@arm.com> | 2022-05-18 14:19:19 +0000 |
commit | 80512b0e1e98cb6782f5526fc8308ae6a571cd59 (patch) | |
tree | bad2f314defadd4b340343d99b6e157b46622039 /src/armnn/Layer.cpp | |
parent | d0420cb62b71f9c015d2b0e889011899051e56c0 (diff) | |
download | armnn-80512b0e1e98cb6782f5526fc8308ae6a571cd59.tar.gz |
IVGCVSW-6929 Support for models with implicit expanded
dimensions
* Added allow-expanded-dims to TFLite parser and ArmNN delegate
* If true ArmNN will disregard dimensions with a size of 1 when
validating tensor shapes. Tensor sizes must still match.
* This allows us to support models where tensors have expanded
dimensions (i.e. extra dimensions with a size of 1).
* Fixed bug in Network where it assumed that only the first option
could be ShapeInferenceMethod.
* Fixed bug where m_ShapeInferenceMethod was lost when copying or
moving Graphs.
* Changed Delegate to pass "infer-output-shape", "allow-expanded-dims"
and other BackendOptions through to the Network during construction.
Signed-off-by: Mike Kelly <mike.kelly@arm.com>
Change-Id: Ibe7c5ae6597796fc9164cb07bd372bd7f8f8cacf
Diffstat (limited to 'src/armnn/Layer.cpp')
-rw-r--r-- | src/armnn/Layer.cpp | 41 |
1 files changed, 36 insertions, 5 deletions
diff --git a/src/armnn/Layer.cpp b/src/armnn/Layer.cpp index 3241b5024e..b1d495244d 100644 --- a/src/armnn/Layer.cpp +++ b/src/armnn/Layer.cpp @@ -11,6 +11,8 @@ #include <armnn/utility/NumericCast.hpp> +#include <armnnUtils/TensorUtils.hpp> + #include <client/include/IProfilingService.hpp> #include <fmt/format.h> @@ -425,11 +427,40 @@ void Layer::ValidateAndCopyShape(const TensorShape& outputShape, { if (shapeInferenceMethod == ShapeInferenceMethod::ValidateOnly) { - ConditionalThrowIfNotEqual<LayerValidationException>( - layerName + ": TensorShape set on OutputSlot[0] does not match the inferred shape.", - outputShape, - inferredShape); - return; + if (m_AllowExpandedDims) + { + std::vector<unsigned int> outputDims = armnnUtils::SqueezeDims(outputShape); + std::vector<unsigned int> inferredDims = armnnUtils::SqueezeDims(inferredShape); + + if (outputDims.size() != inferredDims.size()) + { + std::stringstream ss; + ss << layerName << ": TensorShape set on OutputSlot[" << outputSlotIndex << + "] does not match the inferred shape. "; + ss << outputShape << " != " << inferredShape; + throw LayerValidationException(ss.str()); + } + for (unsigned int i = 0; i < outputDims.size(); ++i) + { + if (outputDims[i] != inferredDims[i]) + { + std::stringstream ss; + ss << layerName << ": TensorShape set on OutputSlot[" << outputSlotIndex << + "] does not match the inferred shape at dimension index ["; + ss << i << "] " << outputShape << " != " << inferredShape; + throw LayerValidationException(ss.str()); + } + } + return; + } + else + { + ConditionalThrowIfNotEqual<LayerValidationException>( + layerName + ": TensorShape set on OutputSlot[0] does not match the inferred shape.", + outputShape, + inferredShape); + return; + } } if (outputShape.GetDimensionality() == Dimensionality::Specified) |