diff options
author | Michalis Spyrou <michalis.spyrou@arm.com> | 2018-08-29 16:28:11 +0100 |
---|---|---|
committer | Michalis Spyrou <michalis.spyrou@arm.com> | 2018-11-14 15:42:37 +0000 |
commit | 6c7c38e70c795077ba727aadeefc670888bec089 (patch) | |
tree | 7969d7976b22b881f2c08e97a772a4537e203629 /tests/validation | |
parent | d8e340d2fef39c78a9afda93b210a8640145df87 (diff) | |
download | ComputeLibrary-6c7c38e70c795077ba727aadeefc670888bec089.tar.gz |
COMPMID-1462 SSD support: Create CL PriorBox
Change-Id: I5bf5d751ec7c02d96c26a769f49d03ea23a248b7
Diffstat (limited to 'tests/validation')
-rw-r--r-- | tests/validation/CL/PriorBoxLayer.cpp | 103 | ||||
-rw-r--r-- | tests/validation/fixtures/PriorBoxLayerFixture.h | 112 | ||||
-rw-r--r-- | tests/validation/reference/PriorBoxLayer.cpp | 158 | ||||
-rw-r--r-- | tests/validation/reference/PriorBoxLayer.h | 44 |
4 files changed, 417 insertions, 0 deletions
diff --git a/tests/validation/CL/PriorBoxLayer.cpp b/tests/validation/CL/PriorBoxLayer.cpp new file mode 100644 index 0000000000..79776b5bcd --- /dev/null +++ b/tests/validation/CL/PriorBoxLayer.cpp @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2018 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "arm_compute/core/Types.h" +#include "arm_compute/runtime/CL/CLTensor.h" +#include "arm_compute/runtime/CL/CLTensorAllocator.h" +#include "arm_compute/runtime/CL/functions/CLPriorBoxLayer.h" +#include "tests/CL/CLAccessor.h" +#include "tests/PaddingCalculator.h" +#include "tests/datasets/PriorBoxLayerDataset.h" +#include "tests/datasets/ShapeDatasets.h" +#include "tests/framework/Asserts.h" +#include "tests/framework/Macros.h" +#include "tests/framework/datasets/Datasets.h" +#include "tests/validation/Helpers.h" +#include "tests/validation/Validation.h" +#include "tests/validation/fixtures/PriorBoxLayerFixture.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace +{ +constexpr AbsoluteTolerance<float> tolerance_f32(0.00001f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F32 */ +} // namespace + +TEST_SUITE(CL) +TEST_SUITE(PriorBoxLayer) + +template <typename T> +using CLPriorBoxLayerFixture = PriorBoxLayerValidationFixture<CLTensor, CLAccessor, CLPriorBoxLayer, T>; + +// *INDENT-OFF* +// clang-format off +DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip( + framework::dataset::make("Input1Info", { TensorInfo(TensorShape(10U, 10U, 2U), 1, DataType::F32), + TensorInfo(TensorShape(10U, 10U, 2U), 1, DataType::F32), // Window shrink + }), + framework::dataset::make("Input2Info", { TensorInfo(TensorShape(10U, 10U, 2U), 1, DataType::F32), + TensorInfo(TensorShape(10U, 10U, 2U), 1, DataType::F32), + })), + framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(1200U, 2U), 1, DataType::F32), + TensorInfo(TensorShape(1000U, 2U), 1, DataType::F32), + })), + framework::dataset::make("PriorBoxInfo",{ PriorBoxLayerInfo(std::vector<float>(1), std::vector<float>(1), 0, true, true, std::vector<float>(1), std::vector<float>(1), Coordinates2D{8, 8}, std::array<float, 2>()), + PriorBoxLayerInfo(std::vector<float>(1), std::vector<float>(1), 0, true, true, std::vector<float>(1), std::vector<float>(1), Coordinates2D{8, 8}, std::array<float, 2>()), + })), + framework::dataset::make("Expected", { true, false})), + input1_info, input2_info, output_info, info, expected) +{ + bool has_error = bool(CLPriorBoxLayer::validate(&input1_info.clone()->set_is_resizable(false), &input2_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), info)); + ARM_COMPUTE_EXPECT(has_error == expected, framework::LogLevel::ERRORS); +} +// clang-format on +// *INDENT-ON* + +TEST_SUITE(Float) +TEST_SUITE(FP32) +FIXTURE_DATA_TEST_CASE(RunSmall, CLPriorBoxLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallPriorBoxLayerDataset(), + framework::dataset::make("DataType", DataType::F32)), + framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) +{ + // Validate output + validate(CLAccessor(_target), _reference, tolerance_f32, 0); +} +FIXTURE_DATA_TEST_CASE(RunLarge, CLPriorBoxLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargePriorBoxLayerDataset(), + framework::dataset::make("DataType", DataType::F32)), + framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) +{ + // Validate output + validate(CLAccessor(_target), _reference, tolerance_f32, 0); +} +TEST_SUITE_END() // Float +TEST_SUITE_END() // FP32 + +TEST_SUITE_END() // PriorBoxLayer +TEST_SUITE_END() // CL +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/fixtures/PriorBoxLayerFixture.h b/tests/validation/fixtures/PriorBoxLayerFixture.h new file mode 100644 index 0000000000..dd7a49ee1f --- /dev/null +++ b/tests/validation/fixtures/PriorBoxLayerFixture.h @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2018 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef ARM_COMPUTE_TEST_PRIOR_BOX_LAYER_FIXTURE +#define ARM_COMPUTE_TEST_PRIOR_BOX_LAYER_FIXTURE + +#include "arm_compute/core/TensorShape.h" +#include "arm_compute/core/Types.h" +#include "arm_compute/core/utils/misc/ShapeCalculator.h" +#include "tests/AssetsLibrary.h" +#include "tests/Globals.h" +#include "tests/IAccessor.h" +#include "tests/framework/Asserts.h" +#include "tests/framework/Fixture.h" +#include "tests/validation/Helpers.h" +#include "tests/validation/reference/PriorBoxLayer.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +template <typename TensorType, typename AccessorType, typename FunctionType, typename T> +class PriorBoxLayerValidationFixture : public framework::Fixture +{ +public: + template <typename...> + void setup(TensorShape input_shape, PriorBoxLayerInfo info, DataType data_type, DataLayout data_layout) + { + TensorInfo input_info(input_shape, 1, data_type); + const TensorShape output_shape = misc::shape_calculator::compute_prior_box_shape(input_info, info); + _data_type = data_type; + + _target = compute_target(input_shape, output_shape, info, data_type, data_layout); + _reference = compute_reference(input_shape, output_shape, info, data_type); + } + +protected: + TensorType compute_target(TensorShape input_shape, TensorShape output_shape, PriorBoxLayerInfo info, DataType data_type, DataLayout data_layout) + { + if(data_layout == DataLayout::NHWC) + { + permute(input_shape, PermutationVector(2U, 0U, 1U)); + permute(output_shape, PermutationVector(2U, 0U, 1U)); + } + + // Create tensors + TensorType src1 = create_tensor<TensorType>(input_shape, data_type, 1, QuantizationInfo(), data_layout); + TensorType src2 = create_tensor<TensorType>(input_shape, data_type, 1, QuantizationInfo(), data_layout); + TensorType dst = create_tensor<TensorType>(output_shape, data_type, 1, QuantizationInfo(), data_layout); + + // Create and configure function + FunctionType prior_box; + prior_box.configure(&src1, &src2, &dst, info); + + ARM_COMPUTE_EXPECT(src1.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(src2.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); + + // Allocate tensors + src1.allocator()->allocate(); + src2.allocator()->allocate(); + dst.allocator()->allocate(); + + ARM_COMPUTE_EXPECT(!src1.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(!src2.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS); + + // Compute function + prior_box.run(); + + return dst; + } + + SimpleTensor<T> compute_reference(const TensorShape &input_shape, const TensorShape &output_shape, PriorBoxLayerInfo info, DataType data_type) + { + // Create reference + SimpleTensor<T> input1{ input_shape, data_type, 1 }; + SimpleTensor<T> input2{ input_shape, data_type, 1 }; + + return reference::prior_box_layer(input1, input2, info, output_shape); + } + + TensorType _target{}; + SimpleTensor<T> _reference{}; + DataType _data_type{}; +}; +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_PRIOR_BOX_LAYER_FIXTURE */ diff --git a/tests/validation/reference/PriorBoxLayer.cpp b/tests/validation/reference/PriorBoxLayer.cpp new file mode 100644 index 0000000000..0fd4a8aa48 --- /dev/null +++ b/tests/validation/reference/PriorBoxLayer.cpp @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2018 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "PriorBoxLayer.h" + +#include "ActivationLayer.h" + +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template <typename T> +SimpleTensor<T> prior_box_layer(const SimpleTensor<T> &src1, const SimpleTensor<T> &src2, const PriorBoxLayerInfo &info, const TensorShape &output_shape) +{ + const auto layer_width = static_cast<int>(src1.shape()[0]); + const auto layer_height = static_cast<int>(src1.shape()[1]); + + int img_width = info.img_size().x; + int img_height = info.img_size().y; + if(img_width == 0 || img_height == 0) + { + img_width = static_cast<int>(src2.shape()[0]); + img_height = static_cast<int>(src2.shape()[1]); + } + + float step_x = info.steps()[0]; + float step_y = info.steps()[1]; + if(step_x == 0.f || step_y == 0.f) + { + step_x = static_cast<float>(img_width) / layer_width; + step_x = static_cast<float>(img_height) / layer_height; + } + + // Calculate number of aspect ratios + const int num_priors = info.aspect_ratios().size() * info.min_sizes().size() + info.max_sizes().size(); + const int total_elements = layer_width * layer_height * num_priors * 4; + + SimpleTensor<T> result(output_shape, src1.data_type()); + + int idx = 0; + for(int y = 0; y < layer_height; ++y) + { + for(int x = 0; x < layer_width; ++x) + { + const float center_x = (x + info.offset()) * step_x; + const float center_y = (y + info.offset()) * step_y; + float box_width; + float box_height; + for(unsigned int i = 0; i < info.min_sizes().size(); ++i) + { + const float min_size = info.min_sizes().at(i); + box_width = min_size; + box_height = min_size; + // (xmin, ymin, xmax, ymax) + result[idx++] = (center_x - box_width / 2.f) / img_width; + result[idx++] = (center_y - box_height / 2.f) / img_height; + result[idx++] = (center_x + box_width / 2.f) / img_width; + result[idx++] = (center_y + box_height / 2.f) / img_height; + + if(!info.max_sizes().empty()) + { + const float max_size = info.max_sizes().at(i); + box_width = sqrt(min_size * max_size); + box_height = box_width; + + // (xmin, ymin, xmax, ymax) + result[idx++] = (center_x - box_width / 2.f) / img_width; + result[idx++] = (center_y - box_height / 2.f) / img_height; + result[idx++] = (center_x + box_width / 2.f) / img_width; + result[idx++] = (center_y + box_height / 2.f) / img_height; + } + + // rest of priors + for(auto ar : info.aspect_ratios()) + { + if(fabs(ar - 1.) < 1e-6) + { + continue; + } + + box_width = min_size * sqrt(ar); + box_height = min_size / sqrt(ar); + + // (xmin, ymin, xmax, ymax) + result[idx++] = (center_x - box_width / 2.f) / img_width; + result[idx++] = (center_y - box_height / 2.f) / img_height; + result[idx++] = (center_x + box_width / 2.f) / img_width; + result[idx++] = (center_y + box_height / 2.f) / img_height; + } + } + } + } + + // clip the coordinates + if(info.clip()) + { + for(int i = 0; i < total_elements; ++i) + { + result[i] = std::min<T>(std::max<T>(result[i], 0.f), 1.f); + } + } + + // set the variance. + if(info.variances().size() == 1) + { + std::fill_n(result.data() + idx, total_elements, info.variances().at(0)); + } + else + { + for(int h = 0; h < layer_height; ++h) + { + for(int w = 0; w < layer_width; ++w) + { + for(int i = 0; i < num_priors; ++i) + { + for(int j = 0; j < 4; ++j) + { + result[idx++] = info.variances().at(j); + } + } + } + } + } + + return result; +} +template SimpleTensor<float> prior_box_layer(const SimpleTensor<float> &src1, const SimpleTensor<float> &src2, const PriorBoxLayerInfo &info, const TensorShape &output_shape); + +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/PriorBoxLayer.h b/tests/validation/reference/PriorBoxLayer.h new file mode 100644 index 0000000000..25e567f59a --- /dev/null +++ b/tests/validation/reference/PriorBoxLayer.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2018 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef __ARM_COMPUTE_TEST_PRIOR_BOX_LAYER_H__ +#define __ARM_COMPUTE_TEST_PRIOR_BOX_LAYER_H__ + +#include "tests/SimpleTensor.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template <typename T> +SimpleTensor<T> prior_box_layer(const SimpleTensor<T> &src1, const SimpleTensor<T> &src2, const PriorBoxLayerInfo &info, const TensorShape &output_shape); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_PRIOR_BOX_LAYER_H__ */ |