George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame^] | 2 | * Copyright (c) 2019 Arm Limited. |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [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_CROP_RESIZE_DATASET |
| 25 | #define ARM_COMPUTE_TEST_CROP_RESIZE_DATASET |
| 26 | |
| 27 | #include "utils/TypePrinter.h" |
| 28 | |
| 29 | #include "arm_compute/core/Types.h" |
| 30 | |
| 31 | namespace arm_compute |
| 32 | { |
| 33 | namespace test |
| 34 | { |
| 35 | namespace datasets |
| 36 | { |
| 37 | class CropResizeDataset |
| 38 | { |
| 39 | public: |
| 40 | using type = std::tuple<TensorShape, TensorShape, Coordinates2D, InterpolationPolicy, float>; |
| 41 | |
| 42 | struct iterator |
| 43 | { |
| 44 | iterator(std::vector<TensorShape>::const_iterator src_shapes_it, |
| 45 | std::vector<TensorShape>::const_iterator boxes_shapes_it, |
| 46 | std::vector<Coordinates2D>::const_iterator crop_size_values_it, |
| 47 | std::vector<InterpolationPolicy>::const_iterator method_values_it, |
| 48 | std::vector<float>::const_iterator extrapolation_values_it) |
| 49 | : _src_shapes_it{ std::move(src_shapes_it) }, |
| 50 | _boxes_shapes_it{ std::move(boxes_shapes_it) }, |
| 51 | _crop_size_values_it{ std::move(crop_size_values_it) }, |
| 52 | _method_values_it{ std::move(method_values_it) }, |
| 53 | _extrapolation_values_it{ std::move(extrapolation_values_it) } |
| 54 | { |
| 55 | } |
| 56 | |
| 57 | std::string description() const |
| 58 | { |
| 59 | std::stringstream description; |
| 60 | description << "Src_Shape=" << *_src_shapes_it << ":"; |
| 61 | description << "Boxes_Shape=" << *_boxes_shapes_it << ":"; |
| 62 | description << "Crop_Size=(" << (*_crop_size_values_it).x << "," << (*_crop_size_values_it).y << "):"; |
| 63 | description << "Method=" << *_method_values_it << ":"; |
| 64 | description << "Extrapolation_value=" << *_extrapolation_values_it << ":"; |
| 65 | return description.str(); |
| 66 | } |
| 67 | |
| 68 | CropResizeDataset::type operator*() const |
| 69 | { |
| 70 | return std::make_tuple(*_src_shapes_it, *_boxes_shapes_it, *_crop_size_values_it, *_method_values_it, *_extrapolation_values_it); |
| 71 | } |
| 72 | |
| 73 | iterator &operator++() |
| 74 | { |
| 75 | ++_src_shapes_it; |
| 76 | ++_boxes_shapes_it; |
| 77 | ++_crop_size_values_it; |
| 78 | ++_method_values_it; |
| 79 | ++_extrapolation_values_it; |
| 80 | return *this; |
| 81 | } |
| 82 | |
| 83 | private: |
| 84 | std::vector<TensorShape>::const_iterator _src_shapes_it; |
| 85 | std::vector<TensorShape>::const_iterator _boxes_shapes_it; |
| 86 | std::vector<Coordinates2D>::const_iterator _crop_size_values_it; |
| 87 | std::vector<InterpolationPolicy>::const_iterator _method_values_it; |
| 88 | std::vector<float>::const_iterator _extrapolation_values_it; |
| 89 | }; |
| 90 | |
| 91 | iterator begin() const |
| 92 | { |
| 93 | return iterator(_src_shapes.begin(), _boxes_shapes.begin(), _crop_size_values.begin(), _method_values.begin(), _extrapolation_values.begin()); |
| 94 | } |
| 95 | |
| 96 | int size() const |
| 97 | { |
| 98 | return std::min(_src_shapes.size(), std::min(_boxes_shapes.size(), std::min(_crop_size_values.size(), std::min(_method_values.size(), _extrapolation_values.size())))); |
| 99 | } |
| 100 | |
| 101 | void add_config(TensorShape src_shape, TensorShape boxes_shape, Coordinates2D crop_size, InterpolationPolicy method, float extrapolation_value) |
| 102 | { |
| 103 | _src_shapes.emplace_back(std::move(src_shape)); |
| 104 | _boxes_shapes.emplace_back(std::move(boxes_shape)); |
| 105 | _crop_size_values.emplace_back(std::move(crop_size)); |
| 106 | _method_values.emplace_back(std::move(method)); |
| 107 | _extrapolation_values.emplace_back(std::move(extrapolation_value)); |
| 108 | } |
| 109 | |
| 110 | protected: |
| 111 | CropResizeDataset() = default; |
| 112 | CropResizeDataset(CropResizeDataset &&) = default; |
| 113 | |
| 114 | private: |
| 115 | std::vector<TensorShape> _src_shapes{}; |
| 116 | std::vector<TensorShape> _boxes_shapes{}; |
| 117 | std::vector<Coordinates2D> _crop_size_values{}; |
| 118 | std::vector<InterpolationPolicy> _method_values{}; |
| 119 | std::vector<float> _extrapolation_values{}; |
| 120 | }; |
| 121 | |
| 122 | class SmallCropResizeDataset final : public CropResizeDataset |
| 123 | { |
| 124 | public: |
| 125 | SmallCropResizeDataset() |
| 126 | { |
| 127 | add_config(TensorShape(1U, 5U, 5U), TensorShape(4, 5), Coordinates2D{ 2, 2 }, InterpolationPolicy::BILINEAR, 100); |
| 128 | add_config(TensorShape(3U, 5U, 5U), TensorShape(4, 5), Coordinates2D{ 2, 2 }, InterpolationPolicy::BILINEAR, 100); |
| 129 | add_config(TensorShape(1U, 5U, 5U), TensorShape(4, 5), Coordinates2D{ 10, 10 }, InterpolationPolicy::BILINEAR, 100); |
| 130 | add_config(TensorShape(15U, 30U, 30U, 10U), TensorShape(4, 20), Coordinates2D{ 10, 10 }, InterpolationPolicy::BILINEAR, 100); |
| 131 | |
| 132 | add_config(TensorShape(1U, 5U, 5U), TensorShape(4, 5), Coordinates2D{ 2, 2 }, InterpolationPolicy::NEAREST_NEIGHBOR, 100); |
| 133 | add_config(TensorShape(3U, 5U, 5U), TensorShape(4, 5), Coordinates2D{ 2, 2 }, InterpolationPolicy::NEAREST_NEIGHBOR, 100); |
| 134 | add_config(TensorShape(1U, 5U, 5U), TensorShape(4, 5), Coordinates2D{ 10, 10 }, InterpolationPolicy::NEAREST_NEIGHBOR, 100); |
| 135 | add_config(TensorShape(15U, 30U, 30U, 10U), TensorShape(4, 20), Coordinates2D{ 10, 10 }, InterpolationPolicy::NEAREST_NEIGHBOR, 100); |
| 136 | } |
| 137 | }; |
| 138 | } // namespace datasets |
| 139 | } // namespace test |
| 140 | } // namespace arm_compute |
| 141 | #endif /* ARM_COMPUTE_TEST_CROP_RESIZE_DATASET */ |