blob: 2a3e03f7ac1ab84e691cbbbbfb602b5791a44a0e [file] [log] [blame]
giuros0118870812018-09-13 09:31:40 +01001/*
Manuel Bottini8481d832019-12-10 15:28:40 +00002 * Copyright (c) 2018-2020 ARM Limited.
giuros0118870812018-09-13 09:31:40 +01003 *
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"
giuros0118870812018-09-13 09:31:40 +010027#include "tests/Globals.h"
Manuel Bottinicc5171b2019-01-09 17:04:39 +000028#include "tests/datasets/ROIDataset.h"
giuros0118870812018-09-13 09:31:40 +010029#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
36namespace arm_compute
37{
38namespace test
39{
40namespace validation
41{
42namespace
43{
Michele Di Giorgio578a9fc2019-08-23 11:49:04 +010044constexpr RelativeTolerance<float> relative_tolerance_f32(0.01f);
45constexpr AbsoluteTolerance<float> absolute_tolerance_f32(0.001f);
Manuel Bottini60f0a412018-10-24 17:27:02 +010046
Michele Di Giorgio578a9fc2019-08-23 11:49:04 +010047constexpr RelativeTolerance<float> relative_tolerance_f16(0.01f);
48constexpr AbsoluteTolerance<float> absolute_tolerance_f16(0.001f);
49
50constexpr AbsoluteTolerance<uint8_t> tolerance_qasymm8(1);
Manuel Bottini8481d832019-12-10 15:28:40 +000051constexpr AbsoluteTolerance<int8_t> tolerance_qasymm8_s(1);
giuros0118870812018-09-13 09:31:40 +010052} // namespace
53
54TEST_SUITE(CL)
55TEST_SUITE(RoiAlign)
56
57// *INDENT-OFF*
58// clang-format off
59DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
60 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(250U, 128U, 3U), 1, DataType::F32),
Michele Di Giorgio578a9fc2019-08-23 11:49:04 +010061 TensorInfo(TensorShape(250U, 128U, 3U), 1, DataType::F32), // Mismatching data type input/rois
62 TensorInfo(TensorShape(250U, 128U, 3U), 1, DataType::F32), // Mismatching data type input/output
63 TensorInfo(TensorShape(250U, 128U, 2U), 1, DataType::F32), // Mismatching depth size input/output
64 TensorInfo(TensorShape(250U, 128U, 3U), 1, DataType::F32), // Mismatching number of rois and output batch size
65 TensorInfo(TensorShape(250U, 128U, 3U), 1, DataType::F32), // Invalid number of values per ROIS
66 TensorInfo(TensorShape(250U, 128U, 3U), 1, DataType::F32), // Mismatching height and width input/output
67 TensorInfo(TensorShape(250U, 128U, 3U), 1, DataType::QASYMM8, QuantizationInfo(1.f / 255.f, 127)), // Invalid ROIS data type
68 TensorInfo(TensorShape(250U, 128U, 3U), 1, DataType::QASYMM8, QuantizationInfo(1.f / 255.f, 127)), // Invalid ROIS Quantization Info
giuros0118870812018-09-13 09:31:40 +010069 }),
George Wort44b4e972019-01-08 11:41:54 +000070 framework::dataset::make("RoisInfo", { TensorInfo(TensorShape(5, 4U), 1, DataType::F32),
71 TensorInfo(TensorShape(5, 4U), 1, DataType::F16),
72 TensorInfo(TensorShape(5, 4U), 1, DataType::F32),
Manuel Bottini60f0a412018-10-24 17:27:02 +010073 TensorInfo(TensorShape(5, 4U), 1, DataType::F32),
74 TensorInfo(TensorShape(5, 10U), 1, DataType::F32),
George Wort44b4e972019-01-08 11:41:54 +000075 TensorInfo(TensorShape(4, 4U), 1, DataType::F32),
Manuel Bottini60f0a412018-10-24 17:27:02 +010076 TensorInfo(TensorShape(5, 4U), 1, DataType::F32),
Michele Di Giorgio578a9fc2019-08-23 11:49:04 +010077 TensorInfo(TensorShape(5, 4U), 1, DataType::F32),
78 TensorInfo(TensorShape(5, 4U), 1, DataType::QASYMM16, QuantizationInfo(0.2f, 0)),
Manuel Bottini60f0a412018-10-24 17:27:02 +010079 })),
George Wort44b4e972019-01-08 11:41:54 +000080 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(7U, 7U, 3U, 4U), 1, DataType::F32),
81 TensorInfo(TensorShape(7U, 7U, 3U, 4U), 1, DataType::F32),
82 TensorInfo(TensorShape(7U, 7U, 3U, 4U), 1, DataType::F16),
83 TensorInfo(TensorShape(7U, 7U, 3U, 4U), 1, DataType::F32),
84 TensorInfo(TensorShape(7U, 7U, 3U, 4U), 1, DataType::F32),
85 TensorInfo(TensorShape(7U, 7U, 3U, 4U), 1, DataType::F32),
86 TensorInfo(TensorShape(5U, 5U, 3U, 4U), 1, DataType::F32),
Michele Di Giorgio578a9fc2019-08-23 11:49:04 +010087 TensorInfo(TensorShape(7U, 7U, 3U, 4U), 1, DataType::QASYMM8, QuantizationInfo(1.f / 255.f, 120)),
88 TensorInfo(TensorShape(7U, 7U, 3U, 4U), 1, DataType::QASYMM8, QuantizationInfo(1.f / 255.f, 120)),
giuros0118870812018-09-13 09:31:40 +010089 })),
90 framework::dataset::make("PoolInfo", { ROIPoolingLayerInfo(7U, 7U, 1./8),
91 ROIPoolingLayerInfo(7U, 7U, 1./8),
92 ROIPoolingLayerInfo(7U, 7U, 1./8),
93 ROIPoolingLayerInfo(7U, 7U, 1./8),
94 ROIPoolingLayerInfo(7U, 7U, 1./8),
Manuel Bottini60f0a412018-10-24 17:27:02 +010095 ROIPoolingLayerInfo(7U, 7U, 1./8),
96 ROIPoolingLayerInfo(7U, 7U, 1./8),
Michele Di Giorgio578a9fc2019-08-23 11:49:04 +010097 ROIPoolingLayerInfo(7U, 7U, 1./8),
giuros0118870812018-09-13 09:31:40 +010098 })),
Michele Di Giorgio578a9fc2019-08-23 11:49:04 +010099 framework::dataset::make("Expected", { true, false, false, false, false, false, false, false, false })),
Manuel Bottini60f0a412018-10-24 17:27:02 +0100100 input_info, rois_info, output_info, pool_info, expected)
giuros0118870812018-09-13 09:31:40 +0100101{
Manuel Bottini60f0a412018-10-24 17:27:02 +0100102 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);
giuros0118870812018-09-13 09:31:40 +0100103}
104// clang-format on
105// *INDENT-ON*
106
Manuel Bottini8481d832019-12-10 15:28:40 +0000107using CLROIAlignLayerFloatFixture = ROIAlignLayerFixture<CLTensor, CLAccessor, CLROIAlignLayer, float, float>;
108using CLROIAlignLayerHalfFixture = ROIAlignLayerFixture<CLTensor, CLAccessor, CLROIAlignLayer, half, half>;
giuros0118870812018-09-13 09:31:40 +0100109
110TEST_SUITE(Float)
Michele Di Giorgio578a9fc2019-08-23 11:49:04 +0100111TEST_SUITE(FP32)
Manuel Bottini8481d832019-12-10 15:28:40 +0000112FIXTURE_DATA_TEST_CASE(Small, CLROIAlignLayerFloatFixture, framework::DatasetMode::ALL,
Michele Di Giorgio578a9fc2019-08-23 11:49:04 +0100113 combine(combine(datasets::SmallROIDataset(),
114 framework::dataset::make("DataType", { DataType::F32 })),
115 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
giuros0118870812018-09-13 09:31:40 +0100116{
117 // Validate output
giuros01eddff5a2018-10-05 14:48:58 +0100118 validate(CLAccessor(_target), _reference, relative_tolerance_f32, .02f, absolute_tolerance_f32);
giuros0118870812018-09-13 09:31:40 +0100119}
Michele Di Giorgio578a9fc2019-08-23 11:49:04 +0100120TEST_SUITE_END() // FP32
121TEST_SUITE(FP16)
Manuel Bottini8481d832019-12-10 15:28:40 +0000122FIXTURE_DATA_TEST_CASE(Small, CLROIAlignLayerHalfFixture, framework::DatasetMode::ALL,
Michele Di Giorgio578a9fc2019-08-23 11:49:04 +0100123 combine(combine(datasets::SmallROIDataset(),
124 framework::dataset::make("DataType", { DataType::F16 })),
125 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
Manuel Bottini60f0a412018-10-24 17:27:02 +0100126{
127 // Validate output
128 validate(CLAccessor(_target), _reference, relative_tolerance_f16, .02f, absolute_tolerance_f16);
129}
Michele Di Giorgio578a9fc2019-08-23 11:49:04 +0100130TEST_SUITE_END() // FP16
giuros0118870812018-09-13 09:31:40 +0100131TEST_SUITE_END() // Float
132
Michele Di Giorgio578a9fc2019-08-23 11:49:04 +0100133template <typename T>
Manuel Bottini8481d832019-12-10 15:28:40 +0000134using CLROIAlignLayerQuantizedFixture = ROIAlignLayerQuantizedFixture<CLTensor, CLAccessor, CLROIAlignLayer, T, uint16_t>;
Michele Di Giorgio578a9fc2019-08-23 11:49:04 +0100135
136TEST_SUITE(Quantized)
137TEST_SUITE(QASYMM8)
138FIXTURE_DATA_TEST_CASE(Small, CLROIAlignLayerQuantizedFixture<uint8_t>, framework::DatasetMode::ALL,
139 combine(combine(combine(combine(datasets::SmallROIDataset(),
140 framework::dataset::make("DataType", { DataType::QASYMM8 })),
141 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })),
142 framework::dataset::make("InputQuantizationInfo", { QuantizationInfo(1.f / 255.f, 127) })),
143 framework::dataset::make("OutputQuantizationInfo", { QuantizationInfo(2.f / 255.f, 120) })))
144{
145 // Validate output
146 validate(CLAccessor(_target), _reference, tolerance_qasymm8);
147}
148TEST_SUITE_END() // QASYMM8
Manuel Bottini8481d832019-12-10 15:28:40 +0000149TEST_SUITE(QASYMM8_SIGNED)
150FIXTURE_DATA_TEST_CASE(Small, CLROIAlignLayerQuantizedFixture<int8_t>, framework::DatasetMode::ALL,
151 combine(combine(combine(combine(datasets::SmallROIDataset(),
152 framework::dataset::make("DataType", { DataType::QASYMM8_SIGNED })),
153 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })),
154 framework::dataset::make("InputQuantizationInfo", { QuantizationInfo(1.f / 255.f, 65) })),
155 framework::dataset::make("OutputQuantizationInfo", { QuantizationInfo(2.f / 255.f, 20) })))
156{
157 // Validate output
158 validate(CLAccessor(_target), _reference, tolerance_qasymm8_s);
159}
160TEST_SUITE_END() // QASYMM8_SIGNED
Michele Di Giorgio578a9fc2019-08-23 11:49:04 +0100161TEST_SUITE_END() // Quantized
162
giuros0118870812018-09-13 09:31:40 +0100163TEST_SUITE_END() // RoiAlign
164TEST_SUITE_END() // CL
165} // namespace validation
166} // namespace test
167} // namespace arm_compute