diff options
author | Isabella Gottardi <isabella.gottardi@arm.com> | 2021-05-12 08:27:15 +0100 |
---|---|---|
committer | Isabella Gottardi <isabella.gottardi@arm.com> | 2021-05-18 09:48:12 +0100 |
commit | 56ee6207c1524ddc4c444c6e48e05eb34105985a (patch) | |
tree | d4fc7823961034e95364f44b34fb098b34b99d0d /source/use_case/kws_asr | |
parent | f4e2c4736f19d2e06fede715bb49c475f93d79a9 (diff) | |
download | ml-embedded-evaluation-kit-56ee6207c1524ddc4c444c6e48e05eb34105985a.tar.gz |
MLECO-1858: Documentation update
* Removing `_` in front of private functions and member
Signed-off-by: Isabella Gottardi <isabella.gottardi@arm.com>
Change-Id: I5a5d652f9647ebb16d2d2bd16ab980e73f7be3cf
Diffstat (limited to 'source/use_case/kws_asr')
-rw-r--r-- | source/use_case/kws_asr/include/DsCnnModel.hpp | 2 | ||||
-rw-r--r-- | source/use_case/kws_asr/include/OutputDecode.hpp | 2 | ||||
-rw-r--r-- | source/use_case/kws_asr/include/Wav2LetterModel.hpp | 2 | ||||
-rw-r--r-- | source/use_case/kws_asr/include/Wav2LetterPostprocess.hpp | 19 | ||||
-rw-r--r-- | source/use_case/kws_asr/include/Wav2LetterPreprocess.hpp | 38 | ||||
-rw-r--r-- | source/use_case/kws_asr/src/DsCnnModel.cc | 22 | ||||
-rw-r--r-- | source/use_case/kws_asr/src/UseCaseHandler.cc | 8 | ||||
-rw-r--r-- | source/use_case/kws_asr/src/Wav2LetterModel.cc | 12 | ||||
-rw-r--r-- | source/use_case/kws_asr/src/Wav2LetterPostprocess.cc | 32 | ||||
-rw-r--r-- | source/use_case/kws_asr/src/Wav2LetterPreprocess.cc | 66 |
10 files changed, 100 insertions, 103 deletions
diff --git a/source/use_case/kws_asr/include/DsCnnModel.hpp b/source/use_case/kws_asr/include/DsCnnModel.hpp index f9d4357..92d96b9 100644 --- a/source/use_case/kws_asr/include/DsCnnModel.hpp +++ b/source/use_case/kws_asr/include/DsCnnModel.hpp @@ -58,7 +58,7 @@ namespace app { static constexpr int ms_maxOpCnt = 10; /* A mutable op resolver instance. */ - tflite::MicroMutableOpResolver<ms_maxOpCnt> _m_opResolver; + tflite::MicroMutableOpResolver<ms_maxOpCnt> m_opResolver; }; } /* namespace app */ diff --git a/source/use_case/kws_asr/include/OutputDecode.hpp b/source/use_case/kws_asr/include/OutputDecode.hpp index 2bbb29c..cea2c33 100644 --- a/source/use_case/kws_asr/include/OutputDecode.hpp +++ b/source/use_case/kws_asr/include/OutputDecode.hpp @@ -27,7 +27,7 @@ namespace asr { /** * @brief Gets the top N classification results from the * output vector. - * @param[in] tensor Label output from classifier. + * @param[in] vecResults Label output from classifier. * @return true if successful, false otherwise. **/ std::string DecodeOutput(const std::vector<ClassificationResult>& vecResults); diff --git a/source/use_case/kws_asr/include/Wav2LetterModel.hpp b/source/use_case/kws_asr/include/Wav2LetterModel.hpp index 9a86bd9..7c327b3 100644 --- a/source/use_case/kws_asr/include/Wav2LetterModel.hpp +++ b/source/use_case/kws_asr/include/Wav2LetterModel.hpp @@ -58,7 +58,7 @@ namespace app { static constexpr int ms_maxOpCnt = 5; /* A mutable op resolver instance. */ - tflite::MicroMutableOpResolver<ms_maxOpCnt> _m_opResolver; + tflite::MicroMutableOpResolver<ms_maxOpCnt> m_opResolver; }; } /* namespace app */ diff --git a/source/use_case/kws_asr/include/Wav2LetterPostprocess.hpp b/source/use_case/kws_asr/include/Wav2LetterPostprocess.hpp index fe60923..5c11412 100644 --- a/source/use_case/kws_asr/include/Wav2LetterPostprocess.hpp +++ b/source/use_case/kws_asr/include/Wav2LetterPostprocess.hpp @@ -33,10 +33,11 @@ namespace asr { public: /** * @brief Constructor - * @param[in] contextLen Left and right context length for - * output tensor. - * @param[in] innerLen This is the length of the section - * between left and right context. + * @param[in] contextLen Left and right context length for + * output tensor. + * @param[in] innerLen This is the length of the section + * between left and right context. + * @param[in] blankTokenIdx Blank token index. **/ Postprocess(uint32_t contextLen, uint32_t innerLen, @@ -61,11 +62,11 @@ namespace asr { bool lastIteration = false); private: - uint32_t _m_contextLen; /* Lengths of left and right contexts. */ - uint32_t _m_innerLen; /* Length of inner context. */ - uint32_t _m_totalLen; /* Total length of the required axis. */ - uint32_t _m_countIterations; /* Current number of iterations. */ - uint32_t _m_blankTokenIdx; /* Index of the labels blank token. */ + uint32_t m_contextLen; /* Lengths of left and right contexts. */ + uint32_t m_innerLen; /* Length of inner context. */ + uint32_t m_totalLen; /* Total length of the required axis. */ + uint32_t m_countIterations; /* Current number of iterations. */ + uint32_t m_blankTokenIdx; /* Index of the labels blank token. */ /** * @brief Checks if the tensor and axis index are valid * inputs to the object - based on how it has been diff --git a/source/use_case/kws_asr/include/Wav2LetterPreprocess.hpp b/source/use_case/kws_asr/include/Wav2LetterPreprocess.hpp index cf40fa8..66d19d3 100644 --- a/source/use_case/kws_asr/include/Wav2LetterPreprocess.hpp +++ b/source/use_case/kws_asr/include/Wav2LetterPreprocess.hpp @@ -145,32 +145,32 @@ namespace asr { const int quantOffset) { /* Check the output size will for everything. */ - if (outputBufSz < (this->_m_mfccBuf.size(0) * 3 * sizeof(T))) { + if (outputBufSz < (this->m_mfccBuf.size(0) * 3 * sizeof(T))) { printf_err("Tensor size too small for features\n"); return false; } /* Populate. */ T * outputBufMfcc = outputBuf; - T * outputBufD1 = outputBuf + this->_m_numMfccFeats; - T * outputBufD2 = outputBufD1 + this->_m_numMfccFeats; - const uint32_t ptrIncr = this->_m_numMfccFeats * 2; /* (3 vectors - 1 vector) */ + T * outputBufD1 = outputBuf + this->m_numMfccFeats; + T * outputBufD2 = outputBufD1 + this->m_numMfccFeats; + const uint32_t ptrIncr = this->m_numMfccFeats * 2; /* (3 vectors - 1 vector) */ const float minVal = std::numeric_limits<T>::min(); const float maxVal = std::numeric_limits<T>::max(); /* We need to do a transpose while copying and concatenating * the tensor. */ - for (uint32_t j = 0; j < this->_m_numFeatVectors; ++j) { - for (uint32_t i = 0; i < this->_m_numMfccFeats; ++i) { + for (uint32_t j = 0; j < this->m_numFeatVectors; ++j) { + for (uint32_t i = 0; i < this->m_numMfccFeats; ++i) { *outputBufMfcc++ = static_cast<T>(this->GetQuantElem( - this->_m_mfccBuf(i, j), quantScale, + this->m_mfccBuf(i, j), quantScale, quantOffset, minVal, maxVal)); *outputBufD1++ = static_cast<T>(this->GetQuantElem( - this->_m_delta1Buf(i, j), quantScale, + this->m_delta1Buf(i, j), quantScale, quantOffset, minVal, maxVal)); *outputBufD2++ = static_cast<T>(this->GetQuantElem( - this->_m_delta2Buf(i, j), quantScale, + this->m_delta2Buf(i, j), quantScale, quantOffset, minVal, maxVal)); } outputBufMfcc += ptrIncr; @@ -182,18 +182,18 @@ namespace asr { } private: - Wav2LetterMFCC _m_mfcc; /* MFCC instance. */ + Wav2LetterMFCC m_mfcc; /* MFCC instance. */ /* Actual buffers to be populated. */ - Array2d<float> _m_mfccBuf; /* Contiguous buffer 1D: MFCC */ - Array2d<float> _m_delta1Buf; /* Contiguous buffer 1D: Delta 1 */ - Array2d<float> _m_delta2Buf; /* Contiguous buffer 1D: Delta 2 */ - - uint32_t _m_windowLen; /* Window length for MFCC. */ - uint32_t _m_windowStride; /* Window stride len for MFCC. */ - uint32_t _m_numMfccFeats; /* Number of MFCC features per window. */ - uint32_t _m_numFeatVectors; /* Number of _m_numMfccFeats. */ - AudioWindow _m_window; /* Sliding window. */ + Array2d<float> m_mfccBuf; /* Contiguous buffer 1D: MFCC */ + Array2d<float> m_delta1Buf; /* Contiguous buffer 1D: Delta 1 */ + Array2d<float> m_delta2Buf; /* Contiguous buffer 1D: Delta 2 */ + + uint32_t m_windowLen; /* Window length for MFCC. */ + uint32_t m_windowStride; /* Window stride len for MFCC. */ + uint32_t m_numMfccFeats; /* Number of MFCC features per window. */ + uint32_t m_numFeatVectors; /* Number of m_numMfccFeats. */ + AudioWindow m_window; /* Sliding window. */ }; diff --git a/source/use_case/kws_asr/src/DsCnnModel.cc b/source/use_case/kws_asr/src/DsCnnModel.cc index b573a12..71d4ceb 100644 --- a/source/use_case/kws_asr/src/DsCnnModel.cc +++ b/source/use_case/kws_asr/src/DsCnnModel.cc @@ -29,23 +29,23 @@ namespace kws { const tflite::MicroOpResolver& arm::app::DsCnnModel::GetOpResolver() { - return this->_m_opResolver; + return this->m_opResolver; } bool arm::app::DsCnnModel::EnlistOperations() { - this->_m_opResolver.AddAveragePool2D(); - this->_m_opResolver.AddConv2D(); - this->_m_opResolver.AddDepthwiseConv2D(); - this->_m_opResolver.AddFullyConnected(); - this->_m_opResolver.AddRelu(); - this->_m_opResolver.AddSoftmax(); - this->_m_opResolver.AddQuantize(); - this->_m_opResolver.AddDequantize(); - this->_m_opResolver.AddReshape(); + this->m_opResolver.AddAveragePool2D(); + this->m_opResolver.AddConv2D(); + this->m_opResolver.AddDepthwiseConv2D(); + this->m_opResolver.AddFullyConnected(); + this->m_opResolver.AddRelu(); + this->m_opResolver.AddSoftmax(); + this->m_opResolver.AddQuantize(); + this->m_opResolver.AddDequantize(); + this->m_opResolver.AddReshape(); #if defined(ARM_NPU) - if (kTfLiteOk == this->_m_opResolver.AddEthosU()) { + if (kTfLiteOk == this->m_opResolver.AddEthosU()) { info("Added %s support to op resolver\n", tflite::GetString_ETHOSU()); } else { diff --git a/source/use_case/kws_asr/src/UseCaseHandler.cc b/source/use_case/kws_asr/src/UseCaseHandler.cc index 0560e88..60c0fd2 100644 --- a/source/use_case/kws_asr/src/UseCaseHandler.cc +++ b/source/use_case/kws_asr/src/UseCaseHandler.cc @@ -67,8 +67,6 @@ namespace app { * object. * @param[in] platform reference to the hal platform object * @param[in] results vector of classification results to be displayed - * @param[in] infTimeMs inference time in milliseconds, if available - * Otherwise, this can be passed in as 0. * @return true if successful, false otherwise **/ static bool PresentInferenceResult(hal_platform& platform, std::vector<arm::app::kws::KwsResult>& results); @@ -78,8 +76,6 @@ namespace app { * object. * @param[in] platform reference to the hal platform object * @param[in] results vector of classification results to be displayed - * @param[in] infTimeMs inference time in milliseconds, if available - * Otherwise, this can be passed in as 0. * @return true if successful, false otherwise **/ static bool PresentInferenceResult(hal_platform& platform, std::vector<arm::app::asr::AsrResult>& results); @@ -291,8 +287,8 @@ namespace app { /** * @brief Performs the ASR pipeline. * - * @param ctx[in/out] pointer to the application context object - * @param kwsOutput[in] struct containing pointer to audio data where ASR should begin + * @param[in,out] ctx pointer to the application context object + * @param[in] kwsOutput struct containing pointer to audio data where ASR should begin * and how much data to process * @return bool true if pipeline executed without failure */ diff --git a/source/use_case/kws_asr/src/Wav2LetterModel.cc b/source/use_case/kws_asr/src/Wav2LetterModel.cc index 2114a3f..62245b9 100644 --- a/source/use_case/kws_asr/src/Wav2LetterModel.cc +++ b/source/use_case/kws_asr/src/Wav2LetterModel.cc @@ -29,18 +29,18 @@ namespace asr { const tflite::MicroOpResolver& arm::app::Wav2LetterModel::GetOpResolver() { - return this->_m_opResolver; + return this->m_opResolver; } bool arm::app::Wav2LetterModel::EnlistOperations() { - this->_m_opResolver.AddConv2D(); - this->_m_opResolver.AddMul(); - this->_m_opResolver.AddMaximum(); - this->_m_opResolver.AddReshape(); + this->m_opResolver.AddConv2D(); + this->m_opResolver.AddMul(); + this->m_opResolver.AddMaximum(); + this->m_opResolver.AddReshape(); #if defined(ARM_NPU) - if (kTfLiteOk == this->_m_opResolver.AddEthosU()) { + if (kTfLiteOk == this->m_opResolver.AddEthosU()) { info("Added %s support to op resolver\n", tflite::GetString_ETHOSU()); } else { diff --git a/source/use_case/kws_asr/src/Wav2LetterPostprocess.cc b/source/use_case/kws_asr/src/Wav2LetterPostprocess.cc index e3c0c20..f2d9357 100644 --- a/source/use_case/kws_asr/src/Wav2LetterPostprocess.cc +++ b/source/use_case/kws_asr/src/Wav2LetterPostprocess.cc @@ -26,11 +26,11 @@ namespace asr { Postprocess::Postprocess(const uint32_t contextLen, const uint32_t innerLen, const uint32_t blankTokenIdx) - : _m_contextLen(contextLen), - _m_innerLen(innerLen), - _m_totalLen(2 * this->_m_contextLen + this->_m_innerLen), - _m_countIterations(0), - _m_blankTokenIdx(blankTokenIdx) + : m_contextLen(contextLen), + m_innerLen(innerLen), + m_totalLen(2 * this->m_contextLen + this->m_innerLen), + m_countIterations(0), + m_blankTokenIdx(blankTokenIdx) {} bool Postprocess::Invoke(TfLiteTensor* tensor, @@ -50,7 +50,7 @@ namespace asr { if (0 == elemSz) { printf_err("Tensor type not supported for post processing\n"); return false; - } else if (elemSz * this->_m_totalLen > tensor->bytes) { + } else if (elemSz * this->m_totalLen > tensor->bytes) { printf_err("Insufficient number of tensor bytes\n"); return false; } @@ -82,7 +82,7 @@ namespace asr { return false; } - if (static_cast<int>(this->_m_totalLen) != + if (static_cast<int>(this->m_totalLen) != tensor->dims->data[axisIdx]) { printf_err("Unexpected tensor dimension for axis %d, \n", tensor->dims->data[axisIdx]); @@ -120,31 +120,31 @@ namespace asr { { /* In this case, the "zero-ing" is quite simple as the region * to be zeroed sits in contiguous memory (row-major). */ - const uint32_t eraseLen = strideSzBytes * this->_m_contextLen; + const uint32_t eraseLen = strideSzBytes * this->m_contextLen; /* Erase left context? */ - if (this->_m_countIterations > 0) { + if (this->m_countIterations > 0) { /* Set output of each classification window to the blank token. */ std::memset(ptrData, 0, eraseLen); - for (size_t windowIdx = 0; windowIdx < this->_m_contextLen; windowIdx++) { - ptrData[windowIdx*strideSzBytes + this->_m_blankTokenIdx] = 1; + for (size_t windowIdx = 0; windowIdx < this->m_contextLen; windowIdx++) { + ptrData[windowIdx*strideSzBytes + this->m_blankTokenIdx] = 1; } } /* Erase right context? */ if (false == lastIteration) { - uint8_t * rightCtxPtr = ptrData + (strideSzBytes * (this->_m_contextLen + this->_m_innerLen)); + uint8_t * rightCtxPtr = ptrData + (strideSzBytes * (this->m_contextLen + this->m_innerLen)); /* Set output of each classification window to the blank token. */ std::memset(rightCtxPtr, 0, eraseLen); - for (size_t windowIdx = 0; windowIdx < this->_m_contextLen; windowIdx++) { - rightCtxPtr[windowIdx*strideSzBytes + this->_m_blankTokenIdx] = 1; + for (size_t windowIdx = 0; windowIdx < this->m_contextLen; windowIdx++) { + rightCtxPtr[windowIdx*strideSzBytes + this->m_blankTokenIdx] = 1; } } if (lastIteration) { - this->_m_countIterations = 0; + this->m_countIterations = 0; } else { - ++this->_m_countIterations; + ++this->m_countIterations; } return true; diff --git a/source/use_case/kws_asr/src/Wav2LetterPreprocess.cc b/source/use_case/kws_asr/src/Wav2LetterPreprocess.cc index 8251396..d3f3579 100644 --- a/source/use_case/kws_asr/src/Wav2LetterPreprocess.cc +++ b/source/use_case/kws_asr/src/Wav2LetterPreprocess.cc @@ -32,18 +32,18 @@ namespace asr { const uint32_t windowLen, const uint32_t windowStride, const uint32_t numMfccVectors): - _m_mfcc(numMfccFeatures, windowLen), - _m_mfccBuf(numMfccFeatures, numMfccVectors), - _m_delta1Buf(numMfccFeatures, numMfccVectors), - _m_delta2Buf(numMfccFeatures, numMfccVectors), - _m_windowLen(windowLen), - _m_windowStride(windowStride), - _m_numMfccFeats(numMfccFeatures), - _m_numFeatVectors(numMfccVectors), - _m_window() + m_mfcc(numMfccFeatures, windowLen), + m_mfccBuf(numMfccFeatures, numMfccVectors), + m_delta1Buf(numMfccFeatures, numMfccVectors), + m_delta2Buf(numMfccFeatures, numMfccVectors), + m_windowLen(windowLen), + m_windowStride(windowStride), + m_numMfccFeats(numMfccFeatures), + m_numFeatVectors(numMfccVectors), + m_window() { if (numMfccFeatures > 0 && windowLen > 0) { - this->_m_mfcc.Init(); + this->m_mfcc.Init(); } } @@ -52,45 +52,45 @@ namespace asr { const uint32_t audioDataLen, TfLiteTensor* tensor) { - this->_m_window = SlidingWindow<const int16_t>( + this->m_window = SlidingWindow<const int16_t>( audioData, audioDataLen, - this->_m_windowLen, this->_m_windowStride); + this->m_windowLen, this->m_windowStride); uint32_t mfccBufIdx = 0; - std::fill(_m_mfccBuf.begin(), _m_mfccBuf.end(), 0.f); - std::fill(_m_delta1Buf.begin(), _m_delta1Buf.end(), 0.f); - std::fill(_m_delta2Buf.begin(), _m_delta2Buf.end(), 0.f); + std::fill(m_mfccBuf.begin(), m_mfccBuf.end(), 0.f); + std::fill(m_delta1Buf.begin(), m_delta1Buf.end(), 0.f); + std::fill(m_delta2Buf.begin(), m_delta2Buf.end(), 0.f); /* While we can slide over the window. */ - while (this->_m_window.HasNext()) { - const int16_t* mfccWindow = this->_m_window.Next(); + while (this->m_window.HasNext()) { + const int16_t* mfccWindow = this->m_window.Next(); auto mfccAudioData = std::vector<int16_t>( mfccWindow, - mfccWindow + this->_m_windowLen); - auto mfcc = this->_m_mfcc.MfccCompute(mfccAudioData); - for (size_t i = 0; i < this->_m_mfccBuf.size(0); ++i) { - this->_m_mfccBuf(i, mfccBufIdx) = mfcc[i]; + mfccWindow + this->m_windowLen); + auto mfcc = this->m_mfcc.MfccCompute(mfccAudioData); + for (size_t i = 0; i < this->m_mfccBuf.size(0); ++i) { + this->m_mfccBuf(i, mfccBufIdx) = mfcc[i]; } ++mfccBufIdx; } /* Pad MFCC if needed by adding MFCC for zeros. */ - if (mfccBufIdx != this->_m_numFeatVectors) { - std::vector<int16_t> zerosWindow = std::vector<int16_t>(this->_m_windowLen, 0); - std::vector<float> mfccZeros = this->_m_mfcc.MfccCompute(zerosWindow); + if (mfccBufIdx != this->m_numFeatVectors) { + std::vector<int16_t> zerosWindow = std::vector<int16_t>(this->m_windowLen, 0); + std::vector<float> mfccZeros = this->m_mfcc.MfccCompute(zerosWindow); - while (mfccBufIdx != this->_m_numFeatVectors) { - memcpy(&this->_m_mfccBuf(0, mfccBufIdx), - mfccZeros.data(), sizeof(float) * _m_numMfccFeats); + while (mfccBufIdx != this->m_numFeatVectors) { + memcpy(&this->m_mfccBuf(0, mfccBufIdx), + mfccZeros.data(), sizeof(float) * m_numMfccFeats); ++mfccBufIdx; } } /* Compute first and second order deltas from MFCCs. */ - this->ComputeDeltas(this->_m_mfccBuf, - this->_m_delta1Buf, - this->_m_delta2Buf); + this->ComputeDeltas(this->m_mfccBuf, + this->m_delta1Buf, + this->m_delta2Buf); /* Normalise. */ this->Normalise(); @@ -206,9 +206,9 @@ namespace asr { void Preprocess::Normalise() { - Preprocess::NormaliseVec(this->_m_mfccBuf); - Preprocess::NormaliseVec(this->_m_delta1Buf); - Preprocess::NormaliseVec(this->_m_delta2Buf); + Preprocess::NormaliseVec(this->m_mfccBuf); + Preprocess::NormaliseVec(this->m_delta1Buf); + Preprocess::NormaliseVec(this->m_delta2Buf); } float Preprocess::GetQuantElem( |