Éanna Ó Catháin | 8f95887 | 2021-09-15 09:32:30 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 27 | TEST_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 | |
| 42 | TEST_CASE("Inference by index") |
| 43 | { |
| 44 | hal_platform platform; |
Éanna Ó Catháin | 8f95887 | 2021-09-15 09:32:30 +0100 | [diff] [blame] | 45 | platform_timer timer; |
| 46 | |
| 47 | /* Initialise the HAL and platform */ |
Kshitij Sisodia | 68fdd11 | 2022-04-06 13:03:20 +0100 | [diff] [blame] | 48 | hal_init(&platform, &timer); |
Éanna Ó Catháin | 8f95887 | 2021-09-15 09:32:30 +0100 | [diff] [blame] | 49 | hal_platform_init(&platform); |
| 50 | |
| 51 | arm::app::VisualWakeWordModel model; /* model wrapper object */ |
| 52 | |
| 53 | /* Load the model */ |
| 54 | REQUIRE(model.Init()); |
| 55 | |
| 56 | /* Instantiate application context */ |
| 57 | arm::app::ApplicationContext caseContext; |
| 58 | arm::app::Profiler profiler{&platform, "pd"}; |
| 59 | caseContext.Set<arm::app::Profiler&>("profiler", profiler); |
| 60 | caseContext.Set<hal_platform&>("platform", platform); |
| 61 | caseContext.Set<arm::app::Model&>("model", model); |
| 62 | caseContext.Set<uint32_t>("imgIndex", 0); |
| 63 | arm::app::Classifier classifier; /* classifier wrapper object */ |
| 64 | caseContext.Set<arm::app::Classifier&>("classifier", classifier); |
| 65 | |
| 66 | std::vector <std::string> labels; |
| 67 | GetLabelsVector(labels); |
| 68 | caseContext.Set<const std::vector <std::string>&>("labels", labels); |
| 69 | |
| 70 | REQUIRE(arm::app::ClassifyImageHandler(caseContext, 0, false)); |
| 71 | |
| 72 | auto results = caseContext.Get<std::vector<arm::app::ClassificationResult>>("results"); |
| 73 | |
Isabella Gottardi | 79d4154 | 2021-10-20 15:52:32 +0100 | [diff] [blame] | 74 | REQUIRE(results[0].m_labelIdx == 1); |
Éanna Ó Catháin | 8f95887 | 2021-09-15 09:32:30 +0100 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | TEST_CASE("Inference run all images") |
| 78 | { |
| 79 | hal_platform platform; |
Éanna Ó Catháin | 8f95887 | 2021-09-15 09:32:30 +0100 | [diff] [blame] | 80 | platform_timer timer; |
| 81 | |
| 82 | /* Initialise the HAL and platform */ |
Kshitij Sisodia | 68fdd11 | 2022-04-06 13:03:20 +0100 | [diff] [blame] | 83 | hal_init(&platform, &timer); |
Éanna Ó Catháin | 8f95887 | 2021-09-15 09:32:30 +0100 | [diff] [blame] | 84 | hal_platform_init(&platform); |
| 85 | |
| 86 | arm::app::VisualWakeWordModel model; /* model wrapper object */ |
| 87 | |
| 88 | /* Load the model */ |
| 89 | REQUIRE(model.Init()); |
| 90 | |
| 91 | /* Instantiate application context */ |
| 92 | arm::app::ApplicationContext caseContext; |
| 93 | arm::app::Profiler profiler{&platform, "pd"}; |
| 94 | caseContext.Set<arm::app::Profiler&>("profiler", profiler); |
| 95 | caseContext.Set<hal_platform&>("platform", platform); |
| 96 | caseContext.Set<arm::app::Model&>("model", model); |
| 97 | caseContext.Set<uint32_t>("imgIndex", 0); |
| 98 | arm::app::Classifier classifier; /* classifier wrapper object */ |
| 99 | caseContext.Set<arm::app::Classifier&>("classifier", classifier); |
| 100 | |
| 101 | std::vector <std::string> labels; |
| 102 | GetLabelsVector(labels); |
| 103 | caseContext.Set<const std::vector <std::string>&>("labels", labels); |
| 104 | |
| 105 | REQUIRE(arm::app::ClassifyImageHandler(caseContext, 0, true)); |
| 106 | } |
| 107 | |
| 108 | TEST_CASE("List all images") |
| 109 | { |
| 110 | hal_platform platform; |
Éanna Ó Catháin | 8f95887 | 2021-09-15 09:32:30 +0100 | [diff] [blame] | 111 | platform_timer timer; |
| 112 | |
| 113 | /* Initialise the HAL and platform */ |
Kshitij Sisodia | 68fdd11 | 2022-04-06 13:03:20 +0100 | [diff] [blame] | 114 | hal_init(&platform, &timer); |
Éanna Ó Catháin | 8f95887 | 2021-09-15 09:32:30 +0100 | [diff] [blame] | 115 | hal_platform_init(&platform); |
| 116 | |
| 117 | arm::app::VisualWakeWordModel model; /* model wrapper object */ |
| 118 | |
| 119 | /* Load the model */ |
| 120 | REQUIRE(model.Init()); |
| 121 | |
| 122 | /* Instantiate application context */ |
| 123 | arm::app::ApplicationContext caseContext; |
| 124 | |
| 125 | caseContext.Set<hal_platform&>("platform", platform); |
| 126 | caseContext.Set<arm::app::Model&>("model", model); |
| 127 | |
| 128 | REQUIRE(arm::app::ListFilesHandler(caseContext)); |
| 129 | } |