From 6a056a4a584035ecd63fe1f70224175f3aca486e Mon Sep 17 00:00:00 2001 From: Teresa Charlin Date: Wed, 1 Dec 2021 10:25:43 +0000 Subject: Revert "IVGCVSW-6252 Armnn Error: Failed to parse operator #1 within subgraph #0 error: Operator not supported" This reverts commit 9fc259682c8b85af58bda42e87703bbec5ae57ce. Fixes: IVGCVSW-6644 ExecuteNetwork tests failing with invalid input shape in Reshape layer Signed-off-by: Teresa Charlin Change-Id: I561e0bd9ed1b92491cb8a08635042e199dd661d8 --- CMakeLists.txt | 1 - src/armnnTfLiteParser/TfLiteParser.cpp | 51 ++------ src/armnnTfLiteParser/test/ReshapeDynamic.cpp | 172 -------------------------- 3 files changed, 9 insertions(+), 215 deletions(-) delete mode 100644 src/armnnTfLiteParser/test/ReshapeDynamic.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index d08641431d..fde058216b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -718,7 +718,6 @@ if(BUILD_UNIT_TESTS) src/armnnTfLiteParser/test/Prelu.cpp src/armnnTfLiteParser/test/Reduce.cpp src/armnnTfLiteParser/test/Reshape.cpp - src/armnnTfLiteParser/test/ReshapeDynamic.cpp src/armnnTfLiteParser/test/ResizeBilinear.cpp src/armnnTfLiteParser/test/ResizeNearestNeighbor.cpp src/armnnTfLiteParser/test/Quantize.cpp diff --git a/src/armnnTfLiteParser/TfLiteParser.cpp b/src/armnnTfLiteParser/TfLiteParser.cpp index 4e0efbbf3c..15ca36d906 100644 --- a/src/armnnTfLiteParser/TfLiteParser.cpp +++ b/src/armnnTfLiteParser/TfLiteParser.cpp @@ -2545,11 +2545,9 @@ void TfLiteParserImpl::ParseReshape(size_t subgraphIndex, size_t operatorIndex) // If there is no built-in option given or if the built-in new_shape parameter was empty if (!targetShapeFound) { - bool secondInputTensorExists = inputs.size() > 1 && inputs[1] != nullptr; - if (secondInputTensorExists) + // Check for a second input tensor + if (inputs.size() > 1 && inputs[1] != nullptr) { - armnn::TensorInfo shapeInfo = ToTensorInfo(inputs[1]); - if (inputs[1]->is_variable) { ARMNN_THROW_PARSE_EXCEPTION( "Target shapes defined in non-const input tensors is not supported"); @@ -2565,47 +2563,16 @@ void TfLiteParserImpl::ParseReshape(size_t subgraphIndex, size_t operatorIndex) ARMNN_THROW_PARSE_EXCEPTION("Target 'shape' input is not an int32 type"); } - // If the provided shape is constant, we can load in from the buffer ... - if (shapeInfo.IsConstant()) + // Extract target shape from input + auto bufferPtr = GetBuffer(m_Model, inputs[1]->buffer); + auto values = reinterpret_cast(bufferPtr->data.data()); + if (!values) { - // Extract target shape from input - auto bufferPtr = GetBuffer(m_Model, inputs[1]->buffer); - auto values = reinterpret_cast(bufferPtr->data.data()); - if (!values) - { - ARMNN_THROW_PARSE_EXCEPTION("Reshape operator target shape input buffer data is null"); - } - for (int i=0; i < inputs[1]->shape[0]; ++i) - { - targetShape.push_back(values[i]); - } + ARMNN_THROW_PARSE_EXCEPTION("Reshape operator target shape input buffer data is null"); } - // ... otherwise, we have to infer it during Runtime. - else + for (int i=0; i < inputs[1]->shape[0]; ++i) { - // The parser only supports shape (batch, -1) or (-1) for non-constant shape input. - unsigned int dims = shapeInfo.GetNumDimensions(); - TensorShape shapes = shapeInfo.GetShape(); - if (dims != 1 || shapes[0] > 2) - { - throw ParseException(fmt::format("Invalid input shape '{}' in Reshape layer '{}' {}. " - "The parser only supports shape (batch, -1) or (-1) for " - "non-constant shape input.", - shapes[0], - layerName, - CHECK_LOCATION().AsString())); - } - - const int32_t numInputElements = inputTensorInfo.GetNumElements(); - const int32_t inputTensorShape = inputTensorInfo.GetShape()[0]; - if (shapes[0] == 1) - { - targetShape = { numInputElements }; - } - else if (shapes[0] == 2) - { - targetShape = { inputTensorShape , numInputElements / inputTensorShape }; - } + targetShape.push_back(values[i]); } } else diff --git a/src/armnnTfLiteParser/test/ReshapeDynamic.cpp b/src/armnnTfLiteParser/test/ReshapeDynamic.cpp deleted file mode 100644 index ca993fb90c..0000000000 --- a/src/armnnTfLiteParser/test/ReshapeDynamic.cpp +++ /dev/null @@ -1,172 +0,0 @@ -// -// Copyright © 2021 Arm Ltd and Contributors. All rights reserved. -// SPDX-License-Identifier: MIT -// - -#include "ParserFlatbuffersFixture.hpp" - - -TEST_SUITE("TensorflowLiteParser_Reshape_Dynamic") -{ -struct ReshapeDynamicFixture : public ParserFlatbuffersFixture -{ - explicit ReshapeDynamicFixture() - { - m_JsonString = R"( -{ - "version": 3, - "operator_codes": [ - { - "deprecated_builtin_code": 77, - "version": 1, - "builtin_code": "ADD" - }, - { - "deprecated_builtin_code": 22, - "version": 1, - "builtin_code": "ADD" - } - ], - "subgraphs": [ - { - "tensors": [ - { - "shape": [ - 1, - 9 - ], - "type": "FLOAT32", - "buffer": 1, - "name": "input_33", - "quantization": { - "details_type": "NONE", - "quantized_dimension": 0 - }, - "is_variable": false, - "shape_signature": [ - -1, - 9 - ] - }, - { - "shape": [ - 2 - ], - "type": "INT32", - "buffer": 2, - "name": "functional_15/tf_op_layer_Shape_9/Shape_9", - "quantization": { - "details_type": "NONE", - "quantized_dimension": 0 - }, - "is_variable": false - }, - { - "shape": [ - 1, - 9 - ], - "type": "FLOAT32", - "buffer": 3, - "name": "Identity", - "quantization": { - "details_type": "NONE", - "quantized_dimension": 0 - }, - "is_variable": false, - "shape_signature": [ - -1, - 9 - ] - } - ], - "inputs": [ - 0 - ], - "outputs": [ - 2 - ], - "operators": [ - { - "opcode_index": 0, - "inputs": [ - 0 - ], - "outputs": [ - 1 - ], - "builtin_options_type": "ShapeOptions", - "builtin_options": { - "out_type": "INT32" - }, - "custom_options_format": "FLEXBUFFERS" - }, - { - "opcode_index": 1, - "inputs": [ - 0, - 1 - ], - "outputs": [ - 2 - ], - "builtin_options_type": "NONE", - "custom_options_format": "FLEXBUFFERS" - } - ], - "name": "main" - } - ], - "description": "MLIR Converted.", - "buffers": [ - { - }, - { - }, - { - }, - { - }, - { - "data": [ - 49, - 46, - 49, - 48, - 46, - 48, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 - ] - } - ], - "metadata": [ - { - "name": "min_runtime_version", - "buffer": 4 - } - ] -} -)"; - - } -}; - -TEST_CASE_FIXTURE(ReshapeDynamicFixture, "ParseReshapeDynamic") -{ - SetupSingleInputSingleOutput("input_33", "Identity"); - RunTest<2, armnn::DataType::Float32>(0, - { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, - { 1, 2, 3, 4, 5, 6, 7, 8, 9 }); - CHECK((m_Parser->GetNetworkOutputBindingInfo(0, "Identity").second.GetShape() - == armnn::TensorShape({1,9}))); -} -} \ No newline at end of file -- cgit v1.2.1