blob: acfc19505538bda50040fca158ebd9d031d0127f [file] [log] [blame]
Michael Levit06fcf752022-01-12 11:53:46 +02001/*
2 * Copyright (c) 2022 Arm Limited. All rights reserved.
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
Isabella Gottardi3107aa22022-01-27 16:39:37 +000017#include "hal.h" /* Brings in platform definitions. */
18#include "InputFiles.hpp" /* For input images. */
19#include "YoloFastestModel.hpp" /* Model class for running inference. */
20#include "UseCaseHandler.hpp" /* Handlers for different user options. */
21#include "UseCaseCommonUtils.hpp" /* Utils functions. */
22#include "DetectorPostProcessing.hpp" /* Post-processing class. */
alexander31ae9f02022-02-10 16:15:54 +000023#include "log_macros.h"
Michael Levit06fcf752022-01-12 11:53:46 +020024
Isabella Gottardi3107aa22022-01-27 16:39:37 +000025static void DisplayDetectionMenu()
26{
27 printf("\n\n");
28 printf("User input required\n");
29 printf("Enter option number from:\n\n");
30 printf(" %u. Run detection on next ifm\n", common::MENU_OPT_RUN_INF_NEXT);
31 printf(" %u. Run detection ifm at chosen index\n", common::MENU_OPT_RUN_INF_CHOSEN);
32 printf(" %u. Run detection on all ifm\n", common::MENU_OPT_RUN_INF_ALL);
33 printf(" %u. Show NN model info\n", common::MENU_OPT_SHOW_MODEL_INFO);
34 printf(" %u. List ifm\n\n", common::MENU_OPT_LIST_IFM);
35 printf(" Choice: ");
36 fflush(stdout);
37}
38
Kshitij Sisodia4cc40212022-04-08 09:54:53 +010039void main_loop()
Michael Levit06fcf752022-01-12 11:53:46 +020040{
41 arm::app::YoloFastestModel model; /* Model wrapper object. */
42
43 /* Load the model. */
44 if (!model.Init()) {
45 printf_err("Failed to initialise model\n");
46 return;
47 }
48
49 /* Instantiate application context. */
50 arm::app::ApplicationContext caseContext;
51
Kshitij Sisodia4cc40212022-04-08 09:54:53 +010052 arm::app::Profiler profiler{"object_detection"};
Michael Levit06fcf752022-01-12 11:53:46 +020053 caseContext.Set<arm::app::Profiler&>("profiler", profiler);
Michael Levit06fcf752022-01-12 11:53:46 +020054 caseContext.Set<arm::app::Model&>("model", model);
55 caseContext.Set<uint32_t>("imgIndex", 0);
Isabella Gottardi3107aa22022-01-27 16:39:37 +000056 arm::app::object_detection::DetectorPostprocessing postp;
57 caseContext.Set<arm::app::object_detection::DetectorPostprocessing&>("postprocess", postp);
Michael Levit06fcf752022-01-12 11:53:46 +020058
Isabella Gottardi3107aa22022-01-27 16:39:37 +000059
Michael Levit06fcf752022-01-12 11:53:46 +020060 /* Loop. */
61 bool executionSuccessful = true;
62 constexpr bool bUseMenu = NUMBER_OF_FILES > 1 ? true : false;
63
64 /* Loop. */
65 do {
66 int menuOption = common::MENU_OPT_RUN_INF_NEXT;
67 if (bUseMenu) {
68 DisplayDetectionMenu();
Kshitij Sisodia68fdd112022-04-06 13:03:20 +010069 menuOption = arm::app::ReadUserInputAsInt();
Michael Levit06fcf752022-01-12 11:53:46 +020070 printf("\n");
71 }
72 switch (menuOption) {
73 case common::MENU_OPT_RUN_INF_NEXT:
74 executionSuccessful = ObjectDetectionHandler(caseContext, caseContext.Get<uint32_t>("imgIndex"), false);
75 break;
76 case common::MENU_OPT_RUN_INF_CHOSEN: {
77 printf(" Enter the image index [0, %d]: ", NUMBER_OF_FILES-1);
78 fflush(stdout);
Kshitij Sisodia68fdd112022-04-06 13:03:20 +010079 auto imgIndex = static_cast<uint32_t>(arm::app::ReadUserInputAsInt());
Michael Levit06fcf752022-01-12 11:53:46 +020080 executionSuccessful = ObjectDetectionHandler(caseContext, imgIndex, false);
81 break;
82 }
83 case common::MENU_OPT_RUN_INF_ALL:
84 executionSuccessful = ObjectDetectionHandler(caseContext, caseContext.Get<uint32_t>("imgIndex"), true);
85 break;
86 case common::MENU_OPT_SHOW_MODEL_INFO:
87 executionSuccessful = model.ShowModelInfoHandler();
88 break;
89 case common::MENU_OPT_LIST_IFM:
90 executionSuccessful = ListFilesHandler(caseContext);
91 break;
92 default:
93 printf("Incorrect choice, try again.");
94 break;
95 }
96 } while (executionSuccessful && bUseMenu);
97 info("Main loop terminated.\n");
98}