Compute Library
 22.11
BoundingBoxTransform.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/ShapeDatasets.h"
32 #include "tests/framework/Macros.h"
35 #include "tests/validation/fixtures/BoundingBoxTransformFixture.h"
36 #include "utils/TypePrinter.h"
37 
38 namespace arm_compute
39 {
40 namespace test
41 {
42 namespace validation
43 {
44 namespace
45 {
46 RelativeTolerance<float> relative_tolerance_f32(0.01f);
47 AbsoluteTolerance<float> absolute_tolerance_f32(0.001f);
48 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
49 RelativeTolerance<half> relative_tolerance_f16(half(0.2));
50 AbsoluteTolerance<float> absolute_tolerance_f16(half(0.02f));
51 #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
52 
53 constexpr AbsoluteTolerance<uint16_t> tolerance_qasymm16(1);
54 
55 // *INDENT-OFF*
56 // clang-format off
57 const auto BboxInfoDataset = framework::dataset::make("BboxInfo", { BoundingBoxTransformInfo(20U, 20U, 2U, true),
58  BoundingBoxTransformInfo(128U, 128U, 4U, true),
59  BoundingBoxTransformInfo(800U, 600U, 1U, false),
60  BoundingBoxTransformInfo(800U, 600U, 2U, true, { { 1.0, 0.5, 1.5, 2.0 } }),
61  BoundingBoxTransformInfo(800U, 600U, 4U, false, { { 1.0, 0.5, 1.5, 2.0 } }),
62  BoundingBoxTransformInfo(800U, 600U, 4U, false, { { 1.0, 0.5, 1.5, 2.0 } }, true)
63  });
64 
65 const auto DeltaDataset = framework::dataset::make("DeltasShape", { TensorShape(36U, 1U),
66  TensorShape(36U, 2U),
67  TensorShape(36U, 2U),
68  TensorShape(40U, 1U),
69  TensorShape(40U, 20U),
70  TensorShape(40U, 100U),
71  TensorShape(40U, 200U)
72  });
73 // clang-format on
74 // *INDENT-ON*
75 } // namespace
76 
77 TEST_SUITE(NEON)
78 TEST_SUITE(BBoxTransform)
79 
80 // *INDENT-OFF*
81 // clang-format off
83  framework::dataset::make("BoxesInfo", { TensorInfo(TensorShape(4U, 128U), 1, DataType::F32),
84  TensorInfo(TensorShape(5U, 128U), 1, DataType::F32), // Wrong number of box fields
85  TensorInfo(TensorShape(4U, 128U), 1, DataType::F16), // Wrong data type
86  TensorInfo(TensorShape(4U, 128U), 1, DataType::F32), // Wrong number of classes
87  TensorInfo(TensorShape(4U, 128U), 1, DataType::F32), // Deltas and predicted boxes have different dimensions
88  TensorInfo(TensorShape(4U, 128U), 1, DataType::F32)}), // Scaling is zero
89  framework::dataset::make("PredBoxesInfo",{ TensorInfo(TensorShape(128U, 128U), 1, DataType::F32),
90  TensorInfo(TensorShape(128U, 128U), 1, DataType::F32),
91  TensorInfo(TensorShape(127U, 128U), 1, DataType::F32),
92  TensorInfo(TensorShape(128U, 100U), 1, DataType::F32),
93  TensorInfo(TensorShape(128U, 100U), 1, DataType::F32),
94  TensorInfo(TensorShape(128U, 128U), 1, DataType::F32)})),
95  framework::dataset::make("DeltasInfo", { TensorInfo(TensorShape(128U, 128U), 1, DataType::F32),
96  TensorInfo(TensorShape(128U, 128U), 1, DataType::F32),
97  TensorInfo(TensorShape(127U, 128U), 1, DataType::F32),
98  TensorInfo(TensorShape(128U, 100U), 1, DataType::F32),
99  TensorInfo(TensorShape(128U, 128U), 1, DataType::F32),
100  TensorInfo(TensorShape(128U, 128U), 1, DataType::F32)})),
101  framework::dataset::make("BoundingBoxTransofmInfo", { BoundingBoxTransformInfo(800.f, 600.f, 1.f),
102  BoundingBoxTransformInfo(800.f, 600.f, 1.f),
103  BoundingBoxTransformInfo(800.f, 600.f, 1.f),
104  BoundingBoxTransformInfo(800.f, 600.f, 1.f),
105  BoundingBoxTransformInfo(800.f, 600.f, 0.f)})),
106  framework::dataset::make("Expected", { true, false, false, false, false, false})),
107  boxes_info, pred_boxes_info, deltas_info, bbox_info, expected)
108 {
109  ARM_COMPUTE_EXPECT(bool(NEBoundingBoxTransform::validate(&boxes_info.clone()->set_is_resizable(true), &pred_boxes_info.clone()->set_is_resizable(true), &deltas_info.clone()->set_is_resizable(true), bbox_info)) == expected, framework::LogLevel::ERRORS);
110 }
111 // clang-format on
112 // *INDENT-ON*
113 
114 template <typename T>
115 using NEBoundingBoxTransformFixture = BoundingBoxTransformFixture<Tensor, Accessor, NEBoundingBoxTransform, T>;
116 
117 TEST_SUITE(Float)
118 TEST_SUITE(FP32)
120  combine(combine(DeltaDataset, BboxInfoDataset), framework::dataset::make("DataType", { DataType::F32 })))
121 {
122  // Validate output
123  validate(Accessor(_target), _reference, relative_tolerance_f32, 0.f, absolute_tolerance_f32);
124 }
125 TEST_SUITE_END() // FP32
126 
127 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
128 TEST_SUITE(FP16)
130  combine(combine(DeltaDataset, BboxInfoDataset), framework::dataset::make("DataType", { DataType::F16 })))
131 {
132  // Validate output
133  validate(Accessor(_target), _reference, relative_tolerance_f16, 0.03f, absolute_tolerance_f16);
134 }
135 TEST_SUITE_END() // FP16
136 #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
137 
138 TEST_SUITE_END() // Float
139 
140 TEST_SUITE(Quantized)
142 template <typename T>
143 using NEBoundingBoxTransformQuantizedFixture = BoundingBoxTransformQuantizedFixture<Tensor, Accessor, NEBoundingBoxTransform, T>;
144 
145 FIXTURE_DATA_TEST_CASE(BoundingBox, NEBoundingBoxTransformQuantizedFixture<uint16_t>, framework::DatasetMode::ALL,
146  combine(combine(combine(DeltaDataset, BboxInfoDataset), framework::dataset::make("DataType", { DataType::QASYMM16 })),
147  framework::dataset::make("DeltasQuantInfo", { QuantizationInfo(0.125f, 0) })))
148 {
149  // Validate output
150  validate(Accessor(_target), _reference, tolerance_qasymm16);
151 }
152 TEST_SUITE_END() // QASYMM16
153 TEST_SUITE_END() // Quantized
154 
155 TEST_SUITE_END() // BBoxTransform
156 TEST_SUITE_END() // Neon
157 } // namespace validation
158 } // namespace test
159 } // namespace arm_compute
half_float::half half
16-bit floating point type
Definition: Types.h:48
1 channel, 1 F32 per channel
ARM_COMPUTE_EXPECT(has_error==expected, framework::LogLevel::ERRORS)
quantized, asymmetric fixed-point 16-bit number
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]
validate(CLAccessor(output_state), expected_output)
FIXTURE_DATA_TEST_CASE(RunSmall, CLAbsLayerFixture< half >, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F16)))
Definition: AbsLayer.cpp:50
static Status validate(const ITensorInfo *boxes, const ITensorInfo *pred_boxes, const ITensorInfo *deltas, const BoundingBoxTransformInfo &info)
Static function to check if given info will lead to a valid configuration of NEBoundingBoxTransform.
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
BoundingBoxTransformFixture< Tensor, Accessor, NEBoundingBoxTransform, T > NEBoundingBoxTransformFixture
combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F32)))
Definition: AbsLayer.cpp:65