diff options
author | Alex Gilday <alexander.gilday@arm.com> | 2018-01-09 11:40:19 +0000 |
---|---|---|
committer | Anthony Barbier <anthony.barbier@arm.com> | 2018-11-02 16:42:33 +0000 |
commit | 345ab188c66017bf80512024a42b8e85ee96c872 (patch) | |
tree | 995d7147444483e8d7c342a9c90e615ca9445bc7 | |
parent | 780db4eb6a9e3dee565d14f36d772038cd3253da (diff) | |
download | ComputeLibrary-345ab188c66017bf80512024a42b8e85ee96c872.tar.gz |
COMPMID-742: Add image input support for Harris Corners tests
Change-Id: I4833eec0734776d8683fe867bb4f4d827f1a2fb7
Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/115503
Tested-by: Jenkins <bsgcomp@arm.com>
Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com>
-rw-r--r-- | tests/AssetsLibrary.h | 26 | ||||
-rw-r--r-- | tests/benchmark/CL/HarrisCorners.cpp | 6 | ||||
-rw-r--r-- | tests/benchmark/NEON/HarrisCorners.cpp | 10 | ||||
-rw-r--r-- | tests/benchmark/fixtures/HarrisCornersFixture.h | 12 | ||||
-rw-r--r-- | tests/datasets/ImageFileDatasets.h | 120 | ||||
-rw-r--r-- | tests/validation/CL/HarrisCorners.cpp | 8 | ||||
-rw-r--r-- | tests/validation/NEON/HarrisCorners.cpp | 8 | ||||
-rw-r--r-- | tests/validation/fixtures/HarrisCornersFixture.h | 32 |
8 files changed, 188 insertions, 34 deletions
diff --git a/tests/AssetsLibrary.h b/tests/AssetsLibrary.h index 49e3a83399..9c93ee0757 100644 --- a/tests/AssetsLibrary.h +++ b/tests/AssetsLibrary.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017, 2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -275,6 +275,17 @@ public: */ void fill(RawTensor &raw, const std::string &name, Format format, Channel channel) const; + /** Fills the specified @p tensor with the content of the raw tensor. + * + * @param[in, out] tensor To be filled tensor. + * @param[in] raw Raw tensor used to fill the tensor. + * + * @warning No check is performed that the specified format actually + * matches the format of the tensor. + */ + template <typename T> + void fill(T &&tensor, RawTensor raw) const; + /** Fill a tensor with uniform distribution across the range of its type * * @param[in, out] tensor To be filled tensor. @@ -475,6 +486,19 @@ void AssetsLibrary::fill(T &&tensor, const std::string &name, Format format, Cha } template <typename T> +void AssetsLibrary::fill(T &&tensor, RawTensor raw) const +{ + for(size_t offset = 0; offset < raw.size(); offset += raw.element_size()) + { + const Coordinates id = index2coord(raw.shape(), offset / raw.element_size()); + + const RawTensor::value_type *const raw_ptr = raw.data() + offset; + const auto out_ptr = static_cast<RawTensor::value_type *>(tensor(id)); + std::copy_n(raw_ptr, raw.element_size(), out_ptr); + } +} + +template <typename T> void AssetsLibrary::fill_tensor_uniform(T &&tensor, std::random_device::result_type seed_offset) const { switch(tensor.data_type()) diff --git a/tests/benchmark/CL/HarrisCorners.cpp b/tests/benchmark/CL/HarrisCorners.cpp index 618968f8c1..990ac24894 100644 --- a/tests/benchmark/CL/HarrisCorners.cpp +++ b/tests/benchmark/CL/HarrisCorners.cpp @@ -28,7 +28,7 @@ #include "arm_compute/runtime/CL/functions/CLHarrisCorners.h" #include "tests/CL/CLAccessor.h" #include "tests/benchmark/fixtures/HarrisCornersFixture.h" -#include "tests/datasets/ShapeDatasets.h" +#include "tests/datasets/ImageFileDatasets.h" #include "tests/framework/Macros.h" #include "tests/framework/datasets/Datasets.h" #include "utils/TypePrinter.h" @@ -54,7 +54,7 @@ using CLHarrisCornersFixture = HarrisCornersFixture<CLTensor, CLHarrisCorners, C TEST_SUITE(CL) TEST_SUITE(HarrisCorners) -REGISTER_FIXTURE_DATA_TEST_CASE(RunSmall, CLHarrisCornersFixture, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(combine(combine(combine(datasets::SmallImageShapes(), +REGISTER_FIXTURE_DATA_TEST_CASE(RunSmall, CLHarrisCornersFixture, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(combine(combine(combine(datasets::SmallImageFiles(), framework::dataset::make("Format", { Format::U8 })), threshold), min_dist), @@ -64,7 +64,7 @@ REGISTER_FIXTURE_DATA_TEST_CASE(RunSmall, CLHarrisCornersFixture, framework::Dat border_mode), framework::dataset::make("UseFP16", { false }))); -REGISTER_FIXTURE_DATA_TEST_CASE(RunLarge, CLHarrisCornersFixture, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(combine(combine(combine(datasets::LargeImageShapes(), +REGISTER_FIXTURE_DATA_TEST_CASE(RunLarge, CLHarrisCornersFixture, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(combine(combine(combine(datasets::LargeImageFiles(), framework::dataset::make("Format", { Format::U8 })), threshold), min_dist), diff --git a/tests/benchmark/NEON/HarrisCorners.cpp b/tests/benchmark/NEON/HarrisCorners.cpp index 4fffded24b..33315ffcd0 100644 --- a/tests/benchmark/NEON/HarrisCorners.cpp +++ b/tests/benchmark/NEON/HarrisCorners.cpp @@ -27,7 +27,7 @@ #include "arm_compute/runtime/TensorAllocator.h" #include "tests/NEON/Accessor.h" #include "tests/benchmark/fixtures/HarrisCornersFixture.h" -#include "tests/datasets/ShapeDatasets.h" +#include "tests/datasets/ImageFileDatasets.h" #include "tests/framework/Macros.h" #include "tests/framework/datasets/Datasets.h" #include "utils/TypePrinter.h" @@ -56,7 +56,7 @@ TEST_SUITE(HarrisCorners) #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC TEST_SUITE(FP16) -REGISTER_FIXTURE_DATA_TEST_CASE(RunSmall, NEHarrisCornersFixture, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(combine(combine(combine(datasets::SmallImageShapes(), +REGISTER_FIXTURE_DATA_TEST_CASE(RunSmall, NEHarrisCornersFixture, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(combine(combine(combine(datasets::SmallImageFiles(), framework::dataset::make("Format", { Format::U8 })), threshold), min_dist), @@ -65,7 +65,7 @@ REGISTER_FIXTURE_DATA_TEST_CASE(RunSmall, NEHarrisCornersFixture, framework::Dat block_size), border_mode), framework::dataset::make("UseFP16", { true }))); -REGISTER_FIXTURE_DATA_TEST_CASE(RunLarge, NEHarrisCornersFixture, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(combine(combine(combine(datasets::LargeImageShapes(), +REGISTER_FIXTURE_DATA_TEST_CASE(RunLarge, NEHarrisCornersFixture, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(combine(combine(combine(datasets::LargeImageFiles(), framework::dataset::make("Format", { Format::U8 })), threshold), min_dist), @@ -78,7 +78,7 @@ TEST_SUITE_END() // FP16 #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC TEST_SUITE(S16) -REGISTER_FIXTURE_DATA_TEST_CASE(RunSmall, NEHarrisCornersFixture, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(combine(combine(combine(datasets::SmallImageShapes(), +REGISTER_FIXTURE_DATA_TEST_CASE(RunSmall, NEHarrisCornersFixture, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(combine(combine(combine(datasets::SmallImageFiles(), framework::dataset::make("Format", { Format::U8 })), threshold), min_dist), @@ -87,7 +87,7 @@ REGISTER_FIXTURE_DATA_TEST_CASE(RunSmall, NEHarrisCornersFixture, framework::Dat block_size), border_mode), framework::dataset::make("UseFP16", { false }))); -REGISTER_FIXTURE_DATA_TEST_CASE(RunLarge, NEHarrisCornersFixture, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(combine(combine(combine(datasets::LargeImageShapes(), +REGISTER_FIXTURE_DATA_TEST_CASE(RunLarge, NEHarrisCornersFixture, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(combine(combine(combine(datasets::LargeImageFiles(), framework::dataset::make("Format", { Format::U8 })), threshold), min_dist), diff --git a/tests/benchmark/fixtures/HarrisCornersFixture.h b/tests/benchmark/fixtures/HarrisCornersFixture.h index 1596ede962..c7ce683ab5 100644 --- a/tests/benchmark/fixtures/HarrisCornersFixture.h +++ b/tests/benchmark/fixtures/HarrisCornersFixture.h @@ -41,12 +41,15 @@ class HarrisCornersFixture : public framework::Fixture { public: template <typename...> - void setup(const TensorShape &shape, Format format, float threshold, float min_dist, float sensitivity, + void setup(std::string image, Format format, float threshold, float min_dist, float sensitivity, int32_t gradient_size, int32_t block_size, BorderMode border_mode, bool use_fp16) { + // Load the image (cached by the library if loaded before) + const RawTensor &raw = library->get(image, format); + // Create tensor - src = create_tensor<TensorType>(shape, format); + src = create_tensor<TensorType>(raw.shape(), format); // Create and configure function harris_corners_func.configure(&src, threshold, min_dist, sensitivity, gradient_size, block_size, &out, border_mode, 0, use_fp16); @@ -54,9 +57,8 @@ public: // Allocate tensor src.allocator()->allocate(); - // Fill tensor - std::uniform_int_distribution<int32_t> distribution(100, 100); - library->fill(Accessor(src), distribution, 0); + // Copy image data to tensor + library->fill(Accessor(src), raw); } void run() diff --git a/tests/datasets/ImageFileDatasets.h b/tests/datasets/ImageFileDatasets.h new file mode 100644 index 0000000000..90a7f0dc56 --- /dev/null +++ b/tests/datasets/ImageFileDatasets.h @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2018 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef ARM_COMPUTE_TEST_IMAGE_FILE_DATASET +#define ARM_COMPUTE_TEST_IMAGE_FILE_DATASET + +#include "tests/framework/datasets/Datasets.h" + +#include <type_traits> + +namespace arm_compute +{ +namespace test +{ +namespace datasets +{ +class ImageFileDataset +{ +public: + struct iterator + { + iterator(std::vector<std::string>::const_iterator name_it) + : _name_it{ std::move(name_it) } + { + } + + std::string description() const + { + std::stringstream description; + description << "ImageFile=" << *_name_it; + return description.str(); + } + + std::tuple<std::string> operator*() const + { + return std::make_tuple(*_name_it); + } + + iterator &operator++() + { + ++_name_it; + + return *this; + } + + private: + std::vector<std::string>::const_iterator _name_it; + }; + + iterator begin() const + { + return iterator(_names.begin()); + } + + int size() const + { + return _names.size(); + } + + void add_image_file(std::string name) + { + _names.emplace_back(std::move(name)); + } + +protected: + ImageFileDataset() = default; + ImageFileDataset(ImageFileDataset &&) = default; + +private: + std::vector<std::string> _names{}; +}; + +/** Data set containing names of small image files. */ +class SmallImageFiles final : public ImageFileDataset +{ +public: + SmallImageFiles() + { + add_image_file("640x480.ppm"); + add_image_file("800x600.ppm"); + add_image_file("1280x720.ppm"); + } +}; + +/** Data set containing names of small image files. */ +class LargeImageFiles final : public ImageFileDataset +{ +public: + LargeImageFiles() + { + add_image_file("1920x1080.ppm"); + add_image_file("4160x3120.ppm"); + add_image_file("5120x3200.ppm"); + } +}; + +} // namespace datasets +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_IMAGE_FILE_DATASET */ diff --git a/tests/validation/CL/HarrisCorners.cpp b/tests/validation/CL/HarrisCorners.cpp index 4188cb54f0..00b6910223 100644 --- a/tests/validation/CL/HarrisCorners.cpp +++ b/tests/validation/CL/HarrisCorners.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017, 2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -30,6 +30,7 @@ #include "tests/CL/CLArrayAccessor.h" #include "tests/PaddingCalculator.h" #include "tests/datasets/BorderModeDataset.h" +#include "tests/datasets/ImageFileDatasets.h" #include "tests/datasets/ShapeDatasets.h" #include "tests/framework/Asserts.h" #include "tests/framework/Macros.h" @@ -101,14 +102,15 @@ DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(conca template <typename T> using CLHarrisCornersFixture = HarrisCornersValidationFixture<CLTensor, CLAccessor, CLKeyPointArray, CLHarrisCorners, T>; -FIXTURE_DATA_TEST_CASE(RunSmall, CLHarrisCornersFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::Small2DShapes(), data), framework::dataset::make("Format", Format::U8))) +FIXTURE_DATA_TEST_CASE(RunSmall, CLHarrisCornersFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallImageFiles(), data), framework::dataset::make("Format", + Format::U8))) { // Validate output CLArrayAccessor<KeyPoint> array(_target); validate_keypoints(array.buffer(), array.buffer() + array.num_values(), _reference.begin(), _reference.end(), RelativeTolerance<float>(0.0001f)); } -FIXTURE_DATA_TEST_CASE(RunLarge, CLHarrisCornersFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::Large2DShapes(), data), framework::dataset::make("Format", Format::U8))) +FIXTURE_DATA_TEST_CASE(RunLarge, CLHarrisCornersFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeImageFiles(), data), framework::dataset::make("Format", Format::U8))) { // Validate output CLArrayAccessor<KeyPoint> array(_target); diff --git a/tests/validation/NEON/HarrisCorners.cpp b/tests/validation/NEON/HarrisCorners.cpp index fa8d3cbad6..b8d791774f 100644 --- a/tests/validation/NEON/HarrisCorners.cpp +++ b/tests/validation/NEON/HarrisCorners.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017, 2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -29,6 +29,7 @@ #include "tests/NEON/ArrayAccessor.h" #include "tests/PaddingCalculator.h" #include "tests/datasets/BorderModeDataset.h" +#include "tests/datasets/ImageFileDatasets.h" #include "tests/datasets/ShapeDatasets.h" #include "tests/framework/Asserts.h" #include "tests/framework/Macros.h" @@ -107,7 +108,8 @@ DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(conca template <typename T> using NEHarrisCornersFixture = HarrisCornersValidationFixture<Tensor, Accessor, KeyPointArray, NEHarrisCorners, T>; -FIXTURE_DATA_TEST_CASE(RunSmall, NEHarrisCornersFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::Small2DShapes(), data), framework::dataset::make("Format", Format::U8))) +FIXTURE_DATA_TEST_CASE(RunSmall, NEHarrisCornersFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallImageFiles(), data), framework::dataset::make("Format", + Format::U8))) { // Validate output ArrayAccessor<KeyPoint> array(_target); @@ -120,7 +122,7 @@ FIXTURE_DATA_TEST_CASE(RunSmall, NEHarrisCornersFixture<uint8_t>, framework::Dat allowed_mismatch_percentage); } -FIXTURE_DATA_TEST_CASE(RunLarge, NEHarrisCornersFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::Large2DShapes(), data), framework::dataset::make("Format", Format::U8))) +FIXTURE_DATA_TEST_CASE(RunLarge, NEHarrisCornersFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeImageFiles(), data), framework::dataset::make("Format", Format::U8))) { // Validate output ArrayAccessor<KeyPoint> array(_target); diff --git a/tests/validation/fixtures/HarrisCornersFixture.h b/tests/validation/fixtures/HarrisCornersFixture.h index 6395e3b6d8..1c30157344 100644 --- a/tests/validation/fixtures/HarrisCornersFixture.h +++ b/tests/validation/fixtures/HarrisCornersFixture.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017, 2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -47,20 +47,20 @@ class HarrisCornersValidationFixture : public framework::Fixture { public: template <typename...> - void setup(TensorShape shape, int gradient_size, int block_size, BorderMode border_mode, bool use_fp16, Format format) + void setup(std::string image, int gradient_size, int block_size, BorderMode border_mode, bool use_fp16, Format format) { HarrisCornersParameters params = harris_corners_parameters(); - _target = compute_target(shape, gradient_size, block_size, border_mode, use_fp16, format, params); + _target = compute_target(image, gradient_size, block_size, border_mode, use_fp16, format, params); //TODO(COMPMID-543): Add use_fp16 to reference - _reference = compute_reference(shape, gradient_size, block_size, border_mode, format, params); + _reference = compute_reference(image, gradient_size, block_size, border_mode, format, params); } protected: template <typename U> - void fill(U &&tensor) + void fill(U &&tensor, RawTensor raw) { - library->fill_tensor_uniform(tensor, 0); + library->fill(tensor, raw); } template <typename F, typename std::enable_if<std::is_same<F, NEHarrisCorners>::value, int>::type = 0> @@ -77,14 +77,16 @@ protected: func.configure(&src, params.threshold, params.min_dist, params.sensitivity, gradient_size, block_size, &corners, border_mode, params.constant_border_value); } - ArrayType compute_target(const TensorShape &shape, int gradient_size, int block_size, BorderMode border_mode, bool use_fp16, Format format, const HarrisCornersParameters ¶ms) + ArrayType compute_target(std::string image, int gradient_size, int block_size, BorderMode border_mode, bool use_fp16, Format format, const HarrisCornersParameters ¶ms) { + // Load the image (cached by the library if loaded before) + const RawTensor &raw = library->get(image, format); + // Create tensors - TensorType src = create_tensor<TensorType>(shape, data_type_from_format(format)); - src.info()->set_format(format); + TensorType src = create_tensor<TensorType>(raw.shape(), format); // Create array of keypoints - ArrayType corners(shape.total_size()); + ArrayType corners(raw.shape().total_size()); // Create harris corners configure function FunctionType harris_corners; @@ -98,7 +100,7 @@ protected: ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS); // Fill tensors - fill(AccessorType(src)); + fill(AccessorType(src), raw); // Compute function harris_corners.run(); @@ -106,13 +108,15 @@ protected: return corners; } - std::vector<KeyPoint> compute_reference(const TensorShape &shape, int gradient_size, int block_size, BorderMode border_mode, Format format, const HarrisCornersParameters ¶ms) + std::vector<KeyPoint> compute_reference(std::string image, int gradient_size, int block_size, BorderMode border_mode, Format format, const HarrisCornersParameters ¶ms) { + // Load the image (cached by the library if loaded before) + const RawTensor &raw = library->get(image, format); // Create reference - SimpleTensor<T> src{ shape, format }; + SimpleTensor<T> src{ raw.shape(), format }; // Fill reference - fill(src); + fill(src, raw); return reference::harris_corner_detector<T>(src, params.threshold, params.min_dist, params.sensitivity, gradient_size, block_size, border_mode, params.constant_border_value); } |