From 23c26277086c78704a17f0dae86da947816320c0 Mon Sep 17 00:00:00 2001 From: George Gekov Date: Mon, 16 Aug 2021 11:32:10 +0100 Subject: MLECO-2079 Adding the C++ KWS example Signed-off-by: Eanna O Cathain Change-Id: I81899bbfaada32f478c2e2fc6441eabb94d8d0fc --- samples/KeywordSpotting/src/Decoder.cpp | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 samples/KeywordSpotting/src/Decoder.cpp (limited to 'samples/KeywordSpotting/src/Decoder.cpp') diff --git a/samples/KeywordSpotting/src/Decoder.cpp b/samples/KeywordSpotting/src/Decoder.cpp new file mode 100644 index 0000000000..107e25caa9 --- /dev/null +++ b/samples/KeywordSpotting/src/Decoder.cpp @@ -0,0 +1,35 @@ +// +// Copyright © 2021 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "Decoder.hpp" + +std::pair kws::Decoder::decodeOutput(std::vector& modelOutput) +{ + + std::vector dequantisedOutput; + //Normalise vector values into new vector + for (auto& value : modelOutput) + { + float normalisedModelOutput = this->quantisationScale * (static_cast(value) - + static_cast(this->quantisationOffset)); + dequantisedOutput.push_back(normalisedModelOutput); + } + + //Get largest value in modelOutput + const std::vector::iterator& maxElementIterator = std::max_element(dequantisedOutput.begin(), + dequantisedOutput.end()); + //Find the labelMapIndex of the largest value which corresponds to a key in a label map + int labelMapIndex = static_cast(std::distance(dequantisedOutput.begin(), maxElementIterator)); + + //Round to two DP + float maxModelOutputProbability = std::roundf((*maxElementIterator) * 100) / 100; + + return std::make_pair(labelMapIndex, maxModelOutputProbability); + +} + + + + -- cgit v1.2.1