diff options
Diffstat (limited to 'source/use_case')
-rw-r--r-- | source/use_case/ad/src/MainLoop.cc | 4 | ||||
-rw-r--r-- | source/use_case/ad/src/UseCaseHandler.cc | 18 | ||||
-rw-r--r-- | source/use_case/asr/src/MainLoop.cc | 4 | ||||
-rw-r--r-- | source/use_case/asr/src/UseCaseHandler.cc | 23 | ||||
-rw-r--r-- | source/use_case/img_class/src/MainLoop.cc | 4 | ||||
-rw-r--r-- | source/use_case/img_class/src/UseCaseHandler.cc | 11 | ||||
-rw-r--r-- | source/use_case/inference_runner/src/UseCaseHandler.cc | 8 | ||||
-rw-r--r-- | source/use_case/kws/src/MainLoop.cc | 4 | ||||
-rw-r--r-- | source/use_case/kws/src/UseCaseHandler.cc | 124 | ||||
-rw-r--r-- | source/use_case/kws_asr/src/MainLoop.cc | 4 | ||||
-rw-r--r-- | source/use_case/kws_asr/src/UseCaseHandler.cc | 37 | ||||
-rw-r--r-- | source/use_case/noise_reduction/src/MainLoop.cc | 4 | ||||
-rw-r--r-- | source/use_case/noise_reduction/src/UseCaseHandler.cc | 12 | ||||
-rw-r--r-- | source/use_case/object_detection/src/MainLoop.cc | 4 | ||||
-rw-r--r-- | source/use_case/object_detection/src/UseCaseHandler.cc | 45 | ||||
-rw-r--r-- | source/use_case/vww/src/MainLoop.cc | 4 | ||||
-rw-r--r-- | source/use_case/vww/src/UseCaseHandler.cc | 11 |
17 files changed, 146 insertions, 175 deletions
diff --git a/source/use_case/ad/src/MainLoop.cc b/source/use_case/ad/src/MainLoop.cc index 5a289bf..e858320 100644 --- a/source/use_case/ad/src/MainLoop.cc +++ b/source/use_case/ad/src/MainLoop.cc @@ -78,7 +78,7 @@ void main_loop(hal_platform& platform) int menuOption = MENU_OPT_RUN_INF_NEXT; if (bUseMenu) { DisplayMenu(); - menuOption = arm::app::ReadUserInputAsInt(platform); + menuOption = arm::app::ReadUserInputAsInt(); printf("\n"); } switch (menuOption) { @@ -93,7 +93,7 @@ void main_loop(hal_platform& platform) NUMBER_OF_FILES-1); fflush(stdout); auto audioIndex = static_cast<uint32_t>( - arm::app::ReadUserInputAsInt(platform)); + arm::app::ReadUserInputAsInt()); executionSuccessful = ClassifyVibrationHandler(caseContext, audioIndex, false); diff --git a/source/use_case/ad/src/UseCaseHandler.cc b/source/use_case/ad/src/UseCaseHandler.cc index 853ab08..5585f36 100644 --- a/source/use_case/ad/src/UseCaseHandler.cc +++ b/source/use_case/ad/src/UseCaseHandler.cc @@ -33,12 +33,11 @@ namespace app { /** * @brief Presents inference results using the data presentation * object. - * @param[in] platform reference to the hal platform object * @param[in] result average sum of classification results * @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); + static bool PresentInferenceResult(float result, float threshold); /** * @brief Returns a function to perform feature calculation and populates input tensor data with @@ -64,7 +63,6 @@ namespace app { /* Vibration classification handler */ bool ClassifyVibrationHandler(ApplicationContext& ctx, uint32_t clipIndex, bool runAll) { - auto& platform = ctx.Get<hal_platform&>("platform"); auto& profiler = ctx.Get<Profiler&>("profiler"); constexpr uint32_t dataPsnTxtInfStartX = 20; @@ -114,7 +112,7 @@ namespace app { auto audioDataStride = nMelSpecVectorsInAudioStride * frameStride; do { - platform.data_psn->clear(COLOR_BLACK); + hal_lcd_clear(COLOR_BLACK); auto currentIndex = ctx.Get<uint32_t>("clipIndex"); @@ -153,7 +151,7 @@ namespace app { /* Display message on the LCD - inference running. */ std::string str_inf{"Running inference... "}; - platform.data_psn->present_data_text( + hal_lcd_display_text( str_inf.c_str(), str_inf.size(), dataPsnTxtInfStartX, dataPsnTxtInfStartY, 0); info("Running inference on audio clip %" PRIu32 " => %s\n", currentIndex, get_filename(currentIndex)); @@ -202,12 +200,12 @@ namespace app { /* Erase. */ str_inf = std::string(str_inf.size(), ' '); - platform.data_psn->present_data_text( + hal_lcd_display_text( str_inf.c_str(), str_inf.size(), dataPsnTxtInfStartX, dataPsnTxtInfStartY, 0); ctx.Set<float>("result", result); - if (!PresentInferenceResult(platform, result, scoreThreshold)) { + if (!PresentInferenceResult(result, scoreThreshold)) { return false; } @@ -221,13 +219,13 @@ namespace app { } - static bool PresentInferenceResult(hal_platform& platform, float result, float threshold) + static bool PresentInferenceResult(float result, float threshold) { constexpr uint32_t dataPsnTxtStartX1 = 20; constexpr uint32_t dataPsnTxtStartY1 = 30; constexpr uint32_t dataPsnTxtYIncr = 16; /* Row index increment */ - platform.data_psn->set_text_color(COLOR_GREEN); + hal_lcd_set_text_color(COLOR_GREEN); /* Display each result */ uint32_t rowIdx1 = dataPsnTxtStartY1 + 2 * dataPsnTxtYIncr; @@ -242,7 +240,7 @@ namespace app { anomalyResult += std::string("Everything fine, no anomaly detected!"); } - platform.data_psn->present_data_text( + hal_lcd_display_text( anomalyScore.c_str(), anomalyScore.size(), dataPsnTxtStartX1, rowIdx1, false); diff --git a/source/use_case/asr/src/MainLoop.cc b/source/use_case/asr/src/MainLoop.cc index 40624f3..058211a 100644 --- a/source/use_case/asr/src/MainLoop.cc +++ b/source/use_case/asr/src/MainLoop.cc @@ -121,7 +121,7 @@ void main_loop(hal_platform& platform) int menuOption = MENU_OPT_RUN_INF_NEXT; if (bUseMenu) { DisplayMenu(); - menuOption = arm::app::ReadUserInputAsInt(platform); + menuOption = arm::app::ReadUserInputAsInt(); printf("\n"); } switch (menuOption) { @@ -136,7 +136,7 @@ void main_loop(hal_platform& platform) NUMBER_OF_FILES-1); fflush(stdout); auto clipIndex = static_cast<uint32_t>( - arm::app::ReadUserInputAsInt(platform)); + arm::app::ReadUserInputAsInt()); executionSuccessful = ClassifyAudioHandler(caseContext, clipIndex, false); diff --git a/source/use_case/asr/src/UseCaseHandler.cc b/source/use_case/asr/src/UseCaseHandler.cc index 7bce2c6..420f725 100644 --- a/source/use_case/asr/src/UseCaseHandler.cc +++ b/source/use_case/asr/src/UseCaseHandler.cc @@ -36,13 +36,10 @@ namespace app { /** * @brief Presents inference results using the data presentation * object. - * @param[in] platform Reference to the hal platform object. * @param[in] results Vector of classification results to be displayed. * @return true if successful, false otherwise. **/ - static bool PresentInferenceResult( - hal_platform& platform, - const std::vector<arm::app::asr::AsrResult>& results); + static bool PresentInferenceResult(const std::vector<arm::app::asr::AsrResult>& results); /* Audio inference classification handler. */ bool ClassifyAudioHandler(ApplicationContext& ctx, uint32_t clipIndex, bool runAll) @@ -50,8 +47,7 @@ namespace app { constexpr uint32_t dataPsnTxtInfStartX = 20; constexpr uint32_t dataPsnTxtInfStartY = 40; - auto& platform = ctx.Get<hal_platform&>("platform"); - platform.data_psn->clear(COLOR_BLACK); + hal_lcd_clear(COLOR_BLACK); auto& profiler = ctx.Get<Profiler&>("profiler"); @@ -103,7 +99,7 @@ namespace app { /* Loop to process audio clips. */ do { - platform.data_psn->clear(COLOR_BLACK); + hal_lcd_clear(COLOR_BLACK); /* Get current audio clip index. */ auto currentIndex = ctx.Get<uint32_t>("clipIndex"); @@ -136,7 +132,7 @@ namespace app { /* Display message on the LCD - inference running. */ std::string str_inf{"Running inference... "}; - platform.data_psn->present_data_text( + hal_lcd_display_text( str_inf.c_str(), str_inf.size(), dataPsnTxtInfStartX, dataPsnTxtInfStartY, 0); @@ -192,13 +188,13 @@ namespace app { /* Erase. */ str_inf = std::string(str_inf.size(), ' '); - platform.data_psn->present_data_text( + hal_lcd_display_text( str_inf.c_str(), str_inf.size(), dataPsnTxtInfStartX, dataPsnTxtInfStartY, 0); ctx.Set<std::vector<arm::app::asr::AsrResult>>("results", results); - if (!PresentInferenceResult(platform, results)) { + if (!PresentInferenceResult(results)) { return false; } @@ -212,14 +208,13 @@ namespace app { } - static bool PresentInferenceResult(hal_platform& platform, - const std::vector<arm::app::asr::AsrResult>& results) + static bool PresentInferenceResult(const std::vector<arm::app::asr::AsrResult>& results) { constexpr uint32_t dataPsnTxtStartX1 = 20; constexpr uint32_t dataPsnTxtStartY1 = 60; constexpr bool allow_multiple_lines = true; - platform.data_psn->set_text_color(COLOR_GREEN); + hal_lcd_set_text_color(COLOR_GREEN); info("Final results:\n"); info("Total number of inferences: %zu\n", results.size()); @@ -243,7 +238,7 @@ namespace app { /* Get the decoded result for the combined result. */ std::string finalResultStr = audio::asr::DecodeOutput(combinedResults); - platform.data_psn->present_data_text( + hal_lcd_display_text( finalResultStr.c_str(), finalResultStr.size(), dataPsnTxtStartX1, dataPsnTxtStartY1, allow_multiple_lines); diff --git a/source/use_case/img_class/src/MainLoop.cc b/source/use_case/img_class/src/MainLoop.cc index 05322d1..7b67a19 100644 --- a/source/use_case/img_class/src/MainLoop.cc +++ b/source/use_case/img_class/src/MainLoop.cc @@ -60,7 +60,7 @@ void main_loop(hal_platform& platform) int menuOption = common::MENU_OPT_RUN_INF_NEXT; if (bUseMenu) { DisplayCommonMenu(); - menuOption = arm::app::ReadUserInputAsInt(platform); + menuOption = arm::app::ReadUserInputAsInt(); printf("\n"); } switch (menuOption) { @@ -70,7 +70,7 @@ void main_loop(hal_platform& platform) case common::MENU_OPT_RUN_INF_CHOSEN: { printf(" Enter the image index [0, %d]: ", NUMBER_OF_FILES-1); fflush(stdout); - auto imgIndex = static_cast<uint32_t>(arm::app::ReadUserInputAsInt(platform)); + auto imgIndex = static_cast<uint32_t>(arm::app::ReadUserInputAsInt()); executionSuccessful = ClassifyImageHandler(caseContext, imgIndex, false); break; } diff --git a/source/use_case/img_class/src/UseCaseHandler.cc b/source/use_case/img_class/src/UseCaseHandler.cc index 1f1d78b..9061282 100644 --- a/source/use_case/img_class/src/UseCaseHandler.cc +++ b/source/use_case/img_class/src/UseCaseHandler.cc @@ -44,7 +44,6 @@ namespace app { /* Image inference classification handler. */ bool ClassifyImageHandler(ApplicationContext& ctx, uint32_t imgIndex, bool runAll) { - auto& platform = ctx.Get<hal_platform&>("platform"); auto& profiler = ctx.Get<Profiler&>("profiler"); constexpr uint32_t dataPsnImgDownscaleFactor = 2; @@ -89,7 +88,7 @@ namespace app { std::vector<ClassificationResult> results; do { - platform.data_psn->clear(COLOR_BLACK); + hal_lcd_clear(COLOR_BLACK); /* Strings for presentation/logging. */ std::string str_inf{"Running inference... "}; @@ -98,7 +97,7 @@ namespace app { LoadImageIntoTensor(ctx.Get<uint32_t>("imgIndex"), inputTensor); /* Display this image on the LCD. */ - platform.data_psn->present_data_image( + hal_lcd_display_image( static_cast<uint8_t *>(inputTensor->data.data), nCols, nRows, nChannels, dataPsnImgStartX, dataPsnImgStartY, dataPsnImgDownscaleFactor); @@ -109,7 +108,7 @@ namespace app { } /* Display message on the LCD - inference running. */ - platform.data_psn->present_data_text(str_inf.c_str(), str_inf.size(), + hal_lcd_display_text(str_inf.c_str(), str_inf.size(), dataPsnTxtInfStartX, dataPsnTxtInfStartY, false); /* Run inference over this image. */ @@ -122,7 +121,7 @@ namespace app { /* Erase. */ str_inf = std::string(str_inf.size(), ' '); - platform.data_psn->present_data_text(str_inf.c_str(), str_inf.size(), + hal_lcd_display_text(str_inf.c_str(), str_inf.size(), dataPsnTxtInfStartX, dataPsnTxtInfStartY, false); auto& classifier = ctx.Get<ImgClassClassifier&>("classifier"); @@ -137,7 +136,7 @@ namespace app { arm::app::DumpTensor(outputTensor); #endif /* VERIFY_TEST_OUTPUT */ - if (!PresentInferenceResult(platform, results)) { + if (!PresentInferenceResult(results)) { return false; } diff --git a/source/use_case/inference_runner/src/UseCaseHandler.cc b/source/use_case/inference_runner/src/UseCaseHandler.cc index 1125830..2f4b7c8 100644 --- a/source/use_case/inference_runner/src/UseCaseHandler.cc +++ b/source/use_case/inference_runner/src/UseCaseHandler.cc @@ -116,7 +116,6 @@ static void DumpOutputs(const Model& model, const char* message) bool RunInferenceHandler(ApplicationContext& ctx) { - auto& platform = ctx.Get<hal_platform&>("platform"); auto& profiler = ctx.Get<Profiler&>("profiler"); auto& model = ctx.Get<Model&>("model"); @@ -143,9 +142,8 @@ bool RunInferenceHandler(ApplicationContext& ctx) std::string str_inf{"Running inference... "}; /* Display message on the LCD - inference running. */ - platform.data_psn->present_data_text( - str_inf.c_str(), str_inf.size(), - dataPsnTxtInfStartX, dataPsnTxtInfStartY, 0); + hal_lcd_display_text(str_inf.c_str(), str_inf.size(), + dataPsnTxtInfStartX, dataPsnTxtInfStartY, 0); if (!RunInference(model, profiler)) { return false; @@ -153,7 +151,7 @@ bool RunInferenceHandler(ApplicationContext& ctx) /* Erase. */ str_inf = std::string(str_inf.size(), ' '); - platform.data_psn->present_data_text( + hal_lcd_display_text( str_inf.c_str(), str_inf.size(), dataPsnTxtInfStartX, dataPsnTxtInfStartY, 0); diff --git a/source/use_case/kws/src/MainLoop.cc b/source/use_case/kws/src/MainLoop.cc index 044c957..76dff8c 100644 --- a/source/use_case/kws/src/MainLoop.cc +++ b/source/use_case/kws/src/MainLoop.cc @@ -87,7 +87,7 @@ void main_loop(hal_platform& platform) int menuOption = MENU_OPT_RUN_INF_NEXT; if (bUseMenu) { DisplayMenu(); - menuOption = arm::app::ReadUserInputAsInt(platform); + menuOption = arm::app::ReadUserInputAsInt(); printf("\n"); } switch (menuOption) { @@ -97,7 +97,7 @@ void main_loop(hal_platform& platform) case MENU_OPT_RUN_INF_CHOSEN: { printf(" Enter the audio clip index [0, %d]: ", NUMBER_OF_FILES-1); fflush(stdout); - auto clipIndex = static_cast<uint32_t>(arm::app::ReadUserInputAsInt(platform)); + auto clipIndex = static_cast<uint32_t>(arm::app::ReadUserInputAsInt()); executionSuccessful = ClassifyAudioHandler(caseContext, clipIndex, false); break; } diff --git a/source/use_case/kws/src/UseCaseHandler.cc b/source/use_case/kws/src/UseCaseHandler.cc index 8dd7724..e04cefc 100644 --- a/source/use_case/kws/src/UseCaseHandler.cc +++ b/source/use_case/kws/src/UseCaseHandler.cc @@ -35,16 +35,14 @@ using KwsClassifier = arm::app::Classifier; namespace arm { namespace app { - + /** * @brief Presents inference results using the data presentation * object. - * @param[in] platform Reference to the hal platform object. * @param[in] results Vector of classification results to be displayed. * @return true if successful, false otherwise. **/ - static bool PresentInferenceResult(hal_platform& platform, - const std::vector<arm::app::kws::KwsResult>& results); + static bool PresentInferenceResult(const std::vector<arm::app::kws::KwsResult>& results); /** * @brief Returns a function to perform feature calculation and populates input tensor data with @@ -68,7 +66,6 @@ namespace app { /* Audio inference handler. */ bool ClassifyAudioHandler(ApplicationContext& ctx, uint32_t clipIndex, bool runAll) { - auto& platform = ctx.Get<hal_platform&>("platform"); auto& profiler = ctx.Get<Profiler&>("profiler"); constexpr uint32_t dataPsnTxtInfStartX = 20; @@ -137,7 +134,7 @@ namespace app { const float secondsPerSample = 1.0/audio::MicroNetKwsMFCC::ms_defaultSamplingFreq; do { - platform.data_psn->clear(COLOR_BLACK); + hal_lcd_clear(COLOR_BLACK); auto currentIndex = ctx.Get<uint32_t>("clipIndex"); @@ -171,7 +168,7 @@ namespace app { /* Display message on the LCD - inference running. */ std::string str_inf{"Running inference... "}; - platform.data_psn->present_data_text( + hal_lcd_display_text( str_inf.c_str(), str_inf.size(), dataPsnTxtInfStartX, dataPsnTxtInfStartY, 0); info("Running inference on audio clip %" PRIu32 " => %s\n", currentIndex, @@ -223,13 +220,13 @@ namespace app { /* Erase. */ str_inf = std::string(str_inf.size(), ' '); - platform.data_psn->present_data_text( + hal_lcd_display_text( str_inf.c_str(), str_inf.size(), dataPsnTxtInfStartX, dataPsnTxtInfStartY, false); ctx.Set<std::vector<arm::app::kws::KwsResult>>("results", results); - if (!PresentInferenceResult(platform, results)) { + if (!PresentInferenceResult(results)) { return false; } @@ -242,61 +239,6 @@ namespace app { return true; } - static bool PresentInferenceResult(hal_platform& platform, - const std::vector<arm::app::kws::KwsResult>& results) - { - constexpr uint32_t dataPsnTxtStartX1 = 20; - constexpr uint32_t dataPsnTxtStartY1 = 30; - constexpr uint32_t dataPsnTxtYIncr = 16; /* Row index increment. */ - - platform.data_psn->set_text_color(COLOR_GREEN); - info("Final results:\n"); - info("Total number of inferences: %zu\n", results.size()); - - /* Display each result */ - uint32_t rowIdx1 = dataPsnTxtStartY1 + 2 * dataPsnTxtYIncr; - - for (uint32_t i = 0; i < results.size(); ++i) { - - std::string topKeyword{"<none>"}; - float score = 0.f; - if (!results[i].m_resultVec.empty()) { - topKeyword = results[i].m_resultVec[0].m_label; - score = results[i].m_resultVec[0].m_normalisedVal; - } - - std::string resultStr = - std::string{"@"} + std::to_string(results[i].m_timeStamp) + - std::string{"s: "} + topKeyword + std::string{" ("} + - std::to_string(static_cast<int>(score * 100)) + std::string{"%)"}; - - platform.data_psn->present_data_text( - resultStr.c_str(), resultStr.size(), - dataPsnTxtStartX1, rowIdx1, false); - rowIdx1 += dataPsnTxtYIncr; - - if (results[i].m_resultVec.empty()) { - info("For timestamp: %f (inference #: %" PRIu32 - "); label: %s; threshold: %f\n", - results[i].m_timeStamp, results[i].m_inferenceNumber, - topKeyword.c_str(), - results[i].m_threshold); - } else { - for (uint32_t j = 0; j < results[i].m_resultVec.size(); ++j) { - info("For timestamp: %f (inference #: %" PRIu32 - "); label: %s, score: %f; threshold: %f\n", - results[i].m_timeStamp, - results[i].m_inferenceNumber, - results[i].m_resultVec[j].m_label.c_str(), - results[i].m_resultVec[j].m_normalisedVal, - results[i].m_threshold); - } - } - } - - return true; - } - /** * @brief Generic feature calculator factory. * @@ -344,6 +286,60 @@ namespace app { }; } + static bool PresentInferenceResult(const std::vector<arm::app::kws::KwsResult>& results) + { + constexpr uint32_t dataPsnTxtStartX1 = 20; + constexpr uint32_t dataPsnTxtStartY1 = 30; + constexpr uint32_t dataPsnTxtYIncr = 16; /* Row index increment. */ + + hal_lcd_set_text_color(COLOR_GREEN); + info("Final results:\n"); + info("Total number of inferences: %zu\n", results.size()); + + /* Display each result */ + uint32_t rowIdx1 = dataPsnTxtStartY1 + 2 * dataPsnTxtYIncr; + + for (uint32_t i = 0; i < results.size(); ++i) { + + std::string topKeyword{"<none>"}; + float score = 0.f; + if (!results[i].m_resultVec.empty()) { + topKeyword = results[i].m_resultVec[0].m_label; + score = results[i].m_resultVec[0].m_normalisedVal; + } + + std::string resultStr = + std::string{"@"} + std::to_string(results[i].m_timeStamp) + + std::string{"s: "} + topKeyword + std::string{" ("} + + std::to_string(static_cast<int>(score * 100)) + std::string{"%)"}; + + hal_lcd_display_text( + resultStr.c_str(), resultStr.size(), + dataPsnTxtStartX1, rowIdx1, false); + rowIdx1 += dataPsnTxtYIncr; + + if (results[i].m_resultVec.empty()) { + info("For timestamp: %f (inference #: %" PRIu32 + "); label: %s; threshold: %f\n", + results[i].m_timeStamp, results[i].m_inferenceNumber, + topKeyword.c_str(), + results[i].m_threshold); + } else { + for (uint32_t j = 0; j < results[i].m_resultVec.size(); ++j) { + info("For timestamp: %f (inference #: %" PRIu32 + "); label: %s, score: %f; threshold: %f\n", + results[i].m_timeStamp, + results[i].m_inferenceNumber, + results[i].m_resultVec[j].m_label.c_str(), + results[i].m_resultVec[j].m_normalisedVal, + results[i].m_threshold); + } + } + } + + return true; + } + template std::function<void (std::vector<int16_t>&, size_t , bool, size_t)> FeatureCalc<int8_t>(TfLiteTensor* inputTensor, size_t cacheSize, diff --git a/source/use_case/kws_asr/src/MainLoop.cc b/source/use_case/kws_asr/src/MainLoop.cc index a2beab3..096c966 100644 --- a/source/use_case/kws_asr/src/MainLoop.cc +++ b/source/use_case/kws_asr/src/MainLoop.cc @@ -156,7 +156,7 @@ void main_loop(hal_platform& platform) int menuOption = MENU_OPT_RUN_INF_NEXT; if (bUseMenu) { DisplayMenu(); - menuOption = arm::app::ReadUserInputAsInt(platform); + menuOption = arm::app::ReadUserInputAsInt(); printf("\n"); } switch (menuOption) { @@ -171,7 +171,7 @@ void main_loop(hal_platform& platform) NUMBER_OF_FILES-1); fflush(stdout); auto clipIndex = static_cast<uint32_t>( - arm::app::ReadUserInputAsInt(platform)); + arm::app::ReadUserInputAsInt()); executionSuccessful = ClassifyAudioHandler(caseContext, clipIndex, false); diff --git a/source/use_case/kws_asr/src/UseCaseHandler.cc b/source/use_case/kws_asr/src/UseCaseHandler.cc index d598de6..1e1a400 100644 --- a/source/use_case/kws_asr/src/UseCaseHandler.cc +++ b/source/use_case/kws_asr/src/UseCaseHandler.cc @@ -53,11 +53,10 @@ namespace app { /** * @brief Presents kws inference results using the data presentation * object. - * @param[in] platform reference to the hal platform object * @param[in] results vector of classification results to be displayed * @return true if successful, false otherwise **/ - static bool PresentInferenceResult(hal_platform& platform, std::vector<arm::app::kws::KwsResult>& results); + static bool PresentInferenceResult(std::vector<arm::app::kws::KwsResult>& results); /** * @brief Presents asr inference results using the data presentation @@ -66,7 +65,7 @@ namespace app { * @param[in] results vector of classification results to be displayed * @return true if successful, false otherwise **/ - static bool PresentInferenceResult(hal_platform& platform, std::vector<arm::app::asr::AsrResult>& results); + static bool PresentInferenceResult(std::vector<arm::app::asr::AsrResult>& results); /** * @brief Returns a function to perform feature calculation and populates input tensor data with @@ -186,9 +185,8 @@ namespace app { std::vector<arm::app::kws::KwsResult> kwsResults; /* Display message on the LCD - inference running. */ - auto& platform = ctx.Get<hal_platform&>("platform"); std::string str_inf{"Running KWS inference... "}; - platform.data_psn->present_data_text( + hal_lcd_display_text( str_inf.c_str(), str_inf.size(), dataPsnTxtInfStartX, dataPsnTxtInfStartY, false); @@ -258,11 +256,11 @@ namespace app { /* Erase. */ str_inf = std::string(str_inf.size(), ' '); - platform.data_psn->present_data_text( + hal_lcd_display_text( str_inf.c_str(), str_inf.size(), dataPsnTxtInfStartX, dataPsnTxtInfStartY, false); - if (!PresentInferenceResult(platform, kwsResults)) { + if (!PresentInferenceResult(kwsResults)) { return output; } @@ -285,8 +283,7 @@ namespace app { constexpr uint32_t dataPsnTxtInfStartY = 40; auto& profiler = ctx.Get<Profiler&>("profiler"); - auto& platform = ctx.Get<hal_platform&>("platform"); - platform.data_psn->clear(COLOR_BLACK); + hal_lcd_clear(COLOR_BLACK); /* Get model reference. */ auto& asrModel = ctx.Get<Model&>("asrmodel"); @@ -356,7 +353,7 @@ namespace app { /* Display message on the LCD - inference running. */ std::string str_inf{"Running ASR inference... "}; - platform.data_psn->present_data_text( + hal_lcd_display_text( str_inf.c_str(), str_inf.size(), dataPsnTxtInfStartX, dataPsnTxtInfStartY, false); @@ -407,11 +404,11 @@ namespace app { /* Erase */ str_inf = std::string(str_inf.size(), ' '); - platform.data_psn->present_data_text( + hal_lcd_display_text( str_inf.c_str(), str_inf.size(), dataPsnTxtInfStartX, dataPsnTxtInfStartY, false); } - if (!PresentInferenceResult(platform, asrResults)) { + if (!PresentInferenceResult(asrResults)) { return false; } @@ -423,8 +420,7 @@ namespace app { /* Audio inference classification handler. */ bool ClassifyAudioHandler(ApplicationContext& ctx, uint32_t clipIndex, bool runAll) { - auto& platform = ctx.Get<hal_platform&>("platform"); - platform.data_psn->clear(COLOR_BLACK); + hal_lcd_clear(COLOR_BLACK); /* If the request has a valid size, set the audio index. */ if (clipIndex < NUMBER_OF_FILES) { @@ -457,14 +453,13 @@ namespace app { } - static bool PresentInferenceResult(hal_platform& platform, - std::vector<arm::app::kws::KwsResult>& results) + static bool PresentInferenceResult(std::vector<arm::app::kws::KwsResult>& results) { constexpr uint32_t dataPsnTxtStartX1 = 20; constexpr uint32_t dataPsnTxtStartY1 = 30; constexpr uint32_t dataPsnTxtYIncr = 16; /* Row index increment. */ - platform.data_psn->set_text_color(COLOR_GREEN); + hal_lcd_set_text_color(COLOR_GREEN); /* Display each result. */ uint32_t rowIdx1 = dataPsnTxtStartY1 + 2 * dataPsnTxtYIncr; @@ -484,7 +479,7 @@ namespace app { std::string{"s: "} + topKeyword + std::string{" ("} + std::to_string(static_cast<int>(score * 100)) + std::string{"%)"}; - platform.data_psn->present_data_text( + hal_lcd_display_text( resultStr.c_str(), resultStr.size(), dataPsnTxtStartX1, rowIdx1, 0); rowIdx1 += dataPsnTxtYIncr; @@ -502,13 +497,13 @@ namespace app { return true; } - static bool PresentInferenceResult(hal_platform& platform, std::vector<arm::app::asr::AsrResult>& results) + static bool PresentInferenceResult(std::vector<arm::app::asr::AsrResult>& results) { constexpr uint32_t dataPsnTxtStartX1 = 20; constexpr uint32_t dataPsnTxtStartY1 = 80; constexpr bool allow_multiple_lines = true; - platform.data_psn->set_text_color(COLOR_GREEN); + hal_lcd_set_text_color(COLOR_GREEN); /* Results from multiple inferences should be combined before processing. */ std::vector<arm::app::ClassificationResult> combinedResults; @@ -528,7 +523,7 @@ namespace app { std::string finalResultStr = audio::asr::DecodeOutput(combinedResults); - platform.data_psn->present_data_text( + hal_lcd_display_text( finalResultStr.c_str(), finalResultStr.size(), dataPsnTxtStartX1, dataPsnTxtStartY1, allow_multiple_lines); diff --git a/source/use_case/noise_reduction/src/MainLoop.cc b/source/use_case/noise_reduction/src/MainLoop.cc index c6214e3..bcaff6d 100644 --- a/source/use_case/noise_reduction/src/MainLoop.cc +++ b/source/use_case/noise_reduction/src/MainLoop.cc @@ -98,7 +98,7 @@ void main_loop(hal_platform& platform) if (bUseMenu) { DisplayMenu(); - menuOption = arm::app::ReadUserInputAsInt(platform); + menuOption = arm::app::ReadUserInputAsInt(); printf("\n"); } switch (menuOption) { @@ -108,7 +108,7 @@ void main_loop(hal_platform& platform) case MENU_OPT_RUN_INF_CHOSEN: { printf(" Enter the audio clip IFM index [0, %d]: ", NUMBER_OF_FILES-1); fflush(stdout); - auto clipIndex = static_cast<uint32_t>(arm::app::ReadUserInputAsInt(platform)); + auto clipIndex = static_cast<uint32_t>(arm::app::ReadUserInputAsInt()); SetAppCtxClipIdx(caseContext, clipIndex); executionSuccessful = NoiseReductionHandler(caseContext, false); break; diff --git a/source/use_case/noise_reduction/src/UseCaseHandler.cc b/source/use_case/noise_reduction/src/UseCaseHandler.cc index 792b460..acb8ba7 100644 --- a/source/use_case/noise_reduction/src/UseCaseHandler.cc +++ b/source/use_case/noise_reduction/src/UseCaseHandler.cc @@ -64,8 +64,6 @@ namespace app { pMemDumpBytesWritten = ctx.Get<size_t*>("MEM_DUMP_BYTE_WRITTEN"); } std::reference_wrapper<size_t> memDumpBytesWritten = std::ref(*pMemDumpBytesWritten); - - auto& platform = ctx.Get<hal_platform&>("platform"); auto& profiler = ctx.Get<Profiler&>("profiler"); /* Get model reference. */ @@ -106,7 +104,7 @@ namespace app { audioFileAccessorFunc = ctx.Get<std::function<const char*(const uint32_t)>>("featureFileNames"); } do{ - platform.data_psn->clear(COLOR_BLACK); + hal_lcd_clear(COLOR_BLACK); auto startDumpAddress = memDumpBaseAddr + memDumpBytesWritten; auto currentIndex = ctx.Get<uint32_t>("clipIndex"); @@ -158,7 +156,7 @@ namespace app { std::string str_inf{"Running inference... "}; /* Display message on the LCD - inference running. */ - platform.data_psn->present_data_text( + hal_lcd_display_text( str_inf.c_str(), str_inf.size(), dataPsnTxtInfStartX, dataPsnTxtInfStartY, false); @@ -191,7 +189,7 @@ namespace app { /* Erase. */ str_inf = std::string(str_inf.size(), ' '); - platform.data_psn->present_data_text( + hal_lcd_display_text( str_inf.c_str(), str_inf.size(), dataPsnTxtInfStartX, dataPsnTxtInfStartY, false); @@ -218,14 +216,14 @@ namespace app { IncrementAppCtxClipIdx(ctx); std::string clearString{' '}; - platform.data_psn->present_data_text( + hal_lcd_display_text( clearString.c_str(), clearString.size(), dataPsnTxtInfStartX, dataPsnTxtInfStartY, false); std::string completeMsg{"Inference complete!"}; /* Display message on the LCD - inference complete. */ - platform.data_psn->present_data_text( + hal_lcd_display_text( completeMsg.c_str(), completeMsg.size(), dataPsnTxtInfStartX, dataPsnTxtInfStartY, false); diff --git a/source/use_case/object_detection/src/MainLoop.cc b/source/use_case/object_detection/src/MainLoop.cc index 4bec357..0f98c8a 100644 --- a/source/use_case/object_detection/src/MainLoop.cc +++ b/source/use_case/object_detection/src/MainLoop.cc @@ -67,7 +67,7 @@ void main_loop(hal_platform& platform) int menuOption = common::MENU_OPT_RUN_INF_NEXT; if (bUseMenu) { DisplayDetectionMenu(); - menuOption = arm::app::ReadUserInputAsInt(platform); + menuOption = arm::app::ReadUserInputAsInt(); printf("\n"); } switch (menuOption) { @@ -77,7 +77,7 @@ void main_loop(hal_platform& platform) case common::MENU_OPT_RUN_INF_CHOSEN: { printf(" Enter the image index [0, %d]: ", NUMBER_OF_FILES-1); fflush(stdout); - auto imgIndex = static_cast<uint32_t>(arm::app::ReadUserInputAsInt(platform)); + auto imgIndex = static_cast<uint32_t>(arm::app::ReadUserInputAsInt()); executionSuccessful = ObjectDetectionHandler(caseContext, imgIndex, false); break; } diff --git a/source/use_case/object_detection/src/UseCaseHandler.cc b/source/use_case/object_detection/src/UseCaseHandler.cc index 27d767d..f3b317e 100644 --- a/source/use_case/object_detection/src/UseCaseHandler.cc +++ b/source/use_case/object_detection/src/UseCaseHandler.cc @@ -30,31 +30,27 @@ namespace app { /** * @brief Presents inference results along using the data presentation * object. - * @param[in] platform Reference to the hal platform object. * @param[in] results Vector of detection results to be displayed. * @return true if successful, false otherwise. **/ - static bool PresentInferenceResult(hal_platform& platform, - const std::vector<arm::app::object_detection::DetectionResult>& results); + static bool PresentInferenceResult(const std::vector<arm::app::object_detection::DetectionResult>& results); /** * @brief Draw boxes directly on the LCD for all detected objects. - * @param[in] platform Reference to the hal platform object. * @param[in] results Vector of detection results to be displayed. * @param[in] imageStartX X coordinate where the image starts on the LCD. * @param[in] imageStartY Y coordinate where the image starts on the LCD. * @param[in] imgDownscaleFactor How much image has been downscaled on LCD. **/ - static void DrawDetectionBoxes(hal_platform& platform, - const std::vector<arm::app::object_detection::DetectionResult>& results, - uint32_t imgStartX, - uint32_t imgStartY, - uint32_t imgDownscaleFactor); + static void DrawDetectionBoxes( + const std::vector<arm::app::object_detection::DetectionResult>& results, + uint32_t imgStartX, + uint32_t imgStartY, + uint32_t imgDownscaleFactor); /* Object detection classification handler. */ bool ObjectDetectionHandler(ApplicationContext& ctx, uint32_t imgIndex, bool runAll) { - auto& platform = ctx.Get<hal_platform&>("platform"); auto& profiler = ctx.Get<Profiler&>("profiler"); constexpr uint32_t dataPsnImgDownscaleFactor = 1; @@ -64,7 +60,7 @@ namespace app { constexpr uint32_t dataPsnTxtInfStartX = 150; constexpr uint32_t dataPsnTxtInfStartY = 40; - platform.data_psn->clear(COLOR_BLACK); + hal_lcd_clear(COLOR_BLACK); auto& model = ctx.Get<Model&>("model"); @@ -114,7 +110,7 @@ namespace app { image::RgbToGrayscale(curr_image, dstPtr, copySz); /* Display image on the LCD. */ - platform.data_psn->present_data_image( + hal_lcd_display_image( (channelsImageDisplayed == 3) ? curr_image : dstPtr, nCols, nRows, channelsImageDisplayed, dataPsnImgStartX, dataPsnImgStartY, dataPsnImgDownscaleFactor); @@ -125,7 +121,7 @@ namespace app { } /* Display message on the LCD - inference running. */ - platform.data_psn->present_data_text(str_inf.c_str(), str_inf.size(), + hal_lcd_display_text(str_inf.c_str(), str_inf.size(), dataPsnTxtInfStartX, dataPsnTxtInfStartY, false); /* Run inference over this image. */ @@ -138,7 +134,7 @@ namespace app { /* Erase. */ str_inf = std::string(str_inf.size(), ' '); - platform.data_psn->present_data_text(str_inf.c_str(), str_inf.size(), + hal_lcd_display_text(str_inf.c_str(), str_inf.size(), dataPsnTxtInfStartX, dataPsnTxtInfStartY, false); /* Detector post-processing*/ @@ -153,14 +149,14 @@ namespace app { results); /* Draw boxes. */ - DrawDetectionBoxes(platform, results, dataPsnImgStartX, dataPsnImgStartY, dataPsnImgDownscaleFactor); + DrawDetectionBoxes(results, dataPsnImgStartX, dataPsnImgStartY, dataPsnImgDownscaleFactor); #if VERIFY_TEST_OUTPUT arm::app::DumpTensor(modelOutput0); arm::app::DumpTensor(modelOutput1); #endif /* VERIFY_TEST_OUTPUT */ - if (!PresentInferenceResult(platform, results)) { + if (!PresentInferenceResult(results)) { return false; } @@ -173,11 +169,9 @@ namespace app { return true; } - - static bool PresentInferenceResult(hal_platform& platform, - const std::vector<arm::app::object_detection::DetectionResult>& results) + static bool PresentInferenceResult(const std::vector<arm::app::object_detection::DetectionResult>& results) { - platform.data_psn->set_text_color(COLOR_GREEN); + hal_lcd_set_text_color(COLOR_GREEN); /* If profiling is enabled, and the time is valid. */ info("Final results:\n"); @@ -192,8 +186,7 @@ namespace app { return true; } - static void DrawDetectionBoxes(hal_platform& platform, - const std::vector<arm::app::object_detection::DetectionResult>& results, + static void DrawDetectionBoxes(const std::vector<arm::app::object_detection::DetectionResult>& results, uint32_t imgStartX, uint32_t imgStartY, uint32_t imgDownscaleFactor) @@ -202,20 +195,20 @@ namespace app { for (const auto& result: results) { /* Top line. */ - platform.data_psn->present_box(imgStartX + result.m_x0/imgDownscaleFactor, + hal_lcd_display_box(imgStartX + result.m_x0/imgDownscaleFactor, imgStartY + result.m_y0/imgDownscaleFactor, result.m_w/imgDownscaleFactor, lineThickness, COLOR_GREEN); /* Bot line. */ - platform.data_psn->present_box(imgStartX + result.m_x0/imgDownscaleFactor, + hal_lcd_display_box(imgStartX + result.m_x0/imgDownscaleFactor, imgStartY + (result.m_y0 + result.m_h)/imgDownscaleFactor - lineThickness, result.m_w/imgDownscaleFactor, lineThickness, COLOR_GREEN); /* Left line. */ - platform.data_psn->present_box(imgStartX + result.m_x0/imgDownscaleFactor, + hal_lcd_display_box(imgStartX + result.m_x0/imgDownscaleFactor, imgStartY + result.m_y0/imgDownscaleFactor, lineThickness, result.m_h/imgDownscaleFactor, COLOR_GREEN); /* Right line. */ - platform.data_psn->present_box(imgStartX + (result.m_x0 + result.m_w)/imgDownscaleFactor - lineThickness, + hal_lcd_display_box(imgStartX + (result.m_x0 + result.m_w)/imgDownscaleFactor - lineThickness, imgStartY + result.m_y0/imgDownscaleFactor, lineThickness, result.m_h/imgDownscaleFactor, COLOR_GREEN); } diff --git a/source/use_case/vww/src/MainLoop.cc b/source/use_case/vww/src/MainLoop.cc index 30e85bf..03d6196 100644 --- a/source/use_case/vww/src/MainLoop.cc +++ b/source/use_case/vww/src/MainLoop.cc @@ -58,7 +58,7 @@ void main_loop(hal_platform &platform) int menuOption = common::MENU_OPT_RUN_INF_NEXT; if (bUseMenu) { DisplayCommonMenu(); - menuOption = arm::app::ReadUserInputAsInt(platform); + menuOption = arm::app::ReadUserInputAsInt(); printf("\n"); } @@ -69,7 +69,7 @@ void main_loop(hal_platform &platform) case common::MENU_OPT_RUN_INF_CHOSEN: { printf(" Enter the image index [0, %d]: ", NUMBER_OF_FILES-1); fflush(stdout); - auto imgIndex = static_cast<uint32_t>(arm::app::ReadUserInputAsInt(platform)); + auto imgIndex = static_cast<uint32_t>(arm::app::ReadUserInputAsInt()); executionSuccessful = ClassifyImageHandler(caseContext, imgIndex, false); break; } diff --git a/source/use_case/vww/src/UseCaseHandler.cc b/source/use_case/vww/src/UseCaseHandler.cc index a47f191..56ba2b5 100644 --- a/source/use_case/vww/src/UseCaseHandler.cc +++ b/source/use_case/vww/src/UseCaseHandler.cc @@ -42,7 +42,6 @@ namespace app { /* Image inference classification handler. */ bool ClassifyImageHandler(ApplicationContext &ctx, uint32_t imgIndex, bool runAll) { - auto& platform = ctx.Get<hal_platform &>("platform"); auto& profiler = ctx.Get<Profiler&>("profiler"); constexpr uint32_t dataPsnImgDownscaleFactor = 1; @@ -89,7 +88,7 @@ namespace app { std::vector<ClassificationResult> results; do { - platform.data_psn->clear(COLOR_BLACK); + hal_lcd_clear(COLOR_BLACK); /* Strings for presentation/logging. */ std::string str_inf{"Running inference... "}; @@ -98,7 +97,7 @@ namespace app { LoadImageIntoTensor(ctx.Get<uint32_t>("imgIndex"), inputTensor); /* Display this image on the LCD. */ - platform.data_psn->present_data_image( + hal_lcd_display_image( static_cast<uint8_t *>(inputTensor->data.data), nCols, nRows, nChannels, dataPsnImgStartX, dataPsnImgStartY, dataPsnImgDownscaleFactor); @@ -115,7 +114,7 @@ namespace app { } /* Display message on the LCD - inference running. */ - platform.data_psn->present_data_text( + hal_lcd_display_text( str_inf.c_str(), str_inf.size(), dataPsnTxtInfStartX, dataPsnTxtInfStartY, 0); @@ -129,7 +128,7 @@ namespace app { /* Erase. */ str_inf = std::string(str_inf.size(), ' '); - platform.data_psn->present_data_text( + hal_lcd_display_text( str_inf.c_str(), str_inf.size(), dataPsnTxtInfStartX, dataPsnTxtInfStartY, 0); @@ -145,7 +144,7 @@ namespace app { arm::app::DumpTensor(outputTensor); #endif /* VERIFY_TEST_OUTPUT */ - if (!PresentInferenceResult(platform, results)) { + if (!PresentInferenceResult(results)) { return false; } |