blob: 20aaefd3de7a9127fe9358bcd51415b20f7322fc [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"
28#include "validation/Datasets.h"
29#include "validation/Helpers.h"
30#include "validation/Reference.h"
31#include "validation/Validation.h"
32#include "validation/ValidationUserConfiguration.h"
33
34#include <random>
35
36using namespace arm_compute;
37using namespace arm_compute::test;
38using namespace arm_compute::test::neon;
39using namespace arm_compute::test::validation;
40
41namespace
42{
43Tensor compute_roi_pooling_layer(const TensorShape &shape, DataType dt, const std::vector<ROI> &rois, ROIPoolingLayerInfo pool_info)
44{
45 TensorShape shape_dst;
46 shape_dst.set(0, pool_info.pooled_width());
47 shape_dst.set(1, pool_info.pooled_height());
48 shape_dst.set(2, shape.z());
49 shape_dst.set(3, rois.size());
50
51 // Create tensors
52 Tensor src = create_tensor(shape, dt);
53 Tensor dst = create_tensor(shape_dst, dt);
54 Array<ROI> rois_array = create_array(rois);
55
56 // Create and configure function
57 NEROIPoolingLayer roi_pool;
58 roi_pool.configure(&src, &rois_array, &dst, pool_info);
59
60 // Allocate tensors
61 src.allocator()->allocate();
62 dst.allocator()->allocate();
63
64 BOOST_TEST(!src.info()->is_resizable());
65 BOOST_TEST(!dst.info()->is_resizable());
66
67 // Fill tensors
68 std::uniform_real_distribution<> distribution(-1, 1);
69 library->fill(NEAccessor(src), distribution, 0);
70
71 // Compute function
72 roi_pool.run();
73
74 return dst;
75}
76} // namespace
77
78#ifndef DOXYGEN_SKIP_THIS
79BOOST_AUTO_TEST_SUITE(NEON)
80BOOST_AUTO_TEST_SUITE(ROIPoolingLayer)
81
82BOOST_AUTO_TEST_SUITE(Float)
83BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit"))
84BOOST_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 }),
85 dt, num_rois, roi_pool_size, roi_scale)
86{
87 TensorShape shape(50U, 47U, 2U, 3U);
88 ROIPoolingLayerInfo pool_info(roi_pool_size, roi_pool_size, roi_scale);
89
90 // Construct ROI vector
91 std::vector<ROI> rois = generate_random_rois(shape, pool_info, num_rois, user_config.seed);
92
93 // Compute function
94 Tensor dst = compute_roi_pooling_layer(shape, dt, rois, pool_info);
95
96 // Compute reference
97 RawTensor ref_dst = Reference::compute_reference_roi_pooling_layer(shape, dt, rois, pool_info);
98
99 // Validate output
100 validate(NEAccessor(dst), ref_dst);
101}
102BOOST_AUTO_TEST_SUITE_END()
103
104BOOST_AUTO_TEST_SUITE_END()
105BOOST_AUTO_TEST_SUITE_END()
106#endif