George Gekov | 23c2627 | 2021-08-16 11:32:10 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2021 Arm Ltd and Contributors. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "Decoder.hpp" |
| 7 | |
| 8 | std::pair<int, float> kws::Decoder::decodeOutput(std::vector<int8_t>& modelOutput) |
| 9 | { |
| 10 | |
| 11 | std::vector<float> dequantisedOutput; |
| 12 | //Normalise vector values into new vector |
| 13 | for (auto& value : modelOutput) |
| 14 | { |
| 15 | float normalisedModelOutput = this->quantisationScale * (static_cast<float >(value) - |
| 16 | static_cast<float >(this->quantisationOffset)); |
| 17 | dequantisedOutput.push_back(normalisedModelOutput); |
| 18 | } |
| 19 | |
| 20 | //Get largest value in modelOutput |
| 21 | const std::vector<float>::iterator& maxElementIterator = std::max_element(dequantisedOutput.begin(), |
| 22 | dequantisedOutput.end()); |
| 23 | //Find the labelMapIndex of the largest value which corresponds to a key in a label map |
| 24 | int labelMapIndex = static_cast<int>(std::distance(dequantisedOutput.begin(), maxElementIterator)); |
| 25 | |
| 26 | //Round to two DP |
| 27 | float maxModelOutputProbability = std::roundf((*maxElementIterator) * 100) / 100; |
| 28 | |
| 29 | return std::make_pair(labelMapIndex, maxModelOutputProbability); |
| 30 | |
| 31 | } |
| 32 | |
| 33 | |
| 34 | |
| 35 | |