Compute Library
 21.02
PadLayer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-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"
28 #include "tests/NEON/Accessor.h"
30 #include "tests/datasets/ShapeDatasets.h"
32 #include "tests/framework/Macros.h"
35 #include "tests/validation/fixtures/PadLayerFixture.h"
36 
37 namespace arm_compute
38 {
39 namespace test
40 {
41 namespace validation
42 {
43 namespace
44 {
45 const auto PaddingSizesDataset = framework::dataset::make("PaddingSize",
46 {
47  PaddingList{ { 0, 0 } },
48  PaddingList{ { 1, 1 } },
49  PaddingList{ { 1, 1 }, { 2, 2 } },
50  PaddingList{ { 1, 1 }, { 1, 1 }, { 1, 1 } },
51  PaddingList{ { 0, 0 }, { 1, 0 }, { 0, 1 } },
52  PaddingList{ { 0, 1 }, { 1, 0 }, { 0, 1 } },
53 });
54 } // namespace
55 
56 TEST_SUITE(NEON)
57 TEST_SUITE(PadLayer)
58 
59 // *INDENT-OFF*
60 // clang-format off
61 
62 DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
63  framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Mismatching data type input/output
64  TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
65  TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32),
66  TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32),
67  TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32),
68  TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
69  TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Mismatching data type input/output
70  TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
71  TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32),
72  TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32),
73  TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32),
75  }),
76  framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F16),
77  TensorInfo(TensorShape(28U, 11U, 2U), 1, DataType::F32),
78  TensorInfo(TensorShape(29U, 17U, 2U), 1, DataType::F32),
79  TensorInfo(TensorShape(29U, 15U, 4U, 3U), 1, DataType::F32),
80  TensorInfo(TensorShape(27U, 14U, 3U, 4U), 1, DataType::F32),
81  TensorInfo(TensorShape(32U, 13U, 2U, 3U), 1, DataType::F32),
82  TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F16),
83  TensorInfo(TensorShape(28U, 11U, 2U), 1, DataType::F32),
84  TensorInfo(TensorShape(29U, 17U, 2U), 1, DataType::F32),
85  TensorInfo(TensorShape(29U, 15U, 4U, 3U), 1, DataType::F32),
86  TensorInfo(TensorShape(27U, 14U, 3U, 4U), 1, DataType::F32),
87  TensorInfo(TensorShape(32U, 13U, 2U, 3U), 1, DataType::F32)
88  })),
89  framework::dataset::make("PaddingSize", { PaddingList{{0, 0}},
90  PaddingList{{1, 1}},
91  PaddingList{{1, 1}, {2, 2}},
92  PaddingList{{1,1}, {1,1}, {1,1}, {1,1}},
93  PaddingList{{0,0}, {1,0}, {0,1}, {1,2}},
94  PaddingList{{0,0}, {0,0}, {0,0}, {1,1}},
95  PaddingList{{0, 0}},
96  PaddingList{{1, 1}},
97  PaddingList{{1, 1}, {2, 2}},
98  PaddingList{{1,1}, {1,1}, {1,1}, {1,1}},
99  PaddingList{{0,0}, {1,0}, {0,1}, {1,2}},
100  PaddingList{{0,0}, {0,0}, {0,0}, {1,1}}
101  })),
114  framework::dataset::make("Expected", { false, false, true, true, true, true, false, false, true, false, false, true })),
115  input_info, output_info, padding, mode, expected)
116 {
117  ARM_COMPUTE_EXPECT(bool(NEPadLayer::validate(&input_info.clone()->set_is_resizable(true), &output_info.clone()->set_is_resizable(true), padding, PixelValue(), mode)) == expected, framework::LogLevel::ERRORS);
118 }
119 
120 // clang-format on
121 // *INDENT-ON*
122 
123 template <typename T>
124 using NEPaddingFixture = PaddingFixture<Tensor, Accessor, NEPadLayer, T>;
125 
126 TEST_SUITE(Float)
127 
128 TEST_SUITE(FP32)
129 FIXTURE_DATA_TEST_CASE(RunSmall, NEPaddingFixture<float>, framework::DatasetMode::ALL,
130  combine(combine(combine(datasets::Small3DShapes(), framework::dataset::make("DataType", { DataType::F32 })),
133 {
134  // Validate output
135  validate(Accessor(_target), _reference);
136 }
138  combine(combine(combine(datasets::Large3DShapes(), framework::dataset::make("DataType", { DataType::F32 })),
141 {
142  // Validate output
143  validate(Accessor(_target), _reference);
144 }
145 TEST_SUITE_END() // FP32
146 
147 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
148 TEST_SUITE(FP16)
150  combine(combine(combine(datasets::Small3DShapes(), framework::dataset::make("DataType", { DataType::F16 })),
153 {
154  // Validate output
155  validate(Accessor(_target), _reference);
156 }
158  combine(combine(combine(datasets::Large3DShapes(), framework::dataset::make("DataType", { DataType::F16 })),
161 {
162  // Validate output
163  validate(Accessor(_target), _reference);
164 }
165 TEST_SUITE_END() // FP16
166 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
167 TEST_SUITE_END() // Float
168 
169 TEST_SUITE(Quantized)
171 FIXTURE_DATA_TEST_CASE(RunSmall, NEPaddingFixture<uint8_t>, framework::DatasetMode::ALL,
172  combine(combine(combine(datasets::Small3DShapes(), framework::dataset::make("DataType", { DataType::QASYMM8 })),
175 {
176  // Validate output
177  validate(Accessor(_target), _reference);
178 }
180  combine(combine(combine(datasets::Large3DShapes(), framework::dataset::make("DataType", { DataType::QASYMM8 })),
183 {
184  // Validate output
185  validate(Accessor(_target), _reference);
186 }
187 TEST_SUITE_END() // QASYMM8
188 TEST_SUITE_END() // Quantized
189 
190 TEST_SUITE_END() // PadLayer
191 TEST_SUITE_END() // Neon
192 } // namespace validation
193 } // namespace test
194 } // namespace arm_compute
Class describing the value of a pixel for any image format.
Definition: PixelValue.h:34
Shape of a tensor.
Definition: TensorShape.h:39
std::vector< PaddingInfo > PaddingList
List of padding information.
Definition: Types.h:481
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-2021 Arm Limited.
1 channel, 1 F16 per channel
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]
static Status validate(const ITensorInfo *input, const ITensorInfo *output, const PaddingList &padding, const PixelValue constant_value=PixelValue(), const PaddingMode mode=PaddingMode::CONSTANT)
Static function to check if given info will lead to a valid configuration of NEPadLayer.
Definition: NEPadLayer.cpp:206
quantized, asymmetric fixed-point 8-bit number unsigned
TEST_SUITE(U8_to_S8) FIXTURE_DATA_TEST_CASE(RunSmall
validate(CLAccessor(output_state), expected_output)
PaddingFixture< Tensor, Accessor, NEPadLayer, T > NEPaddingFixture
Definition: PadLayer.cpp:124
FIXTURE_DATA_TEST_CASE(RunSmall, CLAbsLayerFixture< half >, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F16)))
Definition: AbsLayer.cpp:50
Store the tensor&#39;s metadata.
Definition: TensorInfo.h:45
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}))
DataType
Available data types.
Definition: Types.h:77
combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F32)))
Definition: AbsLayer.cpp:65