summaryrefslogtreecommitdiff
path: root/source/application/main/include
diff options
context:
space:
mode:
authorKshitij Sisodia <kshitij.sisodia@arm.com>2021-12-24 11:05:11 +0000
committerLiam Barry <liam.barry@arm.com>2021-12-24 14:20:36 +0000
commit76a1580861210e0310db23acbc29e1064ae30ead (patch)
treef947145cffd944aa3724c90745fc0e9d8e2fb2f4 /source/application/main/include
parent871fcdc755173b9f7ecb8cf9dc8dc6306329958c (diff)
downloadml-embedded-evaluation-kit-76a1580861210e0310db23acbc29e1064ae30ead.tar.gz
MLECO-2599: Replace DSCNN with MicroNet for KWS
Added SoftMax function to Mathutils to allow MicroNet to output probability as it does not nativelu have this layer. Minor refactoring to accommodate Softmax Calculations Extensive renaming and updating of documentation and resource download script. Added SoftMax function to Mathutils to allow MicroNet to output probability. Change-Id: I7cbbda1024d14b85c9ac1beea7ca8fbffd0b6eb5 Signed-off-by: Liam Barry <liam.barry@arm.com>
Diffstat (limited to 'source/application/main/include')
-rw-r--r--source/application/main/include/Classifier.hpp23
-rw-r--r--source/application/main/include/PlatformMath.hpp7
2 files changed, 26 insertions, 4 deletions
diff --git a/source/application/main/include/Classifier.hpp b/source/application/main/include/Classifier.hpp
index 3ee3148..d899e8e 100644
--- a/source/application/main/include/Classifier.hpp
+++ b/source/application/main/include/Classifier.hpp
@@ -42,18 +42,33 @@ namespace app {
* populated by this function.
* @param[in] labels Labels vector to match classified classes.
* @param[in] topNCount Number of top classifications to pick. Default is 1.
+ * @param[in] useSoftmax Whether Softmax normalisation should be applied to output. Default is false.
* @return true if successful, false otherwise.
**/
+
virtual bool GetClassificationResults(
TfLiteTensor* outputTensor,
std::vector<ClassificationResult>& vecResults,
- const std::vector <std::string>& labels, uint32_t topNCount);
+ const std::vector <std::string>& labels, uint32_t topNCount,
+ bool use_softmax = false);
+
+ /**
+ * @brief Populate the elements of the Classification Result object.
+ * @param[in] topNSet Ordered set of top 5 output class scores and labels.
+ * @param[out] vecResults A vector of classification results.
+ * populated by this function.
+ * @param[in] labels Labels vector to match classified classes.
+ **/
+
+ void SetVectorResults(
+ std::set<std::pair<float, uint32_t>>& topNSet,
+ std::vector<ClassificationResult>& vecResults,
+ const std::vector <std::string>& labels);
private:
/**
* @brief Utility function that gets the top N classification results from the
* output vector.
- * @tparam T value type
* @param[in] tensor Inference output tensor from an NN model.
* @param[out] vecResults A vector of classification results
* populated by this function.
@@ -61,8 +76,8 @@ namespace app {
* @param[in] labels Labels vector to match classified classes.
* @return true if successful, false otherwise.
**/
- template<typename T>
- bool GetTopNResults(TfLiteTensor* tensor,
+
+ bool GetTopNResults(const std::vector<float>& tensor,
std::vector<ClassificationResult>& vecResults,
uint32_t topNCount,
const std::vector <std::string>& labels);
diff --git a/source/application/main/include/PlatformMath.hpp b/source/application/main/include/PlatformMath.hpp
index 6804025..fdb51b2 100644
--- a/source/application/main/include/PlatformMath.hpp
+++ b/source/application/main/include/PlatformMath.hpp
@@ -161,7 +161,14 @@ namespace math {
float* ptrDst,
const uint32_t dstLen);
+ /**
+ * @brief Scales output scores for an arbitrary number of classes so
+ * that they sum to 1, allowing output to be expressed as a probability.
+ * @param[in] vector Vector of floats modified in-place
+ */
+ static void SoftmaxF32(std::vector<float>& vec);
};
+
} /* namespace math */
} /* namespace app */
} /* namespace arm */