From 8de92619e223225aabdca873c02f231d8e941fd1 Mon Sep 17 00:00:00 2001 From: John Richardson Date: Thu, 22 Feb 2018 14:09:31 +0000 Subject: COMPMID-585: Port OpticalFlow to new validation Change-Id: Ia36bd11ca27420d3059eea15df81b237900149ec Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/125175 Tested-by: Jenkins Reviewed-by: John Richardson Reviewed-by: Anthony Barbier --- tests/datasets/OpticalFlowDataset.h | 165 ++++++++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 tests/datasets/OpticalFlowDataset.h (limited to 'tests/datasets/OpticalFlowDataset.h') diff --git a/tests/datasets/OpticalFlowDataset.h b/tests/datasets/OpticalFlowDataset.h new file mode 100644 index 0000000000..9e247206f8 --- /dev/null +++ b/tests/datasets/OpticalFlowDataset.h @@ -0,0 +1,165 @@ +/* + * 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_OPTICAL_FLOW_DATASET +#define ARM_COMPUTE_TEST_OPTICAL_FLOW_DATASET + +#include "tests/validation/Helpers.h" +#include "utils/TypePrinter.h" + +namespace arm_compute +{ +namespace test +{ +namespace datasets +{ +class OpticalFlowDataset +{ +public: + using type = std::tuple; + + struct iterator + { + iterator(std::vector::const_iterator old_image_it, + std::vector::const_iterator new_image_it, + std::vector::const_iterator params_it, + std::vector::const_iterator num_levels_it, + std::vector::const_iterator num_keypoints_it) + : _old_image_it{ std::move(old_image_it) }, + _new_image_it{ std::move(new_image_it) }, + _params_it{ std::move(params_it) }, + _num_levels_it{ std::move(num_levels_it) }, + _num_keypoints_it{ std::move(num_keypoints_it) } + { + } + + std::string description() const + { + std::stringstream description; + description << "NumLevels=" << *_num_levels_it << ":"; + description << "NumKeypoints=" << *_num_keypoints_it << ":"; + description << "Termination=" << _params_it->termination << ":"; + description << "Epsilon=" << _params_it->epsilon << ":"; + description << "NumIterations=" << _params_it->num_iterations << ":"; + description << "WindowDimension=" << _params_it->window_dimension << ":"; + description << "InitialEstimate=" << std::boolalpha << _params_it->use_initial_estimate; + + return description.str(); + } + + OpticalFlowDataset::type operator*() const + { + return std::make_tuple(*_old_image_it, *_new_image_it, *_params_it, *_num_levels_it, *_num_keypoints_it); + } + + iterator &operator++() + { + ++_old_image_it; + ++_new_image_it; + ++_params_it; + ++_num_levels_it; + ++_num_keypoints_it; + + return *this; + } + + private: + std::vector::const_iterator _old_image_it; + std::vector::const_iterator _new_image_it; + std::vector::const_iterator _params_it; + std::vector::const_iterator _num_levels_it; + std::vector::const_iterator _num_keypoints_it; + }; + + iterator begin() const + { + return iterator(_old_image.begin(), + _new_image.begin(), + _params.begin(), + _num_levels.begin(), + _num_keypoints.begin()); + } + + int size() const + { + return std::min(_old_image.size(), std::min(_new_image.size(), std::min(_params.size(), std::min(_num_levels.size(), _num_keypoints.size())))); + } + + void add_config(std::string old_image, std::string new_image, OpticalFlowParameters params, size_t num_levels, size_t num_keypoints) + { + _old_image.emplace_back(std::move(old_image)); + _new_image.emplace_back(std::move(new_image)); + _params.emplace_back(params); + _num_levels.emplace_back(num_levels); + _num_keypoints.emplace_back(num_keypoints); + } + +protected: + OpticalFlowDataset() = default; + OpticalFlowDataset(OpticalFlowDataset &&) = default; + +private: + std::vector _old_image{}; + std::vector _new_image{}; + std::vector _params{}; + std::vector _num_levels{}; + std::vector _num_keypoints{}; +}; + +// *INDENT-OFF* +// clang-format off +class SmallOpticalFlowDataset final : public OpticalFlowDataset +{ +public: + SmallOpticalFlowDataset() + { + // old_image new_image (termination, epsilon, num_iterations, window_dimension, initial_estimate) levels keypoints + add_config("opticalflow_old.pgm", "opticalflow_new.pgm", OpticalFlowParameters(Termination::TERM_CRITERIA_BOTH, 0.01f, 3, 5, true), 3, 1000); + add_config("opticalflow_old.pgm", "opticalflow_new.pgm", OpticalFlowParameters(Termination::TERM_CRITERIA_EPSILON, 0.01f, 3, 5, true), 3, 1000); + add_config("opticalflow_old.pgm", "opticalflow_new.pgm", OpticalFlowParameters(Termination::TERM_CRITERIA_ITERATIONS, 0.01f, 3, 5, true), 3, 1000); + } +}; + +class LargeOpticalFlowDataset final : public OpticalFlowDataset +{ +public: + LargeOpticalFlowDataset() + { + // old_image new_image (termination, epsilon, num_iterations, window_dimension, initial_estimate) levels keypoints + add_config("opticalflow_old.pgm", "opticalflow_new.pgm", OpticalFlowParameters(Termination::TERM_CRITERIA_BOTH, 0.01f, 3, 5, true), 3, 10000); + add_config("opticalflow_old.pgm", "opticalflow_new.pgm", OpticalFlowParameters(Termination::TERM_CRITERIA_EPSILON, 0.01f, 3, 5, true), 3, 10000); + add_config("opticalflow_old.pgm", "opticalflow_new.pgm", OpticalFlowParameters(Termination::TERM_CRITERIA_ITERATIONS, 0.01f, 3, 5, true), 3, 10000); + + // old_image new_image (termination, epsilon, num_iterations, window_dimension, initial_estimate) levels keypoints + add_config("opticalflow_old.pgm", "opticalflow_new.pgm", OpticalFlowParameters(Termination::TERM_CRITERIA_BOTH, 0.01f, 3, 5, false), 3, 10000); + add_config("opticalflow_old.pgm", "opticalflow_new.pgm", OpticalFlowParameters(Termination::TERM_CRITERIA_EPSILON, 0.01f, 3, 5, false), 3, 10000); + add_config("opticalflow_old.pgm", "opticalflow_new.pgm", OpticalFlowParameters(Termination::TERM_CRITERIA_ITERATIONS, 0.01f, 3, 5, false), 3, 10000); + } +}; +// clang-format on +// *INDENT-ON* + +} // namespace datasets +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_OPTICAL_FLOW_DATASET */ -- cgit v1.2.1