blob: 08b051e9c90af190ccc91f05afd5e6a226d28c71 [file] [log] [blame]
Georgios Pinitas7b7858d2017-06-21 16:44:24 +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 "NEON/Helper.h"
25#include "NEON/NEAccessor.h"
26#include "TypePrinter.h"
27#include "arm_compute/runtime/NEON/functions/NEROIPoolingLayer.h"
Moritz Pflanzer94450f12017-06-30 12:48:43 +010028#include "tests/Globals.h"
29#include "tests/Utils.h"
Georgios Pinitas7b7858d2017-06-21 16:44:24 +010030#include "validation/Datasets.h"
31#include "validation/Helpers.h"
32#include "validation/Reference.h"
33#include "validation/Validation.h"
34#include "validation/ValidationUserConfiguration.h"
35
36#include <random>
Georgios Pinitasd4f8c272017-06-30 16:16:19 +010037#include <vector>
Georgios Pinitas7b7858d2017-06-21 16:44:24 +010038
39using namespace arm_compute;
40using namespace arm_compute::test;
41using namespace arm_compute::test::neon;
42using namespace arm_compute::test::validation;
43
44namespace
45{
46Tensor compute_roi_pooling_layer(const TensorShape &shape, DataType dt, const std::vector<ROI> &rois, ROIPoolingLayerInfo pool_info)
47{
48 TensorShape shape_dst;
49 shape_dst.set(0, pool_info.pooled_width());
50 shape_dst.set(1, pool_info.pooled_height());
51 shape_dst.set(2, shape.z());
52 shape_dst.set(3, rois.size());
53
54 // Create tensors
Moritz Pflanzer94450f12017-06-30 12:48:43 +010055 Tensor src = create_tensor<Tensor>(shape, dt);
56 Tensor dst = create_tensor<Tensor>(shape_dst, dt);
Georgios Pinitas7b7858d2017-06-21 16:44:24 +010057 Array<ROI> rois_array = create_array(rois);
58
59 // Create and configure function
60 NEROIPoolingLayer roi_pool;
61 roi_pool.configure(&src, &rois_array, &dst, pool_info);
62
63 // Allocate tensors
64 src.allocator()->allocate();
65 dst.allocator()->allocate();
66
67 BOOST_TEST(!src.info()->is_resizable());
68 BOOST_TEST(!dst.info()->is_resizable());
69
70 // Fill tensors
71 std::uniform_real_distribution<> distribution(-1, 1);
72 library->fill(NEAccessor(src), distribution, 0);
73
74 // Compute function
75 roi_pool.run();
76
77 return dst;
78}
79} // namespace
80
81#ifndef DOXYGEN_SKIP_THIS
82BOOST_AUTO_TEST_SUITE(NEON)
83BOOST_AUTO_TEST_SUITE(ROIPoolingLayer)
84
85BOOST_AUTO_TEST_SUITE(Float)
86BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit"))
87BOOST_DATA_TEST_CASE(RunSmall, CNNFloatDataTypes() * boost::unit_test::data::make({ 10, 20, 40 }) * boost::unit_test::data::make({ 7, 9 }) * boost::unit_test::data::make({ 1.f / 8.f, 1.f / 16.f }),
88 dt, num_rois, roi_pool_size, roi_scale)
89{
90 TensorShape shape(50U, 47U, 2U, 3U);
91 ROIPoolingLayerInfo pool_info(roi_pool_size, roi_pool_size, roi_scale);
92
93 // Construct ROI vector
94 std::vector<ROI> rois = generate_random_rois(shape, pool_info, num_rois, user_config.seed);
95
96 // Compute function
97 Tensor dst = compute_roi_pooling_layer(shape, dt, rois, pool_info);
98
99 // Compute reference
100 RawTensor ref_dst = Reference::compute_reference_roi_pooling_layer(shape, dt, rois, pool_info);
101
102 // Validate output
103 validate(NEAccessor(dst), ref_dst);
104}
105BOOST_AUTO_TEST_SUITE_END()
106
107BOOST_AUTO_TEST_SUITE_END()
108BOOST_AUTO_TEST_SUITE_END()
109#endif