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 | |
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')
33 files changed, 313 insertions, 319 deletions
diff --git a/source/use_case/ad/include/AdMelSpectrogram.hpp b/source/use_case/ad/include/AdMelSpectrogram.hpp index 30a77c1..05c5bfc 100644 --- a/source/use_case/ad/include/AdMelSpectrogram.hpp +++ b/source/use_case/ad/include/AdMelSpectrogram.hpp @@ -69,7 +69,7 @@ namespace audio { * energies to logarithmic scale. The difference from * default behaviour is that the power is converted to dB * and subsequently clamped. - * @param[in/out] melEnergies - 1D vector of Mel energies + * @param[in,out] melEnergies - 1D vector of Mel energies **/ virtual void ConvertToLogarithmicScale(std::vector<float>& melEnergies) override; diff --git a/source/use_case/ad/include/AdModel.hpp b/source/use_case/ad/include/AdModel.hpp index bbdf91c..8d914c4 100644 --- a/source/use_case/ad/include/AdModel.hpp +++ b/source/use_case/ad/include/AdModel.hpp @@ -44,7 +44,7 @@ namespace app { static constexpr int ms_maxOpCnt = 6; /* 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/ad/include/AdPostProcessing.hpp b/source/use_case/ad/include/AdPostProcessing.hpp index f3b35a1..7eaec84 100644 --- a/source/use_case/ad/include/AdPostProcessing.hpp +++ b/source/use_case/ad/include/AdPostProcessing.hpp @@ -38,7 +38,7 @@ namespace app { /** @brief Given a wav file name return AD model output index. * @param[in] wavFileName Audio WAV filename. - * File name should be in format <anything>_<goes>_XX_<here>.wav + * File name should be in format anything_goes_XX_here.wav * where XX is the machine ID e.g. 00, 02, 04 or 06 * @return AD model output index as 8 bit integer. **/ diff --git a/source/use_case/ad/include/MelSpectrogram.hpp b/source/use_case/ad/include/MelSpectrogram.hpp index 22b5d29..d3ea3f7 100644 --- a/source/use_case/ad/include/MelSpectrogram.hpp +++ b/source/use_case/ad/include/MelSpectrogram.hpp @@ -65,16 +65,16 @@ namespace audio { /** * @brief Extract Mel Spectrogram for one single small frame of * audio data e.g. 640 samples. - * @param[in] audioData - Vector of audio samples to calculate + * @param[in] audioData Vector of audio samples to calculate * features for. - * @param[in] trainingMean - Value to subtract from the the computed mel spectrogram, default 0. + * @param[in] trainingMean Value to subtract from the the computed mel spectrogram, default 0. * @return Vector of extracted Mel Spectrogram features. **/ std::vector<float> ComputeMelSpec(const std::vector<int16_t>& audioData, float trainingMean = 0); /** * @brief Constructor - * @param[in] params - Mel Spectrogram parameters + * @param[in] params Mel Spectrogram parameters */ explicit MelSpectrogram(const MelSpecParams& params); @@ -87,10 +87,11 @@ namespace audio { /** * @brief Extract Mel Spectrogram features and quantise for one single small * frame of audio data e.g. 640 samples. - * @param[in] audioData - Vector of audio samples to calculate + * @param[in] audioData Vector of audio samples to calculate * features for. - * @param[in] quantScale - quantisation scale. - * @param[in] quantOffset - quantisation offset + * @param[in] quantScale quantisation scale. + * @param[in] quantOffset quantisation offset. + * @param[in] trainingMean training mean. * @return Vector of extracted quantised Mel Spectrogram features. **/ template<typename T> @@ -103,12 +104,12 @@ namespace audio { float minVal = std::numeric_limits<T>::min(); float maxVal = std::numeric_limits<T>::max(); - std::vector<T> melSpecOut(this->_m_params.m_numFbankBins); - const size_t numFbankBins = this->_m_params.m_numFbankBins; + std::vector<T> melSpecOut(this->m_params.m_numFbankBins); + const size_t numFbankBins = this->m_params.m_numFbankBins; /* Quantize to T. */ for (size_t k = 0; k < numFbankBins; ++k) { - auto quantizedEnergy = std::round(((this->_m_melEnergies[k]) / quantScale) + quantOffset); + auto quantizedEnergy = std::round(((this->m_melEnergies[k]) / quantScale) + quantOffset); melSpecOut[k] = static_cast<T>(std::min<float>(std::max<float>(quantizedEnergy, minVal), maxVal)); } @@ -124,9 +125,9 @@ namespace audio { protected: /** * @brief Project input frequency to Mel Scale. - * @param[in] freq - input frequency in floating point - * @param[in] useHTKmethod - bool to signal if HTK method is to be - * used for calculation + * @param[in] freq input frequency in floating point + * @param[in] useHTKMethod bool to signal if HTK method is to be + * used for calculation * @return Mel transformed frequency in floating point **/ static float MelScale(const float freq, @@ -135,9 +136,9 @@ namespace audio { /** * @brief Inverse Mel transform - convert MEL warped frequency * back to normal frequency - * @param[in] freq - Mel frequency in floating point - * @param[in] useHTKmethod - bool to signal if HTK method is to be - * used for calculation + * @param[in] melFreq Mel frequency in floating point + * @param[in] useHTKMethod bool to signal if HTK method is to be + * used for calculation * @return Real world frequency in floating point **/ static float InverseMelScale(const float melFreq, @@ -168,7 +169,7 @@ namespace audio { /** * @brief Converts the Mel energies for logarithmic scale - * @param[in/out] melEnergies - 1D vector of Mel energies + * @param[in,out] melEnergies 1D vector of Mel energies **/ virtual void ConvertToLogarithmicScale(std::vector<float>& melEnergies); @@ -176,10 +177,10 @@ namespace audio { * @brief Given the low and high Mel values, get the normaliser * for weights to be applied when populating the filter * bank. - * @param[in] leftMel - low Mel frequency value - * @param[in] rightMel - high Mel frequency value - * @param[in] useHTKMethod - bool to signal if HTK method is to be - * used for calculation + * @param[in] leftMel low Mel frequency value + * @param[in] rightMel high Mel frequency value + * @param[in] useHTKMethod bool to signal if HTK method is to be + * used for calculation * @return Return float value to be applied * when populating the filter bank. */ @@ -189,16 +190,16 @@ namespace audio { const bool useHTKMethod); private: - MelSpecParams _m_params; - std::vector<float> _m_frame; - std::vector<float> _m_buffer; - std::vector<float> _m_melEnergies; - std::vector<float> _m_windowFunc; - std::vector<std::vector<float>> _m_melFilterBank; - std::vector<uint32_t> _m_filterBankFilterFirst; - std::vector<uint32_t> _m_filterBankFilterLast; - bool _m_filterBankInitialised; - arm::app::math::FftInstance _m_fftInstance; + MelSpecParams m_params; + std::vector<float> m_frame; + std::vector<float> m_buffer; + std::vector<float> m_melEnergies; + std::vector<float> m_windowFunc; + std::vector<std::vector<float>> m_melFilterBank; + std::vector<uint32_t> m_filterBankFilterFirst; + std::vector<uint32_t> m_filterBankFilterLast; + bool m_filterBankInitialised; + arm::app::math::FftInstance m_fftInstance; /** * @brief Initialises the filter banks. diff --git a/source/use_case/ad/src/AdModel.cc b/source/use_case/ad/src/AdModel.cc index 148bc98..82ad822 100644 --- a/source/use_case/ad/src/AdModel.cc +++ b/source/use_case/ad/src/AdModel.cc @@ -20,19 +20,19 @@ const tflite::MicroOpResolver& arm::app::AdModel::GetOpResolver() { - return this->_m_opResolver; + return this->m_opResolver; } bool arm::app::AdModel::EnlistOperations() { - this->_m_opResolver.AddAveragePool2D(); - this->_m_opResolver.AddConv2D(); - this->_m_opResolver.AddDepthwiseConv2D(); - this->_m_opResolver.AddRelu6(); - this->_m_opResolver.AddReshape(); + this->m_opResolver.AddAveragePool2D(); + this->m_opResolver.AddConv2D(); + this->m_opResolver.AddDepthwiseConv2D(); + this->m_opResolver.AddRelu6(); + 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/ad/src/MelSpectrogram.cc b/source/use_case/ad/src/MelSpectrogram.cc index f1752e1..fa7714a 100644 --- a/source/use_case/ad/src/MelSpectrogram.cc +++ b/source/use_case/ad/src/MelSpectrogram.cc @@ -61,27 +61,27 @@ namespace audio { } MelSpectrogram::MelSpectrogram(const MelSpecParams& params): - _m_params(params), - _m_filterBankInitialised(false) + m_params(params), + m_filterBankInitialised(false) { - this->_m_buffer = std::vector<float>( - this->_m_params.m_frameLenPadded, 0.0); - this->_m_frame = std::vector<float>( - this->_m_params.m_frameLenPadded, 0.0); - this->_m_melEnergies = std::vector<float>( - this->_m_params.m_numFbankBins, 0.0); + this->m_buffer = std::vector<float>( + this->m_params.m_frameLenPadded, 0.0); + this->m_frame = std::vector<float>( + this->m_params.m_frameLenPadded, 0.0); + this->m_melEnergies = std::vector<float>( + this->m_params.m_numFbankBins, 0.0); - this->_m_windowFunc = std::vector<float>(this->_m_params.m_frameLen); - const auto multiplier = static_cast<float>(2 * M_PI / this->_m_params.m_frameLen); + this->m_windowFunc = std::vector<float>(this->m_params.m_frameLen); + const auto multiplier = static_cast<float>(2 * M_PI / this->m_params.m_frameLen); /* Create window function. */ - for (size_t i = 0; i < this->_m_params.m_frameLen; ++i) { - this->_m_windowFunc[i] = (0.5 - (0.5 * + for (size_t i = 0; i < this->m_params.m_frameLen; ++i) { + this->m_windowFunc[i] = (0.5 - (0.5 * math::MathUtils::CosineF32(static_cast<float>(i) * multiplier))); } - math::MathUtils::FftInitF32(this->_m_params.m_frameLenPadded, this->_m_fftInstance); - debug("Instantiated Mel Spectrogram object: %s\n", this->_m_params.Str().c_str()); + math::MathUtils::FftInitF32(this->m_params.m_frameLenPadded, this->m_fftInstance); + debug("Instantiated Mel Spectrogram object: %s\n", this->m_params.Str().c_str()); } void MelSpectrogram::Init() @@ -161,20 +161,20 @@ namespace audio { void MelSpectrogram::ConvertToPowerSpectrum() { - const uint32_t halfDim = this->_m_buffer.size() / 2; + const uint32_t halfDim = this->m_buffer.size() / 2; /* Handle this special case. */ - float firstEnergy = this->_m_buffer[0] * this->_m_buffer[0]; - float lastEnergy = this->_m_buffer[1] * this->_m_buffer[1]; + float firstEnergy = this->m_buffer[0] * this->m_buffer[0]; + float lastEnergy = this->m_buffer[1] * this->m_buffer[1]; math::MathUtils::ComplexMagnitudeSquaredF32( - this->_m_buffer.data(), - this->_m_buffer.size(), - this->_m_buffer.data(), - this->_m_buffer.size()/2); + this->m_buffer.data(), + this->m_buffer.size(), + this->m_buffer.data(), + this->m_buffer.size()/2); - this->_m_buffer[0] = firstEnergy; - this->_m_buffer[halfDim] = lastEnergy; + this->m_buffer[0] = firstEnergy; + this->m_buffer[halfDim] = lastEnergy; } float MelSpectrogram::GetMelFilterBankNormaliser( @@ -193,14 +193,14 @@ namespace audio { void MelSpectrogram::InitMelFilterBank() { if (!this->IsMelFilterBankInited()) { - this->_m_melFilterBank = this->CreateMelFilterBank(); - this->_m_filterBankInitialised = true; + this->m_melFilterBank = this->CreateMelFilterBank(); + this->m_filterBankInitialised = true; } } bool MelSpectrogram::IsMelFilterBankInited() const { - return this->_m_filterBankInitialised; + return this->m_filterBankInitialised; } std::vector<float> MelSpectrogram::ComputeMelSpec(const std::vector<int16_t>& audioData, float trainingMean) @@ -209,64 +209,64 @@ namespace audio { /* TensorFlow way of normalizing .wav data to (-1, 1). */ constexpr float normaliser = 1.0/(1<<15); - for (size_t i = 0; i < this->_m_params.m_frameLen; ++i) { - this->_m_frame[i] = static_cast<float>(audioData[i]) * normaliser; + for (size_t i = 0; i < this->m_params.m_frameLen; ++i) { + this->m_frame[i] = static_cast<float>(audioData[i]) * normaliser; } /* Apply window function to input frame. */ - for(size_t i = 0; i < this->_m_params.m_frameLen; ++i) { - this->_m_frame[i] *= this->_m_windowFunc[i]; + for(size_t i = 0; i < this->m_params.m_frameLen; ++i) { + this->m_frame[i] *= this->m_windowFunc[i]; } /* Set remaining frame values to 0. */ - std::fill(this->_m_frame.begin() + this->_m_params.m_frameLen,this->_m_frame.end(), 0); + std::fill(this->m_frame.begin() + this->m_params.m_frameLen,this->m_frame.end(), 0); /* Compute FFT. */ - math::MathUtils::FftF32(this->_m_frame, this->_m_buffer, this->_m_fftInstance); + math::MathUtils::FftF32(this->m_frame, this->m_buffer, this->m_fftInstance); /* Convert to power spectrum. */ this->ConvertToPowerSpectrum(); /* Apply mel filterbanks. */ - if (!this->ApplyMelFilterBank(this->_m_buffer, - this->_m_melFilterBank, - this->_m_filterBankFilterFirst, - this->_m_filterBankFilterLast, - this->_m_melEnergies)) { + if (!this->ApplyMelFilterBank(this->m_buffer, + this->m_melFilterBank, + this->m_filterBankFilterFirst, + this->m_filterBankFilterLast, + this->m_melEnergies)) { printf_err("Failed to apply MEL filter banks\n"); } /* Convert to logarithmic scale */ - this->ConvertToLogarithmicScale(this->_m_melEnergies); + this->ConvertToLogarithmicScale(this->m_melEnergies); /* Perform mean subtraction. */ - for (auto& energy:this->_m_melEnergies) { + for (auto& energy:this->m_melEnergies) { energy -= trainingMean; } - return this->_m_melEnergies; + return this->m_melEnergies; } std::vector<std::vector<float>> MelSpectrogram::CreateMelFilterBank() { - size_t numFftBins = this->_m_params.m_frameLenPadded / 2; - float fftBinWidth = static_cast<float>(this->_m_params.m_samplingFreq) / this->_m_params.m_frameLenPadded; + size_t numFftBins = this->m_params.m_frameLenPadded / 2; + float fftBinWidth = static_cast<float>(this->m_params.m_samplingFreq) / this->m_params.m_frameLenPadded; - float melLowFreq = MelSpectrogram::MelScale(this->_m_params.m_melLoFreq, - this->_m_params.m_useHtkMethod); - float melHighFreq = MelSpectrogram::MelScale(this->_m_params.m_melHiFreq, - this->_m_params.m_useHtkMethod); - float melFreqDelta = (melHighFreq - melLowFreq) / (this->_m_params.m_numFbankBins + 1); + float melLowFreq = MelSpectrogram::MelScale(this->m_params.m_melLoFreq, + this->m_params.m_useHtkMethod); + float melHighFreq = MelSpectrogram::MelScale(this->m_params.m_melHiFreq, + this->m_params.m_useHtkMethod); + float melFreqDelta = (melHighFreq - melLowFreq) / (this->m_params.m_numFbankBins + 1); std::vector<float> thisBin = std::vector<float>(numFftBins); std::vector<std::vector<float>> melFilterBank( - this->_m_params.m_numFbankBins); - this->_m_filterBankFilterFirst = - std::vector<uint32_t>(this->_m_params.m_numFbankBins); - this->_m_filterBankFilterLast = - std::vector<uint32_t>(this->_m_params.m_numFbankBins); + this->m_params.m_numFbankBins); + this->m_filterBankFilterFirst = + std::vector<uint32_t>(this->m_params.m_numFbankBins); + this->m_filterBankFilterLast = + std::vector<uint32_t>(this->m_params.m_numFbankBins); - for (size_t bin = 0; bin < this->_m_params.m_numFbankBins; bin++) { + for (size_t bin = 0; bin < this->m_params.m_numFbankBins; bin++) { float leftMel = melLowFreq + bin * melFreqDelta; float centerMel = melLowFreq + (bin + 1) * melFreqDelta; float rightMel = melLowFreq + (bin + 2) * melFreqDelta; @@ -274,11 +274,11 @@ namespace audio { uint32_t firstIndex = 0; uint32_t lastIndex = 0; bool firstIndexFound = false; - const float normaliser = this->GetMelFilterBankNormaliser(leftMel, rightMel, this->_m_params.m_useHtkMethod); + const float normaliser = this->GetMelFilterBankNormaliser(leftMel, rightMel, this->m_params.m_useHtkMethod); for (size_t i = 0; i < numFftBins; ++i) { float freq = (fftBinWidth * i); /* Center freq of this fft bin. */ - float mel = MelSpectrogram::MelScale(freq, this->_m_params.m_useHtkMethod); + float mel = MelSpectrogram::MelScale(freq, this->m_params.m_useHtkMethod); thisBin[i] = 0.0; if (mel > leftMel && mel < rightMel) { @@ -298,8 +298,8 @@ namespace audio { } } - this->_m_filterBankFilterFirst[bin] = firstIndex; - this->_m_filterBankFilterLast[bin] = lastIndex; + this->m_filterBankFilterFirst[bin] = firstIndex; + this->m_filterBankFilterLast[bin] = lastIndex; /* Copy the part we care about. */ for (uint32_t i = firstIndex; i <= lastIndex; ++i) { diff --git a/source/use_case/ad/src/UseCaseHandler.cc b/source/use_case/ad/src/UseCaseHandler.cc index 233b0f4..ec35156 100644 --- a/source/use_case/ad/src/UseCaseHandler.cc +++ b/source/use_case/ad/src/UseCaseHandler.cc @@ -30,13 +30,13 @@ namespace app { /** * @brief Helper function to increment current audio clip index - * @param[in/out] ctx pointer to the application context object + * @param[in,out] ctx pointer to the application context object **/ static void IncrementAppCtxClipIdx(ApplicationContext& ctx); /** * @brief Helper function to set the audio clip index - * @param[in/out] ctx pointer to the application context object + * @param[in,out] ctx pointer to the application context object * @param[in] idx value to be set * @return true if index is set, false otherwise **/ @@ -47,7 +47,7 @@ namespace app { * object. * @param[in] platform reference to the hal platform object * @param[in] result average sum of classification results - * @param[in] threhsold if larger than this value we have an anomaly + * @param[in] threshold if larger than this value we have an anomaly * @return true if successful, false otherwise **/ static bool PresentInferenceResult(hal_platform& platform, float result, float threshold); @@ -61,9 +61,10 @@ namespace app { * * Warning: mfcc calculator provided as input must have the same life scope as returned function. * - * @param[in] mfcc MFCC feature calculator. - * @param[in/out] inputTensor Input tensor pointer to store calculated features. - * @param[i] cacheSize Size of the feture vectors cache (number of feature vectors). + * @param[in] melSpec MFCC feature calculator. + * @param[in,out] inputTensor Input tensor pointer to store calculated features. + * @param[in] cacheSize Size of the feture vectors cache (number of feature vectors). + * @param[in] trainingMean Training mean. * @return function function to be called providing audio sample and sliding window index. */ static std::function<void (std::vector<int16_t>&, int, bool, size_t, size_t)> diff --git a/source/use_case/asr/include/OutputDecode.hpp b/source/use_case/asr/include/OutputDecode.hpp index 6095531..9d39057 100644 --- a/source/use_case/asr/include/OutputDecode.hpp +++ b/source/use_case/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/asr/include/Wav2LetterModel.hpp b/source/use_case/asr/include/Wav2LetterModel.hpp index 4c62578..55395b9 100644 --- a/source/use_case/asr/include/Wav2LetterModel.hpp +++ b/source/use_case/asr/include/Wav2LetterModel.hpp @@ -52,7 +52,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/asr/include/Wav2LetterPostprocess.hpp b/source/use_case/asr/include/Wav2LetterPostprocess.hpp index e16d35b..a744e0f 100644 --- a/source/use_case/asr/include/Wav2LetterPostprocess.hpp +++ b/source/use_case/asr/include/Wav2LetterPostprocess.hpp @@ -37,6 +37,7 @@ namespace asr { * 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/asr/include/Wav2LetterPreprocess.hpp b/source/use_case/asr/include/Wav2LetterPreprocess.hpp index 10512b9..b0e0c67 100644 --- a/source/use_case/asr/include/Wav2LetterPreprocess.hpp +++ b/source/use_case/asr/include/Wav2LetterPreprocess.hpp @@ -144,31 +144,31 @@ namespace asr { const int quantOffset) { /* Check the output size will fit 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(); /* Need to 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>(Preprocess::GetQuantElem( - this->_m_mfccBuf(i, j), quantScale, + this->m_mfccBuf(i, j), quantScale, quantOffset, minVal, maxVal)); *outputBufD1++ = static_cast<T>(Preprocess::GetQuantElem( - this->_m_delta1Buf(i, j), quantScale, + this->m_delta1Buf(i, j), quantScale, quantOffset, minVal, maxVal)); *outputBufD2++ = static_cast<T>(Preprocess::GetQuantElem( - this->_m_delta2Buf(i, j), quantScale, + this->m_delta2Buf(i, j), quantScale, quantOffset, minVal, maxVal)); } outputBufMfcc += ptrIncr; @@ -180,18 +180,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/asr/src/UseCaseHandler.cc b/source/use_case/asr/src/UseCaseHandler.cc index 43b17dc..dcc879f 100644 --- a/source/use_case/asr/src/UseCaseHandler.cc +++ b/source/use_case/asr/src/UseCaseHandler.cc @@ -50,8 +50,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( diff --git a/source/use_case/asr/src/Wav2LetterModel.cc b/source/use_case/asr/src/Wav2LetterModel.cc index 5aefecd..6f87be8 100644 --- a/source/use_case/asr/src/Wav2LetterModel.cc +++ b/source/use_case/asr/src/Wav2LetterModel.cc @@ -20,18 +20,18 @@ 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/asr/src/Wav2LetterPostprocess.cc b/source/use_case/asr/src/Wav2LetterPostprocess.cc index b1bcdc8..fd11eef 100644 --- a/source/use_case/asr/src/Wav2LetterPostprocess.cc +++ b/source/use_case/asr/src/Wav2LetterPostprocess.cc @@ -27,11 +27,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, @@ -51,7 +51,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; } @@ -88,7 +88,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]); @@ -124,31 +124,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/asr/src/Wav2LetterPreprocess.cc b/source/use_case/asr/src/Wav2LetterPreprocess.cc index d65ea75..e5ac3ca 100644 --- a/source/use_case/asr/src/Wav2LetterPreprocess.cc +++ b/source/use_case/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. */ - Preprocess::ComputeDeltas(this->_m_mfccBuf, - this->_m_delta1Buf, - this->_m_delta2Buf); + Preprocess::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( diff --git a/source/use_case/img_class/include/MobileNetModel.hpp b/source/use_case/img_class/include/MobileNetModel.hpp index 2540564..503f1ac 100644 --- a/source/use_case/img_class/include/MobileNetModel.hpp +++ b/source/use_case/img_class/include/MobileNetModel.hpp @@ -46,7 +46,7 @@ namespace app { static constexpr int ms_maxOpCnt = 7; /* 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/img_class/src/MobileNetModel.cc b/source/use_case/img_class/src/MobileNetModel.cc index eeaa109..b937382 100644 --- a/source/use_case/img_class/src/MobileNetModel.cc +++ b/source/use_case/img_class/src/MobileNetModel.cc @@ -20,20 +20,20 @@ const tflite::MicroOpResolver& arm::app::MobileNetModel::GetOpResolver() { - return this->_m_opResolver; + return this->m_opResolver; } bool arm::app::MobileNetModel::EnlistOperations() { - this->_m_opResolver.AddDepthwiseConv2D(); - this->_m_opResolver.AddConv2D(); - this->_m_opResolver.AddAveragePool2D(); - this->_m_opResolver.AddAdd(); - this->_m_opResolver.AddReshape(); - this->_m_opResolver.AddSoftmax(); + this->m_opResolver.AddDepthwiseConv2D(); + this->m_opResolver.AddConv2D(); + this->m_opResolver.AddAveragePool2D(); + this->m_opResolver.AddAdd(); + this->m_opResolver.AddReshape(); + this->m_opResolver.AddSoftmax(); #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/img_class/src/UseCaseHandler.cc b/source/use_case/img_class/src/UseCaseHandler.cc index fa77512..337cb29 100644 --- a/source/use_case/img_class/src/UseCaseHandler.cc +++ b/source/use_case/img_class/src/UseCaseHandler.cc @@ -58,8 +58,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, diff --git a/source/use_case/inference_runner/include/TestModel.hpp b/source/use_case/inference_runner/include/TestModel.hpp index 0b3e9b9..0846bd4 100644 --- a/source/use_case/inference_runner/include/TestModel.hpp +++ b/source/use_case/inference_runner/include/TestModel.hpp @@ -38,7 +38,7 @@ namespace app { private: /* No need to define individual ops at the cost of extra memory. */ - tflite::AllOpsResolver _m_opResolver; + tflite::AllOpsResolver m_opResolver; }; } /* namespace app */ diff --git a/source/use_case/inference_runner/src/TestModel.cc b/source/use_case/inference_runner/src/TestModel.cc index 0926a96..4512a9b 100644 --- a/source/use_case/inference_runner/src/TestModel.cc +++ b/source/use_case/inference_runner/src/TestModel.cc @@ -20,7 +20,7 @@ const tflite::AllOpsResolver& arm::app::TestModel::GetOpResolver() { - return this->_m_opResolver; + return this->m_opResolver; } extern uint8_t* GetModelPointer(); diff --git a/source/use_case/kws/include/DsCnnModel.hpp b/source/use_case/kws/include/DsCnnModel.hpp index e9ac18c..a1a45cd 100644 --- a/source/use_case/kws/include/DsCnnModel.hpp +++ b/source/use_case/kws/include/DsCnnModel.hpp @@ -50,7 +50,7 @@ namespace app { static constexpr int ms_maxOpCnt = 8; /* 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/src/DsCnnModel.cc b/source/use_case/kws/src/DsCnnModel.cc index a093eb4..4edfc04 100644 --- a/source/use_case/kws/src/DsCnnModel.cc +++ b/source/use_case/kws/src/DsCnnModel.cc @@ -20,21 +20,21 @@ const tflite::MicroOpResolver& arm::app::DsCnnModel::GetOpResolver() { - return this->_m_opResolver; + return this->m_opResolver; } bool arm::app::DsCnnModel::EnlistOperations() { - 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.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(); #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/src/UseCaseHandler.cc b/source/use_case/kws/src/UseCaseHandler.cc index eaf53c1..2144c03 100644 --- a/source/use_case/kws/src/UseCaseHandler.cc +++ b/source/use_case/kws/src/UseCaseHandler.cc @@ -52,8 +52,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, @@ -341,11 +339,11 @@ namespace app { * Real features math is done by a lambda function provided as a parameter. * Features are written to input tensor memory. * - * @tparam T Feature vector type. - * @param inputTensor Model input tensor pointer. - * @param cacheSize Number of feature vectors to cache. Defined by the sliding window overlap. - * @param compute Features calculator function. - * @return Lambda function to compute features. + * @tparam T Feature vector type. + * @param[in] inputTensor Model input tensor pointer. + * @param[in] cacheSize Number of feature vectors to cache. Defined by the sliding window overlap. + * @param[in] compute Features calculator function. + * @return Lambda function to compute features. */ template<class T> std::function<void (std::vector<int16_t>&, size_t, bool, size_t)> 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( |