É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 | { |
Kshitij Sisodia | 4cc4021 | 2022-04-08 09:54:53 +0100 | [diff] [blame^] | 44 | hal_platform_init(); |
Éanna Ó Catháin | 8f95887 | 2021-09-15 09:32:30 +0100 | [diff] [blame] | 45 | |
| 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 Sisodia | 4cc4021 | 2022-04-08 09:54:53 +0100 | [diff] [blame^] | 53 | arm::app::Profiler profiler{"pd"}; |
Éanna Ó Catháin | 8f95887 | 2021-09-15 09:32:30 +0100 | [diff] [blame] | 54 | caseContext.Set<arm::app::Profiler&>("profiler", profiler); |
Éanna Ó Catháin | 8f95887 | 2021-09-15 09:32:30 +0100 | [diff] [blame] | 55 | 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 Gottardi | 79d4154 | 2021-10-20 15:52:32 +0100 | [diff] [blame] | 68 | REQUIRE(results[0].m_labelIdx == 1); |
Éanna Ó Catháin | 8f95887 | 2021-09-15 09:32:30 +0100 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | TEST_CASE("Inference run all images") |
| 72 | { |
Éanna Ó Catháin | 8f95887 | 2021-09-15 09:32:30 +0100 | [diff] [blame] | 73 | /* Initialise the HAL and platform */ |
Kshitij Sisodia | 4cc4021 | 2022-04-08 09:54:53 +0100 | [diff] [blame^] | 74 | hal_platform_init(); |
Éanna Ó Catháin | 8f95887 | 2021-09-15 09:32:30 +0100 | [diff] [blame] | 75 | |
| 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 Sisodia | 4cc4021 | 2022-04-08 09:54:53 +0100 | [diff] [blame^] | 83 | arm::app::Profiler profiler{"pd"}; |
Éanna Ó Catháin | 8f95887 | 2021-09-15 09:32:30 +0100 | [diff] [blame] | 84 | caseContext.Set<arm::app::Profiler&>("profiler", profiler); |
Éanna Ó Catháin | 8f95887 | 2021-09-15 09:32:30 +0100 | [diff] [blame] | 85 | 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 | |
| 97 | TEST_CASE("List all images") |
| 98 | { |
Éanna Ó Catháin | 8f95887 | 2021-09-15 09:32:30 +0100 | [diff] [blame] | 99 | /* Initialise the HAL and platform */ |
Kshitij Sisodia | 4cc4021 | 2022-04-08 09:54:53 +0100 | [diff] [blame^] | 100 | hal_platform_init(); |
Éanna Ó Catháin | 8f95887 | 2021-09-15 09:32:30 +0100 | [diff] [blame] | 101 | |
| 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áin | 8f95887 | 2021-09-15 09:32:30 +0100 | [diff] [blame] | 110 | caseContext.Set<arm::app::Model&>("model", model); |
| 111 | |
| 112 | REQUIRE(arm::app::ListFilesHandler(caseContext)); |
| 113 | } |