giuros01 | 1887081 | 2018-09-13 09:31:40 +0100 | [diff] [blame] | 1 | /* |
Manuel Bottini | cc5171b | 2019-01-09 17:04:39 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2019 ARM Limited. |
giuros01 | 1887081 | 2018-09-13 09:31:40 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | #include "arm_compute/runtime/CL/CLScheduler.h" |
| 25 | #include "arm_compute/runtime/CL/functions/CLROIAlignLayer.h" |
| 26 | #include "tests/CL/CLAccessor.h" |
giuros01 | 1887081 | 2018-09-13 09:31:40 +0100 | [diff] [blame] | 27 | #include "tests/Globals.h" |
Manuel Bottini | cc5171b | 2019-01-09 17:04:39 +0000 | [diff] [blame] | 28 | #include "tests/datasets/ROIDataset.h" |
giuros01 | 1887081 | 2018-09-13 09:31:40 +0100 | [diff] [blame] | 29 | #include "tests/datasets/ShapeDatasets.h" |
| 30 | #include "tests/framework/Macros.h" |
| 31 | #include "tests/framework/datasets/Datasets.h" |
| 32 | #include "tests/validation/Validation.h" |
| 33 | #include "tests/validation/fixtures/ROIAlignLayerFixture.h" |
| 34 | #include "utils/TypePrinter.h" |
| 35 | |
| 36 | namespace arm_compute |
| 37 | { |
| 38 | namespace test |
| 39 | { |
| 40 | namespace validation |
| 41 | { |
| 42 | namespace |
| 43 | { |
Michele Di Giorgio | 578a9fc | 2019-08-23 11:49:04 +0100 | [diff] [blame^] | 44 | constexpr RelativeTolerance<float> relative_tolerance_f32(0.01f); |
| 45 | constexpr AbsoluteTolerance<float> absolute_tolerance_f32(0.001f); |
Manuel Bottini | 60f0a41 | 2018-10-24 17:27:02 +0100 | [diff] [blame] | 46 | |
Michele Di Giorgio | 578a9fc | 2019-08-23 11:49:04 +0100 | [diff] [blame^] | 47 | constexpr RelativeTolerance<float> relative_tolerance_f16(0.01f); |
| 48 | constexpr AbsoluteTolerance<float> absolute_tolerance_f16(0.001f); |
| 49 | |
| 50 | constexpr AbsoluteTolerance<uint8_t> tolerance_qasymm8(1); |
giuros01 | 1887081 | 2018-09-13 09:31:40 +0100 | [diff] [blame] | 51 | } // namespace |
| 52 | |
| 53 | TEST_SUITE(CL) |
| 54 | TEST_SUITE(RoiAlign) |
| 55 | |
| 56 | // *INDENT-OFF* |
| 57 | // clang-format off |
| 58 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip( |
| 59 | framework::dataset::make("InputInfo", { TensorInfo(TensorShape(250U, 128U, 3U), 1, DataType::F32), |
Michele Di Giorgio | 578a9fc | 2019-08-23 11:49:04 +0100 | [diff] [blame^] | 60 | TensorInfo(TensorShape(250U, 128U, 3U), 1, DataType::F32), // Mismatching data type input/rois |
| 61 | TensorInfo(TensorShape(250U, 128U, 3U), 1, DataType::F32), // Mismatching data type input/output |
| 62 | TensorInfo(TensorShape(250U, 128U, 2U), 1, DataType::F32), // Mismatching depth size input/output |
| 63 | TensorInfo(TensorShape(250U, 128U, 3U), 1, DataType::F32), // Mismatching number of rois and output batch size |
| 64 | TensorInfo(TensorShape(250U, 128U, 3U), 1, DataType::F32), // Invalid number of values per ROIS |
| 65 | TensorInfo(TensorShape(250U, 128U, 3U), 1, DataType::F32), // Mismatching height and width input/output |
| 66 | TensorInfo(TensorShape(250U, 128U, 3U), 1, DataType::QASYMM8, QuantizationInfo(1.f / 255.f, 127)), // Invalid ROIS data type |
| 67 | TensorInfo(TensorShape(250U, 128U, 3U), 1, DataType::QASYMM8, QuantizationInfo(1.f / 255.f, 127)), // Invalid ROIS Quantization Info |
giuros01 | 1887081 | 2018-09-13 09:31:40 +0100 | [diff] [blame] | 68 | }), |
George Wort | 44b4e97 | 2019-01-08 11:41:54 +0000 | [diff] [blame] | 69 | framework::dataset::make("RoisInfo", { TensorInfo(TensorShape(5, 4U), 1, DataType::F32), |
| 70 | TensorInfo(TensorShape(5, 4U), 1, DataType::F16), |
| 71 | TensorInfo(TensorShape(5, 4U), 1, DataType::F32), |
Manuel Bottini | 60f0a41 | 2018-10-24 17:27:02 +0100 | [diff] [blame] | 72 | TensorInfo(TensorShape(5, 4U), 1, DataType::F32), |
| 73 | TensorInfo(TensorShape(5, 10U), 1, DataType::F32), |
George Wort | 44b4e97 | 2019-01-08 11:41:54 +0000 | [diff] [blame] | 74 | TensorInfo(TensorShape(4, 4U), 1, DataType::F32), |
Manuel Bottini | 60f0a41 | 2018-10-24 17:27:02 +0100 | [diff] [blame] | 75 | TensorInfo(TensorShape(5, 4U), 1, DataType::F32), |
Michele Di Giorgio | 578a9fc | 2019-08-23 11:49:04 +0100 | [diff] [blame^] | 76 | TensorInfo(TensorShape(5, 4U), 1, DataType::F32), |
| 77 | TensorInfo(TensorShape(5, 4U), 1, DataType::QASYMM16, QuantizationInfo(0.2f, 0)), |
Manuel Bottini | 60f0a41 | 2018-10-24 17:27:02 +0100 | [diff] [blame] | 78 | })), |
George Wort | 44b4e97 | 2019-01-08 11:41:54 +0000 | [diff] [blame] | 79 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(7U, 7U, 3U, 4U), 1, DataType::F32), |
| 80 | TensorInfo(TensorShape(7U, 7U, 3U, 4U), 1, DataType::F32), |
| 81 | TensorInfo(TensorShape(7U, 7U, 3U, 4U), 1, DataType::F16), |
| 82 | TensorInfo(TensorShape(7U, 7U, 3U, 4U), 1, DataType::F32), |
| 83 | TensorInfo(TensorShape(7U, 7U, 3U, 4U), 1, DataType::F32), |
| 84 | TensorInfo(TensorShape(7U, 7U, 3U, 4U), 1, DataType::F32), |
| 85 | TensorInfo(TensorShape(5U, 5U, 3U, 4U), 1, DataType::F32), |
Michele Di Giorgio | 578a9fc | 2019-08-23 11:49:04 +0100 | [diff] [blame^] | 86 | TensorInfo(TensorShape(7U, 7U, 3U, 4U), 1, DataType::QASYMM8, QuantizationInfo(1.f / 255.f, 120)), |
| 87 | TensorInfo(TensorShape(7U, 7U, 3U, 4U), 1, DataType::QASYMM8, QuantizationInfo(1.f / 255.f, 120)), |
giuros01 | 1887081 | 2018-09-13 09:31:40 +0100 | [diff] [blame] | 88 | })), |
| 89 | framework::dataset::make("PoolInfo", { ROIPoolingLayerInfo(7U, 7U, 1./8), |
| 90 | ROIPoolingLayerInfo(7U, 7U, 1./8), |
| 91 | ROIPoolingLayerInfo(7U, 7U, 1./8), |
| 92 | ROIPoolingLayerInfo(7U, 7U, 1./8), |
| 93 | ROIPoolingLayerInfo(7U, 7U, 1./8), |
Manuel Bottini | 60f0a41 | 2018-10-24 17:27:02 +0100 | [diff] [blame] | 94 | ROIPoolingLayerInfo(7U, 7U, 1./8), |
| 95 | ROIPoolingLayerInfo(7U, 7U, 1./8), |
Michele Di Giorgio | 578a9fc | 2019-08-23 11:49:04 +0100 | [diff] [blame^] | 96 | ROIPoolingLayerInfo(7U, 7U, 1./8), |
giuros01 | 1887081 | 2018-09-13 09:31:40 +0100 | [diff] [blame] | 97 | })), |
Michele Di Giorgio | 578a9fc | 2019-08-23 11:49:04 +0100 | [diff] [blame^] | 98 | framework::dataset::make("Expected", { true, false, false, false, false, false, false, false, false })), |
Manuel Bottini | 60f0a41 | 2018-10-24 17:27:02 +0100 | [diff] [blame] | 99 | input_info, rois_info, output_info, pool_info, expected) |
giuros01 | 1887081 | 2018-09-13 09:31:40 +0100 | [diff] [blame] | 100 | { |
Manuel Bottini | 60f0a41 | 2018-10-24 17:27:02 +0100 | [diff] [blame] | 101 | ARM_COMPUTE_EXPECT(bool(CLROIAlignLayer::validate(&input_info.clone()->set_is_resizable(true), &rois_info.clone()->set_is_resizable(true), &output_info.clone()->set_is_resizable(true), pool_info)) == expected, framework::LogLevel::ERRORS); |
giuros01 | 1887081 | 2018-09-13 09:31:40 +0100 | [diff] [blame] | 102 | } |
| 103 | // clang-format on |
| 104 | // *INDENT-ON* |
| 105 | |
| 106 | template <typename T> |
Manuel Bottini | 60f0a41 | 2018-10-24 17:27:02 +0100 | [diff] [blame] | 107 | using CLROIAlignLayerFixture = ROIAlignLayerFixture<CLTensor, CLAccessor, CLROIAlignLayer, T>; |
giuros01 | 1887081 | 2018-09-13 09:31:40 +0100 | [diff] [blame] | 108 | |
| 109 | TEST_SUITE(Float) |
Michele Di Giorgio | 578a9fc | 2019-08-23 11:49:04 +0100 | [diff] [blame^] | 110 | TEST_SUITE(FP32) |
| 111 | FIXTURE_DATA_TEST_CASE(Small, CLROIAlignLayerFixture<float>, framework::DatasetMode::ALL, |
| 112 | combine(combine(datasets::SmallROIDataset(), |
| 113 | framework::dataset::make("DataType", { DataType::F32 })), |
| 114 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) |
giuros01 | 1887081 | 2018-09-13 09:31:40 +0100 | [diff] [blame] | 115 | { |
| 116 | // Validate output |
giuros01 | eddff5a | 2018-10-05 14:48:58 +0100 | [diff] [blame] | 117 | validate(CLAccessor(_target), _reference, relative_tolerance_f32, .02f, absolute_tolerance_f32); |
giuros01 | 1887081 | 2018-09-13 09:31:40 +0100 | [diff] [blame] | 118 | } |
Michele Di Giorgio | 578a9fc | 2019-08-23 11:49:04 +0100 | [diff] [blame^] | 119 | TEST_SUITE_END() // FP32 |
| 120 | TEST_SUITE(FP16) |
| 121 | FIXTURE_DATA_TEST_CASE(Small, CLROIAlignLayerFixture<half>, framework::DatasetMode::ALL, |
| 122 | combine(combine(datasets::SmallROIDataset(), |
| 123 | framework::dataset::make("DataType", { DataType::F16 })), |
| 124 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) |
Manuel Bottini | 60f0a41 | 2018-10-24 17:27:02 +0100 | [diff] [blame] | 125 | { |
| 126 | // Validate output |
| 127 | validate(CLAccessor(_target), _reference, relative_tolerance_f16, .02f, absolute_tolerance_f16); |
| 128 | } |
Michele Di Giorgio | 578a9fc | 2019-08-23 11:49:04 +0100 | [diff] [blame^] | 129 | TEST_SUITE_END() // FP16 |
giuros01 | 1887081 | 2018-09-13 09:31:40 +0100 | [diff] [blame] | 130 | TEST_SUITE_END() // Float |
| 131 | |
Michele Di Giorgio | 578a9fc | 2019-08-23 11:49:04 +0100 | [diff] [blame^] | 132 | template <typename T> |
| 133 | using CLROIAlignLayerQuantizedFixture = ROIAlignLayerQuantizedFixture<CLTensor, CLAccessor, CLROIAlignLayer, T>; |
| 134 | |
| 135 | TEST_SUITE(Quantized) |
| 136 | TEST_SUITE(QASYMM8) |
| 137 | FIXTURE_DATA_TEST_CASE(Small, CLROIAlignLayerQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, |
| 138 | combine(combine(combine(combine(datasets::SmallROIDataset(), |
| 139 | framework::dataset::make("DataType", { DataType::QASYMM8 })), |
| 140 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })), |
| 141 | framework::dataset::make("InputQuantizationInfo", { QuantizationInfo(1.f / 255.f, 127) })), |
| 142 | framework::dataset::make("OutputQuantizationInfo", { QuantizationInfo(2.f / 255.f, 120) }))) |
| 143 | { |
| 144 | // Validate output |
| 145 | validate(CLAccessor(_target), _reference, tolerance_qasymm8); |
| 146 | } |
| 147 | TEST_SUITE_END() // QASYMM8 |
| 148 | TEST_SUITE_END() // Quantized |
| 149 | |
giuros01 | 1887081 | 2018-09-13 09:31:40 +0100 | [diff] [blame] | 150 | TEST_SUITE_END() // RoiAlign |
| 151 | TEST_SUITE_END() // CL |
| 152 | } // namespace validation |
| 153 | } // namespace test |
| 154 | } // namespace arm_compute |