From 3ab85485968c0e70d0378de3243119fb7b2f7e94 Mon Sep 17 00:00:00 2001 From: Teresa Charlin Date: Tue, 8 Jun 2021 16:59:29 +0100 Subject: IVGCVSW-6075 Add ParseExpandDims to TfliteParser * Add ExpandDims tests in tfliteparser * Add support for negative axis to squeeze Signed-off-by: Teresa Charlin Signed-off-by: Finn Williams Change-Id: I604c9b4ac6514895e9e3d4d85c2937e797d288e0 --- src/armnnTfLiteParser/TfLiteParser.cpp | 56 ++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 6 deletions(-) (limited to 'src/armnnTfLiteParser/TfLiteParser.cpp') diff --git a/src/armnnTfLiteParser/TfLiteParser.cpp b/src/armnnTfLiteParser/TfLiteParser.cpp index f38f45fcdf..2df47eb198 100644 --- a/src/armnnTfLiteParser/TfLiteParser.cpp +++ b/src/armnnTfLiteParser/TfLiteParser.cpp @@ -623,6 +623,7 @@ TfLiteParserImpl::TfLiteParserImpl(const OptionalAddReshapeLayer(reshapeDesc, layerName.c_str()); + ARMNN_ASSERT(layer != nullptr); + layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); + + auto inputTensorIndexes = AsUnsignedVector(GetInputTensorIds(m_Model, subgraphIndex, operatorIndex)); + RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]}); + + auto outputTensorIndexes = AsUnsignedVector(GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex)); + RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]}); +} + void TfLiteParserImpl::ParseTranspose(size_t subgraphIndex, size_t operatorIndex) { CHECK_MODEL(m_Model, subgraphIndex, operatorIndex); @@ -1586,11 +1618,10 @@ void TfLiteParserImpl::ParseSpaceToBatchND(size_t subgraphIndex, size_t operator RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]}); } -armnn::TensorInfo TfLiteParserImpl::OutputShapeOfSqueeze(const std::vector & squeezeDimsIn, +armnn::TensorInfo TfLiteParserImpl::OutputShapeOfSqueeze(std::vector squeezeDims, const armnn::TensorInfo & inputTensorInfo) { - CHECK_VALID_SIZE(squeezeDimsIn.size(), 0, 1, 2, 3, 4); - std::vector squeezeDims = squeezeDimsIn; + CHECK_VALID_SIZE(squeezeDims.size(), 0, 1, 2, 3, 4); static const uint32_t dimensionSequence[] = { 0, 1, 2, 3 }; if (inputTensorInfo.GetNumDimensions() > 4) @@ -1688,9 +1719,22 @@ void TfLiteParserImpl::ParseSqueeze(size_t subgraphIndex, size_t operatorIndex) auto layerName = fmt::format("Squeeze:{}:{}", subgraphIndex, operatorIndex); armnn::TensorInfo inputTensorInfo = ToTensorInfo(inputs[0]); - armnn::TensorInfo outputTensorInfo = - TfLiteParserImpl::OutputShapeOfSqueeze(AsUnsignedVector(options->squeeze_dims), - inputTensorInfo); + + std::vector squeezeDim; + // A single negative dim index is interpreted as a negative index in python + // Meaning the index will be the shape size plus the negative index value + if (options->squeeze_dims.size() == 1 && options->squeeze_dims[0] < 0) + { + int32_t dim = static_cast(inputTensorInfo.GetShape().GetNumDimensions()) + options->squeeze_dims[0]; + squeezeDim.push_back(static_cast(dim)); + } + else + { + squeezeDim = AsUnsignedVector(options->squeeze_dims); + } + + armnn::TensorInfo outputTensorInfo = TfLiteParserImpl::OutputShapeOfSqueeze(squeezeDim, inputTensorInfo); + CheckMatchingQuantization(inputTensorInfo, outputTensorInfo, layerName, "Input 0", "Output 0"); ReshapeDescriptor reshapeDesc; -- cgit v1.2.1