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