blob: fe3782bb1060f15cf7eda9b6575aaf99b859a050 [file] [log] [blame]
Éanna Ó Catháin8f958872021-09-15 09:32:30 +01001/*
2 * Copyright (c) 2021 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 <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"
26
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +010027namespace arm {
Liam Barry213a5432022-05-09 17:06:19 +010028namespace app {
29 static uint8_t tensorArena[ACTIVATION_BUF_SZ] ACTIVATION_BUF_ATTRIBUTE;
30 namespace vww {
31 extern uint8_t* GetModelPointer();
32 extern size_t GetModelLen();
33 } /* namespace vww */
34} /* namespace app */
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +010035} /* namespace arm */
36
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010037TEST_CASE("Model info")
38{
39 arm::app::VisualWakeWordModel model; /* model wrapper object */
40
41 /* Load the model */
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +010042 REQUIRE(model.Init(arm::app::tensorArena,
Liam Barry213a5432022-05-09 17:06:19 +010043 sizeof(arm::app::tensorArena),
44 arm::app::vww::GetModelPointer(),
45 arm::app::vww::GetModelLen()));
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010046
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
55TEST_CASE("Inference by index")
56{
Kshitij Sisodia4cc40212022-04-08 09:54:53 +010057 hal_platform_init();
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010058
59 arm::app::VisualWakeWordModel model; /* model wrapper object */
60
61 /* Load the model */
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +010062 REQUIRE(model.Init(arm::app::tensorArena,
Liam Barry213a5432022-05-09 17:06:19 +010063 sizeof(arm::app::tensorArena),
64 arm::app::vww::GetModelPointer(),
65 arm::app::vww::GetModelLen()));
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010066
67 /* Instantiate application context */
68 arm::app::ApplicationContext caseContext;
Kshitij Sisodia4cc40212022-04-08 09:54:53 +010069 arm::app::Profiler profiler{"pd"};
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010070 caseContext.Set<arm::app::Profiler&>("profiler", profiler);
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010071 caseContext.Set<arm::app::Model&>("model", model);
72 caseContext.Set<uint32_t>("imgIndex", 0);
73 arm::app::Classifier classifier; /* classifier wrapper object */
74 caseContext.Set<arm::app::Classifier&>("classifier", classifier);
75
76 std::vector <std::string> labels;
77 GetLabelsVector(labels);
78 caseContext.Set<const std::vector <std::string>&>("labels", labels);
79
80 REQUIRE(arm::app::ClassifyImageHandler(caseContext, 0, false));
81
82 auto results = caseContext.Get<std::vector<arm::app::ClassificationResult>>("results");
83
Isabella Gottardi79d41542021-10-20 15:52:32 +010084 REQUIRE(results[0].m_labelIdx == 1);
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010085}
86
87TEST_CASE("Inference run all images")
88{
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010089 /* Initialise the HAL and platform */
Kshitij Sisodia4cc40212022-04-08 09:54:53 +010090 hal_platform_init();
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010091
92 arm::app::VisualWakeWordModel model; /* model wrapper object */
93
94 /* Load the model */
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +010095 REQUIRE(model.Init(arm::app::tensorArena,
Liam Barry213a5432022-05-09 17:06:19 +010096 sizeof(arm::app::tensorArena),
97 arm::app::vww::GetModelPointer(),
98 arm::app::vww::GetModelLen()));
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010099
100 /* Instantiate application context */
101 arm::app::ApplicationContext caseContext;
Kshitij Sisodia4cc40212022-04-08 09:54:53 +0100102 arm::app::Profiler profiler{"pd"};
Éanna Ó Catháin8f958872021-09-15 09:32:30 +0100103 caseContext.Set<arm::app::Profiler&>("profiler", profiler);
Éanna Ó Catháin8f958872021-09-15 09:32:30 +0100104 caseContext.Set<arm::app::Model&>("model", model);
105 caseContext.Set<uint32_t>("imgIndex", 0);
106 arm::app::Classifier classifier; /* classifier wrapper object */
107 caseContext.Set<arm::app::Classifier&>("classifier", classifier);
108
109 std::vector <std::string> labels;
110 GetLabelsVector(labels);
111 caseContext.Set<const std::vector <std::string>&>("labels", labels);
112
113 REQUIRE(arm::app::ClassifyImageHandler(caseContext, 0, true));
114}
115
116TEST_CASE("List all images")
117{
Éanna Ó Catháin8f958872021-09-15 09:32:30 +0100118 /* Initialise the HAL and platform */
Kshitij Sisodia4cc40212022-04-08 09:54:53 +0100119 hal_platform_init();
Éanna Ó Catháin8f958872021-09-15 09:32:30 +0100120
121 arm::app::VisualWakeWordModel model; /* model wrapper object */
122
123 /* Load the model */
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +0100124 REQUIRE(model.Init(arm::app::tensorArena,
Liam Barry213a5432022-05-09 17:06:19 +0100125 sizeof(arm::app::tensorArena),
126 arm::app::vww::GetModelPointer(),
127 arm::app::vww::GetModelLen()));
Éanna Ó Catháin8f958872021-09-15 09:32:30 +0100128
129 /* Instantiate application context */
130 arm::app::ApplicationContext caseContext;
131
Éanna Ó Catháin8f958872021-09-15 09:32:30 +0100132 caseContext.Set<arm::app::Model&>("model", model);
133
134 REQUIRE(arm::app::ListFilesHandler(caseContext));
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +0100135}