blob: ec804ccb84ffe03c654ee2db51ff26e0f2c16090 [file] [log] [blame]
SiCong Li3e363692017-07-04 15:02:10 +01001/*
2 * Copyright (c) 2017 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 "CL/CLAccessor.h"
25#include "CL/CLArrayAccessor.h"
SiCong Li3e363692017-07-04 15:02:10 +010026#include "arm_compute/runtime/CL/CLArray.h"
27#include "arm_compute/runtime/CL/functions/CLROIPoolingLayer.h"
28#include "tests/Globals.h"
29#include "tests/Utils.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010030#include "tests/validation_old/Datasets.h"
31#include "tests/validation_old/Reference.h"
32#include "tests/validation_old/Validation.h"
33#include "tests/validation_old/ValidationUserConfiguration.h"
Anthony Barbier2a07e182017-08-04 18:20:27 +010034#include "utils/TypePrinter.h"
SiCong Li3e363692017-07-04 15:02:10 +010035
36#include <random>
37#include <vector>
38
39using namespace arm_compute;
40using namespace arm_compute::test;
41using namespace arm_compute::test::validation;
42
43namespace
44{
45CLTensor compute_roi_pooling_layer(const TensorShape &shape, DataType dt, const std::vector<ROI> &rois, ROIPoolingLayerInfo pool_info)
46{
47 TensorShape shape_dst;
48 shape_dst.set(0, pool_info.pooled_width());
49 shape_dst.set(1, pool_info.pooled_height());
50 shape_dst.set(2, shape.z());
51 shape_dst.set(3, rois.size());
52
53 // Create tensors
54 CLTensor src = create_tensor<CLTensor>(shape, dt);
55 CLTensor dst = create_tensor<CLTensor>(shape_dst, dt);
56
57 // Create ROI array
58 CLArray<ROI> rois_array(rois.size());
59 fill_array(CLArrayAccessor<ROI>(rois_array), rois);
60
61 // Create and configure function
62 CLROIPoolingLayer roi_pool;
63 roi_pool.configure(&src, &rois_array, &dst, pool_info);
64
65 // Allocate tensors
66 src.allocator()->allocate();
67 dst.allocator()->allocate();
68
69 BOOST_TEST(!src.info()->is_resizable());
70 BOOST_TEST(!dst.info()->is_resizable());
71
72 // Fill tensors
73 std::uniform_real_distribution<> distribution(-1, 1);
74 library->fill(CLAccessor(src), distribution, 0);
75
76 // Compute function
77 roi_pool.run();
78
79 return dst;
80}
81} // namespace
82
83#ifndef DOXYGEN_SKIP_THIS
84BOOST_AUTO_TEST_SUITE(CL)
85BOOST_AUTO_TEST_SUITE(ROIPoolingLayer)
86
87BOOST_AUTO_TEST_SUITE(Float)
SiCong Licfb65532017-09-12 19:06:28 +010088BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit"))
SiCong Li3e363692017-07-04 15:02:10 +010089BOOST_DATA_TEST_CASE(RunSmall, boost::unit_test::data::make({ DataType::F16, DataType::F32 }) * boost::unit_test::data::make({ 10, 20, 40 }) * boost::unit_test::data::make({ 7, 9 }) *
90 boost::unit_test::data::make({ 1.f / 8.f, 1.f / 16.f }),
91 dt, num_rois, roi_pool_size, roi_scale)
92{
93 TensorShape shape(50U, 47U, 2U, 3U);
94 ROIPoolingLayerInfo pool_info(roi_pool_size, roi_pool_size, roi_scale);
95
96 // Construct ROI vector
97 std::vector<ROI> rois = generate_random_rois(shape, pool_info, num_rois, user_config.seed);
98
99 // Compute function
100 CLTensor dst = compute_roi_pooling_layer(shape, dt, rois, pool_info);
101
102 // Compute reference
103 RawTensor ref_dst = Reference::compute_reference_roi_pooling_layer(shape, dt, rois, pool_info);
104
105 // Validate output
106 validate(CLAccessor(dst), ref_dst);
107}
108BOOST_AUTO_TEST_SUITE_END()
109
110BOOST_AUTO_TEST_SUITE_END()
111BOOST_AUTO_TEST_SUITE_END()
112#endif /* DOXYGEN_SKIP_THIS */