blob: 66d86b3ef7d132b06d47a147536a76bf92004a06 [file] [log] [blame]
Éanna Ó Catháin8f958872021-09-15 09:32:30 +01001/*
Richard Burtonf32a86a2022-11-15 11:46:11 +00002 * SPDX-FileCopyrightText: Copyright 2021-2022 Arm Limited and/or its affiliates <open-source-office@arm.com>
Éanna Ó Catháin8f958872021-09-15 09:32:30 +01003 * 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 <catch.hpp>
18#include "VisualWakeWordModel.hpp"
19#include "hal.h"
20
21#include "ClassificationResult.hpp"
22#include "Labels.hpp"
23#include "UseCaseHandler.hpp"
24#include "Classifier.hpp"
25#include "UseCaseCommonUtils.hpp"
Richard Burtonec5e99b2022-10-05 11:00:37 +010026#include "BufAttributes.hpp"
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010027
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +010028namespace arm {
Liam Barry213a5432022-05-09 17:06:19 +010029namespace app {
30 static uint8_t tensorArena[ACTIVATION_BUF_SZ] ACTIVATION_BUF_ATTRIBUTE;
31 namespace vww {
32 extern uint8_t* GetModelPointer();
33 extern size_t GetModelLen();
34 } /* namespace vww */
35} /* namespace app */
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +010036} /* namespace arm */
37
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010038TEST_CASE("Model info")
39{
40 arm::app::VisualWakeWordModel model; /* model wrapper object */
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::vww::GetModelPointer(),
46 arm::app::vww::GetModelLen()));
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010047
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
56TEST_CASE("Inference by index")
57{
Kshitij Sisodia4cc40212022-04-08 09:54:53 +010058 hal_platform_init();
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010059
60 arm::app::VisualWakeWordModel model; /* model wrapper object */
61
62 /* Load the model */
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +010063 REQUIRE(model.Init(arm::app::tensorArena,
Liam Barry213a5432022-05-09 17:06:19 +010064 sizeof(arm::app::tensorArena),
65 arm::app::vww::GetModelPointer(),
66 arm::app::vww::GetModelLen()));
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010067
68 /* Instantiate application context */
69 arm::app::ApplicationContext caseContext;
Kshitij Sisodia4cc40212022-04-08 09:54:53 +010070 arm::app::Profiler profiler{"pd"};
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010071 caseContext.Set<arm::app::Profiler&>("profiler", profiler);
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010072 caseContext.Set<arm::app::Model&>("model", model);
73 caseContext.Set<uint32_t>("imgIndex", 0);
74 arm::app::Classifier classifier; /* classifier wrapper object */
75 caseContext.Set<arm::app::Classifier&>("classifier", classifier);
76
77 std::vector <std::string> labels;
78 GetLabelsVector(labels);
79 caseContext.Set<const std::vector <std::string>&>("labels", labels);
80
81 REQUIRE(arm::app::ClassifyImageHandler(caseContext, 0, false));
82
83 auto results = caseContext.Get<std::vector<arm::app::ClassificationResult>>("results");
84
Isabella Gottardi79d41542021-10-20 15:52:32 +010085 REQUIRE(results[0].m_labelIdx == 1);
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010086}
87
88TEST_CASE("Inference run all images")
89{
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010090 /* Initialise the HAL and platform */
Kshitij Sisodia4cc40212022-04-08 09:54:53 +010091 hal_platform_init();
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010092
93 arm::app::VisualWakeWordModel model; /* model wrapper object */
94
95 /* Load the model */
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +010096 REQUIRE(model.Init(arm::app::tensorArena,
Liam Barry213a5432022-05-09 17:06:19 +010097 sizeof(arm::app::tensorArena),
98 arm::app::vww::GetModelPointer(),
99 arm::app::vww::GetModelLen()));
Éanna Ó Catháin8f958872021-09-15 09:32:30 +0100100
101 /* Instantiate application context */
102 arm::app::ApplicationContext caseContext;
Kshitij Sisodia4cc40212022-04-08 09:54:53 +0100103 arm::app::Profiler profiler{"pd"};
Éanna Ó Catháin8f958872021-09-15 09:32:30 +0100104 caseContext.Set<arm::app::Profiler&>("profiler", profiler);
Éanna Ó Catháin8f958872021-09-15 09:32:30 +0100105 caseContext.Set<arm::app::Model&>("model", model);
106 caseContext.Set<uint32_t>("imgIndex", 0);
107 arm::app::Classifier classifier; /* classifier wrapper object */
108 caseContext.Set<arm::app::Classifier&>("classifier", classifier);
109
110 std::vector <std::string> labels;
111 GetLabelsVector(labels);
112 caseContext.Set<const std::vector <std::string>&>("labels", labels);
113
114 REQUIRE(arm::app::ClassifyImageHandler(caseContext, 0, true));
115}
116
117TEST_CASE("List all images")
118{
Éanna Ó Catháin8f958872021-09-15 09:32:30 +0100119 /* Initialise the HAL and platform */
Kshitij Sisodia4cc40212022-04-08 09:54:53 +0100120 hal_platform_init();
Éanna Ó Catháin8f958872021-09-15 09:32:30 +0100121
122 arm::app::VisualWakeWordModel model; /* model wrapper object */
123
124 /* Load the model */
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +0100125 REQUIRE(model.Init(arm::app::tensorArena,
Liam Barry213a5432022-05-09 17:06:19 +0100126 sizeof(arm::app::tensorArena),
127 arm::app::vww::GetModelPointer(),
128 arm::app::vww::GetModelLen()));
Éanna Ó Catháin8f958872021-09-15 09:32:30 +0100129
130 /* Instantiate application context */
131 arm::app::ApplicationContext caseContext;
132
Éanna Ó Catháin8f958872021-09-15 09:32:30 +0100133 caseContext.Set<arm::app::Model&>("model", model);
134
135 REQUIRE(arm::app::ListFilesHandler(caseContext));
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +0100136}