aboutsummaryrefslogtreecommitdiff
path: root/samples/KeywordSpotting/src/Decoder.cpp
diff options
context:
space:
mode:
authorGeorge Gekov <george.gekov@arm.com>2021-08-16 11:32:10 +0100
committerJim Flynn <jim.flynn@arm.com>2022-02-05 19:49:06 +0000
commit23c26277086c78704a17f0dae86da947816320c0 (patch)
tree88b02fd1fae3130256d059251788a7ef68d2831f /samples/KeywordSpotting/src/Decoder.cpp
parent922b912fd2d462bac0809bac5669310ad1506310 (diff)
downloadarmnn-23c26277086c78704a17f0dae86da947816320c0.tar.gz
MLECO-2079 Adding the C++ KWS example
Signed-off-by: Eanna O Cathain <eanna.ocathain@arm.com> Change-Id: I81899bbfaada32f478c2e2fc6441eabb94d8d0fc
Diffstat (limited to 'samples/KeywordSpotting/src/Decoder.cpp')
-rw-r--r--samples/KeywordSpotting/src/Decoder.cpp35
1 files changed, 35 insertions, 0 deletions
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<int, float> kws::Decoder::decodeOutput(std::vector<int8_t>& modelOutput)
+{
+
+ std::vector<float> dequantisedOutput;
+ //Normalise vector values into new vector
+ for (auto& value : modelOutput)
+ {
+ float normalisedModelOutput = this->quantisationScale * (static_cast<float >(value) -
+ static_cast<float >(this->quantisationOffset));
+ dequantisedOutput.push_back(normalisedModelOutput);
+ }
+
+ //Get largest value in modelOutput
+ const std::vector<float>::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<int>(std::distance(dequantisedOutput.begin(), maxElementIterator));
+
+ //Round to two DP
+ float maxModelOutputProbability = std::roundf((*maxElementIterator) * 100) / 100;
+
+ return std::make_pair(labelMapIndex, maxModelOutputProbability);
+
+}
+
+
+
+