Compute Library
 22.05
ROIAlignLayer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2021 Arm Limited.
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/core/Types.h"
25 
29 #include "tests/Globals.h"
30 #include "tests/NEON/Accessor.h"
31 #include "tests/datasets/ROIDataset.h"
32 #include "tests/datasets/ShapeDatasets.h"
33 #include "tests/framework/Macros.h"
36 #include "tests/validation/fixtures/ROIAlignLayerFixture.h"
37 #include "utils/TypePrinter.h"
38 
39 namespace arm_compute
40 {
41 namespace test
42 {
43 namespace validation
44 {
45 namespace
46 {
47 RelativeTolerance<float> relative_tolerance_f32(0.01f);
48 AbsoluteTolerance<float> absolute_tolerance_f32(0.001f);
49 
50 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
51 RelativeTolerance<float> relative_tolerance_f16(0.01f);
52 AbsoluteTolerance<float> absolute_tolerance_f16(0.001f);
53 #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
54 
55 constexpr AbsoluteTolerance<uint8_t> tolerance_qasymm8(1);
56 constexpr AbsoluteTolerance<int8_t> tolerance_qasymm8_s(1);
57 } // namespace
58 
59 TEST_SUITE(NEON)
60 TEST_SUITE(RoiAlign)
61 
62 // *INDENT-OFF*
63 // clang-format off
64 DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
65  framework::dataset::make("InputInfo", { TensorInfo(TensorShape(250U, 128U, 3U), 1, DataType::F32),
66  TensorInfo(TensorShape(250U, 128U, 3U), 1, DataType::F32), // Mismatching data type input/rois
67  TensorInfo(TensorShape(250U, 128U, 3U), 1, DataType::F32), // Mismatching data type input/output
68  TensorInfo(TensorShape(250U, 128U, 2U), 1, DataType::F32), // Mismatching depth size input/output
69  TensorInfo(TensorShape(250U, 128U, 3U), 1, DataType::F32), // Mismatching number of rois and output batch size
70  TensorInfo(TensorShape(250U, 128U, 3U), 1, DataType::F32), // Invalid number of values per ROIS
71  TensorInfo(TensorShape(250U, 128U, 3U), 1, DataType::F32), // Mismatching height and width input/output
72 
73  }),
81  })),
82  framework::dataset::make("OutputInfo",{ 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::F16),
85  TensorInfo(TensorShape(7U, 7U, 3U, 4U), 1, DataType::F32),
86  TensorInfo(TensorShape(7U, 7U, 3U, 4U), 1, DataType::F32),
87  TensorInfo(TensorShape(7U, 7U, 3U, 4U), 1, DataType::F32),
88  TensorInfo(TensorShape(5U, 5U, 3U, 4U), 1, DataType::F32),
89  })),
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),
95  ROIPoolingLayerInfo(7U, 7U, 1./8),
96  ROIPoolingLayerInfo(7U, 7U, 1./8),
97  })),
98  framework::dataset::make("Expected", { true, false, false, false, false, false, false })),
99  input_info, rois_info, output_info, pool_info, expected)
100 {
101  ARM_COMPUTE_EXPECT(bool(NEROIAlignLayer::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);
102 }
103 
104 // clang-format on
105 // *INDENT-ON*
106 
107 using NEROIAlignLayerFloatFixture = ROIAlignLayerFixture<Tensor, Accessor, NEROIAlignLayer, float, float>;
108 
109 TEST_SUITE(Float)
110 FIXTURE_DATA_TEST_CASE(SmallROIAlignLayerFloat, NEROIAlignLayerFloatFixture, framework::DatasetMode::ALL,
111  framework::dataset::combine(framework::dataset::combine(datasets::SmallROIDataset(),
112  framework::dataset::make("DataType", { DataType::F32 })),
114 {
115  // Validate output
116  validate(Accessor(_target), _reference, relative_tolerance_f32, .02f, absolute_tolerance_f32);
117 }
118 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
119 using NEROIAlignLayerHalfFixture = ROIAlignLayerFixture<Tensor, Accessor, NEROIAlignLayer, half, half>;
120 FIXTURE_DATA_TEST_CASE(SmallROIAlignLayerHalf, NEROIAlignLayerHalfFixture, framework::DatasetMode::ALL,
121  framework::dataset::combine(framework::dataset::combine(datasets::SmallROIDataset(),
122  framework::dataset::make("DataType", { DataType::F16 })),
124 {
125  // Validate output
126  validate(Accessor(_target), _reference, relative_tolerance_f16, .02f, absolute_tolerance_f16);
127 }
128 #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
129 
130 TEST_SUITE_END() // Float
131 
132 TEST_SUITE(Quantized)
133 template <typename T>
134 using NEROIAlignLayerQuantizedFixture = ROIAlignLayerQuantizedFixture<Tensor, Accessor, NEROIAlignLayer, T, uint16_t>;
135 
137 FIXTURE_DATA_TEST_CASE(Small, NEROIAlignLayerQuantizedFixture<uint8_t>, framework::DatasetMode::ALL,
138  combine(combine(combine(combine(datasets::SmallROIDataset(),
139  framework::dataset::make("DataType", { DataType::QASYMM8 })),
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(Accessor(_target), _reference, tolerance_qasymm8);
146 }
147 TEST_SUITE_END() // QASYMM8
148 
150 FIXTURE_DATA_TEST_CASE(Small, NEROIAlignLayerQuantizedFixture<int8_t>, framework::DatasetMode::ALL,
151  combine(combine(combine(combine(datasets::SmallROIDataset(),
152  framework::dataset::make("DataType", { DataType::QASYMM8_SIGNED })),
154  framework::dataset::make("InputQuantizationInfo", { QuantizationInfo(1.f / 255.f, 127) })),
155  framework::dataset::make("OutputQuantizationInfo", { QuantizationInfo(2.f / 255.f, 120) })))
156 {
157  // Validate output
158  validate(Accessor(_target), _reference, tolerance_qasymm8_s);
159 }
160 TEST_SUITE_END() // QASYMM8_SIGNED
161 TEST_SUITE_END() // Quantized
162 
163 TEST_SUITE_END() // RoiAlign
164 TEST_SUITE_END() // Neon
165 } // namespace validation
166 } // namespace test
167 } // namespace arm_compute
ROIAlignLayerFixture< Tensor, Accessor, NEROIAlignLayer, float, float > NEROIAlignLayerFloatFixture
static Status validate(const ITensorInfo *input, const ITensorInfo *rois, ITensorInfo *output, const ROIPoolingLayerInfo &pool_info)
Static function to check if given info will lead to a valid configuration of NEROIAlignLayerKernel.
Shape of a tensor.
Definition: TensorShape.h:39
1 channel, 1 F32 per channel
ARM_COMPUTE_EXPECT(has_error==expected, framework::LogLevel::ERRORS)
std::enable_if< is_container< T >::value, ContainerDataset< T > >::type make(std::string name, T &&values)
Helper function to create a ContainerDataset.
Copyright (c) 2017-2022 Arm Limited.
1 channel, 1 F16 per channel
Quantization information.
DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QASYMM8), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16), }), framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F16), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QASYMM8), TensorInfo(TensorShape(30U, 11U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16, QuantizationInfo(1.f/32768.f, 0)), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16, QuantizationInfo(1.f/32768.f, 0)), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16, QuantizationInfo(1.f/32768.f, 0)), })), framework::dataset::make("ActivationInfo", { ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::TANH), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::TANH), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::SQRT), })), framework::dataset::make("Expected", { false, true, true, true, false, false, true, true, false })), input_info, output_info, act_info, expected)
Accessor implementation for Tensor objects.
Definition: Accessor.h:35
DatasetMode
Possible dataset modes.
Definition: DatasetModes.h:40
TEST_SUITE_END() FIXTURE_DATA_TEST_CASE(RunSmall
[CLActivationLayer Test snippet]
quantized, asymmetric fixed-point 8-bit number unsigned
validate(CLAccessor(output_state), expected_output)
CartesianProductDataset< T, U > combine(T &&dataset1, U &&dataset2)
Helper function to create a CartesianProductDataset.
Num samples, channels, height, width.
FIXTURE_DATA_TEST_CASE(RunSmall, CLAbsLayerFixture< half >, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F16)))
Definition: AbsLayer.cpp:50
ROI Pooling Layer Information class.
Definition: Types.h:1384
Num samples, height, width, channels.
Store the tensor&#39;s metadata.
Definition: TensorInfo.h:43
quantized, asymmetric fixed-point 8-bit number signed
zip(zip(framework::dataset::make("Weights", { TensorInfo(TensorShape(32U, 13U, 2U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U, 1U), 1, DataType::F32), }), framework::dataset::make("MVBGInfo",{ TensorInfo(TensorShape(2U), 1, DataType::F32), TensorInfo(TensorShape(2U), 1, DataType::F16), TensorInfo(TensorShape(5U), 1, DataType::F32), })), framework::dataset::make("Expected", { true, false, false}))
TEST_SUITE(QASYMM8_to_F32) FIXTURE_DATA_TEST_CASE(RunSmall
DataType
Available data types.
Definition: Types.h:79
combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F32)))
Definition: AbsLayer.cpp:65