blob: 4291164163636adf94cc658d5fabd3d7ef163dcd [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. */
alexander31ae9f02022-02-10 16:15:54 +000022#include "log_macros.h"
Michael Levit06fcf752022-01-12 11:53:46 +020023
Isabella Gottardi3107aa22022-01-27 16:39:37 +000024static void DisplayDetectionMenu()
25{
26 printf("\n\n");
27 printf("User input required\n");
28 printf("Enter option number from:\n\n");
29 printf(" %u. Run detection on next ifm\n", common::MENU_OPT_RUN_INF_NEXT);
30 printf(" %u. Run detection ifm at chosen index\n", common::MENU_OPT_RUN_INF_CHOSEN);
31 printf(" %u. Run detection on all ifm\n", common::MENU_OPT_RUN_INF_ALL);
32 printf(" %u. Show NN model info\n", common::MENU_OPT_SHOW_MODEL_INFO);
33 printf(" %u. List ifm\n\n", common::MENU_OPT_LIST_IFM);
34 printf(" Choice: ");
35 fflush(stdout);
36}
37
Kshitij Sisodia4cc40212022-04-08 09:54:53 +010038void main_loop()
Michael Levit06fcf752022-01-12 11:53:46 +020039{
40 arm::app::YoloFastestModel model; /* Model wrapper object. */
41
42 /* Load the model. */
43 if (!model.Init()) {
44 printf_err("Failed to initialise model\n");
45 return;
46 }
47
48 /* Instantiate application context. */
49 arm::app::ApplicationContext caseContext;
50
Kshitij Sisodia4cc40212022-04-08 09:54:53 +010051 arm::app::Profiler profiler{"object_detection"};
Michael Levit06fcf752022-01-12 11:53:46 +020052 caseContext.Set<arm::app::Profiler&>("profiler", profiler);
Michael Levit06fcf752022-01-12 11:53:46 +020053 caseContext.Set<arm::app::Model&>("model", model);
54 caseContext.Set<uint32_t>("imgIndex", 0);
Isabella Gottardi3107aa22022-01-27 16:39:37 +000055
Michael Levit06fcf752022-01-12 11:53:46 +020056 /* Loop. */
57 bool executionSuccessful = true;
58 constexpr bool bUseMenu = NUMBER_OF_FILES > 1 ? true : false;
59
60 /* Loop. */
61 do {
62 int menuOption = common::MENU_OPT_RUN_INF_NEXT;
63 if (bUseMenu) {
64 DisplayDetectionMenu();
Kshitij Sisodia68fdd112022-04-06 13:03:20 +010065 menuOption = arm::app::ReadUserInputAsInt();
Michael Levit06fcf752022-01-12 11:53:46 +020066 printf("\n");
67 }
68 switch (menuOption) {
69 case common::MENU_OPT_RUN_INF_NEXT:
70 executionSuccessful = ObjectDetectionHandler(caseContext, caseContext.Get<uint32_t>("imgIndex"), false);
71 break;
72 case common::MENU_OPT_RUN_INF_CHOSEN: {
73 printf(" Enter the image index [0, %d]: ", NUMBER_OF_FILES-1);
74 fflush(stdout);
Kshitij Sisodia68fdd112022-04-06 13:03:20 +010075 auto imgIndex = static_cast<uint32_t>(arm::app::ReadUserInputAsInt());
Michael Levit06fcf752022-01-12 11:53:46 +020076 executionSuccessful = ObjectDetectionHandler(caseContext, imgIndex, false);
77 break;
78 }
79 case common::MENU_OPT_RUN_INF_ALL:
80 executionSuccessful = ObjectDetectionHandler(caseContext, caseContext.Get<uint32_t>("imgIndex"), true);
81 break;
82 case common::MENU_OPT_SHOW_MODEL_INFO:
83 executionSuccessful = model.ShowModelInfoHandler();
84 break;
85 case common::MENU_OPT_LIST_IFM:
86 executionSuccessful = ListFilesHandler(caseContext);
87 break;
88 default:
89 printf("Incorrect choice, try again.");
90 break;
91 }
92 } while (executionSuccessful && bUseMenu);
93 info("Main loop terminated.\n");
94}