blob: b0fbf96db715455f9a1fb9c05d98c650d0e84d1b [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 */
17#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 "DetectionUseCaseUtils.hpp" /* Utils functions specific to object detection. */
23
24
25void main_loop(hal_platform& platform)
26{
27 arm::app::YoloFastestModel model; /* Model wrapper object. */
28
29 /* Load the model. */
30 if (!model.Init()) {
31 printf_err("Failed to initialise model\n");
32 return;
33 }
34
35 /* Instantiate application context. */
36 arm::app::ApplicationContext caseContext;
37
38 arm::app::Profiler profiler{&platform, "object_detection"};
39 caseContext.Set<arm::app::Profiler&>("profiler", profiler);
40 caseContext.Set<hal_platform&>("platform", platform);
41 caseContext.Set<arm::app::Model&>("model", model);
42 caseContext.Set<uint32_t>("imgIndex", 0);
43
44
45 /* Loop. */
46 bool executionSuccessful = true;
47 constexpr bool bUseMenu = NUMBER_OF_FILES > 1 ? true : false;
48
49 /* Loop. */
50 do {
51 int menuOption = common::MENU_OPT_RUN_INF_NEXT;
52 if (bUseMenu) {
53 DisplayDetectionMenu();
54 menuOption = arm::app::ReadUserInputAsInt(platform);
55 printf("\n");
56 }
57 switch (menuOption) {
58 case common::MENU_OPT_RUN_INF_NEXT:
59 executionSuccessful = ObjectDetectionHandler(caseContext, caseContext.Get<uint32_t>("imgIndex"), false);
60 break;
61 case common::MENU_OPT_RUN_INF_CHOSEN: {
62 printf(" Enter the image index [0, %d]: ", NUMBER_OF_FILES-1);
63 fflush(stdout);
64 auto imgIndex = static_cast<uint32_t>(arm::app::ReadUserInputAsInt(platform));
65 executionSuccessful = ObjectDetectionHandler(caseContext, imgIndex, false);
66 break;
67 }
68 case common::MENU_OPT_RUN_INF_ALL:
69 executionSuccessful = ObjectDetectionHandler(caseContext, caseContext.Get<uint32_t>("imgIndex"), true);
70 break;
71 case common::MENU_OPT_SHOW_MODEL_INFO:
72 executionSuccessful = model.ShowModelInfoHandler();
73 break;
74 case common::MENU_OPT_LIST_IFM:
75 executionSuccessful = ListFilesHandler(caseContext);
76 break;
77 default:
78 printf("Incorrect choice, try again.");
79 break;
80 }
81 } while (executionSuccessful && bUseMenu);
82 info("Main loop terminated.\n");
83}