From 1b3e2ead82db933ea8e97063cea132cb042b079a Mon Sep 17 00:00:00 2001 From: keidav01 Date: Thu, 21 Feb 2019 10:07:37 +0000 Subject: IVGCVSW-2429 Add Detection PostProcess Parser to TensorFlow Lite Parser * Added parser function in TFLiteParser * Removed custom options gating * Added unit test * Removed template usage in VerifyTensorInfo for DeserializeParser Change-Id: If198654ed70060855a05f8aaed010293405bd103 Signed-off-by: keidav01 --- .../test/ParserFlatbuffersFixture.hpp | 120 +++++++++++++++++++-- 1 file changed, 111 insertions(+), 9 deletions(-) (limited to 'src/armnnTfLiteParser/test/ParserFlatbuffersFixture.hpp') diff --git a/src/armnnTfLiteParser/test/ParserFlatbuffersFixture.hpp b/src/armnnTfLiteParser/test/ParserFlatbuffersFixture.hpp index 8d0ee01aa9..50e674ef2c 100644 --- a/src/armnnTfLiteParser/test/ParserFlatbuffersFixture.hpp +++ b/src/armnnTfLiteParser/test/ParserFlatbuffersFixture.hpp @@ -116,7 +116,7 @@ struct ParserFlatbuffersFixture } /// 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. + /// This assumes the network has a single input and a single output. template > @@ -133,6 +133,32 @@ struct ParserFlatbuffersFixture const std::map>& inputData, 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. + /// 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 , + typename DataType2 = armnn::ResolveType> + void RunTest(size_t subgraphId, + const std::map>& inputData, + 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. + /// 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, + typename DataType2 = armnn::ResolveType> + void RunTest(std::size_t subgraphId, + const std::map>& inputData, + const std::map>& expectedOutputData); + void CheckTensors(const TensorRawPtr& tensors, size_t shapeSize, const std::vector& shape, tflite::TensorType tensorType, uint32_t buffer, const std::string& name, const std::vector& min, const std::vector& max, @@ -157,24 +183,46 @@ struct ParserFlatbuffersFixture } }; +/// 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. template void ParserFlatbuffersFixture::RunTest(size_t subgraphId, const std::vector& inputData, const std::vector& expectedOutputData) { - RunTest(subgraphId, + RunTest(subgraphId, { { m_SingleInputName, inputData } }, { { m_SingleOutputName, expectedOutputData } }); } +/// Multiple Inputs, Multiple Outputs +/// 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. template void ParserFlatbuffersFixture::RunTest(size_t subgraphId, const std::map>& inputData, const std::map>& expectedOutputData) +{ + RunTest(subgraphId, inputData, expectedOutputData); +} + +/// Multiple Inputs, 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>& inputData, + const std::map>& expectedOutputData) { using BindingPointInfo = std::pair; @@ -183,18 +231,18 @@ void ParserFlatbuffersFixture::RunTest(size_t subgraphId, for (auto&& it : inputData) { BindingPointInfo bindingInfo = m_Parser->GetNetworkInputBindingInfo(subgraphId, it.first); - armnn::VerifyTensorInfoDataType(bindingInfo.second); + armnn::VerifyTensorInfoDataType(bindingInfo.second, armnnType1); inputTensors.push_back({ bindingInfo.first, armnn::ConstTensor(bindingInfo.second, it.second.data()) }); } // Allocate storage for the output tensors to be written to and setup the armnn output tensors. - std::map> outputStorage; + std::map> outputStorage; armnn::OutputTensors outputTensors; for (auto&& it : expectedOutputData) { BindingPointInfo bindingInfo = m_Parser->GetNetworkOutputBindingInfo(subgraphId, it.first); - armnn::VerifyTensorInfoDataType(bindingInfo.second); - outputStorage.emplace(it.first, MakeTensor(bindingInfo.second)); + armnn::VerifyTensorInfoDataType(bindingInfo.second, armnnType2); + outputStorage.emplace(it.first, MakeTensor(bindingInfo.second)); outputTensors.push_back( { bindingInfo.first, armnn::Tensor(bindingInfo.second, outputStorage.at(it.first).data()) }); } @@ -205,7 +253,61 @@ void ParserFlatbuffersFixture::RunTest(size_t subgraphId, for (auto&& it : expectedOutputData) { BindingPointInfo bindingInfo = m_Parser->GetNetworkOutputBindingInfo(subgraphId, it.first); - auto outputExpected = MakeTensor(bindingInfo.second, it.second); + auto outputExpected = MakeTensor(bindingInfo.second, it.second); BOOST_TEST(CompareTensors(outputExpected, outputStorage[it.first])); } } + +/// 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. +/// 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(std::size_t subgraphId, + const std::map>& inputData, + const std::map>& expectedOutputData) +{ + using BindingPointInfo = std::pair; + + // Setup the armnn input tensors from the given vectors. + armnn::InputTensors inputTensors; + for (auto&& it : inputData) + { + 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()) }); + } + + armnn::OutputTensors outputTensors; + outputTensors.reserve(expectedOutputData.size()); + std::map> outputStorage; + for (auto&& it : expectedOutputData) + { + BindingPointInfo bindingInfo = m_Parser->GetNetworkOutputBindingInfo(subgraphId, it.first); + armnn::VerifyTensorInfoDataType(bindingInfo.second, armnnType2); + + std::vector out(it.second.size()); + outputStorage.emplace(it.first, out); + outputTensors.push_back({ bindingInfo.first, + armnn::Tensor(bindingInfo.second, + outputStorage.at(it.first).data()) }); + } + + m_Runtime->EnqueueWorkload(m_NetworkIdentifier, inputTensors, outputTensors); + + // Checks the results. + for (auto&& it : expectedOutputData) + { + std::vector out = outputStorage.at(it.first); + { + for (unsigned int i = 0; i < out.size(); ++i) + { + BOOST_TEST(it.second[i] == out[i], boost::test_tools::tolerance(0.000001f)); + } + } + } +} -- cgit v1.2.1