blob: b9caf6115e4692f9d2c3aec516248c045f2af87e [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{
alexander3c798932021-03-26 21:42:19 +000046 /* Initialise the HAL and platform. */
Kshitij Sisodia4cc40212022-04-08 09:54:53 +010047 hal_platform_init();
alexander3c798932021-03-26 21:42:19 +000048
49 /* Model wrapper object. */
Isabella Gottardi8df12f32021-04-07 17:15:31 +010050 arm::app::MobileNetModel model;
alexander3c798932021-03-26 21:42:19 +000051
52 /* Load the model. */
53 REQUIRE(model.Init());
54
55 /* Instantiate application context. */
56 arm::app::ApplicationContext caseContext;
57
Kshitij Sisodia4cc40212022-04-08 09:54:53 +010058 arm::app::Profiler profiler{"img_class"};
Isabella Gottardi8df12f32021-04-07 17:15:31 +010059 caseContext.Set<arm::app::Profiler&>("profiler", profiler);
alexander3c798932021-03-26 21:42:19 +000060 caseContext.Set<arm::app::Model&>("model", model);
61 caseContext.Set<uint32_t>("imgIndex", 0);
62 arm::app::Classifier classifier; /* Classifier wrapper object. */
63 caseContext.Set<arm::app::Classifier&>("classifier", classifier);
64
65 std::vector <std::string> labels;
66 GetLabelsVector(labels);
67 caseContext.Set<const std::vector <std::string>&>("labels", labels);
68
69 REQUIRE(arm::app::ClassifyImageHandler(caseContext, 0, false));
70
71 auto results = caseContext.Get<std::vector<arm::app::ClassificationResult>>("results");
72
73 REQUIRE(results[0].m_labelIdx == 282);
74}
75
76
77TEST_CASE("Inference run all images", "[.]")
78{
alexander3c798932021-03-26 21:42:19 +000079 /* Initialise the HAL and platform. */
Kshitij Sisodia4cc40212022-04-08 09:54:53 +010080 hal_platform_init();
alexander3c798932021-03-26 21:42:19 +000081
82 /* Model wrapper object. */
83 arm::app::MobileNetModel model;
84
85 /* Load the model. */
86 REQUIRE(model.Init());
87
88 /* Instantiate application context. */
89 arm::app::ApplicationContext caseContext;
90
Kshitij Sisodia4cc40212022-04-08 09:54:53 +010091 arm::app::Profiler profiler{"img_class"};
Isabella Gottardi8df12f32021-04-07 17:15:31 +010092 caseContext.Set<arm::app::Profiler&>("profiler", profiler);
alexander3c798932021-03-26 21:42:19 +000093 caseContext.Set<arm::app::Model&>("model", model);
94 caseContext.Set<uint32_t>("imgIndex", 0);
95 arm::app::Classifier classifier; /* classifier wrapper object. */
96 caseContext.Set<arm::app::Classifier&>("classifier", classifier);
97
98 std::vector <std::string> labels;
99 GetLabelsVector(labels);
100 caseContext.Set<const std::vector <std::string>&>("labels", labels);
101
102 REQUIRE(arm::app::ClassifyImageHandler(caseContext, 0, true));
103}
104
105
106TEST_CASE("List all images")
107{
alexander3c798932021-03-26 21:42:19 +0000108 /* Initialise the HAL and platform. */
Kshitij Sisodia4cc40212022-04-08 09:54:53 +0100109 hal_platform_init();
alexander3c798932021-03-26 21:42:19 +0000110
111 /* Model wrapper object. */
112 arm::app::MobileNetModel model;
113
114 /* Load the model. */
115 REQUIRE(model.Init());
116
117 /* Instantiate application context. */
118 arm::app::ApplicationContext caseContext;
alexander3c798932021-03-26 21:42:19 +0000119 caseContext.Set<arm::app::Model&>("model", model);
120
121 REQUIRE(arm::app::ListFilesHandler(caseContext));
122}