blob: b989415d951d0ca5edc9affb3db1942941115e86 [file] [log] [blame]
alexander3c798932021-03-26 21:42:19 +00001/*
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 "ClassificationResult.hpp"
18#include "Classifier.hpp"
19#include "hal.h"
20#include "Labels.hpp"
21#include "MobileNetModel.hpp"
22#include "UseCaseHandler.hpp"
23#include "UseCaseCommonUtils.hpp"
24
25#include <catch.hpp>
26
27TEST_CASE("Model info")
28{
29 /* Model wrapper object. */
30 arm::app::MobileNetModel model;
31
32 /* Load the model. */
33 REQUIRE(model.Init());
34
35 /* Instantiate application context. */
36 arm::app::ApplicationContext caseContext;
37
38 caseContext.Set<arm::app::Model&>("model", model);
39
40 REQUIRE(model.ShowModelInfoHandler());
41}
42
43
44TEST_CASE("Inference by index", "[.]")
45{
46 hal_platform platform;
47 data_acq_module data_acq;
48 data_psn_module data_psn;
49 platform_timer timer;
50
51 /* Initialise the HAL and platform. */
52 hal_init(&platform, &data_acq, &data_psn, &timer);
53 hal_platform_init(&platform);
54
55 /* Model wrapper object. */
Isabella Gottardi8df12f32021-04-07 17:15:31 +010056 arm::app::MobileNetModel model;
alexander3c798932021-03-26 21:42:19 +000057
58 /* Load the model. */
59 REQUIRE(model.Init());
60
61 /* Instantiate application context. */
62 arm::app::ApplicationContext caseContext;
63
Isabella Gottardi8df12f32021-04-07 17:15:31 +010064 arm::app::Profiler profiler{&platform, "img_class"};
65 caseContext.Set<arm::app::Profiler&>("profiler", profiler);
alexander3c798932021-03-26 21:42:19 +000066 caseContext.Set<hal_platform&>("platform", platform);
67 caseContext.Set<arm::app::Model&>("model", model);
68 caseContext.Set<uint32_t>("imgIndex", 0);
69 arm::app::Classifier classifier; /* Classifier wrapper object. */
70 caseContext.Set<arm::app::Classifier&>("classifier", classifier);
71
72 std::vector <std::string> labels;
73 GetLabelsVector(labels);
74 caseContext.Set<const std::vector <std::string>&>("labels", labels);
75
76 REQUIRE(arm::app::ClassifyImageHandler(caseContext, 0, false));
77
78 auto results = caseContext.Get<std::vector<arm::app::ClassificationResult>>("results");
79
80 REQUIRE(results[0].m_labelIdx == 282);
81}
82
83
84TEST_CASE("Inference run all images", "[.]")
85{
86 hal_platform platform;
87 data_acq_module data_acq;
88 data_psn_module data_psn;
89 platform_timer timer;
90
91 /* Initialise the HAL and platform. */
92 hal_init(&platform, &data_acq, &data_psn, &timer);
93 hal_platform_init(&platform);
94
95 /* Model wrapper object. */
96 arm::app::MobileNetModel model;
97
98 /* Load the model. */
99 REQUIRE(model.Init());
100
101 /* Instantiate application context. */
102 arm::app::ApplicationContext caseContext;
103
Isabella Gottardi8df12f32021-04-07 17:15:31 +0100104 arm::app::Profiler profiler{&platform, "img_class"};
105 caseContext.Set<arm::app::Profiler&>("profiler", profiler);
alexander3c798932021-03-26 21:42:19 +0000106 caseContext.Set<hal_platform&>("platform", platform);
107 caseContext.Set<arm::app::Model&>("model", model);
108 caseContext.Set<uint32_t>("imgIndex", 0);
109 arm::app::Classifier classifier; /* classifier wrapper object. */
110 caseContext.Set<arm::app::Classifier&>("classifier", classifier);
111
112 std::vector <std::string> labels;
113 GetLabelsVector(labels);
114 caseContext.Set<const std::vector <std::string>&>("labels", labels);
115
116 REQUIRE(arm::app::ClassifyImageHandler(caseContext, 0, true));
117}
118
119
120TEST_CASE("List all images")
121{
122 hal_platform platform;
123 data_acq_module data_acq;
124 data_psn_module data_psn;
125 platform_timer timer;
126
127 /* Initialise the HAL and platform. */
128 hal_init(&platform, &data_acq, &data_psn, &timer);
129 hal_platform_init(&platform);
130
131 /* Model wrapper object. */
132 arm::app::MobileNetModel model;
133
134 /* Load the model. */
135 REQUIRE(model.Init());
136
137 /* Instantiate application context. */
138 arm::app::ApplicationContext caseContext;
139
140 caseContext.Set<hal_platform&>("platform", platform);
141 caseContext.Set<arm::app::Model&>("model", model);
142
143 REQUIRE(arm::app::ListFilesHandler(caseContext));
144}