summaryrefslogtreecommitdiff
path: root/source/application/main/UseCaseCommonUtils.cc
diff options
context:
space:
mode:
Diffstat (limited to 'source/application/main/UseCaseCommonUtils.cc')
-rw-r--r--source/application/main/UseCaseCommonUtils.cc165
1 files changed, 76 insertions, 89 deletions
diff --git a/source/application/main/UseCaseCommonUtils.cc b/source/application/main/UseCaseCommonUtils.cc
index d1276ab..7d0a2ca 100644
--- a/source/application/main/UseCaseCommonUtils.cc
+++ b/source/application/main/UseCaseCommonUtils.cc
@@ -1,6 +1,6 @@
/*
- * SPDX-FileCopyrightText: Copyright 2021-2022 Arm Limited and/or its affiliates <open-source-office@arm.com>
- * SPDX-License-Identifier: Apache-2.0
+ * SPDX-FileCopyrightText: Copyright 2021-2022 Arm Limited and/or its affiliates
+ * <open-source-office@arm.com> SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@
#include <cinttypes>
-
void DisplayCommonMenu()
{
printf("\n\n");
@@ -36,7 +35,7 @@ void DisplayCommonMenu()
fflush(stdout);
}
-bool PresentInferenceResult(const std::vector<arm::app::ClassificationResult> &results)
+bool PresentInferenceResult(const std::vector<arm::app::ClassificationResult>& results)
{
constexpr uint32_t dataPsnTxtStartX1 = 150;
constexpr uint32_t dataPsnTxtStartY1 = 30;
@@ -44,7 +43,7 @@ bool PresentInferenceResult(const std::vector<arm::app::ClassificationResult> &r
constexpr uint32_t dataPsnTxtStartX2 = 10;
constexpr uint32_t dataPsnTxtStartY2 = 150;
- constexpr uint32_t dataPsnTxtYIncr = 16; /* Row index increment. */
+ constexpr uint32_t dataPsnTxtYIncr = 16; /* Row index increment. */
hal_lcd_set_text_color(COLOR_GREEN);
@@ -56,31 +55,28 @@ bool PresentInferenceResult(const std::vector<arm::app::ClassificationResult> &r
info("Total number of inferences: 1\n");
for (uint32_t i = 0; i < results.size(); ++i) {
- std::string resultStr =
- std::to_string(i + 1) + ") " +
- std::to_string(results[i].m_labelIdx) +
- " (" + std::to_string(results[i].m_normalisedVal) + ")";
+ std::string resultStr = std::to_string(i + 1) + ") " +
+ std::to_string(results[i].m_labelIdx) + " (" +
+ std::to_string(results[i].m_normalisedVal) + ")";
hal_lcd_display_text(
- resultStr.c_str(), resultStr.size(),
- dataPsnTxtStartX1, rowIdx1, false);
+ resultStr.c_str(), resultStr.size(), dataPsnTxtStartX1, rowIdx1, false);
rowIdx1 += dataPsnTxtYIncr;
resultStr = std::to_string(i + 1) + ") " + results[i].m_label;
- hal_lcd_display_text(
- resultStr.c_str(), resultStr.size(),
- dataPsnTxtStartX2, rowIdx2, 0);
+ hal_lcd_display_text(resultStr.c_str(), resultStr.size(), dataPsnTxtStartX2, rowIdx2, 0);
rowIdx2 += dataPsnTxtYIncr;
- info("%" PRIu32 ") %" PRIu32 " (%f) -> %s\n", i,
- results[i].m_labelIdx, results[i].m_normalisedVal,
- results[i].m_label.c_str());
+ info("%" PRIu32 ") %" PRIu32 " (%f) -> %s\n",
+ i,
+ results[i].m_labelIdx,
+ results[i].m_normalisedVal,
+ results[i].m_label.c_str());
}
return true;
}
-
void IncrementAppCtxIfmIdx(arm::app::ApplicationContext& ctx, const std::string& useCase)
{
#if NUMBER_OF_FILES > 0
@@ -92,7 +88,7 @@ void IncrementAppCtxIfmIdx(arm::app::ApplicationContext& ctx, const std::string&
}
++curImIdx;
ctx.Set<uint32_t>(useCase, curImIdx);
-#else /* NUMBER_OF_FILES > 0 */
+#else /* NUMBER_OF_FILES > 0 */
UNUSED(ctx);
UNUSED(useCase);
#endif /* NUMBER_OF_FILES > 0 */
@@ -102,13 +98,12 @@ bool SetAppCtxIfmIdx(arm::app::ApplicationContext& ctx, uint32_t idx, const std:
{
#if NUMBER_OF_FILES > 0
if (idx >= NUMBER_OF_FILES) {
- printf_err("Invalid idx %" PRIu32 " (expected less than %u)\n",
- idx, NUMBER_OF_FILES);
+ printf_err("Invalid idx %" PRIu32 " (expected less than %u)\n", idx, NUMBER_OF_FILES);
return false;
}
ctx.Set<uint32_t>(ctxIfmName, idx);
return true;
-#else /* NUMBER_OF_FILES > 0 */
+#else /* NUMBER_OF_FILES > 0 */
UNUSED(ctx);
UNUSED(idx);
UNUSED(ctxIfmName);
@@ -119,83 +114,76 @@ bool SetAppCtxIfmIdx(arm::app::ApplicationContext& ctx, uint32_t idx, const std:
namespace arm {
namespace app {
+ bool RunInference(arm::app::Model& model, Profiler& profiler)
+ {
+ profiler.StartProfiling("Inference");
+ bool runInf = model.RunInference();
+ profiler.StopProfiling();
-bool RunInference(arm::app::Model& model, Profiler& profiler)
-{
- profiler.StartProfiling("Inference");
- bool runInf = model.RunInference();
- profiler.StopProfiling();
-
- return runInf;
-}
-
-int ReadUserInputAsInt()
-{
- char chInput[128];
- memset(chInput, 0, sizeof(chInput));
+ return runInf;
+ }
- hal_get_user_input(chInput, sizeof(chInput));
- return atoi(chInput);
-}
+ int ReadUserInputAsInt()
+ {
+ char chInput[128];
+ memset(chInput, 0, sizeof(chInput));
-void DumpTensorData(const uint8_t* tensorData,
- size_t size,
- size_t lineBreakForNumElements)
-{
- char strhex[8];
- std::string strdump;
+ hal_get_user_input(chInput, sizeof(chInput));
+ return atoi(chInput);
+ }
- for (size_t i = 0; i < size; ++i) {
- if (0 == i % lineBreakForNumElements) {
- printf("%s\n\t", strdump.c_str());
- strdump.clear();
+ 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);
}
- snprintf(strhex, sizeof(strhex) - 1,
- "0x%02x, ", tensorData[i]);
- strdump += std::string(strhex);
- }
- if (!strdump.empty()) {
- printf("%s\n", strdump.c_str());
+ 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;
- }
+ void DumpTensor(const TfLiteTensor* tensor, const size_t lineBreakForNumElements)
+ {
+ if (!tensor) {
+ printf_err("invalid tensor\n");
+ return;
+ }
- const uint32_t tensorSz = tensor->bytes;
- const auto* tensorData = tflite::GetTensorData<uint8_t>(tensor);
+ const uint32_t tensorSz = tensor->bytes;
+ const auto* tensorData = tflite::GetTensorData<uint8_t>(tensor);
- DumpTensorData(tensorData, tensorSz, lineBreakForNumElements);
-}
+ DumpTensorData(tensorData, tensorSz, lineBreakForNumElements);
+ }
-bool ListFilesHandler(ApplicationContext& ctx)
-{
- auto& model = ctx.Get<Model&>("model");
+ bool ListFilesHandler(ApplicationContext& ctx)
+ {
+ auto& model = ctx.Get<Model&>("model");
- constexpr uint32_t dataPsnTxtStartX = 20;
- constexpr uint32_t dataPsnTxtStartY = 40;
+ constexpr uint32_t dataPsnTxtStartX = 20;
+ constexpr uint32_t dataPsnTxtStartY = 40;
- if (!model.IsInited()) {
- printf_err("Model is not initialised! Terminating processing.\n");
- return false;
- }
+ if (!model.IsInited()) {
+ printf_err("Model is not initialised! Terminating processing.\n");
+ return false;
+ }
- /* Clear the LCD */
- hal_lcd_clear(COLOR_BLACK);
+ /* Clear the LCD */
+ hal_lcd_clear(COLOR_BLACK);
- /* Show the total number of embedded files. */
- std::string strNumFiles = std::string{"Total Number of Files: "} +
- std::to_string(NUMBER_OF_FILES);
- hal_lcd_display_text(strNumFiles.c_str(),
- strNumFiles.size(),
- dataPsnTxtStartX,
- dataPsnTxtStartY,
- false);
+ /* Show the total number of embedded files. */
+ std::string strNumFiles =
+ std::string{"Total Number of Files: "} + std::to_string(NUMBER_OF_FILES);
+ hal_lcd_display_text(
+ strNumFiles.c_str(), strNumFiles.size(), dataPsnTxtStartX, dataPsnTxtStartY, false);
#if NUMBER_OF_FILES > 0
constexpr uint32_t dataPsnTxtYIncr = 16;
@@ -203,17 +191,16 @@ bool ListFilesHandler(ApplicationContext& ctx)
uint32_t yVal = dataPsnTxtStartY + dataPsnTxtYIncr;
for (uint32_t i = 0; i < NUMBER_OF_FILES; ++i, yVal += dataPsnTxtYIncr) {
- std::string currentFilename{get_filename(i)};
- hal_lcd_display_text(currentFilename.c_str(),
- currentFilename.size(),
- dataPsnTxtStartX, yVal, false);
+ std::string currentFilename{GetFilename(i)};
+ hal_lcd_display_text(
+ currentFilename.c_str(), currentFilename.size(), dataPsnTxtStartX, yVal, false);
info("\t%" PRIu32 " => %s\n", i, currentFilename.c_str());
}
#endif /* NUMBER_OF_FILES > 0 */
return true;
-}
+ }
} /* namespace app */
} /* namespace arm */