MLECO-3164: Additional refactoring of KWS API
Part 1
* Add KwsClassifier
* KwsPostProcess can now be told to average results
* Averaging is handlded by KwsClassifier
* Current sliding window index is now an argument of DoPreProcess
Change-Id: I07626da595ad1cbd982e8366f0d1bb56d1040459
diff --git a/source/application/api/use_case/kws/include/KwsProcessing.hpp b/source/application/api/use_case/kws/include/KwsProcessing.hpp
index 0ede425..e2d3ff9 100644
--- a/source/application/api/use_case/kws/include/KwsProcessing.hpp
+++ b/source/application/api/use_case/kws/include/KwsProcessing.hpp
@@ -19,7 +19,7 @@
#include "AudioUtils.hpp"
#include "BaseProcessing.hpp"
-#include "Classifier.hpp"
+#include "KwsClassifier.hpp"
#include "MicroNetKwsMfcc.hpp"
#include <functional>
@@ -55,9 +55,8 @@
* @param[in] inputSize Size of the input data.
* @return true if successful, false otherwise.
**/
- bool DoPreProcess(const void* input, size_t inputSize) override;
+ bool DoPreProcess(const void* input, size_t inferenceIndex = 0) override;
- size_t m_audioWindowIndex = 0; /* Index of audio slider, used when caching features in longer clips. */
size_t m_audioDataWindowSize; /* Amount of audio needed for 1 inference. */
size_t m_audioDataStride; /* Amount of audio to stride across if doing >1 inference in longer clips. */
@@ -106,11 +105,11 @@
class KwsPostProcess : public BasePostProcess {
private:
- TfLiteTensor* m_outputTensor; /* Model output tensor. */
- Classifier& m_kwsClassifier; /* KWS Classifier object. */
- const std::vector<std::string>& m_labels; /* KWS Labels. */
- std::vector<ClassificationResult>& m_results; /* Results vector for a single inference. */
-
+ TfLiteTensor* m_outputTensor; /* Model output tensor. */
+ KwsClassifier& m_kwsClassifier; /* KWS Classifier object. */
+ const std::vector<std::string>& m_labels; /* KWS Labels. */
+ std::vector<ClassificationResult>& m_results; /* Results vector for a single inference. */
+ std::vector<std::vector<float>> m_resultHistory; /* Store previous results so they can be averaged. */
public:
/**
* @brief Constructor
@@ -119,9 +118,9 @@
* @param[in] labels Vector of string labels to identify each output of the model.
* @param[in/out] results Vector of classification results to store decoded outputs.
**/
- KwsPostProcess(TfLiteTensor* outputTensor, Classifier& classifier,
+ KwsPostProcess(TfLiteTensor* outputTensor, KwsClassifier& classifier,
const std::vector<std::string>& labels,
- std::vector<ClassificationResult>& results);
+ std::vector<ClassificationResult>& results, size_t averagingWindowLen = 1);
/**
* @brief Should perform post-processing of the result of inference then