diff options
author | alexander <alexander.efremov@arm.com> | 2021-07-06 19:47:59 +0100 |
---|---|---|
committer | Alexander Efremov <alexander.efremov@arm.com> | 2021-07-08 17:30:49 +0100 |
commit | 80eecfbdaad689c52d5a6d370a322f3d6a6150e4 (patch) | |
tree | 3c7d06d1e9e227981fa072fccab5a360a39ad1d7 /source/application | |
parent | 1da52aeb4468ad97c09e383400bbabc8c3c77227 (diff) | |
download | ml-embedded-evaluation-kit-80eecfbdaad689c52d5a6d370a322f3d6a6150e4.tar.gz |
MLECO-1987: Minor refactoring.
ASRSlidingWindow can be used in other use-cases,
thus it was renamed to decouple from ASR.
Signed-off-by: alexander <alexander.efremov@arm.com>
Change-Id: I2df977e4f18f490a532e0f27e3625b153ca464d7
Diffstat (limited to 'source/application')
-rw-r--r-- | source/application/main/UseCaseCommonUtils.cc | 45 | ||||
-rw-r--r-- | source/application/main/include/AudioUtils.hpp | 29 | ||||
-rw-r--r-- | source/application/main/include/UseCaseCommonUtils.hpp | 9 |
3 files changed, 48 insertions, 35 deletions
diff --git a/source/application/main/UseCaseCommonUtils.cc b/source/application/main/UseCaseCommonUtils.cc index b3653d9..615f684 100644 --- a/source/application/main/UseCaseCommonUtils.cc +++ b/source/application/main/UseCaseCommonUtils.cc @@ -41,11 +41,30 @@ namespace app { return atoi(chInput); } - void DumpTensor(TfLiteTensor* tensor, const size_t lineBreakForNumElements) - { - char strhex[8]; - std::string strdump; + void DumpTensorData(const uint8_t* tensorData, + size_t size, + size_t lineBreakForNumElements) + { + char strhex[8]; + std::string strdump; + + for (size_t i = 0; i < size; ++i) { + if (0 == i % lineBreakForNumElements) { + printf("%s\n\t", strdump.c_str()); + strdump.clear(); + } + snprintf(strhex, sizeof(strhex) - 1, + "0x%02x, ", tensorData[i]); + strdump += std::string(strhex); + } + + if (!strdump.empty()) { + printf("%s\n", strdump.c_str()); + } + } + void DumpTensor(const TfLiteTensor* tensor, const size_t lineBreakForNumElements) + { if (!tensor) { printf_err("invalid tensor\n"); return; @@ -54,19 +73,7 @@ namespace app { const uint32_t tensorSz = tensor->bytes; const uint8_t* tensorData = tflite::GetTensorData<uint8_t>(tensor); - for (size_t i = 0; i < tensorSz; ++i) { - if (0 == i % lineBreakForNumElements) { - printf("%s\n\t", strdump.c_str()); - strdump.clear(); - } - snprintf(strhex, sizeof(strhex) - 1, - "0x%02x, ", tensorData[i]); - strdump += std::string(strhex); - } - - if (strdump.size()) { - printf("%s\n", strdump.c_str()); - } + DumpTensorData(tensorData, tensorSz, lineBreakForNumElements); } bool ListFilesHandler(ApplicationContext& ctx) @@ -92,7 +99,7 @@ namespace app { strNumFiles.size(), dataPsnTxtStartX, dataPsnTxtStartY, - 0); + false); #if NUMBER_OF_FILES > 0 constexpr uint32_t dataPsnTxtYIncr = 16; @@ -103,7 +110,7 @@ namespace app { std::string currentFilename{get_filename(i)}; platform.data_psn->present_data_text(currentFilename.c_str(), currentFilename.size(), - dataPsnTxtStartX, yVal, 0); + dataPsnTxtStartX, yVal, false); info("\t%" PRIu32 " => %s\n", i, currentFilename.c_str()); } diff --git a/source/application/main/include/AudioUtils.hpp b/source/application/main/include/AudioUtils.hpp index cba981d..cbf7bb7 100644 --- a/source/application/main/include/AudioUtils.hpp +++ b/source/application/main/include/AudioUtils.hpp @@ -124,18 +124,6 @@ namespace audio { return ((m_dataSize - m_size)/m_stride); } - /** - * @brief Calculates number of times the window can stride through the given data. - * May not be a whole number. - * @return Number of strides to cover all data. - */ - float FractionalTotalStrides() { - if (this->m_dataSize < this->m_size) { - return 0; - } else { - return ((this->m_dataSize - this->m_size)/ static_cast<float>(this->m_stride)); - } - } protected: T *m_start = nullptr; @@ -146,11 +134,11 @@ namespace audio { }; /* - * Sliding window for ASR will cover the whole of the input, even if + * Sliding window that will cover the whole length of the input, even if * this means the last window is not a full window length. */ template<class T> - class ASRSlidingWindow : public SlidingWindow<T> { + class FractionalSlidingWindow : public SlidingWindow<T> { public: using SlidingWindow<T>::SlidingWindow; @@ -161,6 +149,19 @@ namespace audio { bool HasNext() { return this->m_count < 1 + this->FractionalTotalStrides() && (this->NextWindowStartIndex() < this->m_dataSize); } + + /** + * @brief Calculates number of times the window can stride through the given data. + * May not be a whole number. + * @return Number of strides to cover all data. + */ + float FractionalTotalStrides() { + if (this->m_dataSize < this->m_size) { + return 0; + } else { + return ((this->m_dataSize - this->m_size) / static_cast<float>(this->m_stride)); + } + } }; diff --git a/source/application/main/include/UseCaseCommonUtils.hpp b/source/application/main/include/UseCaseCommonUtils.hpp index d328392..0af22f3 100644 --- a/source/application/main/include/UseCaseCommonUtils.hpp +++ b/source/application/main/include/UseCaseCommonUtils.hpp @@ -58,8 +58,13 @@ namespace app { * @param[in] lineBreakForNumElements number of elements * after which line break will be added. **/ - void DumpTensor(TfLiteTensor* tensor, - const size_t lineBreakForNumElements = 16); + void DumpTensor(const TfLiteTensor* tensor, + size_t lineBreakForNumElements = 16); + + + void DumpTensorData(const uint8_t* tensorData, + size_t size, + size_t lineBreakForNumElements = 16); #endif /* VERIFY_TEST_OUTPUT */ /** |