From 2686849118217ba692439407adb53ec3849d48ac Mon Sep 17 00:00:00 2001 From: Sadik Armagan Date: Fri, 22 Jan 2021 14:25:31 +0000 Subject: MLCE-335 'DEPTH_TO_SPACE and GATHER operator support in TfLiteParser' * Added GATHER operator support to TfLiteParser * Added DEPTH_TO_SPACE operator support to TfLiteParser Signed-off-by: Sadik Armagan Change-Id: Id5d3b54e2d850eb9f19417029efbeb73a3029e69 --- .../test/ParserFlatbuffersFixture.hpp | 102 ++++++++++++++++++--- 1 file changed, 89 insertions(+), 13 deletions(-) (limited to 'src/armnnTfLiteParser/test/ParserFlatbuffersFixture.hpp') diff --git a/src/armnnTfLiteParser/test/ParserFlatbuffersFixture.hpp b/src/armnnTfLiteParser/test/ParserFlatbuffersFixture.hpp index 50a312fcf6..fc1d94e21f 100644 --- a/src/armnnTfLiteParser/test/ParserFlatbuffersFixture.hpp +++ b/src/armnnTfLiteParser/test/ParserFlatbuffersFixture.hpp @@ -152,6 +152,18 @@ struct ParserFlatbuffersFixture const std::map>>& expectedOutputData, bool isDynamic = false); + /// Multiple Inputs with different DataTypes, Multiple Outputs w/ Variable DataTypes + /// Executes the network with the given input tensors and checks the results against the given output tensors. + /// This overload supports multiple inputs and multiple outputs, identified by name along with the allowance for + /// the input datatype to be different to the output + template + void RunTest(size_t subgraphId, + const std::map>>& input1Data, + const std::map>>& input2Data, + const std::map>>& expectedOutputData); /// Multiple Inputs, Multiple Outputs w/ Variable Datatypes and different dimension sizes. /// Executes the network with the given input tensors and checks the results against the given output tensors. @@ -212,8 +224,30 @@ struct ParserFlatbuffersFixture tensors->quantization.get()->zero_point.begin(), tensors->quantization.get()->zero_point.end()); } + +private: + /// Fills the InputTensors with given input data + template + void FillInputTensors(armnn::InputTensors& inputTensors, + const std::map>>& inputData, + size_t subgraphId); }; +/// Fills the InputTensors with given input data +template +void ParserFlatbuffersFixture::FillInputTensors( + armnn::InputTensors& inputTensors, + const std::map>>& inputData, + size_t subgraphId) +{ + for (auto&& it : inputData) + { + armnn::BindingPointInfo bindingInfo = m_Parser->GetNetworkInputBindingInfo(subgraphId, it.first); + armnn::VerifyTensorInfoDataType(bindingInfo.second, dataType); + inputTensors.push_back({ bindingInfo.first, armnn::ConstTensor(bindingInfo.second, it.second.data()) }); + } +} + /// Single Input, Single Output /// Executes the network with the given input tensor and checks the result against the given output tensor. /// This overload assumes the network has a single input and a single output. @@ -256,12 +290,7 @@ void ParserFlatbuffersFixture::RunTest(size_t subgraphId, // Setup the armnn input tensors from the given vectors. armnn::InputTensors inputTensors; - for (auto&& it : inputData) - { - armnn::BindingPointInfo bindingInfo = m_Parser->GetNetworkInputBindingInfo(subgraphId, it.first); - armnn::VerifyTensorInfoDataType(bindingInfo.second, armnnType1); - inputTensors.push_back({ bindingInfo.first, armnn::ConstTensor(bindingInfo.second, it.second.data()) }); - } + FillInputTensors(inputTensors, inputData, subgraphId); // Allocate storage for the output tensors to be written to and setup the armnn output tensors. std::map> outputStorage; @@ -310,13 +339,7 @@ void ParserFlatbuffersFixture::RunTest(std::size_t subgraphId, // Setup the armnn input tensors from the given vectors. armnn::InputTensors inputTensors; - for (auto&& it : inputData) - { - armnn::BindingPointInfo bindingInfo = m_Parser->GetNetworkInputBindingInfo(subgraphId, it.first); - armnn::VerifyTensorInfoDataType(bindingInfo.second, armnnType1); - - inputTensors.push_back({ bindingInfo.first, armnn::ConstTensor(bindingInfo.second, it.second.data()) }); - } + FillInputTensors(inputTensors, inputData, subgraphId); armnn::OutputTensors outputTensors; outputTensors.reserve(expectedOutputData.size()); @@ -347,3 +370,56 @@ void ParserFlatbuffersFixture::RunTest(std::size_t subgraphId, } } } + +/// Multiple Inputs with different DataTypes, Multiple Outputs w/ Variable DataTypes +/// Executes the network with the given input tensors and checks the results against the given output tensors. +/// This overload supports multiple inputs and multiple outputs, identified by name along with the allowance for +/// the input datatype to be different to the output +template +void ParserFlatbuffersFixture::RunTest(size_t subgraphId, + const std::map>>& input1Data, + const std::map>>& input2Data, + const std::map>>& expectedOutputData) +{ + using DataType2 = armnn::ResolveType; + + // Setup the armnn input tensors from the given vectors. + armnn::InputTensors inputTensors; + FillInputTensors(inputTensors, input1Data, subgraphId); + FillInputTensors(inputTensors, input2Data, subgraphId); + + // Allocate storage for the output tensors to be written to and setup the armnn output tensors. + std::map> outputStorage; + armnn::OutputTensors outputTensors; + for (auto&& it : expectedOutputData) + { + armnn::LayerBindingId outputBindingId = m_Parser->GetNetworkOutputBindingInfo(subgraphId, it.first).first; + armnn::TensorInfo outputTensorInfo = m_Runtime->GetOutputTensorInfo(m_NetworkIdentifier, outputBindingId); + + // Check that output tensors have correct number of dimensions (NumOutputDimensions specified in test) + auto outputNumDimensions = outputTensorInfo.GetNumDimensions(); + BOOST_CHECK_MESSAGE((outputNumDimensions == NumOutputDimensions), + fmt::format("Number of dimensions expected {}, but got {} for output layer {}", + NumOutputDimensions, + outputNumDimensions, + it.first)); + + armnn::VerifyTensorInfoDataType(outputTensorInfo, outputType); + outputStorage.emplace(it.first, MakeTensor(outputTensorInfo)); + outputTensors.push_back( + { outputBindingId, armnn::Tensor(outputTensorInfo, outputStorage.at(it.first).data()) }); + } + + m_Runtime->EnqueueWorkload(m_NetworkIdentifier, inputTensors, outputTensors); + + // Compare each output tensor to the expected values + for (auto&& it : expectedOutputData) + { + armnn::BindingPointInfo bindingInfo = m_Parser->GetNetworkOutputBindingInfo(subgraphId, it.first); + auto outputExpected = MakeTensor(bindingInfo.second, it.second); + BOOST_TEST(CompareTensors(outputExpected, outputStorage[it.first], false)); + } +} \ No newline at end of file -- cgit v1.2.1