Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 1 | /* |
Georgios Pinitas | 1599787 | 2018-02-19 13:58:22 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 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 | #ifndef ARM_COMPUTE_TEST_POOLING_LAYER_DATASET |
| 25 | #define ARM_COMPUTE_TEST_POOLING_LAYER_DATASET |
| 26 | |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/TensorShape.h" |
| 28 | #include "arm_compute/core/Types.h" |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 29 | #include "utils/TypePrinter.h" |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 30 | |
| 31 | namespace arm_compute |
| 32 | { |
| 33 | namespace test |
| 34 | { |
| 35 | namespace datasets |
| 36 | { |
| 37 | class PoolingLayerDataset |
| 38 | { |
| 39 | public: |
Giorgio Arena | 3c520c5 | 2018-05-01 11:47:24 +0100 | [diff] [blame] | 40 | using type = std::tuple<TensorShape, PoolingLayerInfo>; |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 41 | |
| 42 | struct iterator |
| 43 | { |
| 44 | iterator(std::vector<TensorShape>::const_iterator src_it, |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 45 | std::vector<PoolingLayerInfo>::const_iterator infos_it) |
| 46 | : _src_it{ std::move(src_it) }, |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 47 | _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 Spyrou | 57dac84 | 2018-03-01 16:03:50 +0000 | [diff] [blame] | 55 | description << "Info=" << *_infos_it << ":"; |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 56 | return description.str(); |
| 57 | } |
| 58 | |
| 59 | PoolingLayerDataset::type operator*() const |
| 60 | { |
Giorgio Arena | 3c520c5 | 2018-05-01 11:47:24 +0100 | [diff] [blame] | 61 | return std::make_tuple(*_src_it, *_infos_it); |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | iterator &operator++() |
| 65 | { |
| 66 | ++_src_it; |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 67 | ++_infos_it; |
| 68 | |
| 69 | return *this; |
| 70 | } |
| 71 | |
| 72 | private: |
| 73 | std::vector<TensorShape>::const_iterator _src_it; |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 74 | std::vector<PoolingLayerInfo>::const_iterator _infos_it; |
| 75 | }; |
| 76 | |
| 77 | iterator begin() const |
| 78 | { |
Giorgio Arena | 3c520c5 | 2018-05-01 11:47:24 +0100 | [diff] [blame] | 79 | return iterator(_src_shapes.begin(), _infos.begin()); |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | int size() const |
| 83 | { |
Giorgio Arena | 3c520c5 | 2018-05-01 11:47:24 +0100 | [diff] [blame] | 84 | return std::min(_src_shapes.size(), _infos.size()); |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 85 | } |
| 86 | |
Giorgio Arena | 3c520c5 | 2018-05-01 11:47:24 +0100 | [diff] [blame] | 87 | void add_config(TensorShape src, PoolingLayerInfo info) |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 88 | { |
| 89 | _src_shapes.emplace_back(std::move(src)); |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 90 | _infos.emplace_back(std::move(info)); |
| 91 | } |
| 92 | |
| 93 | protected: |
| 94 | PoolingLayerDataset() = default; |
| 95 | PoolingLayerDataset(PoolingLayerDataset &&) = default; |
| 96 | |
| 97 | private: |
| 98 | std::vector<TensorShape> _src_shapes{}; |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 99 | std::vector<PoolingLayerInfo> _infos{}; |
| 100 | }; |
Georgios Pinitas | 1599787 | 2018-02-19 13:58:22 +0000 | [diff] [blame] | 101 | |
| 102 | // Special pooling dataset |
| 103 | class PoolingLayerDatasetSpecial final : public PoolingLayerDataset |
| 104 | { |
| 105 | public: |
| 106 | PoolingLayerDatasetSpecial() |
| 107 | { |
| 108 | // Special cases |
Giorgio Arena | 3c520c5 | 2018-05-01 11:47:24 +0100 | [diff] [blame] | 109 | add_config(TensorShape(60U, 52U, 3U, 2U), PoolingLayerInfo(PoolingType::AVG, Size2D(100, 100), PadStrideInfo(5, 5, 50, 50), true)); |
Georgios Pinitas | 1599787 | 2018-02-19 13:58:22 +0000 | [diff] [blame] | 110 | // Asymmetric padding |
Giorgio Arena | 3c520c5 | 2018-05-01 11:47:24 +0100 | [diff] [blame] | 111 | add_config(TensorShape(112U, 112U, 32U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 1, 0, 1, DimensionRoundingType::FLOOR))); |
| 112 | add_config(TensorShape(14U, 14U, 832U), PoolingLayerInfo(PoolingType::MAX, 2, PadStrideInfo(1, 1, 0, 0, DimensionRoundingType::CEIL))); |
Georgios Pinitas | 1599787 | 2018-02-19 13:58:22 +0000 | [diff] [blame] | 113 | } |
| 114 | }; |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 115 | } // namespace datasets |
| 116 | } // namespace test |
| 117 | } // namespace arm_compute |
| 118 | #endif /* ARM_COMPUTE_TEST_POOLING_LAYER_DATASET */ |