From 345ab188c66017bf80512024a42b8e85ee96c872 Mon Sep 17 00:00:00 2001 From: Alex Gilday Date: Tue, 9 Jan 2018 11:40:19 +0000 Subject: 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 Reviewed-by: Georgios Pinitas --- tests/AssetsLibrary.h | 26 ++++- tests/benchmark/CL/HarrisCorners.cpp | 6 +- tests/benchmark/NEON/HarrisCorners.cpp | 10 +- tests/benchmark/fixtures/HarrisCornersFixture.h | 12 ++- tests/datasets/ImageFileDatasets.h | 120 +++++++++++++++++++++++ tests/validation/CL/HarrisCorners.cpp | 8 +- tests/validation/NEON/HarrisCorners.cpp | 8 +- tests/validation/fixtures/HarrisCornersFixture.h | 32 +++--- 8 files changed, 188 insertions(+), 34 deletions(-) create mode 100644 tests/datasets/ImageFileDatasets.h (limited to 'tests') 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 + 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. @@ -474,6 +485,19 @@ void AssetsLibrary::fill(T &&tensor, const std::string &name, Format format, Cha } } +template +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(tensor(id)); + std::copy_n(raw_ptr, raw.element_size(), out_ptr); + } +} + template void AssetsLibrary::fill_tensor_uniform(T &&tensor, std::random_device::result_type seed_offset) const { 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 - 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(shape, format); + src = create_tensor(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 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 + +namespace arm_compute +{ +namespace test +{ +namespace datasets +{ +class ImageFileDataset +{ +public: + struct iterator + { + iterator(std::vector::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 operator*() const + { + return std::make_tuple(*_name_it); + } + + iterator &operator++() + { + ++_name_it; + + return *this; + } + + private: + std::vector::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 _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 using CLHarrisCornersFixture = HarrisCornersValidationFixture; -FIXTURE_DATA_TEST_CASE(RunSmall, CLHarrisCornersFixture, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::Small2DShapes(), data), framework::dataset::make("Format", Format::U8))) +FIXTURE_DATA_TEST_CASE(RunSmall, CLHarrisCornersFixture, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallImageFiles(), data), framework::dataset::make("Format", + Format::U8))) { // Validate output CLArrayAccessor array(_target); validate_keypoints(array.buffer(), array.buffer() + array.num_values(), _reference.begin(), _reference.end(), RelativeTolerance(0.0001f)); } -FIXTURE_DATA_TEST_CASE(RunLarge, CLHarrisCornersFixture, framework::DatasetMode::NIGHTLY, combine(combine(datasets::Large2DShapes(), data), framework::dataset::make("Format", Format::U8))) +FIXTURE_DATA_TEST_CASE(RunLarge, CLHarrisCornersFixture, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeImageFiles(), data), framework::dataset::make("Format", Format::U8))) { // Validate output CLArrayAccessor 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 using NEHarrisCornersFixture = HarrisCornersValidationFixture; -FIXTURE_DATA_TEST_CASE(RunSmall, NEHarrisCornersFixture, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::Small2DShapes(), data), framework::dataset::make("Format", Format::U8))) +FIXTURE_DATA_TEST_CASE(RunSmall, NEHarrisCornersFixture, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallImageFiles(), data), framework::dataset::make("Format", + Format::U8))) { // Validate output ArrayAccessor array(_target); @@ -120,7 +122,7 @@ FIXTURE_DATA_TEST_CASE(RunSmall, NEHarrisCornersFixture, framework::Dat allowed_mismatch_percentage); } -FIXTURE_DATA_TEST_CASE(RunLarge, NEHarrisCornersFixture, framework::DatasetMode::NIGHTLY, combine(combine(datasets::Large2DShapes(), data), framework::dataset::make("Format", Format::U8))) +FIXTURE_DATA_TEST_CASE(RunLarge, NEHarrisCornersFixture, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeImageFiles(), data), framework::dataset::make("Format", Format::U8))) { // Validate output ArrayAccessor 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 - 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 - void fill(U &&tensor) + void fill(U &&tensor, RawTensor raw) { - library->fill_tensor_uniform(tensor, 0); + library->fill(tensor, raw); } template ::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(shape, data_type_from_format(format)); - src.info()->set_format(format); + TensorType src = create_tensor(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 compute_reference(const TensorShape &shape, int gradient_size, int block_size, BorderMode border_mode, Format format, const HarrisCornersParameters ¶ms) + std::vector 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 src{ shape, format }; + SimpleTensor src{ raw.shape(), format }; // Fill reference - fill(src); + fill(src, raw); return reference::harris_corner_detector(src, params.threshold, params.min_dist, params.sensitivity, gradient_size, block_size, border_mode, params.constant_border_value); } -- cgit v1.2.1