Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2022 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 "DetectionResult.hpp" |
Isabella Gottardi | 3107aa2 | 2022-01-27 16:39:37 +0000 | [diff] [blame] | 18 | #include "DetectorPostProcessing.hpp" |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 19 | #include "hal.h" |
| 20 | #include "YoloFastestModel.hpp" |
| 21 | #include "UseCaseHandler.hpp" |
| 22 | #include "UseCaseCommonUtils.hpp" |
| 23 | |
| 24 | #include <catch.hpp> |
| 25 | |
| 26 | TEST_CASE("Model info") |
| 27 | { |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 28 | /* Model wrapper object. */ |
| 29 | arm::app::YoloFastestModel model; |
| 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 | |
| 43 | TEST_CASE("Inference by index") |
| 44 | { |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 45 | /* Initialise the HAL and platform. */ |
Kshitij Sisodia | 4cc4021 | 2022-04-08 09:54:53 +0100 | [diff] [blame^] | 46 | hal_platform_init(); |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 47 | |
| 48 | /* Model wrapper object. */ |
| 49 | arm::app::YoloFastestModel model; |
| 50 | |
| 51 | /* Load the model. */ |
| 52 | REQUIRE(model.Init()); |
| 53 | |
| 54 | /* Instantiate application context. */ |
| 55 | arm::app::ApplicationContext caseContext; |
| 56 | |
Kshitij Sisodia | 4cc4021 | 2022-04-08 09:54:53 +0100 | [diff] [blame^] | 57 | arm::app::Profiler profiler{"object_detection"}; |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 58 | caseContext.Set<arm::app::Profiler&>("profiler", profiler); |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 59 | caseContext.Set<arm::app::Model&>("model", model); |
| 60 | caseContext.Set<uint32_t>("imgIndex", 0); |
Isabella Gottardi | 3107aa2 | 2022-01-27 16:39:37 +0000 | [diff] [blame] | 61 | arm::app::object_detection::DetectorPostprocessing postp; |
| 62 | caseContext.Set<arm::app::object_detection::DetectorPostprocessing&>("postprocess", postp); |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 63 | |
| 64 | REQUIRE(arm::app::ObjectDetectionHandler(caseContext, 0, false)); |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | |
| 68 | TEST_CASE("Inference run all images") |
| 69 | { |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 70 | /* Initialise the HAL and platform. */ |
Kshitij Sisodia | 4cc4021 | 2022-04-08 09:54:53 +0100 | [diff] [blame^] | 71 | hal_platform_init(); |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 72 | |
| 73 | /* Model wrapper object. */ |
| 74 | arm::app::YoloFastestModel model; |
| 75 | |
| 76 | /* Load the model. */ |
| 77 | REQUIRE(model.Init()); |
| 78 | |
| 79 | /* Instantiate application context. */ |
| 80 | arm::app::ApplicationContext caseContext; |
| 81 | |
Kshitij Sisodia | 4cc4021 | 2022-04-08 09:54:53 +0100 | [diff] [blame^] | 82 | arm::app::Profiler profiler{"object_detection"}; |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 83 | caseContext.Set<arm::app::Profiler&>("profiler", profiler); |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 84 | caseContext.Set<arm::app::Model&>("model", model); |
| 85 | caseContext.Set<uint32_t>("imgIndex", 0); |
Isabella Gottardi | 3107aa2 | 2022-01-27 16:39:37 +0000 | [diff] [blame] | 86 | arm::app::object_detection::DetectorPostprocessing postp; |
| 87 | caseContext.Set<arm::app::object_detection::DetectorPostprocessing&>("postprocess", postp); |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 88 | |
| 89 | REQUIRE(arm::app::ObjectDetectionHandler(caseContext, 0, true)); |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | |
| 93 | TEST_CASE("List all images") |
| 94 | { |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 95 | /* Initialise the HAL and platform. */ |
Kshitij Sisodia | 4cc4021 | 2022-04-08 09:54:53 +0100 | [diff] [blame^] | 96 | hal_platform_init(); |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 97 | |
| 98 | /* Model wrapper object. */ |
| 99 | arm::app::YoloFastestModel model; |
| 100 | |
| 101 | /* Load the model. */ |
| 102 | REQUIRE(model.Init()); |
| 103 | |
| 104 | /* Instantiate application context. */ |
| 105 | arm::app::ApplicationContext caseContext; |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 106 | caseContext.Set<arm::app::Model&>("model", model); |
| 107 | |
| 108 | REQUIRE(arm::app::ListFilesHandler(caseContext)); |
| 109 | } |