blob: 531764b6c3b0f838e23426c4414d2afa76f946a8 [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{
Kshitij Sisodia4cc40212022-04-08 09:54:53 +010044 hal_platform_init();
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010045
46 arm::app::VisualWakeWordModel model; /* model wrapper object */
47
48 /* Load the model */
49 REQUIRE(model.Init());
50
51 /* Instantiate application context */
52 arm::app::ApplicationContext caseContext;
Kshitij Sisodia4cc40212022-04-08 09:54:53 +010053 arm::app::Profiler profiler{"pd"};
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010054 caseContext.Set<arm::app::Profiler&>("profiler", profiler);
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010055 caseContext.Set<arm::app::Model&>("model", model);
56 caseContext.Set<uint32_t>("imgIndex", 0);
57 arm::app::Classifier classifier; /* classifier wrapper object */
58 caseContext.Set<arm::app::Classifier&>("classifier", classifier);
59
60 std::vector <std::string> labels;
61 GetLabelsVector(labels);
62 caseContext.Set<const std::vector <std::string>&>("labels", labels);
63
64 REQUIRE(arm::app::ClassifyImageHandler(caseContext, 0, false));
65
66 auto results = caseContext.Get<std::vector<arm::app::ClassificationResult>>("results");
67
Isabella Gottardi79d41542021-10-20 15:52:32 +010068 REQUIRE(results[0].m_labelIdx == 1);
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010069}
70
71TEST_CASE("Inference run all images")
72{
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010073 /* Initialise the HAL and platform */
Kshitij Sisodia4cc40212022-04-08 09:54:53 +010074 hal_platform_init();
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010075
76 arm::app::VisualWakeWordModel model; /* model wrapper object */
77
78 /* Load the model */
79 REQUIRE(model.Init());
80
81 /* Instantiate application context */
82 arm::app::ApplicationContext caseContext;
Kshitij Sisodia4cc40212022-04-08 09:54:53 +010083 arm::app::Profiler profiler{"pd"};
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010084 caseContext.Set<arm::app::Profiler&>("profiler", profiler);
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010085 caseContext.Set<arm::app::Model&>("model", model);
86 caseContext.Set<uint32_t>("imgIndex", 0);
87 arm::app::Classifier classifier; /* classifier wrapper object */
88 caseContext.Set<arm::app::Classifier&>("classifier", classifier);
89
90 std::vector <std::string> labels;
91 GetLabelsVector(labels);
92 caseContext.Set<const std::vector <std::string>&>("labels", labels);
93
94 REQUIRE(arm::app::ClassifyImageHandler(caseContext, 0, true));
95}
96
97TEST_CASE("List all images")
98{
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010099 /* Initialise the HAL and platform */
Kshitij Sisodia4cc40212022-04-08 09:54:53 +0100100 hal_platform_init();
Éanna Ó Catháin8f958872021-09-15 09:32:30 +0100101
102 arm::app::VisualWakeWordModel model; /* model wrapper object */
103
104 /* Load the model */
105 REQUIRE(model.Init());
106
107 /* Instantiate application context */
108 arm::app::ApplicationContext caseContext;
109
Éanna Ó Catháin8f958872021-09-15 09:32:30 +0100110 caseContext.Set<arm::app::Model&>("model", model);
111
112 REQUIRE(arm::app::ListFilesHandler(caseContext));
113}