blob: 1557240fd24900915f3e7655ed5e73ab1f759883 [file] [log] [blame]
Moritz Pflanzeree493ae2017-07-05 10:52:21 +01001/*
Freddie Liardetafcbb8f2021-05-04 12:41:16 +01002 * Copyright (c) 2017-2021 Arm Limited.
Moritz Pflanzeree493ae2017-07-05 10:52:21 +01003 *
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#ifndef ARM_COMPUTE_TEST_POOLING_LAYER_DATASET
25#define ARM_COMPUTE_TEST_POOLING_LAYER_DATASET
26
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010027#include "arm_compute/core/TensorShape.h"
28#include "arm_compute/core/Types.h"
Anthony Barbier2a07e182017-08-04 18:20:27 +010029#include "utils/TypePrinter.h"
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010030
31namespace arm_compute
32{
33namespace test
34{
35namespace datasets
36{
37class PoolingLayerDataset
38{
39public:
Giorgio Arena3c520c52018-05-01 11:47:24 +010040 using type = std::tuple<TensorShape, PoolingLayerInfo>;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010041
42 struct iterator
43 {
44 iterator(std::vector<TensorShape>::const_iterator src_it,
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010045 std::vector<PoolingLayerInfo>::const_iterator infos_it)
46 : _src_it{ std::move(src_it) },
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010047 _infos_it{ std::move(infos_it) }
48 {
49 }
50
51 std::string description() const
52 {
53 std::stringstream description;
54 description << "In=" << *_src_it << ":";
Michalis Spyrou57dac842018-03-01 16:03:50 +000055 description << "Info=" << *_infos_it << ":";
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010056 return description.str();
57 }
58
59 PoolingLayerDataset::type operator*() const
60 {
Giorgio Arena3c520c52018-05-01 11:47:24 +010061 return std::make_tuple(*_src_it, *_infos_it);
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010062 }
63
64 iterator &operator++()
65 {
66 ++_src_it;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010067 ++_infos_it;
68
69 return *this;
70 }
71
72 private:
73 std::vector<TensorShape>::const_iterator _src_it;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010074 std::vector<PoolingLayerInfo>::const_iterator _infos_it;
75 };
76
77 iterator begin() const
78 {
Giorgio Arena3c520c52018-05-01 11:47:24 +010079 return iterator(_src_shapes.begin(), _infos.begin());
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010080 }
81
82 int size() const
83 {
Giorgio Arena3c520c52018-05-01 11:47:24 +010084 return std::min(_src_shapes.size(), _infos.size());
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010085 }
86
Giorgio Arena3c520c52018-05-01 11:47:24 +010087 void add_config(TensorShape src, PoolingLayerInfo info)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010088 {
89 _src_shapes.emplace_back(std::move(src));
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010090 _infos.emplace_back(std::move(info));
91 }
92
93protected:
94 PoolingLayerDataset() = default;
95 PoolingLayerDataset(PoolingLayerDataset &&) = default;
96
97private:
98 std::vector<TensorShape> _src_shapes{};
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010099 std::vector<PoolingLayerInfo> _infos{};
100};
Georgios Pinitas15997872018-02-19 13:58:22 +0000101
102// Special pooling dataset
103class PoolingLayerDatasetSpecial final : public PoolingLayerDataset
104{
105public:
106 PoolingLayerDatasetSpecial()
107 {
108 // Special cases
Freddie Liardetafcbb8f2021-05-04 12:41:16 +0100109 add_config(TensorShape(2U, 3U, 4U, 1U), PoolingLayerInfo(PoolingType::AVG, Size2D(2, 2), DataLayout::NCHW, PadStrideInfo(3, 3, 0, 0), true));
Sang-Hoon Park11fedda2020-01-15 14:44:04 +0000110 add_config(TensorShape(60U, 52U, 3U, 2U), PoolingLayerInfo(PoolingType::AVG, Size2D(100, 100), DataLayout::NCHW, PadStrideInfo(5, 5, 50, 50), true));
Georgios Pinitas15997872018-02-19 13:58:22 +0000111 // Asymmetric padding
Sang-Hoon Park11fedda2020-01-15 14:44:04 +0000112 add_config(TensorShape(112U, 112U, 32U), PoolingLayerInfo(PoolingType::MAX, 3, DataLayout::NCHW, PadStrideInfo(2, 2, 0, 1, 0, 1, DimensionRoundingType::FLOOR)));
113 add_config(TensorShape(14U, 14U, 832U), PoolingLayerInfo(PoolingType::MAX, 2, DataLayout::NCHW, PadStrideInfo(1, 1, 0, 0, DimensionRoundingType::CEIL)));
Georgios Pinitas15997872018-02-19 13:58:22 +0000114 }
115};
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100116} // namespace datasets
117} // namespace test
118} // namespace arm_compute
119#endif /* ARM_COMPUTE_TEST_POOLING_LAYER_DATASET */