From da47048a4ec5c7deaa29ff0313c42163993119de Mon Sep 17 00:00:00 2001 From: Derek Lamberti Date: Tue, 14 May 2019 16:55:25 +0100 Subject: IVGCVSW-3001 Dequantize the output prior to printing Change-Id: Ibd5fb4ad102aec1f71ab99402a3e3a08b04b926b Signed-off-by: Derek Lamberti --- tests/ExecuteNetwork/ExecuteNetwork.cpp | 65 ++++++++++++++++++++++++++++----- 1 file changed, 55 insertions(+), 10 deletions(-) diff --git a/tests/ExecuteNetwork/ExecuteNetwork.cpp b/tests/ExecuteNetwork/ExecuteNetwork.cpp index 1de22ed5d0..8ca69d8292 100644 --- a/tests/ExecuteNetwork/ExecuteNetwork.cpp +++ b/tests/ExecuteNetwork/ExecuteNetwork.cpp @@ -191,6 +191,57 @@ void RemoveDuplicateDevices(std::vector& computeDevices) computeDevices.end()); } +struct TensorPrinter : public boost::static_visitor<> +{ + TensorPrinter(const std::string& binding, const armnn::TensorInfo& info) + : m_OutputBinding(binding) + , m_Scale(info.GetQuantizationScale()) + , m_Offset(info.GetQuantizationOffset()) + {} + + void operator()(const std::vector& values) + { + ForEachValue(values, [](float value){ + printf("%f ", value); + }); + } + + void operator()(const std::vector& values) + { + auto& scale = m_Scale; + auto& offset = m_Offset; + ForEachValue(values, [&scale, &offset](uint8_t value) + { + printf("%f ", armnn::Dequantize(value, scale, offset)); + }); + } + + void operator()(const std::vector& values) + { + ForEachValue(values, [](int value) + { + printf("%d ", value); + }); + } + +private: + template + void ForEachValue(const Container& c, Delegate delegate) + { + std::cout << m_OutputBinding << ": "; + for (const auto& value : c) + { + delegate(value); + } + printf("\n"); + } + + std::string m_OutputBinding; + float m_Scale=0.0f; + int m_Offset=0; +}; + + } // namespace template @@ -299,18 +350,12 @@ int MainImpl(const char* modelPath, auto inference_duration = model.Run(inputDataContainers, outputDataContainers); // Print output tensors + const auto& infosOut = model.GetOutputBindingInfos(); for (size_t i = 0; i < numOutputs; i++) { - boost::apply_visitor([&](auto&& value) - { - std::cout << params.m_OutputBindings[i] << ": "; - for (size_t i = 0; i < value.size(); ++i) - { - printf("%f ", static_cast(value[i])); - } - printf("\n"); - }, - outputDataContainers[i]); + const armnn::TensorInfo& infoOut = infosOut[i].second; + TensorPrinter printer(params.m_OutputBindings[i], infoOut); + boost::apply_visitor(printer, outputDataContainers[i]); } BOOST_LOG_TRIVIAL(info) << "\nInference time: " << std::setprecision(2) -- cgit v1.2.1