blob: ffb49768c1b10d7e3f497cb33715dddacd818733 [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"
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +010023#include "BufAttributes.hpp"
Michael Levit06fcf752022-01-12 11:53:46 +020024
25#include <catch.hpp>
26
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +010027namespace arm {
28 namespace app {
29 static uint8_t tensorArena[ACTIVATION_BUF_SZ] ACTIVATION_BUF_ATTRIBUTE;
30 } /* namespace app */
31} /* namespace arm */
32
33extern uint8_t* GetModelPointer();
34extern size_t GetModelLen();
35
Michael Levit06fcf752022-01-12 11:53:46 +020036TEST_CASE("Model info")
37{
Michael Levit06fcf752022-01-12 11:53:46 +020038 /* Model wrapper object. */
39 arm::app::YoloFastestModel model;
40
41 /* Load the model. */
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +010042 REQUIRE(model.Init(arm::app::tensorArena,
43 sizeof(arm::app::tensorArena),
44 GetModelPointer(),
45 GetModelLen()));
Michael Levit06fcf752022-01-12 11:53:46 +020046
47 /* Instantiate application context. */
48 arm::app::ApplicationContext caseContext;
49
50 caseContext.Set<arm::app::Model&>("model", model);
51
52 REQUIRE(model.ShowModelInfoHandler());
53}
54
55
56TEST_CASE("Inference by index")
57{
Michael Levit06fcf752022-01-12 11:53:46 +020058 /* Initialise the HAL and platform. */
Kshitij Sisodia4cc40212022-04-08 09:54:53 +010059 hal_platform_init();
Michael Levit06fcf752022-01-12 11:53:46 +020060
61 /* Model wrapper object. */
62 arm::app::YoloFastestModel model;
63
64 /* Load the model. */
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +010065 REQUIRE(model.Init(arm::app::tensorArena,
66 sizeof(arm::app::tensorArena),
67 GetModelPointer(),
68 GetModelLen()));
Michael Levit06fcf752022-01-12 11:53:46 +020069
70 /* Instantiate application context. */
71 arm::app::ApplicationContext caseContext;
72
Kshitij Sisodia4cc40212022-04-08 09:54:53 +010073 arm::app::Profiler profiler{"object_detection"};
Michael Levit06fcf752022-01-12 11:53:46 +020074 caseContext.Set<arm::app::Profiler&>("profiler", profiler);
Michael Levit06fcf752022-01-12 11:53:46 +020075 caseContext.Set<arm::app::Model&>("model", model);
76 caseContext.Set<uint32_t>("imgIndex", 0);
77
78 REQUIRE(arm::app::ObjectDetectionHandler(caseContext, 0, false));
Michael Levit06fcf752022-01-12 11:53:46 +020079}
80
81
82TEST_CASE("Inference run all images")
83{
Michael Levit06fcf752022-01-12 11:53:46 +020084 /* Initialise the HAL and platform. */
Kshitij Sisodia4cc40212022-04-08 09:54:53 +010085 hal_platform_init();
Michael Levit06fcf752022-01-12 11:53:46 +020086
87 /* Model wrapper object. */
88 arm::app::YoloFastestModel model;
89
90 /* Load the model. */
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +010091 REQUIRE(model.Init(arm::app::tensorArena,
92 sizeof(arm::app::tensorArena),
93 GetModelPointer(),
94 GetModelLen()));
Michael Levit06fcf752022-01-12 11:53:46 +020095
96 /* Instantiate application context. */
97 arm::app::ApplicationContext caseContext;
98
Kshitij Sisodia4cc40212022-04-08 09:54:53 +010099 arm::app::Profiler profiler{"object_detection"};
Michael Levit06fcf752022-01-12 11:53:46 +0200100 caseContext.Set<arm::app::Profiler&>("profiler", profiler);
Michael Levit06fcf752022-01-12 11:53:46 +0200101 caseContext.Set<arm::app::Model&>("model", model);
102 caseContext.Set<uint32_t>("imgIndex", 0);
103
104 REQUIRE(arm::app::ObjectDetectionHandler(caseContext, 0, true));
Michael Levit06fcf752022-01-12 11:53:46 +0200105}
106
107
108TEST_CASE("List all images")
109{
Michael Levit06fcf752022-01-12 11:53:46 +0200110 /* Initialise the HAL and platform. */
Kshitij Sisodia4cc40212022-04-08 09:54:53 +0100111 hal_platform_init();
Michael Levit06fcf752022-01-12 11:53:46 +0200112
113 /* Model wrapper object. */
114 arm::app::YoloFastestModel model;
115
116 /* Load the model. */
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +0100117 REQUIRE(model.Init(arm::app::tensorArena,
118 sizeof(arm::app::tensorArena),
119 GetModelPointer(),
120 GetModelLen()));
Michael Levit06fcf752022-01-12 11:53:46 +0200121
122 /* Instantiate application context. */
123 arm::app::ApplicationContext caseContext;
Michael Levit06fcf752022-01-12 11:53:46 +0200124 caseContext.Set<arm::app::Model&>("model", model);
125
126 REQUIRE(arm::app::ListFilesHandler(caseContext));
127}