Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 1 | /* |
Richard Burton | f32a86a | 2022-11-15 11:46:11 +0000 | [diff] [blame] | 2 | * SPDX-FileCopyrightText: Copyright 2022 Arm Limited and/or its affiliates <open-source-office@arm.com> |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 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" |
Kshitij Sisodia | aa4bcb1 | 2022-05-06 09:13:03 +0100 | [diff] [blame] | 23 | #include "BufAttributes.hpp" |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 24 | |
| 25 | #include <catch.hpp> |
| 26 | |
Kshitij Sisodia | aa4bcb1 | 2022-05-06 09:13:03 +0100 | [diff] [blame] | 27 | namespace arm { |
| 28 | namespace app { |
| 29 | static uint8_t tensorArena[ACTIVATION_BUF_SZ] ACTIVATION_BUF_ATTRIBUTE; |
Liam Barry | 213a543 | 2022-05-09 17:06:19 +0100 | [diff] [blame] | 30 | namespace object_detection { |
| 31 | extern uint8_t* GetModelPointer(); |
| 32 | extern size_t GetModelLen(); |
| 33 | } /* namespace object_detection */ |
Kshitij Sisodia | aa4bcb1 | 2022-05-06 09:13:03 +0100 | [diff] [blame] | 34 | } /* namespace app */ |
| 35 | } /* namespace arm */ |
| 36 | |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 37 | TEST_CASE("Model info") |
| 38 | { |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 39 | /* Model wrapper object. */ |
| 40 | arm::app::YoloFastestModel model; |
| 41 | |
| 42 | /* Load the model. */ |
Kshitij Sisodia | aa4bcb1 | 2022-05-06 09:13:03 +0100 | [diff] [blame] | 43 | REQUIRE(model.Init(arm::app::tensorArena, |
Liam Barry | 213a543 | 2022-05-09 17:06:19 +0100 | [diff] [blame] | 44 | sizeof(arm::app::tensorArena), |
| 45 | arm::app::object_detection::GetModelPointer(), |
| 46 | arm::app::object_detection::GetModelLen())); |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 47 | |
| 48 | /* Instantiate application context. */ |
| 49 | arm::app::ApplicationContext caseContext; |
| 50 | |
| 51 | caseContext.Set<arm::app::Model&>("model", model); |
| 52 | |
| 53 | REQUIRE(model.ShowModelInfoHandler()); |
| 54 | } |
| 55 | |
| 56 | |
| 57 | TEST_CASE("Inference by index") |
| 58 | { |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 59 | /* Initialise the HAL and platform. */ |
Kshitij Sisodia | 4cc4021 | 2022-04-08 09:54:53 +0100 | [diff] [blame] | 60 | hal_platform_init(); |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 61 | |
| 62 | /* Model wrapper object. */ |
| 63 | arm::app::YoloFastestModel model; |
| 64 | |
| 65 | /* Load the model. */ |
Kshitij Sisodia | aa4bcb1 | 2022-05-06 09:13:03 +0100 | [diff] [blame] | 66 | REQUIRE(model.Init(arm::app::tensorArena, |
Liam Barry | 213a543 | 2022-05-09 17:06:19 +0100 | [diff] [blame] | 67 | sizeof(arm::app::tensorArena), |
| 68 | arm::app::object_detection::GetModelPointer(), |
| 69 | arm::app::object_detection::GetModelLen())); |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 70 | |
| 71 | /* Instantiate application context. */ |
| 72 | arm::app::ApplicationContext caseContext; |
| 73 | |
Kshitij Sisodia | 4cc4021 | 2022-04-08 09:54:53 +0100 | [diff] [blame] | 74 | arm::app::Profiler profiler{"object_detection"}; |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 75 | caseContext.Set<arm::app::Profiler&>("profiler", profiler); |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 76 | caseContext.Set<arm::app::Model&>("model", model); |
| 77 | caseContext.Set<uint32_t>("imgIndex", 0); |
| 78 | |
| 79 | REQUIRE(arm::app::ObjectDetectionHandler(caseContext, 0, false)); |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | |
| 83 | TEST_CASE("Inference run all images") |
| 84 | { |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 85 | /* Initialise the HAL and platform. */ |
Kshitij Sisodia | 4cc4021 | 2022-04-08 09:54:53 +0100 | [diff] [blame] | 86 | hal_platform_init(); |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 87 | |
| 88 | /* Model wrapper object. */ |
| 89 | arm::app::YoloFastestModel model; |
| 90 | |
| 91 | /* Load the model. */ |
Kshitij Sisodia | aa4bcb1 | 2022-05-06 09:13:03 +0100 | [diff] [blame] | 92 | REQUIRE(model.Init(arm::app::tensorArena, |
Liam Barry | 213a543 | 2022-05-09 17:06:19 +0100 | [diff] [blame] | 93 | sizeof(arm::app::tensorArena), |
| 94 | arm::app::object_detection::GetModelPointer(), |
| 95 | arm::app::object_detection::GetModelLen())); |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 96 | |
| 97 | /* Instantiate application context. */ |
| 98 | arm::app::ApplicationContext caseContext; |
| 99 | |
Kshitij Sisodia | 4cc4021 | 2022-04-08 09:54:53 +0100 | [diff] [blame] | 100 | arm::app::Profiler profiler{"object_detection"}; |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 101 | caseContext.Set<arm::app::Profiler&>("profiler", profiler); |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 102 | caseContext.Set<arm::app::Model&>("model", model); |
| 103 | caseContext.Set<uint32_t>("imgIndex", 0); |
| 104 | |
| 105 | REQUIRE(arm::app::ObjectDetectionHandler(caseContext, 0, true)); |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | |
| 109 | TEST_CASE("List all images") |
| 110 | { |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 111 | /* Initialise the HAL and platform. */ |
Kshitij Sisodia | 4cc4021 | 2022-04-08 09:54:53 +0100 | [diff] [blame] | 112 | hal_platform_init(); |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 113 | |
| 114 | /* Model wrapper object. */ |
| 115 | arm::app::YoloFastestModel model; |
| 116 | |
| 117 | /* Load the model. */ |
Kshitij Sisodia | aa4bcb1 | 2022-05-06 09:13:03 +0100 | [diff] [blame] | 118 | REQUIRE(model.Init(arm::app::tensorArena, |
Liam Barry | 213a543 | 2022-05-09 17:06:19 +0100 | [diff] [blame] | 119 | sizeof(arm::app::tensorArena), |
| 120 | arm::app::object_detection::GetModelPointer(), |
| 121 | arm::app::object_detection::GetModelLen())); |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 122 | |
| 123 | /* Instantiate application context. */ |
| 124 | arm::app::ApplicationContext caseContext; |
Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 125 | caseContext.Set<arm::app::Model&>("model", model); |
| 126 | |
| 127 | REQUIRE(arm::app::ListFilesHandler(caseContext)); |
| 128 | } |