blob: 891423b30aea2dff24c0407bb8588f953775c37c [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
27TEST_CASE("Model info")
28{
29 arm::app::VisualWakeWordModel model; /* model wrapper object */
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
42TEST_CASE("Inference by index")
43{
44 hal_platform platform;
45 data_acq_module data_acq;
46 data_psn_module data_psn;
47 platform_timer timer;
48
49 /* Initialise the HAL and platform */
50 hal_init(&platform, &data_acq, &data_psn, &timer);
51 hal_platform_init(&platform);
52
53 arm::app::VisualWakeWordModel model; /* model wrapper object */
54
55 /* Load the model */
56 REQUIRE(model.Init());
57
58 /* Instantiate application context */
59 arm::app::ApplicationContext caseContext;
60 arm::app::Profiler profiler{&platform, "pd"};
61 caseContext.Set<arm::app::Profiler&>("profiler", profiler);
62 caseContext.Set<hal_platform&>("platform", platform);
63 caseContext.Set<arm::app::Model&>("model", model);
64 caseContext.Set<uint32_t>("imgIndex", 0);
65 arm::app::Classifier classifier; /* classifier wrapper object */
66 caseContext.Set<arm::app::Classifier&>("classifier", classifier);
67
68 std::vector <std::string> labels;
69 GetLabelsVector(labels);
70 caseContext.Set<const std::vector <std::string>&>("labels", labels);
71
72 REQUIRE(arm::app::ClassifyImageHandler(caseContext, 0, false));
73
74 auto results = caseContext.Get<std::vector<arm::app::ClassificationResult>>("results");
75
76 REQUIRE(results[0].m_labelIdx == 0);
77}
78
79TEST_CASE("Inference run all images")
80{
81 hal_platform platform;
82 data_acq_module data_acq;
83 data_psn_module data_psn;
84 platform_timer timer;
85
86 /* Initialise the HAL and platform */
87 hal_init(&platform, &data_acq, &data_psn, &timer);
88 hal_platform_init(&platform);
89
90 arm::app::VisualWakeWordModel model; /* model wrapper object */
91
92 /* Load the model */
93 REQUIRE(model.Init());
94
95 /* Instantiate application context */
96 arm::app::ApplicationContext caseContext;
97 arm::app::Profiler profiler{&platform, "pd"};
98 caseContext.Set<arm::app::Profiler&>("profiler", profiler);
99 caseContext.Set<hal_platform&>("platform", platform);
100 caseContext.Set<arm::app::Model&>("model", model);
101 caseContext.Set<uint32_t>("imgIndex", 0);
102 arm::app::Classifier classifier; /* classifier wrapper object */
103 caseContext.Set<arm::app::Classifier&>("classifier", classifier);
104
105 std::vector <std::string> labels;
106 GetLabelsVector(labels);
107 caseContext.Set<const std::vector <std::string>&>("labels", labels);
108
109 REQUIRE(arm::app::ClassifyImageHandler(caseContext, 0, true));
110}
111
112TEST_CASE("List all images")
113{
114 hal_platform platform;
115 data_acq_module data_acq;
116 data_psn_module data_psn;
117 platform_timer timer;
118
119 /* Initialise the HAL and platform */
120 hal_init(&platform, &data_acq, &data_psn, &timer);
121 hal_platform_init(&platform);
122
123 arm::app::VisualWakeWordModel model; /* model wrapper object */
124
125 /* Load the model */
126 REQUIRE(model.Init());
127
128 /* Instantiate application context */
129 arm::app::ApplicationContext caseContext;
130
131 caseContext.Set<hal_platform&>("platform", platform);
132 caseContext.Set<arm::app::Model&>("model", model);
133
134 REQUIRE(arm::app::ListFilesHandler(caseContext));
135}