blob: e0e4a2f6d01fd8e58186e7dcd7c61bb7e327e2fa [file] [log] [blame]
Michael Levit06fcf752022-01-12 11:53:46 +02001/*
Richard Burtonf32a86a2022-11-15 11:46:11 +00002 * SPDX-FileCopyrightText: Copyright 2022 Arm Limited and/or its affiliates <open-source-office@arm.com>
Michael Levit06fcf752022-01-12 11:53:46 +02003 * 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;
Liam Barry213a5432022-05-09 17:06:19 +010030 namespace object_detection {
31 extern uint8_t* GetModelPointer();
32 extern size_t GetModelLen();
33 } /* namespace object_detection */
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +010034 } /* namespace app */
35} /* namespace arm */
36
Michael Levit06fcf752022-01-12 11:53:46 +020037TEST_CASE("Model info")
38{
Michael Levit06fcf752022-01-12 11:53:46 +020039 /* Model wrapper object. */
40 arm::app::YoloFastestModel model;
41
42 /* Load the model. */
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +010043 REQUIRE(model.Init(arm::app::tensorArena,
Liam Barry213a5432022-05-09 17:06:19 +010044 sizeof(arm::app::tensorArena),
45 arm::app::object_detection::GetModelPointer(),
46 arm::app::object_detection::GetModelLen()));
Michael Levit06fcf752022-01-12 11:53:46 +020047
48 /* Instantiate application context. */
49 arm::app::ApplicationContext caseContext;
50
51 caseContext.Set<arm::app::Model&>("model", model);
52
53 REQUIRE(model.ShowModelInfoHandler());
54}
55
56
57TEST_CASE("Inference by index")
58{
Michael Levit06fcf752022-01-12 11:53:46 +020059 /* Initialise the HAL and platform. */
Kshitij Sisodia4cc40212022-04-08 09:54:53 +010060 hal_platform_init();
Michael Levit06fcf752022-01-12 11:53:46 +020061
62 /* Model wrapper object. */
63 arm::app::YoloFastestModel model;
64
65 /* Load the model. */
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +010066 REQUIRE(model.Init(arm::app::tensorArena,
Liam Barry213a5432022-05-09 17:06:19 +010067 sizeof(arm::app::tensorArena),
68 arm::app::object_detection::GetModelPointer(),
69 arm::app::object_detection::GetModelLen()));
Michael Levit06fcf752022-01-12 11:53:46 +020070
71 /* Instantiate application context. */
72 arm::app::ApplicationContext caseContext;
73
Kshitij Sisodia4cc40212022-04-08 09:54:53 +010074 arm::app::Profiler profiler{"object_detection"};
Michael Levit06fcf752022-01-12 11:53:46 +020075 caseContext.Set<arm::app::Profiler&>("profiler", profiler);
Michael Levit06fcf752022-01-12 11:53:46 +020076 caseContext.Set<arm::app::Model&>("model", model);
77 caseContext.Set<uint32_t>("imgIndex", 0);
78
79 REQUIRE(arm::app::ObjectDetectionHandler(caseContext, 0, false));
Michael Levit06fcf752022-01-12 11:53:46 +020080}
81
82
83TEST_CASE("Inference run all images")
84{
Michael Levit06fcf752022-01-12 11:53:46 +020085 /* Initialise the HAL and platform. */
Kshitij Sisodia4cc40212022-04-08 09:54:53 +010086 hal_platform_init();
Michael Levit06fcf752022-01-12 11:53:46 +020087
88 /* Model wrapper object. */
89 arm::app::YoloFastestModel model;
90
91 /* Load the model. */
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +010092 REQUIRE(model.Init(arm::app::tensorArena,
Liam Barry213a5432022-05-09 17:06:19 +010093 sizeof(arm::app::tensorArena),
94 arm::app::object_detection::GetModelPointer(),
95 arm::app::object_detection::GetModelLen()));
Michael Levit06fcf752022-01-12 11:53:46 +020096
97 /* Instantiate application context. */
98 arm::app::ApplicationContext caseContext;
99
Kshitij Sisodia4cc40212022-04-08 09:54:53 +0100100 arm::app::Profiler profiler{"object_detection"};
Michael Levit06fcf752022-01-12 11:53:46 +0200101 caseContext.Set<arm::app::Profiler&>("profiler", profiler);
Michael Levit06fcf752022-01-12 11:53:46 +0200102 caseContext.Set<arm::app::Model&>("model", model);
103 caseContext.Set<uint32_t>("imgIndex", 0);
104
105 REQUIRE(arm::app::ObjectDetectionHandler(caseContext, 0, true));
Michael Levit06fcf752022-01-12 11:53:46 +0200106}
107
108
109TEST_CASE("List all images")
110{
Michael Levit06fcf752022-01-12 11:53:46 +0200111 /* Initialise the HAL and platform. */
Kshitij Sisodia4cc40212022-04-08 09:54:53 +0100112 hal_platform_init();
Michael Levit06fcf752022-01-12 11:53:46 +0200113
114 /* Model wrapper object. */
115 arm::app::YoloFastestModel model;
116
117 /* Load the model. */
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +0100118 REQUIRE(model.Init(arm::app::tensorArena,
Liam Barry213a5432022-05-09 17:06:19 +0100119 sizeof(arm::app::tensorArena),
120 arm::app::object_detection::GetModelPointer(),
121 arm::app::object_detection::GetModelLen()));
Michael Levit06fcf752022-01-12 11:53:46 +0200122
123 /* Instantiate application context. */
124 arm::app::ApplicationContext caseContext;
Michael Levit06fcf752022-01-12 11:53:46 +0200125 caseContext.Set<arm::app::Model&>("model", model);
126
127 REQUIRE(arm::app::ListFilesHandler(caseContext));
128}