summaryrefslogtreecommitdiff
path: root/source/use_case/img_class/src/UseCaseHandler.cc
diff options
context:
space:
mode:
Diffstat (limited to 'source/use_case/img_class/src/UseCaseHandler.cc')
-rw-r--r--source/use_case/img_class/src/UseCaseHandler.cc64
1 files changed, 35 insertions, 29 deletions
diff --git a/source/use_case/img_class/src/UseCaseHandler.cc b/source/use_case/img_class/src/UseCaseHandler.cc
index 4732064..52c42f3 100644
--- a/source/use_case/img_class/src/UseCaseHandler.cc
+++ b/source/use_case/img_class/src/UseCaseHandler.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.
@@ -17,13 +17,13 @@
#include "UseCaseHandler.hpp"
#include "Classifier.hpp"
+#include "ImageUtils.hpp"
+#include "ImgClassProcessing.hpp"
#include "InputFiles.hpp"
#include "MobileNetModel.hpp"
-#include "ImageUtils.hpp"
#include "UseCaseCommonUtils.hpp"
#include "hal.h"
#include "log_macros.h"
-#include "ImgClassProcessing.hpp"
#include <cinttypes>
@@ -36,7 +36,7 @@ namespace app {
bool ClassifyImageHandler(ApplicationContext& ctx, uint32_t imgIndex, bool runAll)
{
auto& profiler = ctx.Get<Profiler&>("profiler");
- auto& model = ctx.Get<Model&>("model");
+ auto& model = ctx.Get<Model&>("model");
/* If the request has a valid size, set the image index as it might not be set. */
if (imgIndex < NUMBER_OF_FILES) {
if (!SetAppCtxIfmIdx(ctx, imgIndex, "imgIndex")) {
@@ -46,19 +46,18 @@ namespace app {
auto initialImgIdx = ctx.Get<uint32_t>("imgIndex");
constexpr uint32_t dataPsnImgDownscaleFactor = 2;
- constexpr uint32_t dataPsnImgStartX = 10;
- constexpr uint32_t dataPsnImgStartY = 35;
+ constexpr uint32_t dataPsnImgStartX = 10;
+ constexpr uint32_t dataPsnImgStartY = 35;
constexpr uint32_t dataPsnTxtInfStartX = 150;
constexpr uint32_t dataPsnTxtInfStartY = 40;
-
if (!model.IsInited()) {
printf_err("Model is not initialised! Terminating processing.\n");
return false;
}
- TfLiteTensor* inputTensor = model.GetInputTensor(0);
+ TfLiteTensor* inputTensor = model.GetInputTensor(0);
TfLiteTensor* outputTensor = model.GetOutputTensor(0);
if (!inputTensor->dims) {
printf_err("Invalid input tensor dims\n");
@@ -70,17 +69,19 @@ namespace app {
/* Get input shape for displaying the image. */
TfLiteIntArray* inputShape = model.GetInputShape(0);
- const uint32_t nCols = inputShape->data[arm::app::MobileNetModel::ms_inputColsIdx];
- const uint32_t nRows = inputShape->data[arm::app::MobileNetModel::ms_inputRowsIdx];
+ const uint32_t nCols = inputShape->data[arm::app::MobileNetModel::ms_inputColsIdx];
+ const uint32_t nRows = inputShape->data[arm::app::MobileNetModel::ms_inputRowsIdx];
const uint32_t nChannels = inputShape->data[arm::app::MobileNetModel::ms_inputChannelsIdx];
/* Set up pre and post-processing. */
ImgClassPreProcess preProcess = ImgClassPreProcess(inputTensor, model.IsDataSigned());
std::vector<ClassificationResult> results;
- ImgClassPostProcess postProcess = ImgClassPostProcess(outputTensor,
- ctx.Get<ImgClassClassifier&>("classifier"), ctx.Get<std::vector<std::string>&>("labels"),
- results);
+ ImgClassPostProcess postProcess =
+ ImgClassPostProcess(outputTensor,
+ ctx.Get<ImgClassClassifier&>("classifier"),
+ ctx.Get<std::vector<std::string>&>("labels"),
+ results);
do {
hal_lcd_clear(COLOR_BLACK);
@@ -88,29 +89,34 @@ namespace app {
/* Strings for presentation/logging. */
std::string str_inf{"Running inference... "};
- const uint8_t* imgSrc = get_img_array(ctx.Get<uint32_t>("imgIndex"));
+ const uint8_t* imgSrc = GetImgArray(ctx.Get<uint32_t>("imgIndex"));
if (nullptr == imgSrc) {
- printf_err("Failed to get image index %" PRIu32 " (max: %u)\n", ctx.Get<uint32_t>("imgIndex"),
+ printf_err("Failed to get image index %" PRIu32 " (max: %u)\n",
+ ctx.Get<uint32_t>("imgIndex"),
NUMBER_OF_FILES - 1);
return false;
}
/* Display this image on the LCD. */
- hal_lcd_display_image(
- imgSrc,
- nCols, nRows, nChannels,
- dataPsnImgStartX, dataPsnImgStartY, dataPsnImgDownscaleFactor);
+ hal_lcd_display_image(imgSrc,
+ nCols,
+ nRows,
+ nChannels,
+ dataPsnImgStartX,
+ dataPsnImgStartY,
+ dataPsnImgDownscaleFactor);
/* Display message on the LCD - inference running. */
- hal_lcd_display_text(str_inf.c_str(), str_inf.size(),
- dataPsnTxtInfStartX, dataPsnTxtInfStartY, false);
+ hal_lcd_display_text(
+ str_inf.c_str(), str_inf.size(), dataPsnTxtInfStartX, dataPsnTxtInfStartY, false);
/* Select the image to run inference with. */
- info("Running inference on image %" PRIu32 " => %s\n", ctx.Get<uint32_t>("imgIndex"),
- get_filename(ctx.Get<uint32_t>("imgIndex")));
+ info("Running inference on image %" PRIu32 " => %s\n",
+ ctx.Get<uint32_t>("imgIndex"),
+ GetFilename(ctx.Get<uint32_t>("imgIndex")));
- const size_t imgSz = inputTensor->bytes < IMAGE_DATA_SIZE ?
- inputTensor->bytes : IMAGE_DATA_SIZE;
+ const size_t imgSz =
+ inputTensor->bytes < IMAGE_DATA_SIZE ? inputTensor->bytes : IMAGE_DATA_SIZE;
/* Run the pre-processing, inference and post-processing. */
if (!preProcess.DoPreProcess(imgSrc, imgSz)) {
@@ -130,8 +136,8 @@ namespace app {
/* Erase. */
str_inf = std::string(str_inf.size(), ' ');
- hal_lcd_display_text(str_inf.c_str(), str_inf.size(),
- dataPsnTxtInfStartX, dataPsnTxtInfStartY, false);
+ hal_lcd_display_text(
+ str_inf.c_str(), str_inf.size(), dataPsnTxtInfStartX, dataPsnTxtInfStartY, false);
/* Add results to context for access outside handler. */
ctx.Set<std::vector<ClassificationResult>>("results", results);
@@ -146,7 +152,7 @@ namespace app {
profiler.PrintProfilingResult();
- IncrementAppCtxIfmIdx(ctx,"imgIndex");
+ IncrementAppCtxIfmIdx(ctx, "imgIndex");
} while (runAll && ctx.Get<uint32_t>("imgIndex") != initialImgIdx);