blob: 79e76bd0d54cfba44514df4d296bc0c4199ccfbb [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 "DetectionResult.hpp"
Isabella Gottardi3107aa22022-01-27 16:39:37 +000018#include "DetectorPostProcessing.hpp"
Michael Levit06fcf752022-01-12 11:53:46 +020019#include "hal.h"
20#include "YoloFastestModel.hpp"
21#include "UseCaseHandler.hpp"
22#include "UseCaseCommonUtils.hpp"
23
24#include <catch.hpp>
25
26TEST_CASE("Model info")
27{
Michael Levit06fcf752022-01-12 11:53:46 +020028 /* Model wrapper object. */
29 arm::app::YoloFastestModel model;
30
31 /* Load the model. */
32 REQUIRE(model.Init());
33
34 /* Instantiate application context. */
35 arm::app::ApplicationContext caseContext;
36
37 caseContext.Set<arm::app::Model&>("model", model);
38
39 REQUIRE(model.ShowModelInfoHandler());
40}
41
42
43TEST_CASE("Inference by index")
44{
Michael Levit06fcf752022-01-12 11:53:46 +020045 hal_platform platform;
Michael Levit06fcf752022-01-12 11:53:46 +020046 platform_timer timer;
47
48 /* Initialise the HAL and platform. */
Kshitij Sisodia68fdd112022-04-06 13:03:20 +010049 hal_init(&platform, &timer);
Michael Levit06fcf752022-01-12 11:53:46 +020050 hal_platform_init(&platform);
51
52 /* Model wrapper object. */
53 arm::app::YoloFastestModel model;
54
55 /* Load the model. */
56 REQUIRE(model.Init());
57
58 /* Instantiate application context. */
59 arm::app::ApplicationContext caseContext;
60
61 arm::app::Profiler profiler{&platform, "object_detection"};
62 caseContext.Set<arm::app::Profiler&>("profiler", profiler);
63 caseContext.Set<hal_platform&>("platform", platform);
64 caseContext.Set<arm::app::Model&>("model", model);
65 caseContext.Set<uint32_t>("imgIndex", 0);
Isabella Gottardi3107aa22022-01-27 16:39:37 +000066 arm::app::object_detection::DetectorPostprocessing postp;
67 caseContext.Set<arm::app::object_detection::DetectorPostprocessing&>("postprocess", postp);
Michael Levit06fcf752022-01-12 11:53:46 +020068
69 REQUIRE(arm::app::ObjectDetectionHandler(caseContext, 0, false));
Michael Levit06fcf752022-01-12 11:53:46 +020070}
71
72
73TEST_CASE("Inference run all images")
74{
Michael Levit06fcf752022-01-12 11:53:46 +020075 hal_platform platform;
Michael Levit06fcf752022-01-12 11:53:46 +020076 platform_timer timer;
77
78 /* Initialise the HAL and platform. */
Kshitij Sisodia68fdd112022-04-06 13:03:20 +010079 hal_init(&platform, &timer);
Michael Levit06fcf752022-01-12 11:53:46 +020080 hal_platform_init(&platform);
81
82 /* Model wrapper object. */
83 arm::app::YoloFastestModel model;
84
85 /* Load the model. */
86 REQUIRE(model.Init());
87
88 /* Instantiate application context. */
89 arm::app::ApplicationContext caseContext;
90
91 arm::app::Profiler profiler{&platform, "object_detection"};
92 caseContext.Set<arm::app::Profiler&>("profiler", profiler);
93 caseContext.Set<hal_platform&>("platform", platform);
94 caseContext.Set<arm::app::Model&>("model", model);
95 caseContext.Set<uint32_t>("imgIndex", 0);
Isabella Gottardi3107aa22022-01-27 16:39:37 +000096 arm::app::object_detection::DetectorPostprocessing postp;
97 caseContext.Set<arm::app::object_detection::DetectorPostprocessing&>("postprocess", postp);
Michael Levit06fcf752022-01-12 11:53:46 +020098
99 REQUIRE(arm::app::ObjectDetectionHandler(caseContext, 0, true));
Michael Levit06fcf752022-01-12 11:53:46 +0200100}
101
102
103TEST_CASE("List all images")
104{
Michael Levit06fcf752022-01-12 11:53:46 +0200105 hal_platform platform;
Michael Levit06fcf752022-01-12 11:53:46 +0200106 platform_timer timer;
107
108 /* Initialise the HAL and platform. */
Kshitij Sisodia68fdd112022-04-06 13:03:20 +0100109 hal_init(&platform, &timer);
Michael Levit06fcf752022-01-12 11:53:46 +0200110 hal_platform_init(&platform);
111
112 /* Model wrapper object. */
113 arm::app::YoloFastestModel model;
114
115 /* Load the model. */
116 REQUIRE(model.Init());
117
118 /* Instantiate application context. */
119 arm::app::ApplicationContext caseContext;
120
121 caseContext.Set<hal_platform&>("platform", platform);
122 caseContext.Set<arm::app::Model&>("model", model);
123
124 REQUIRE(arm::app::ListFilesHandler(caseContext));
125}