diff options
Diffstat (limited to 'tests/validation/reference')
63 files changed, 0 insertions, 5501 deletions
diff --git a/tests/validation/reference/Box3x3.cpp b/tests/validation/reference/Box3x3.cpp deleted file mode 100644 index ccc7f1b3b9..0000000000 --- a/tests/validation/reference/Box3x3.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2017-2020 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. - */ -#include "arm_compute/core/Helpers.h" - -#include "Box3x3.h" -#include "Utils.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> box3x3(const SimpleTensor<T> &src, BorderMode border_mode, T constant_border_value) -{ - SimpleTensor<T> dst(src.shape(), src.data_type()); - const std::array<T, 9> filter{ { 1, 1, 1, 1, 1, 1, 1, 1, 1 } }; - const float scale = 1.f / static_cast<float>(filter.size()); - const uint32_t num_elements = src.num_elements(); -#if defined(_OPENMP) - #pragma omp parallel for -#endif /* _OPENMP */ - for(uint32_t element_idx = 0; element_idx < num_elements; ++element_idx) - { - const Coordinates id = index2coord(src.shape(), element_idx); - apply_2d_spatial_filter(id, src, dst, TensorShape(3U, 3U), filter.data(), scale, border_mode, constant_border_value); - } - return dst; -} - -template SimpleTensor<uint8_t> box3x3(const SimpleTensor<uint8_t> &src, BorderMode border_mode, uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/Box3x3.h b/tests/validation/reference/Box3x3.h deleted file mode 100644 index f377f280af..0000000000 --- a/tests/validation/reference/Box3x3.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017-2019 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_BOX3X3_H -#define ARM_COMPUTE_TEST_BOX3X3_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> box3x3(const SimpleTensor<T> &src, BorderMode border_mode, T constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_BOX3X3_H */ diff --git a/tests/validation/reference/CannyEdgeDetector.cpp b/tests/validation/reference/CannyEdgeDetector.cpp deleted file mode 100644 index aa2351ddd8..0000000000 --- a/tests/validation/reference/CannyEdgeDetector.cpp +++ /dev/null @@ -1,254 +0,0 @@ -/* - * Copyright (c) 2017-2019 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. - */ -#include "CannyEdgeDetector.h" - -#include "Utils.h" -#include "support/ToolchainSupport.h" -#include "tests/validation/Helpers.h" -#include "tests/validation/reference/Magnitude.h" -#include "tests/validation/reference/NonMaximaSuppression.h" -#include "tests/validation/reference/Phase.h" -#include "tests/validation/reference/Sobel.h" - -#include <cmath> -#include <stack> - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -namespace -{ -const auto MARK_ZERO = 0u; -const auto MARK_MAYBE = 127u; -const auto MARK_EDGE = 255u; - -template <typename T> -void trace_edge(SimpleTensor<T> &dst, const ValidRegion &valid_region) -{ - std::stack<Coordinates> pixels_stack; - for(auto i = 0; i < dst.num_elements(); ++i) - { - if(dst[i] == MARK_EDGE) - { - pixels_stack.push(index2coord(dst.shape(), i)); - } - } - - while(!pixels_stack.empty()) - { - const Coordinates pixel_coord = pixels_stack.top(); - pixels_stack.pop(); - - std::array<Coordinates, 8> neighbours = - { - { - Coordinates(pixel_coord.x() - 1, pixel_coord.y() + 0), - Coordinates(pixel_coord.x() + 1, pixel_coord.y() + 0), - Coordinates(pixel_coord.x() - 1, pixel_coord.y() - 1), - Coordinates(pixel_coord.x() + 1, pixel_coord.y() + 1), - Coordinates(pixel_coord.x() + 0, pixel_coord.y() - 1), - Coordinates(pixel_coord.x() + 0, pixel_coord.y() + 1), - Coordinates(pixel_coord.x() + 1, pixel_coord.y() - 1), - Coordinates(pixel_coord.x() - 1, pixel_coord.y() + 1) - } - }; - - // Mark MAYBE neighbours as edges since they are next to an EDGE - std::for_each(neighbours.begin(), neighbours.end(), [&](Coordinates & coord) - { - if(is_in_valid_region(valid_region, coord)) - { - const size_t pixel_index = coord2index(dst.shape(), coord); - const T pixel = dst[pixel_index]; - if(pixel == MARK_MAYBE) - { - dst[pixel_index] = MARK_EDGE; - pixels_stack.push(coord); - } - } - }); - } - - // Mark all remaining MAYBE pixels as ZERO (not edges) - for(auto i = 0; i < dst.num_elements(); ++i) - { - if(dst[i] == MARK_MAYBE) - { - dst[i] = MARK_ZERO; - } - } -} - -template <typename U, typename T> -SimpleTensor<T> canny_edge_detector_impl(const SimpleTensor<T> &src, int32_t upper, int32_t lower, int gradient_size, MagnitudeType norm_type, - BorderMode border_mode, T constant_border_value) -{ - ARM_COMPUTE_ERROR_ON(gradient_size != 3 && gradient_size != 5 && gradient_size != 7); - ARM_COMPUTE_ERROR_ON(lower < 0 || lower >= upper); - - // Output: T == uint8_t - SimpleTensor<T> dst{ src.shape(), src.data_type() }; - ValidRegion valid_region = shape_to_valid_region(src.shape(), border_mode == BorderMode::UNDEFINED, BorderSize(gradient_size / 2 + 1)); - - // Sobel computation: U == int16_t or int32_t - SimpleTensor<U> gx{}; - SimpleTensor<U> gy{}; - std::tie(gx, gy) = sobel<U>(src, gradient_size, border_mode, constant_border_value, GradientDimension::GRAD_XY); - - using unsigned_U = typename traits::make_unsigned_conditional_t<U>::type; - using promoted_U = typename common_promoted_signed_type<U>::intermediate_type; - - // Gradient magnitude and phase (edge direction) - const DataType mag_data_type = gx.data_type() == DataType::S16 ? DataType::U16 : DataType::U32; - SimpleTensor<unsigned_U> grad_mag{ gx.shape(), mag_data_type }; - SimpleTensor<uint8_t> grad_dir{ gy.shape(), DataType::U8 }; - - for(auto i = 0; i < grad_mag.num_elements(); ++i) - { - double mag = 0.f; - - if(norm_type == MagnitudeType::L2NORM) - { - mag = support::cpp11::round(std::sqrt(static_cast<promoted_U>(gx[i]) * gx[i] + static_cast<promoted_U>(gy[i]) * gy[i])); - } - else // MagnitudeType::L1NORM - { - mag = static_cast<promoted_U>(std::abs(gx[i])) + static_cast<promoted_U>(std::abs(gy[i])); - } - - float angle = 180.f * std::atan2(static_cast<float>(gy[i]), static_cast<float>(gx[i])) / M_PI; - grad_dir[i] = support::cpp11::round(angle < 0.f ? 180 + angle : angle); - grad_mag[i] = saturate_cast<unsigned_U>(mag); - } - - /* - Quantise the phase into 4 directions - 0° dir=0 0.0 <= p < 22.5 or 157.5 <= p < 180 - 45° dir=1 22.5 <= p < 67.5 - 90° dir=2 67.5 <= p < 112.5 - 135° dir=3 112.5 <= p < 157.5 - */ - for(auto i = 0; i < grad_dir.num_elements(); ++i) - { - const auto direction = std::fabs(grad_dir[i]); - grad_dir[i] = (direction < 22.5 || direction >= 157.5) ? 0 : (direction < 67.5) ? 1 : (direction < 112.5) ? 2 : 3; - } - - // Non-maximum suppression - std::vector<int> strong_edges; - const auto upper_thresh = static_cast<uint32_t>(upper); - const auto lower_thresh = static_cast<uint32_t>(lower); - - const auto pixel_at_offset = [&](const SimpleTensor<unsigned_U> &tensor, const Coordinates & coord, int xoffset, int yoffset) - { - return tensor_elem_at(tensor, Coordinates{ coord.x() + xoffset, coord.y() + yoffset }, border_mode, static_cast<unsigned_U>(constant_border_value)); - }; - - for(auto i = 0; i < dst.num_elements(); ++i) - { - const auto coord = index2coord(dst.shape(), i); - if(!is_in_valid_region(valid_region, coord) || grad_mag[i] <= lower_thresh) - { - dst[i] = MARK_ZERO; - continue; - } - - unsigned_U mag_90; - unsigned_U mag90; - switch(grad_dir[i]) - { - case 0: // North/South edge direction, compare against East/West pixels (left & right) - mag_90 = pixel_at_offset(grad_mag, coord, -1, 0); - mag90 = pixel_at_offset(grad_mag, coord, 1, 0); - break; - case 1: // NE/SW edge direction, compare against NW/SE pixels (top-left & bottom-right) - mag_90 = pixel_at_offset(grad_mag, coord, -1, -1); - mag90 = pixel_at_offset(grad_mag, coord, +1, +1); - break; - case 2: // East/West edge direction, compare against North/South pixels (top & bottom) - mag_90 = pixel_at_offset(grad_mag, coord, 0, -1); - mag90 = pixel_at_offset(grad_mag, coord, 0, +1); - break; - case 3: // NW/SE edge direction, compare against NE/SW pixels (top-right & bottom-left) - mag_90 = pixel_at_offset(grad_mag, coord, +1, -1); - mag90 = pixel_at_offset(grad_mag, coord, -1, +1); - break; - default: - ARM_COMPUTE_ERROR("Invalid gradient phase provided"); - break; - } - - // Potential edge if greater than both pixels at +/-90° on either side - if(grad_mag[i] > mag_90 && grad_mag[i] > mag90) - { - // Double thresholding and edge tracing - if(grad_mag[i] > upper_thresh) - { - dst[i] = MARK_EDGE; // Definite edge pixel - strong_edges.emplace_back(i); - } - else - { - dst[i] = MARK_MAYBE; - } - } - else - { - dst[i] = MARK_ZERO; // Since not greater than neighbours - } - } - - // Final edge tracing - trace_edge<T>(dst, valid_region); - return dst; -} -} // namespace - -template <typename T> -SimpleTensor<T> canny_edge_detector(const SimpleTensor<T> &src, - int32_t upper_thresh, int32_t lower_thresh, int gradient_size, MagnitudeType norm_type, - BorderMode border_mode, T constant_border_value) -{ - if(gradient_size < 7) - { - return canny_edge_detector_impl<int16_t>(src, upper_thresh, lower_thresh, gradient_size, norm_type, border_mode, constant_border_value); - } - else - { - return canny_edge_detector_impl<int32_t>(src, upper_thresh, lower_thresh, gradient_size, norm_type, border_mode, constant_border_value); - } -} - -template SimpleTensor<uint8_t> canny_edge_detector(const SimpleTensor<uint8_t> &src, - int32_t upper_thresh, int32_t lower_thresh, int gradient_size, MagnitudeType norm_type, - BorderMode border_mode, uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/CannyEdgeDetector.h b/tests/validation/reference/CannyEdgeDetector.h deleted file mode 100644 index e05895ab95..0000000000 --- a/tests/validation/reference/CannyEdgeDetector.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2017-2019 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_CANNY_EDGE_DETECTOR_H -#define ARM_COMPUTE_TEST_CANNY_EDGE_DETECTOR_H - -#include "arm_compute/core/Types.h" -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> canny_edge_detector(const SimpleTensor<T> &src, - int32_t upper_thresh, int32_t lower_thresh, int gradient_size, MagnitudeType norm_type, - BorderMode border_mode, T constant_border_value = 0); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_CANNY_EDGE_DETECTOR_H */ diff --git a/tests/validation/reference/ChannelCombine.cpp b/tests/validation/reference/ChannelCombine.cpp deleted file mode 100644 index dcd4cf551b..0000000000 --- a/tests/validation/reference/ChannelCombine.cpp +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Copyright (c) 2017-2020 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. - */ -#include "ChannelCombine.h" - -#include "arm_compute/core/Types.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -namespace -{ -template <typename T> -inline std::vector<SimpleTensor<T>> create_image_planes(const TensorShape &shape, Format format) -{ - TensorShape image_shape = adjust_odd_shape(shape, format); - - std::vector<SimpleTensor<T>> image_planes; - - switch(format) - { - case Format::RGB888: - case Format::RGBA8888: - case Format::YUYV422: - case Format::UYVY422: - { - image_planes.emplace_back(image_shape, format); - break; - } - case Format::NV12: - case Format::NV21: - { - TensorShape shape_uv88 = calculate_subsampled_shape(image_shape, Format::UV88); - - image_planes.emplace_back(image_shape, Format::U8); - image_planes.emplace_back(shape_uv88, Format::UV88); - break; - } - case Format::IYUV: - { - TensorShape shape_sub2 = calculate_subsampled_shape(image_shape, Format::IYUV); - - image_planes.emplace_back(image_shape, Format::U8); - image_planes.emplace_back(shape_sub2, Format::U8); - image_planes.emplace_back(shape_sub2, Format::U8); - break; - } - case Format::YUV444: - { - image_planes.emplace_back(image_shape, Format::U8); - image_planes.emplace_back(image_shape, Format::U8); - image_planes.emplace_back(image_shape, Format::U8); - break; - } - default: - ARM_COMPUTE_ERROR("Not supported"); - break; - } - - return image_planes; -} -} // namespace - -template <typename T> -std::vector<SimpleTensor<T>> channel_combine(const TensorShape &shape, const std::vector<SimpleTensor<T>> &image_planes, Format format) -{ - std::vector<SimpleTensor<T>> dst = create_image_planes<T>(shape, format); - -#if defined(_OPENMP) - #pragma omp parallel for -#endif /* _OPENMP */ - for(unsigned int plane_idx = 0; plane_idx < dst.size(); ++plane_idx) - { - SimpleTensor<T> &dst_tensor = dst[plane_idx]; - const uint32_t num_elements = dst_tensor.num_elements(); - - for(uint32_t element_idx = 0; element_idx < num_elements; ++element_idx) - { - Coordinates coord = index2coord(dst_tensor.shape(), element_idx); - - switch(format) - { - case Format::RGB888: - case Format::RGBA8888: - { - // Copy R/G/B or A channel - for(int channel_idx = 0; channel_idx < dst_tensor.num_channels(); ++channel_idx) - { - const T &src_value = reinterpret_cast<const T *>(image_planes[channel_idx](coord))[0]; - T &dst_value = reinterpret_cast<T *>(dst_tensor(coord))[channel_idx]; - - dst_value = src_value; - } - break; - } - case Format::YUYV422: - case Format::UYVY422: - { - // Find coordinates of the sub-sampled pixel - const Coordinates coord_hori(coord.x() / 2, coord.y()); - - const T &src0 = reinterpret_cast<const T *>(image_planes[0](coord))[0]; - const T &src1 = reinterpret_cast<const T *>(image_planes[1](coord_hori))[0]; - - const int shift = (Format::YUYV422 == format) ? 1 : 0; - T &dst0 = reinterpret_cast<T *>(dst_tensor(coord))[1 - shift]; - T &dst1 = reinterpret_cast<T *>(dst_tensor(coord))[0 + shift]; - - dst0 = src0; - dst1 = src1; - - Coordinates coord2 = index2coord(dst_tensor.shape(), ++element_idx); - - const T &src2 = reinterpret_cast<const T *>(image_planes[0](coord2))[0]; - const T &src3 = reinterpret_cast<const T *>(image_planes[2](coord_hori))[0]; - - T &dst2 = reinterpret_cast<T *>(dst_tensor(coord2))[1 - shift]; - T &dst3 = reinterpret_cast<T *>(dst_tensor(coord2))[0 + shift]; - - dst2 = src2; - dst3 = src3; - - break; - } - case Format::NV12: - case Format::NV21: - { - if(0U == plane_idx) - { - // Get and combine Y channel from plane0 of destination multi-image - dst_tensor[element_idx] = image_planes[0][element_idx]; - } - else - { - const int shift = (Format::NV12 == format) ? 0 : 1; - - // Get U channel from plane1 and V channel from plane2 of the source - const T &src_u0 = reinterpret_cast<const T *>(image_planes[1](coord))[0]; - const T &src_v0 = reinterpret_cast<const T *>(image_planes[2](coord))[0]; - - // Get U and V channel from plane1 of destination multi-image - T &dst_u0 = reinterpret_cast<T *>(dst_tensor(coord))[0 + shift]; - T &dst_v0 = reinterpret_cast<T *>(dst_tensor(coord))[1 - shift]; - - // Combine channel U and V - dst_u0 = src_u0; - dst_v0 = src_v0; - } - - break; - } - case Format::IYUV: - case Format::YUV444: - { - // Get Y/U/V element - const T &src = reinterpret_cast<const T *>(image_planes[plane_idx](coord))[0]; - T &dst = reinterpret_cast<T *>(dst_tensor(coord))[0]; - - // Copy Y/U/V plane - dst = src; - - break; - } - default: - ARM_COMPUTE_ERROR("Not supported"); - break; - } - } - } - - return dst; -} - -template std::vector<SimpleTensor<uint8_t>> channel_combine(const TensorShape &shape, const std::vector<SimpleTensor<uint8_t>> &image_planes, Format format); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/ChannelCombine.h b/tests/validation/reference/ChannelCombine.h deleted file mode 100644 index 315e2d4dd4..0000000000 --- a/tests/validation/reference/ChannelCombine.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017-2019 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_CHANNEL_COMBINE_H -#define ARM_COMPUTE_TEST_CHANNEL_COMBINE_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -std::vector<SimpleTensor<T>> channel_combine(const TensorShape &shape, const std::vector<SimpleTensor<T>> &image_planes, Format format); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_CHANNEL_COMBINE_H */ diff --git a/tests/validation/reference/ChannelExtract.cpp b/tests/validation/reference/ChannelExtract.cpp deleted file mode 100644 index 8674510269..0000000000 --- a/tests/validation/reference/ChannelExtract.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2017-2020 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. - */ -#include "ChannelExtract.h" - -#include "arm_compute/core/Types.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<uint8_t> channel_extract(const TensorShape &shape, const std::vector<SimpleTensor<T>> &tensor_planes, Format format, Channel channel) -{ - // Find plane and channel index - const unsigned int plane_idx = plane_idx_from_channel(format, channel); - const unsigned int channel_idx = channel_idx_from_format(format, channel); - - // Create dst and get src tensor - SimpleTensor<T> src = tensor_planes[plane_idx]; - SimpleTensor<T> dst{ calculate_subsampled_shape(shape, format, channel), Format::U8 }; - - // Single planar formats with subsampling require a double horizontal step - const int step_x = ((Format::YUYV422 == format || Format::UYVY422 == format) && Channel::Y != channel) ? 2 : 1; - const int width = dst.shape().x(); - const int height = dst.shape().y(); - - // Loop over each pixel and extract channel -#if defined(_OPENMP) - #pragma omp parallel for collapse(2) -#endif /* _OPENMP */ - for(int y = 0; y < height; ++y) - { - for(int x = 0; x < width; ++x) - { - const Coordinates src_coord{ x * step_x, y }; - const Coordinates dst_coord{ x, y }; - - const auto *src_pixel = reinterpret_cast<const T *>(src(src_coord)); - auto *dst_pixel = reinterpret_cast<T *>(dst(dst_coord)); - - dst_pixel[0] = src_pixel[channel_idx]; // NOLINT - } - } - - return dst; -} - -template SimpleTensor<uint8_t> channel_extract(const TensorShape &shape, const std::vector<SimpleTensor<uint8_t>> &tensor_planes, Format format, Channel channel); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/ChannelExtract.h b/tests/validation/reference/ChannelExtract.h deleted file mode 100644 index ce1e6732bd..0000000000 --- a/tests/validation/reference/ChannelExtract.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017-2019 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_CHANNEL_EXTRACT_H -#define ARM_COMPUTE_TEST_CHANNEL_EXTRACT_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<uint8_t> channel_extract(const TensorShape &shape, const std::vector<SimpleTensor<T>> &tensor_planes, Format format, Channel channel); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_CHANNEL_EXTRACT_H */ diff --git a/tests/validation/reference/ColorConvert.cpp b/tests/validation/reference/ColorConvert.cpp deleted file mode 100644 index c6a4630999..0000000000 --- a/tests/validation/reference/ColorConvert.cpp +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Copyright (c) 2017-2019 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. - */ -#include "ColorConvert.h" - -#include "arm_compute/core/Types.h" -#include "tests/validation/Helpers.h" -#include "tests/validation/reference/ColorConvertHelper.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -namespace -{ -template <typename T> -inline std::vector<SimpleTensor<T>> create_image_planes(const TensorShape &shape, Format format) -{ - TensorShape image_shape = adjust_odd_shape(shape, format); - - std::vector<SimpleTensor<T>> image_planes; - - switch(format) - { - case Format::U8: - case Format::RGB888: - case Format::RGBA8888: - case Format::YUYV422: - case Format::UYVY422: - { - image_planes.emplace_back(image_shape, format); - break; - } - case Format::NV12: - case Format::NV21: - { - TensorShape shape_uv88 = calculate_subsampled_shape(image_shape, Format::UV88); - - image_planes.emplace_back(image_shape, Format::U8); - image_planes.emplace_back(shape_uv88, Format::UV88); - break; - } - case Format::IYUV: - { - TensorShape shape_sub2 = calculate_subsampled_shape(image_shape, Format::IYUV); - - image_planes.emplace_back(image_shape, Format::U8); - image_planes.emplace_back(shape_sub2, Format::U8); - image_planes.emplace_back(shape_sub2, Format::U8); - break; - } - case Format::YUV444: - { - image_planes.emplace_back(image_shape, Format::U8); - image_planes.emplace_back(image_shape, Format::U8); - image_planes.emplace_back(image_shape, Format::U8); - break; - } - default: - ARM_COMPUTE_ERROR("Not supported"); - break; - } - - return image_planes; -} -} // namespace - -template <typename T> -std::vector<SimpleTensor<T>> color_convert(const TensorShape &shape, const std::vector<SimpleTensor<T>> &tensor_planes, Format src_format, Format dst_format) -{ - std::vector<SimpleTensor<T>> dst = create_image_planes<T>(shape, dst_format); - - switch(src_format) - { - case Format::RGB888: - { - switch(dst_format) - { - case Format::RGBA8888: - colorconvert_helper::detail::colorconvert_rgb_to_rgbx(tensor_planes[0], dst[0]); - break; - case Format::U8: - colorconvert_helper::detail::colorconvert_rgb_to_u8(tensor_planes[0], dst[0]); - break; - case Format::NV12: - colorconvert_helper::detail::colorconvert_rgb_to_nv12(tensor_planes[0], dst); - break; - case Format::IYUV: - colorconvert_helper::detail::colorconvert_rgb_to_iyuv(tensor_planes[0], dst); - break; - case Format::YUV444: - colorconvert_helper::detail::colorconvert_rgb_to_yuv4(tensor_planes[0], dst); - break; - default: - ARM_COMPUTE_ERROR("Not Supported"); - break; - } - break; - } - case Format::RGBA8888: - { - switch(dst_format) - { - case Format::RGB888: - colorconvert_helper::detail::colorconvert_rgbx_to_rgb(tensor_planes[0], dst[0]); - break; - case Format::NV12: - colorconvert_helper::detail::colorconvert_rgb_to_nv12(tensor_planes[0], dst); - break; - case Format::IYUV: - colorconvert_helper::detail::colorconvert_rgb_to_iyuv(tensor_planes[0], dst); - break; - case Format::YUV444: - colorconvert_helper::detail::colorconvert_rgb_to_yuv4(tensor_planes[0], dst); - break; - default: - ARM_COMPUTE_ERROR("Not Supported"); - break; - } - break; - } - case Format::UYVY422: - case Format::YUYV422: - { - switch(dst_format) - { - case Format::RGB888: - case Format::RGBA8888: - colorconvert_helper::detail::colorconvert_yuyv_to_rgb(tensor_planes[0], src_format, dst[0]); - break; - case Format::NV12: - colorconvert_helper::detail::colorconvert_yuyv_to_nv12(tensor_planes[0], src_format, dst); - break; - case Format::IYUV: - colorconvert_helper::detail::colorconvert_yuyv_to_iyuv(tensor_planes[0], src_format, dst); - break; - default: - ARM_COMPUTE_ERROR("Not Supported"); - break; - } - break; - } - case Format::IYUV: - { - switch(dst_format) - { - case Format::RGB888: - case Format::RGBA8888: - colorconvert_helper::detail::colorconvert_iyuv_to_rgb(tensor_planes, dst[0]); - break; - default: - ARM_COMPUTE_ERROR("Not Supported"); - break; - } - break; - } - case Format::NV12: - case Format::NV21: - { - switch(dst_format) - { - case Format::RGB888: - case Format::RGBA8888: - colorconvert_helper::detail::colorconvert_nv12_to_rgb(src_format, tensor_planes, dst[0]); - break; - case Format::IYUV: - colorconvert_helper::detail::colorconvert_nv_to_iyuv(tensor_planes, src_format, dst); - break; - case Format::YUV444: - colorconvert_helper::detail::colorconvert_nv_to_yuv4(tensor_planes, src_format, dst); - break; - default: - ARM_COMPUTE_ERROR("Not Supported"); - break; - } - break; - } - default: - ARM_COMPUTE_ERROR("Not supported"); - break; - } - return dst; -} - -template std::vector<SimpleTensor<uint8_t>> color_convert(const TensorShape &shape, const std::vector<SimpleTensor<uint8_t>> &tensor_planes, Format src_format, Format dst_format); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/ColorConvert.h b/tests/validation/reference/ColorConvert.h deleted file mode 100644 index 28776cb85f..0000000000 --- a/tests/validation/reference/ColorConvert.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017-2019 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_COLOR_CONVERT_H -#define ARM_COMPUTE_TEST_COLOR_CONVERT_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -std::vector<SimpleTensor<T>> color_convert(const TensorShape &shape, const std::vector<SimpleTensor<T>> &tensor_planes, Format src_format, Format dst_format); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_COLOR_CONVERT_H */ diff --git a/tests/validation/reference/Derivative.cpp b/tests/validation/reference/Derivative.cpp deleted file mode 100644 index c65ebcada5..0000000000 --- a/tests/validation/reference/Derivative.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2017-2020 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. - */ -#include "Derivative.h" - -#include "Utils.h" -#include "tests/Types.h" - -#include <array> - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -namespace -{ -const std::array<int8_t, 9> derivative_3_x{ { 0, 0, 0, -1, 0, 1, 0, 0, 0 } }; -const std::array<int8_t, 9> derivative_3_y{ { 0, -1, 0, 0, 0, 0, 0, 1, 0 } }; - -template <typename T> -struct data_type; - -template <> -struct data_type<int16_t> -{ - const static DataType value = DataType::S16; -}; -} // namespace - -template <typename T, typename U> -std::pair<SimpleTensor<T>, SimpleTensor<T>> derivative(const SimpleTensor<U> &src, BorderMode border_mode, uint8_t constant_border_value, GradientDimension gradient_dimension) -{ - const unsigned int filter_size = 3; - - SimpleTensor<T> dst_x(src.shape(), data_type<T>::value, src.num_channels()); - SimpleTensor<T> dst_y(src.shape(), data_type<T>::value, src.num_channels()); - - ValidRegion valid_region = shape_to_valid_region(src.shape(), border_mode == BorderMode::UNDEFINED, BorderSize(filter_size / 2)); - - const uint32_t num_elements = src.num_elements(); -#if defined(_OPENMP) - #pragma omp parallel for -#endif /* _OPENMP */ - for(uint32_t i = 0; i < num_elements; ++i) - { - Coordinates coord = index2coord(src.shape(), i); - - if(!is_in_valid_region(valid_region, coord)) - { - continue; - } - - switch(gradient_dimension) - { - case GradientDimension::GRAD_X: - apply_2d_spatial_filter(coord, src, dst_x, TensorShape{ filter_size, filter_size }, derivative_3_x.data(), 1.f, border_mode, - constant_border_value); - break; - case GradientDimension::GRAD_Y: - apply_2d_spatial_filter(coord, src, dst_y, TensorShape{ filter_size, filter_size }, derivative_3_y.data(), 1.f, border_mode, - constant_border_value); - break; - case GradientDimension::GRAD_XY: - apply_2d_spatial_filter(coord, src, dst_x, TensorShape{ filter_size, filter_size }, derivative_3_x.data(), 1.f, border_mode, - constant_border_value); - apply_2d_spatial_filter(coord, src, dst_y, TensorShape{ filter_size, filter_size }, derivative_3_y.data(), 1.f, border_mode, - constant_border_value); - break; - default: - ARM_COMPUTE_ERROR("Gradient dimension not supported"); - } - } - - return std::make_pair(dst_x, dst_y); -} - -template std::pair<SimpleTensor<int16_t>, SimpleTensor<int16_t>> derivative(const SimpleTensor<uint8_t> &src, BorderMode border_mode, uint8_t constant_border_value, - GradientDimension gradient_dimension); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/Derivative.h b/tests/validation/reference/Derivative.h deleted file mode 100644 index 16f764e90e..0000000000 --- a/tests/validation/reference/Derivative.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2017-2019 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_DERIVATIVE_H -#define ARM_COMPUTE_TEST_DERIVATIVE_H - -#include "tests/SimpleTensor.h" -#include "tests/Types.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T, typename U> -std::pair<SimpleTensor<T>, SimpleTensor<T>> derivative(const SimpleTensor<U> &src, BorderMode border_mode, uint8_t constant_border_value, GradientDimension gradient_dimension); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_DERIVATIVE_H */ diff --git a/tests/validation/reference/Dilate.cpp b/tests/validation/reference/Dilate.cpp deleted file mode 100644 index be8ccb6f3a..0000000000 --- a/tests/validation/reference/Dilate.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2017-2020 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. - */ -#include "Dilate.h" - -#include "Utils.h" -#include "tests/validation/Helpers.h" - -#include <algorithm> -#include <array> - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> dilate(const SimpleTensor<T> &src, BorderMode border_mode, T constant_border_value) -{ - /* - -1 x +1 - -1 [tl][tc][tr] -1 - y [ml][xy][mr] y - +1 [bl][bc][br] +1 - -1 x +1 - dilate: - dst(x, y) = max[ src(x', y') for x-1<=x'<=x+1, y-1<=y'<=y+1 ] = max({tl, tc, tr, ml, xy, mr, bl, bc, br}) - */ - SimpleTensor<T> dst(src.shape(), src.data_type()); - const uint32_t num_elements = src.num_elements(); - -#if defined(_OPENMP) - #pragma omp parallel for -#endif /* _OPENMP */ - for(uint32_t i = 0; i < num_elements; ++i) - { - Coordinates coord = index2coord(src.shape(), i); - const int x = coord.x(); - const int y = coord.y(); - - std::array<T, 9> neighbours = { { 0 } }; - for(int row = y - 1, j = 0; row <= y + 1; ++row) - { - for(int col = x - 1; col <= x + 1; ++col, ++j) - { - coord.set(0, col); - coord.set(1, row); - neighbours[j] = tensor_elem_at(src, coord, border_mode, constant_border_value); - } - } - - dst[i] = *std::max_element(neighbours.cbegin(), neighbours.cend()); - } - - return dst; -} - -template SimpleTensor<uint8_t> dilate(const SimpleTensor<uint8_t> &src, BorderMode border_mode, uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/Dilate.h b/tests/validation/reference/Dilate.h deleted file mode 100644 index 640bc9dd73..0000000000 --- a/tests/validation/reference/Dilate.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017-2019 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_DILATE_H -#define ARM_COMPUTE_TEST_DILATE_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> dilate(const SimpleTensor<T> &src, BorderMode border_mode, T constant_border_value = 0); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_DILATE_H */ diff --git a/tests/validation/reference/EqualizeHistogram.cpp b/tests/validation/reference/EqualizeHistogram.cpp deleted file mode 100644 index 8a957d7085..0000000000 --- a/tests/validation/reference/EqualizeHistogram.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (c) 2017-2020 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. - */ -#include "EqualizeHistogram.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> equalize_histogram(const SimpleTensor<T> &src) -{ - const size_t num_bins = 256; // 0-255 inclusive - - std::vector<T> lut(num_bins); - std::vector<uint32_t> hist(num_bins); - std::vector<uint32_t> cd(num_bins); // cumulative distribution - - SimpleTensor<T> dst(src.shape(), src.data_type()); - - // Create the histogram - for(int element_idx = 0; element_idx < src.num_elements(); ++element_idx) - { - hist[src[element_idx]]++; - } - - // Calculate cumulative distribution - std::partial_sum(hist.begin(), hist.end(), cd.begin()); - - // Get the number of pixels that have the lowest non-zero value - const uint32_t cd_min = *std::find_if(hist.begin(), hist.end(), [](const uint32_t &x) - { - return x > 0; - }); - - const size_t total_num_pixels = cd.back(); - - // Single color - create linear distribution - if(total_num_pixels == cd_min) - { - std::iota(lut.begin(), lut.end(), 0); - } - else - { - const float diff = total_num_pixels - cd_min; - - for(size_t i = 0; i < num_bins; ++i) - { - lut[i] = lround((cd[i] - cd_min) / diff * 255.f); - } - } - - // Fill output tensor with equalized values -#if defined(_OPENMP) - #pragma omp parallel for -#endif /* _OPENMP */ - for(int i = 0; i < src.num_elements(); ++i) - { - dst[i] = lut[src[i]]; - } - - return dst; -} - -template SimpleTensor<uint8_t> equalize_histogram(const SimpleTensor<uint8_t> &src); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/EqualizeHistogram.h b/tests/validation/reference/EqualizeHistogram.h deleted file mode 100644 index c79b2131aa..0000000000 --- a/tests/validation/reference/EqualizeHistogram.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017-2019 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_EQUALIZE_HISTOGRAM_H -#define ARM_COMPUTE_TEST_EQUALIZE_HISTOGRAM_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> equalize_histogram(const SimpleTensor<T> &src); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_EQUALIZE_HISTOGRAM_H */ diff --git a/tests/validation/reference/FastCorners.cpp b/tests/validation/reference/FastCorners.cpp deleted file mode 100644 index 25fbf1b6f2..0000000000 --- a/tests/validation/reference/FastCorners.cpp +++ /dev/null @@ -1,241 +0,0 @@ -/* - * Copyright (c) 2017-2019 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. - */ -#include "FastCorners.h" - -#include "Utils.h" -#include "tests/validation/Helpers.h" -#include "tests/validation/reference/NonMaximaSuppression.h" - -#include "tests/framework/Asserts.h" -#include <iomanip> - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -namespace -{ -constexpr unsigned int bresenham_radius = 3; -constexpr unsigned int bresenham_count = 16; - -/* - Offsets of the 16 pixels in the Bresenham circle of radius 3 centered on P - . . . . . . . . . - . . . F 0 1 . . . - . . E . . . 2 . . - . D . . . . . 3 . - . C . . P . . 4 . - . B . . . . . 5 . - . . A . . . 6 . . - . . . 9 8 7 . . . - . . . . . . . . . -*/ -const std::array<std::array<int, 2>, 16> circle_offsets = -{ - { - { { 0, -3 } }, // 0 - pixel #1 - { { 1, -3 } }, // 1 - pixel #2 - { { 2, -2 } }, // 2 - pixel #3 - { { 3, -1 } }, // 3 - pixel #4 - { { 3, 0 } }, // 4 - pixel #5 - { { 3, 1 } }, // 5 - pixel #6 - { { 2, 2 } }, // 6 - pixel #7 - { { 1, 3 } }, // 7 - pixel #8 - { { 0, 3 } }, // 8 - pixel #9 - { { -1, 3 } }, // 9 - pixel #10 - { { -2, 2 } }, // A - pixel #11 - { { -3, 1 } }, // B - pixel #12 - { { -3, 0 } }, // C - pixel #13 - { { -3, -1 } }, // D - pixel #14 - { { -2, -2 } }, // E - pixel #15 - { { -1, -3 } } // F - pixel #16 - } -}; - -/* - FAST-9 bit masks for consecutive points surrounding a corner candidate - Rejection of non-corners is expedited by checking pixels 1, 9, then 5, 13... -*/ -const std::array<uint16_t, 16> fast9_masks = -{ - { - 0x01FF, // 0000 0001 1111 1111 - 0x03FE, // 0000 0011 1111 1110 - 0x07FC, // 0000 0111 1111 1100 - 0x0FF8, // 0000 1111 1111 1000 - 0x1FF0, // 0001 1111 1111 0000 - 0x3FE0, // 0011 1111 1110 0000 - 0x7FC0, // 0111 1111 1100 0000 - 0xFF80, // 1111 1111 1000 0000 - 0xFF01, // 1111 1111 0000 0001 - 0xFE03, // 1111 1110 0000 0011 - 0xFC07, // 1111 1100 0000 0111 - 0xF80F, // 1111 1000 0000 1111 - 0xF01F, // 1111 0000 0001 1111 - 0xE03F, // 1110 0000 0011 1111 - 0xC07F, // 1100 0000 0111 1111 - 0x80FF // 1000 0000 1111 1111 - } -}; - -inline bool in_range(const uint8_t low, const uint8_t high, const uint8_t val) -{ - return low <= val && val <= high; -} - -template <typename T, typename F> -bool is_a_corner(const Coordinates &candidate, const SimpleTensor<T> &src, uint8_t threshold, BorderMode border_mode, T constant_border_value, F intensity_at) -{ - const auto intensity_p = tensor_elem_at(src, candidate, border_mode, constant_border_value); - const auto thresh_bright = intensity_p + threshold; - const auto thresh_dark = intensity_p - threshold; - - // Quicker rejection of non-corner points by checking pixels 1, 9 then 5, 13 around the candidate - const auto p1 = intensity_at(candidate, 0); - const auto p9 = intensity_at(candidate, 8); - const auto p5 = intensity_at(candidate, 4); - const auto p13 = intensity_at(candidate, 12); - - if((in_range(thresh_dark, thresh_bright, p1) && in_range(thresh_dark, thresh_bright, p9)) - || (in_range(thresh_dark, thresh_bright, p5) && in_range(thresh_dark, thresh_bright, p13))) - { - return false; - } - - uint16_t mask_bright = 0; - uint16_t mask_dark = 0; - - // Set bits of the brighter/darker pixels mask accordingly - for(unsigned int n = 0; n < bresenham_count; ++n) - { - T intensity_n = intensity_at(candidate, n); - mask_bright |= (intensity_n > thresh_bright) << n; - mask_dark |= (intensity_n < thresh_dark) << n; - } - - // Mark as corner candidate if brighter/darker pixel sequence satisfies any one of the FAST-9 masks - const auto found = std::find_if(fast9_masks.begin(), fast9_masks.end(), [&](decltype(fast9_masks[0]) mask) - { - return (mask_bright & mask) == mask || (mask_dark & mask) == mask; - }); - - return found != fast9_masks.end(); -} -} // namespace - -template <typename T> -std::vector<KeyPoint> fast_corners(const SimpleTensor<T> &src, float input_thresh, bool suppress_nonmax, BorderMode border_mode, T constant_border_value) -{ - // Get intensity of pixel at given index on the Bresenham circle around a candidate point - const auto intensity_at = [&](const Coordinates & point, const unsigned int idx) - { - const auto offset = circle_offsets[idx]; - Coordinates px{ point.x() + offset[0], point.y() + offset[1] }; - return tensor_elem_at(src, px, border_mode, constant_border_value); - }; - - const auto threshold = static_cast<uint8_t>(input_thresh); - std::vector<KeyPoint> corners; - - // 1. Detect potential corners (the segment test) - std::vector<Coordinates> corner_candidates; - SimpleTensor<uint8_t> scores(src.shape(), DataType::U8); - ValidRegion valid_region = shape_to_valid_region(src.shape(), BorderMode::UNDEFINED == border_mode, BorderSize(bresenham_radius)); - - const uint32_t num_elements = src.num_elements(); - for(uint32_t i = 0; i < num_elements; ++i) - { - Coordinates candidate = index2coord(src.shape(), i); - scores[i] = 0; - if(!is_in_valid_region(valid_region, candidate)) - { - continue; - } - - if(is_a_corner(candidate, src, threshold, border_mode, constant_border_value, intensity_at)) - { - corner_candidates.emplace_back(candidate); - scores[i] = 1; - } - } - - // 2. Calculate corner scores if necessary - if(suppress_nonmax) - { - for(const auto &candidate : corner_candidates) - { - const auto index = coord2index(scores.shape(), candidate); - uint8_t thresh_max = UINT8_MAX; - uint8_t thresh_min = threshold; - uint8_t response = (thresh_min + thresh_max) / 2; - - // Corner score (response) is the largest threshold for which the pixel remains a corner - while(thresh_max - thresh_min > 1) - { - response = (thresh_min + thresh_max) / 2; - if(is_a_corner(candidate, src, response, border_mode, constant_border_value, intensity_at)) - { - thresh_min = response; // raise threshold - } - else - { - thresh_max = response; // lower threshold - } - } - scores[index] = thresh_min; - } - - scores = non_maxima_suppression(scores, border_mode, constant_border_value); - valid_region = shape_to_valid_region(scores.shape(), BorderMode::UNDEFINED == border_mode, BorderSize(bresenham_radius + 1)); - } - - for(const auto &candidate : corner_candidates) - { - const auto index = coord2index(scores.shape(), candidate); - if(scores[index] > 0.f && is_in_valid_region(valid_region, candidate)) - { - KeyPoint corner; - corner.x = candidate.x(); - corner.y = candidate.y(); - corner.strength = scores[index]; - corner.tracking_status = 1; - corner.scale = 0.f; - corner.orientation = 0.f; - corner.error = 0.f; - corners.emplace_back(corner); - } - } - - return corners; -} - -template std::vector<KeyPoint> fast_corners(const SimpleTensor<uint8_t> &src, float threshold, bool suppress_nonmax, BorderMode border_mode, uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/FastCorners.h b/tests/validation/reference/FastCorners.h deleted file mode 100644 index 2c4506de5c..0000000000 --- a/tests/validation/reference/FastCorners.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2017-2019 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_FAST_CORNERS_H -#define ARM_COMPUTE_TEST_FAST_CORNERS_H - -#include "arm_compute/core/Types.h" -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -std::vector<KeyPoint> fast_corners(const SimpleTensor<T> &src, float input_thresh, bool suppress_nonmax, BorderMode border_mode, T constant_border_value = 0); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_FAST_CORNERS_H */ diff --git a/tests/validation/reference/Gaussian3x3.cpp b/tests/validation/reference/Gaussian3x3.cpp deleted file mode 100644 index 2e307e8152..0000000000 --- a/tests/validation/reference/Gaussian3x3.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2017-2020 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. - */ -#include "arm_compute/core/Helpers.h" - -#include "Gaussian3x3.h" -#include "Utils.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> gaussian3x3(const SimpleTensor<T> &src, BorderMode border_mode, T constant_border_value) -{ - SimpleTensor<T> dst(src.shape(), src.data_type()); - const std::array<T, 9> filter{ { 1, 2, 1, 2, 4, 2, 1, 2, 1 } }; - const float scale = 1.f / 16.f; - const uint32_t num_elements = src.num_elements(); - -#if defined(_OPENMP) - #pragma omp parallel for -#endif /* _OPENMP */ - for(uint32_t element_idx = 0; element_idx < num_elements; ++element_idx) - { - const Coordinates id = index2coord(src.shape(), element_idx); - apply_2d_spatial_filter(id, src, dst, TensorShape(3U, 3U), filter.data(), scale, border_mode, constant_border_value); - } - return dst; -} - -template SimpleTensor<uint8_t> gaussian3x3(const SimpleTensor<uint8_t> &src, BorderMode border_mode, uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/Gaussian3x3.h b/tests/validation/reference/Gaussian3x3.h deleted file mode 100644 index a433db6693..0000000000 --- a/tests/validation/reference/Gaussian3x3.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017-2019 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_GAUSSIAN3X3_H -#define ARM_COMPUTE_TEST_GAUSSIAN3X3_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> gaussian3x3(const SimpleTensor<T> &src, BorderMode border_mode, T constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_GAUSSIAN3X3_H */ diff --git a/tests/validation/reference/Gaussian5x5.cpp b/tests/validation/reference/Gaussian5x5.cpp deleted file mode 100644 index 2133d8980e..0000000000 --- a/tests/validation/reference/Gaussian5x5.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2017-2020 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. - */ -#include "arm_compute/core/Helpers.h" - -#include "Gaussian5x5.h" -#include "Utils.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> gaussian5x5(const SimpleTensor<T> &src, BorderMode border_mode, T constant_border_value) -{ - SimpleTensor<T> dst(src.shape(), src.data_type()); - const std::array<T, 25> filter{ { - 1, 4, 6, 4, 1, - 4, 16, 24, 16, 4, - 6, 24, 36, 24, 6, - 4, 16, 24, 16, 4, - 1, 4, 6, 4, 1 - } }; - const float scale = 1.f / 256.f; - const uint32_t num_elements = src.num_elements(); - -#if defined(_OPENMP) - #pragma omp parallel for -#endif /* _OPENMP */ - for(uint32_t element_idx = 0; element_idx < num_elements; ++element_idx) - { - const Coordinates id = index2coord(src.shape(), element_idx); - apply_2d_spatial_filter(id, src, dst, TensorShape(5U, 5U), filter.data(), scale, border_mode, constant_border_value); - } - return dst; -} - -template SimpleTensor<uint8_t> gaussian5x5(const SimpleTensor<uint8_t> &src, BorderMode border_mode, uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/Gaussian5x5.h b/tests/validation/reference/Gaussian5x5.h deleted file mode 100644 index 42920bd4c0..0000000000 --- a/tests/validation/reference/Gaussian5x5.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017-2019 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_GAUSSIAN5X5_H -#define ARM_COMPUTE_TEST_GAUSSIAN5X5_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> gaussian5x5(const SimpleTensor<T> &src, BorderMode border_mode, T constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_GAUSSIAN5X5_H */ diff --git a/tests/validation/reference/GaussianPyramidHalf.cpp b/tests/validation/reference/GaussianPyramidHalf.cpp deleted file mode 100644 index 5bddd853a0..0000000000 --- a/tests/validation/reference/GaussianPyramidHalf.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2017-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. - */ -#include "GaussianPyramidHalf.h" - -#include "arm_compute/core/Helpers.h" - -#include "Gaussian5x5.h" -#include "Scale.h" -#include "Utils.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -std::vector<SimpleTensor<T>> gaussian_pyramid_half(const SimpleTensor<T> &src, BorderMode border_mode, uint8_t constant_border_value, size_t num_levels) -{ - std::vector<SimpleTensor<T>> dst; - - // Level0 is equal to src - dst.push_back(src); - - for(size_t i = 1; i < num_levels; ++i) - { - // Gaussian Filter - const SimpleTensor<T> out_gaus5x5 = reference::gaussian5x5(dst[i - 1], border_mode, constant_border_value); - - // Scale down by 2 with nearest interpolation - const SimpleTensor<T> out = reference::scale(out_gaus5x5, SCALE_PYRAMID_HALF, SCALE_PYRAMID_HALF, InterpolationPolicy::NEAREST_NEIGHBOR, border_mode, constant_border_value, SamplingPolicy::CENTER, - true); - - dst.push_back(out); - } - - return dst; -} - -template std::vector<SimpleTensor<uint8_t>> gaussian_pyramid_half(const SimpleTensor<uint8_t> &src, BorderMode border_mode, uint8_t constant_border_value, size_t num_levels); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/GaussianPyramidHalf.h b/tests/validation/reference/GaussianPyramidHalf.h deleted file mode 100644 index 225ef00727..0000000000 --- a/tests/validation/reference/GaussianPyramidHalf.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017-2019 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_GAUSSIAN_PYRAMID_HALF_H -#define ARM_COMPUTE_TEST_GAUSSIAN_PYRAMID_HALF_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -std::vector<SimpleTensor<T>> gaussian_pyramid_half(const SimpleTensor<T> &src, BorderMode border_mode, uint8_t constant_border_value, size_t num_levels); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_GAUSSIAN_PYRAMID_HALF_H */
\ No newline at end of file diff --git a/tests/validation/reference/HOGDescriptor.cpp b/tests/validation/reference/HOGDescriptor.cpp deleted file mode 100644 index e00beaf5d7..0000000000 --- a/tests/validation/reference/HOGDescriptor.cpp +++ /dev/null @@ -1,264 +0,0 @@ -/* - * Copyright (c) 2017-2019 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. - */ -#include "HOGDescriptor.h" - -#include "Derivative.h" -#include "Magnitude.h" -#include "Phase.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -namespace -{ -template <typename T> -void hog_orientation_compute(const SimpleTensor<T> &mag, const SimpleTensor<T> &phase, std::vector<T> &bins, const HOGInfo &hog_info) -{ - const Size2D &cell_size = hog_info.cell_size(); - const size_t num_bins = hog_info.num_bins(); - - float phase_scale = (PhaseType::SIGNED == hog_info.phase_type() ? num_bins / 360.0f : num_bins / 180.0f); - phase_scale *= (PhaseType::SIGNED == hog_info.phase_type() ? 360.0f / 255.0f : 1.0f); - - int row_idx = 0; - for(size_t yc = 0; yc < cell_size.height; ++yc) - { - for(size_t xc = 0; xc < cell_size.width; xc++) - { - const float mag_value = mag[(row_idx + xc)]; - const float phase_value = phase[(row_idx + xc)] * phase_scale + 0.5f; - const float w1 = phase_value - floor(phase_value); - - // The quantised phase is the histogram index [0, num_bins - 1] - // Check limit of histogram index. If hidx == num_bins, hidx = 0 - const auto hidx = static_cast<unsigned int>(phase_value) % num_bins; - - // Weighted vote between 2 bins - bins[hidx] += mag_value * (1.0f - w1); - bins[(hidx + 1) % num_bins] += mag_value * w1; - } - - row_idx += cell_size.width; - } -} - -template <typename T> -void hog_block_normalization_compute(SimpleTensor<T> &block, SimpleTensor<T> &desc, const HOGInfo &hog_info, uint32_t block_idx) -{ - const int num_bins_per_block = desc.num_channels(); - const HOGNormType norm_type = hog_info.normalization_type(); - const Coordinates id = index2coord(desc.shape(), block_idx); - - float sum = 0.0f; - - // Calculate sum - for(int i = 0; i < num_bins_per_block; ++i) - { - const float val = block[i]; - sum += (norm_type == HOGNormType::L1_NORM) ? std::fabs(val) : val * val; - } - - // Calculate normalization scale - float scale = 1.0f / (std::sqrt(sum) + num_bins_per_block * 0.1f); - - if(norm_type == HOGNormType::L2HYS_NORM) - { - // Reset sum - sum = 0.0f; - for(int i = 0; i < num_bins_per_block; ++i) - { - float val = block[i] * scale; - - // Clip scaled input_value if over l2_hyst_threshold - val = fmin(val, hog_info.l2_hyst_threshold()); - sum += val * val; - block[i] = val; - } - - // We use the same constants of OpenCV - scale = 1.0f / (std::sqrt(sum) + 1e-3f); - } - - for(int i = 0; i < num_bins_per_block; ++i) - { - block[i] *= scale; - reinterpret_cast<float *>(desc(id))[i] = block[i]; - } -} -} // namespace - -template <typename T, typename U, typename V> -void hog_orientation_binning(const SimpleTensor<T> &mag, const SimpleTensor<U> &phase, SimpleTensor<V> &hog_space, const HOGInfo &hog_info) -{ - const Size2D &cell_size = hog_info.cell_size(); - - const size_t num_bins = hog_info.num_bins(); - const size_t shape_width = hog_space.shape().x() * hog_info.cell_size().width; - const size_t shape_height = hog_space.shape().y() * hog_info.cell_size().height; - - TensorShape cell_shape(cell_size.width, cell_size.height); - - SimpleTensor<V> mag_cell(cell_shape, DataType::F32); - SimpleTensor<V> phase_cell(cell_shape, DataType::F32); - - int cell_idx = 0; - int y_offset = 0; - - // Traverse shape - for(auto sy = cell_size.height; sy <= shape_height; sy += cell_size.height) - { - int x_offset = 0; - for(auto sx = cell_size.width; sx <= shape_width; sx += cell_size.width) - { - int row_idx = 0; - int elem_idx = 0; - - // Traverse cell - for(auto y = 0u; y < cell_size.height; ++y) - { - for(auto x = 0u; x < cell_size.width; ++x) - { - int shape_idx = x + row_idx + x_offset + y_offset; - mag_cell[elem_idx] = mag[shape_idx]; - phase_cell[elem_idx] = phase[shape_idx]; - elem_idx++; - } - - row_idx += shape_width; - } - - // Partition magnitude values into bins based on phase values - std::vector<V> bins(num_bins); - hog_orientation_compute(mag_cell, phase_cell, bins, hog_info); - - for(size_t i = 0; i < num_bins; ++i) - { - hog_space[cell_idx * num_bins + i] = bins[i]; - } - - x_offset += cell_size.width; - cell_idx++; - } - - y_offset += (cell_size.height * shape_width); - } -} - -template <typename T> -void hog_block_normalization(SimpleTensor<T> &desc, const SimpleTensor<T> &hog_space, const HOGInfo &hog_info) -{ - const Size2D cells_per_block = hog_info.num_cells_per_block(); - const Size2D cells_per_block_stride = hog_info.num_cells_per_block_stride(); - const Size2D &block_size = hog_info.block_size(); - const Size2D &block_stride = hog_info.block_stride(); - const size_t num_bins = hog_info.num_bins(); - - const size_t shape_width = hog_space.shape().x() * hog_info.cell_size().width; - const size_t shape_height = hog_space.shape().y() * hog_info.cell_size().height; - const size_t num_bins_per_block_x = cells_per_block.width * num_bins; - - // Tensor representing single block - SimpleTensor<T> block(TensorShape{ 1u, 1u }, DataType::F32, cells_per_block.area() * num_bins); - - uint32_t block_idx = 0; - int block_y_offset = 0; - - // Traverse shape - for(auto sy = block_size.height; sy <= shape_height; sy += block_stride.height) - { - int block_x_offset = 0; - for(auto sx = block_size.width; sx <= shape_width; sx += block_stride.width) - { - int cell_y_offset = 0; - int elem_idx = 0; - - // Traverse block - for(auto y = 0u; y < cells_per_block.height; ++y) - { - for(auto x = 0u; x < num_bins_per_block_x; ++x) - { - int idx = x + cell_y_offset + block_x_offset + block_y_offset; - block[elem_idx] = hog_space[idx]; - elem_idx++; - } - - cell_y_offset += hog_space.shape().x() * num_bins; - } - - // Normalize block and write to descriptor - hog_block_normalization_compute(block, desc, hog_info, block_idx); - - block_x_offset += cells_per_block_stride.width * num_bins; - block_idx++; - } - - block_y_offset += cells_per_block_stride.height * num_bins * hog_space.shape().x(); - } -} - -template <typename T, typename U> -SimpleTensor<T> hog_descriptor(const SimpleTensor<U> &src, BorderMode border_mode, U constant_border_value, const HOGInfo &hog_info) -{ - SimpleTensor<int16_t> grad_x; - SimpleTensor<int16_t> grad_y; - - // Create tensor info for HOG descriptor - TensorInfo desc_info(hog_info, src.shape().x(), src.shape().y()); - SimpleTensor<T> desc(desc_info.tensor_shape(), DataType::F32, desc_info.num_channels()); - - // Create HOG space tensor (num_cells_x, num_cells_y) - TensorShape hog_space_shape(src.shape().x() / hog_info.cell_size().width, - src.shape().y() / hog_info.cell_size().height); - - // For each cell a histogram with a num_bins is created - TensorInfo info_hog_space(hog_space_shape, hog_info.num_bins(), DataType::F32); - SimpleTensor<T> hog_space(info_hog_space.tensor_shape(), DataType::F32, info_hog_space.num_channels()); - - // Calculate derivative - std::tie(grad_x, grad_y) = derivative<int16_t>(src, border_mode, constant_border_value, GradientDimension::GRAD_XY); - - // For each cell create histogram based on magnitude and phase - hog_orientation_binning(magnitude(grad_x, grad_y, MagnitudeType::L2NORM), - phase(grad_x, grad_y, hog_info.phase_type()), - hog_space, - hog_info); - - // Normalize histograms based on block size - hog_block_normalization(desc, hog_space, hog_info); - - return desc; -} - -template void hog_orientation_binning(const SimpleTensor<int16_t> &mag, const SimpleTensor<uint8_t> &phase, SimpleTensor<float> &hog_space, const HOGInfo &hog_info); -template void hog_block_normalization(SimpleTensor<float> &desc, const SimpleTensor<float> &hog_space, const HOGInfo &hog_info); -template SimpleTensor<float> hog_descriptor(const SimpleTensor<uint8_t> &src, BorderMode border_mode, uint8_t constant_border_value, const HOGInfo &hog_info); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/HOGDescriptor.h b/tests/validation/reference/HOGDescriptor.h deleted file mode 100644 index dffeb655b2..0000000000 --- a/tests/validation/reference/HOGDescriptor.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2017-2019 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_HOG_DESCRIPTOR_H -#define ARM_COMPUTE_TEST_HOG_DESCRIPTOR_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T, typename U, typename V> -void hog_orientation_binning(const SimpleTensor<T> &mag, const SimpleTensor<U> &phase, SimpleTensor<V> &hog_space, const HOGInfo &hog_info); - -template <typename T> -void hog_block_normalization(SimpleTensor<T> &desc, const SimpleTensor<T> &hog_space, const HOGInfo &hog_info); - -template <typename T, typename U> -SimpleTensor<T> hog_descriptor(const SimpleTensor<U> &src, BorderMode border_mode, U constant_border_value, const HOGInfo &hog_info); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_HOG_DESCRIPTOR_H */ diff --git a/tests/validation/reference/HOGDetector.cpp b/tests/validation/reference/HOGDetector.cpp deleted file mode 100644 index 798c3fc142..0000000000 --- a/tests/validation/reference/HOGDetector.cpp +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (c) 2018-2019 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. - */ -#include "HOGDetector.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -namespace -{ -/** Computes the number of detection windows to iterate over in the feature vector. */ -Size2D num_detection_windows(const TensorShape &shape, const Size2D &window_step, const HOGInfo &hog_info) -{ - const size_t num_block_strides_width = hog_info.detection_window_size().width / hog_info.block_stride().width; - const size_t num_block_strides_height = hog_info.detection_window_size().height / hog_info.block_stride().height; - - return Size2D{ floor_to_multiple(shape.x() - num_block_strides_width, window_step.width) + window_step.width, - floor_to_multiple(shape.y() - num_block_strides_height, window_step.height) + window_step.height }; -} -} // namespace - -template <typename T> -std::vector<DetectionWindow> hog_detector(const SimpleTensor<T> &src, const std::vector<T> &descriptor, unsigned int max_num_detection_windows, - const HOGInfo &hog_info, const Size2D &detection_window_stride, float threshold, uint16_t idx_class) -{ - ARM_COMPUTE_ERROR_ON_MSG((detection_window_stride.width % hog_info.block_stride().width != 0), - "Detection window stride width must be multiple of block stride width"); - ARM_COMPUTE_ERROR_ON_MSG((detection_window_stride.height % hog_info.block_stride().height != 0), - "Detection window stride height must be multiple of block stride height"); - - // Create vector for identifying each detection window - std::vector<DetectionWindow> windows; - - // Calculate detection window step - const Size2D window_step(detection_window_stride.width / hog_info.block_stride().width, - detection_window_stride.height / hog_info.block_stride().height); - - // Calculate number of detection windows - const Size2D num_windows = num_detection_windows(src.shape(), window_step, hog_info); - - // Calculate detection window and row offsets in feature vector - const size_t src_offset_x = window_step.width * hog_info.num_bins() * hog_info.num_cells_per_block().area(); - const size_t src_offset_y = window_step.height * hog_info.num_bins() * hog_info.num_cells_per_block().area() * src.shape().x(); - const size_t src_offset_row = src.num_channels() * src.shape().x(); - - // Calculate detection window attributes - const Size2D num_block_positions_per_detection_window = hog_info.num_block_positions_per_image(hog_info.detection_window_size()); - const unsigned int num_bins_per_descriptor_x = num_block_positions_per_detection_window.width * src.num_channels(); - const unsigned int num_blocks_per_descriptor_y = num_block_positions_per_detection_window.height; - - ARM_COMPUTE_ERROR_ON((num_bins_per_descriptor_x * num_blocks_per_descriptor_y + 1) != hog_info.descriptor_size()); - - size_t win_id = 0; - - // Traverse feature vector in detection window steps - for(auto win_y = 0u, offset_y = 0u; win_y < num_windows.height; win_y += window_step.height, offset_y += src_offset_y) - { - for(auto win_x = 0u, offset_x = 0u; win_x < num_windows.width; win_x += window_step.width, offset_x += src_offset_x) - { - // Reset the score - float score = 0.0f; - - // Traverse detection window - for(auto y = 0u, offset_row = 0u; y < num_blocks_per_descriptor_y; ++y, offset_row += src_offset_row) - { - const int bin_offset = y * num_bins_per_descriptor_x; - - for(auto x = 0u; x < num_bins_per_descriptor_x; ++x) - { - // Compute Linear SVM - const float a = src[x + offset_x + offset_y + offset_row]; - const float b = descriptor[x + bin_offset]; - score += a * b; - } - } - - // Add the bias. The bias is located at the position (descriptor_size() - 1) - score += descriptor[num_bins_per_descriptor_x * num_blocks_per_descriptor_y]; - - if(score > threshold) - { - DetectionWindow window; - - if(win_id++ < max_num_detection_windows) - { - window.x = win_x * hog_info.block_stride().width; - window.y = win_y * hog_info.block_stride().height; - window.width = hog_info.detection_window_size().width; - window.height = hog_info.detection_window_size().height; - window.idx_class = idx_class; - window.score = score; - - windows.push_back(window); - } - } - } - } - - return windows; -} - -template std::vector<DetectionWindow> hog_detector(const SimpleTensor<float> &src, const std::vector<float> &descriptor, unsigned int max_num_detection_windows, - const HOGInfo &hog_info, const Size2D &detection_window_stride, float threshold, uint16_t idx_class); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/HOGDetector.h b/tests/validation/reference/HOGDetector.h deleted file mode 100644 index 9809ae384f..0000000000 --- a/tests/validation/reference/HOGDetector.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2018-2019 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_HOG_DETECTOR_H -#define ARM_COMPUTE_TEST_HOG_DETECTOR_H - -#include "arm_compute/core/Types.h" -#include "arm_compute/core/Utils.h" -#include "tests/SimpleTensor.h" - -#include <vector> - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -std::vector<DetectionWindow> hog_detector(const SimpleTensor<T> &src, const std::vector<T> &descriptor, unsigned int max_num_detection_windows, - const HOGInfo &hog_info, const Size2D &detection_window_stride, float threshold = 0.0f, uint16_t idx_class = 0); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_HOG_DETECTOR_H */ diff --git a/tests/validation/reference/HOGMultiDetection.cpp b/tests/validation/reference/HOGMultiDetection.cpp deleted file mode 100644 index 50d846c0be..0000000000 --- a/tests/validation/reference/HOGMultiDetection.cpp +++ /dev/null @@ -1,279 +0,0 @@ -/* - * Copyright (c) 2017-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. - */ -#include "HOGMultiDetection.h" - -#include "Derivative.h" -#include "HOGDescriptor.h" -#include "HOGDetector.h" -#include "Magnitude.h" -#include "Phase.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -namespace -{ -void validate_models(const std::vector<HOGInfo> &models) -{ - ARM_COMPUTE_ERROR_ON(0 == models.size()); - - for(size_t i = 1; i < models.size(); ++i) - { - ARM_COMPUTE_ERROR_ON_MSG(models[0].phase_type() != models[i].phase_type(), - "All HOG parameters must have the same phase type"); - - ARM_COMPUTE_ERROR_ON_MSG(models[0].normalization_type() != models[i].normalization_type(), - "All HOG parameters must have the same normalization_type"); - - ARM_COMPUTE_ERROR_ON_MSG((models[0].l2_hyst_threshold() != models[i].l2_hyst_threshold()) && (models[0].normalization_type() == arm_compute::HOGNormType::L2HYS_NORM), - "All HOG parameters must have the same l2 hysteresis threshold if you use L2 hysteresis normalization type"); - } -} -} // namespace - -void detection_windows_non_maxima_suppression(std::vector<DetectionWindow> &multi_windows, float min_distance) -{ - const size_t num_candidates = multi_windows.size(); - size_t num_detections = 0; - - // Sort by idx_class first and by score second - std::sort(multi_windows.begin(), multi_windows.end(), [](const DetectionWindow & lhs, const DetectionWindow & rhs) - { - if(lhs.idx_class < rhs.idx_class) - { - return true; - } - if(rhs.idx_class < lhs.idx_class) - { - return false; - } - - // idx_classes are equal so compare by score - if(lhs.score > rhs.score) - { - return true; - } - if(rhs.score > lhs.score) - { - return false; - } - - return false; - }); - - const float min_distance_pow2 = min_distance * min_distance; - - // Euclidean distance - for(size_t i = 0; i < num_candidates; ++i) - { - if(0.0f != multi_windows.at(i).score) - { - DetectionWindow cur; - cur.x = multi_windows.at(i).x; - cur.y = multi_windows.at(i).y; - cur.width = multi_windows.at(i).width; - cur.height = multi_windows.at(i).height; - cur.idx_class = multi_windows.at(i).idx_class; - cur.score = multi_windows.at(i).score; - - // Store window - multi_windows.at(num_detections) = cur; - ++num_detections; - - const float xc = cur.x + cur.width * 0.5f; - const float yc = cur.y + cur.height * 0.5f; - - for(size_t k = i + 1; k < (num_candidates) && (cur.idx_class == multi_windows.at(k).idx_class); ++k) - { - const float xn = multi_windows.at(k).x + multi_windows.at(k).width * 0.5f; - const float yn = multi_windows.at(k).y + multi_windows.at(k).height * 0.5f; - - const float dx = std::fabs(xn - xc); - const float dy = std::fabs(yn - yc); - - if(dx < min_distance && dy < min_distance) - { - const float d = dx * dx + dy * dy; - - if(d < min_distance_pow2) - { - // Invalidate detection window - multi_windows.at(k).score = 0.0f; - } - } - } - } - } - - multi_windows.resize(num_detections); -} - -template <typename T> -std::vector<DetectionWindow> hog_multi_detection(const SimpleTensor<T> &src, BorderMode border_mode, T constant_border_value, - const std::vector<HOGInfo> &models, std::vector<std::vector<float>> descriptors, - unsigned int max_num_detection_windows, float threshold, bool non_maxima_suppression, float min_distance) -{ - ARM_COMPUTE_ERROR_ON(descriptors.size() != models.size()); - validate_models(models); - - const size_t width = src.shape().x(); - const size_t height = src.shape().y(); - const size_t num_models = models.size(); - - // Initialize previous values - size_t prev_num_bins = models[0].num_bins(); - Size2D prev_cell_size = models[0].cell_size(); - Size2D prev_block_size = models[0].block_size(); - Size2D prev_block_stride = models[0].block_stride(); - - std::vector<size_t> input_orient_bin; - std::vector<size_t> input_hog_detect; - std::vector<std::pair<size_t, size_t>> input_block_norm; - - input_orient_bin.push_back(0); - input_hog_detect.push_back(0); - input_block_norm.emplace_back(0, 0); - - // Iterate through the number of models and check if orientation binning - // and block normalization steps can be skipped - for(size_t i = 1; i < num_models; ++i) - { - size_t cur_num_bins = models[i].num_bins(); - Size2D cur_cell_size = models[i].cell_size(); - Size2D cur_block_size = models[i].block_size(); - Size2D cur_block_stride = models[i].block_stride(); - - // Check if binning and normalization steps are required - if((cur_num_bins != prev_num_bins) || (cur_cell_size.width != prev_cell_size.width) || (cur_cell_size.height != prev_cell_size.height)) - { - prev_num_bins = cur_num_bins; - prev_cell_size = cur_cell_size; - prev_block_size = cur_block_size; - prev_block_stride = cur_block_stride; - - // Compute orientation binning and block normalization. Update input to process - input_orient_bin.push_back(i); - input_block_norm.emplace_back(i, input_orient_bin.size() - 1); - } - else if((cur_block_size.width != prev_block_size.width) || (cur_block_size.height != prev_block_size.height) || (cur_block_stride.width != prev_block_stride.width) - || (cur_block_stride.height != prev_block_stride.height)) - { - prev_block_size = cur_block_size; - prev_block_stride = cur_block_stride; - - // Compute block normalization. Update input to process - input_block_norm.emplace_back(i, input_orient_bin.size() - 1); - } - - // Update input to process for hog detector - input_hog_detect.push_back(input_block_norm.size() - 1); - } - - size_t num_orient_bin = input_orient_bin.size(); - size_t num_block_norm = input_block_norm.size(); - size_t num_hog_detect = input_hog_detect.size(); - - std::vector<SimpleTensor<float>> hog_spaces(num_orient_bin); - std::vector<SimpleTensor<float>> hog_norm_spaces(num_block_norm); - - // Calculate derivative - SimpleTensor<int16_t> grad_x; - SimpleTensor<int16_t> grad_y; - std::tie(grad_x, grad_y) = derivative<int16_t>(src, border_mode, constant_border_value, GradientDimension::GRAD_XY); - - // Calculate magnitude and phase - SimpleTensor<int16_t> _mag = magnitude(grad_x, grad_y, MagnitudeType::L2NORM); - SimpleTensor<uint8_t> _phase = phase(grad_x, grad_y, models[0].phase_type()); - - // Calculate Tensors for the HOG space and orientation binning - for(size_t i = 0; i < num_orient_bin; ++i) - { - const size_t idx_multi_hog = input_orient_bin[i]; - - const size_t num_bins = models[idx_multi_hog].num_bins(); - const size_t num_cells_x = width / models[idx_multi_hog].cell_size().width; - const size_t num_cells_y = height / models[idx_multi_hog].cell_size().height; - - // TensorShape of hog space - TensorShape hog_space_shape(num_cells_x, num_cells_y); - - // Initialise HOG space - TensorInfo info_hog_space(hog_space_shape, num_bins, DataType::F32); - hog_spaces.at(i) = SimpleTensor<float>(info_hog_space.tensor_shape(), DataType::F32, info_hog_space.num_channels()); - - // For each cell create histogram based on magnitude and phase - hog_orientation_binning(_mag, _phase, hog_spaces[i], models[idx_multi_hog]); - } - - // Calculate Tensors for the normalized HOG space and block normalization - for(size_t i = 0; i < num_block_norm; ++i) - { - const size_t idx_multi_hog = input_block_norm[i].first; - const size_t idx_orient_bin = input_block_norm[i].second; - - // Create tensor info for HOG descriptor - TensorInfo tensor_info(models[idx_multi_hog], src.shape().x(), src.shape().y()); - hog_norm_spaces.at(i) = SimpleTensor<float>(tensor_info.tensor_shape(), DataType::F32, tensor_info.num_channels()); - - // Normalize histograms based on block size - hog_block_normalization(hog_norm_spaces[i], hog_spaces[idx_orient_bin], models[idx_multi_hog]); - } - - std::vector<DetectionWindow> multi_windows; - - // Calculate Detection Windows for HOG detector - for(size_t i = 0; i < num_hog_detect; ++i) - { - const size_t idx_block_norm = input_hog_detect[i]; - - // NOTE: Detection window stride fixed to block stride - const Size2D detection_window_stride = models[i].block_stride(); - - std::vector<DetectionWindow> windows = hog_detector(hog_norm_spaces[idx_block_norm], descriptors[i], - max_num_detection_windows, models[i], detection_window_stride, threshold, i); - - multi_windows.insert(multi_windows.end(), windows.begin(), windows.end()); - } - - // Suppress Non-maxima detection windows - if(non_maxima_suppression) - { - detection_windows_non_maxima_suppression(multi_windows, min_distance); - } - - return multi_windows; -} - -template std::vector<DetectionWindow> hog_multi_detection(const SimpleTensor<uint8_t> &src, BorderMode border_mode, uint8_t constant_border_value, - const std::vector<HOGInfo> &models, std::vector<std::vector<float>> descriptors, - unsigned int max_num_detection_windows, float threshold, bool non_maxima_suppression, float min_distance); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/HOGMultiDetection.h b/tests/validation/reference/HOGMultiDetection.h deleted file mode 100644 index 7194af70c7..0000000000 --- a/tests/validation/reference/HOGMultiDetection.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2018-2019 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_HOG_MULTI_DETECTION_H -#define ARM_COMPUTE_TEST_HOG_MULTI_DETECTION_H - -#include "arm_compute/core/Types.h" -#include "tests/SimpleTensor.h" - -#include <vector> - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -std::vector<DetectionWindow> hog_multi_detection(const SimpleTensor<T> &src, BorderMode border_mode, T constant_border_value, - const std::vector<HOGInfo> &models, std::vector<std::vector<float>> descriptors, - unsigned int max_num_detection_windows, float threshold = 0.0f, bool non_maxima_suppression = false, float min_distance = 1.0f); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_HOG_MULTI_DETECTION_H */ diff --git a/tests/validation/reference/HarrisCornerDetector.cpp b/tests/validation/reference/HarrisCornerDetector.cpp deleted file mode 100644 index 6c46b3de5d..0000000000 --- a/tests/validation/reference/HarrisCornerDetector.cpp +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright (c) 2017 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. - */ -#include "HarrisCornerDetector.h" - -#include "Utils.h" -#include "tests/validation/Helpers.h" -#include "tests/validation/reference/NonMaximaSuppression.h" -#include "tests/validation/reference/Sobel.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -namespace -{ -template <typename T> -std::tuple<SimpleTensor<T>, SimpleTensor<T>, float> compute_sobel(const SimpleTensor<uint8_t> &src, int gradient_size, int block_size, BorderMode border_mode, uint8_t constant_border_value) -{ - SimpleTensor<T> grad_x; - SimpleTensor<T> grad_y; - float norm_factor = 0.f; - - std::tie(grad_x, grad_y) = sobel<T>(src, gradient_size, border_mode, constant_border_value, GradientDimension::GRAD_XY); - - switch(gradient_size) - { - case 3: - norm_factor = 1.f / (4 * 255 * block_size); - break; - case 5: - norm_factor = 1.f / (16 * 255 * block_size); - break; - case 7: - norm_factor = 1.f / (64 * 255 * block_size); - break; - default: - ARM_COMPUTE_ERROR("Gradient size not supported."); - } - - return std::make_tuple(grad_x, grad_y, norm_factor); -} - -template <typename T, typename U> -std::vector<KeyPoint> harris_corner_detector_impl(const SimpleTensor<U> &src, float threshold, float min_dist, float sensitivity, int gradient_size, int block_size, BorderMode border_mode, - U constant_border_value) -{ - ARM_COMPUTE_ERROR_ON(block_size != 3 && block_size != 5 && block_size != 7); - - SimpleTensor<T> grad_x; - SimpleTensor<T> grad_y; - float norm_factor = 0.f; - - // Sobel - std::tie(grad_x, grad_y, norm_factor) = compute_sobel<T>(src, gradient_size, block_size, border_mode, constant_border_value); - - SimpleTensor<float> scores(src.shape(), DataType::F32); - ValidRegion scores_region = shape_to_valid_region(scores.shape(), border_mode == BorderMode::UNDEFINED, BorderSize(gradient_size / 2 + block_size / 2)); - - // Calculate scores - for(int i = 0; i < scores.num_elements(); ++i) - { - Coordinates src_coord = index2coord(src.shape(), i); - Coordinates block_top_left{ src_coord.x() - block_size / 2, src_coord.y() - block_size / 2 }; - Coordinates block_bottom_right{ src_coord.x() + block_size / 2, src_coord.y() + block_size / 2 }; - - if(!is_in_valid_region(scores_region, src_coord)) - { - scores[i] = 0.f; - continue; - } - - float Gx2 = 0.f; - float Gy2 = 0.f; - float Gxy = 0.f; - - // Calculate Gx^2, Gy^2 and Gxy within the given window - for(int y = block_top_left.y(); y <= block_bottom_right.y(); ++y) - { - for(int x = block_top_left.x(); x <= block_bottom_right.x(); ++x) - { - Coordinates block_coord(x, y); - - const float norm_x = tensor_elem_at(grad_x, block_coord, border_mode, static_cast<T>(constant_border_value)) * norm_factor; - const float norm_y = tensor_elem_at(grad_y, block_coord, border_mode, static_cast<T>(constant_border_value)) * norm_factor; - - Gx2 += std::pow(norm_x, 2); - Gy2 += std::pow(norm_y, 2); - Gxy += norm_x * norm_y; - } - } - - const float trace2 = std::pow(Gx2 + Gy2, 2); - const float det = Gx2 * Gy2 - std::pow(Gxy, 2); - const float response = det - sensitivity * trace2; - - if(response > threshold) - { - scores[i] = response; - } - else - { - scores[i] = 0.f; - } - } - - // Suppress non-maxima candidates - SimpleTensor<float> suppressed_scores = non_maxima_suppression(scores, border_mode != BorderMode::UNDEFINED ? BorderMode::CONSTANT : BorderMode::UNDEFINED, 0.f); - ValidRegion suppressed_scores_region = shape_to_valid_region(suppressed_scores.shape(), border_mode == BorderMode::UNDEFINED, BorderSize(gradient_size / 2 + block_size / 2 + 1)); - - // Create vector of candidate corners - std::vector<KeyPoint> corner_candidates; - - for(int i = 0; i < suppressed_scores.num_elements(); ++i) - { - Coordinates coord = index2coord(suppressed_scores.shape(), i); - - if(is_in_valid_region(suppressed_scores_region, coord) && suppressed_scores[i] != 0.f) - { - KeyPoint corner; - corner.x = coord.x(); - corner.y = coord.y(); - corner.tracking_status = 1; - corner.strength = suppressed_scores[i]; - corner.scale = 0.f; - corner.orientation = 0.f; - corner.error = 0.f; - - corner_candidates.emplace_back(corner); - } - } - - // Sort descending by strength - std::sort(corner_candidates.begin(), corner_candidates.end(), [](const KeyPoint & a, const KeyPoint & b) - { - return a.strength > b.strength; - }); - - std::vector<KeyPoint> corners; - corners.reserve(corner_candidates.size()); - - // Only add corner if there is no stronger within min_dist - for(const KeyPoint &point : corner_candidates) - { - const auto strongest = std::find_if(corners.begin(), corners.end(), [&](const KeyPoint & other) - { - return std::sqrt((std::pow(point.x - other.x, 2) + std::pow(point.y - other.y, 2))) < min_dist; - }); - - if(strongest == corners.end()) - { - corners.emplace_back(point); - } - } - - corners.shrink_to_fit(); - - return corners; -} -} // namespace - -template <typename T> -std::vector<KeyPoint> harris_corner_detector(const SimpleTensor<T> &src, float threshold, float min_dist, float sensitivity, int gradient_size, int block_size, BorderMode border_mode, - T constant_border_value) -{ - if(gradient_size < 7) - { - return harris_corner_detector_impl<int16_t>(src, threshold, min_dist, sensitivity, gradient_size, block_size, border_mode, constant_border_value); - } - else - { - return harris_corner_detector_impl<int32_t>(src, threshold, min_dist, sensitivity, gradient_size, block_size, border_mode, constant_border_value); - } -} - -template std::vector<KeyPoint> harris_corner_detector(const SimpleTensor<uint8_t> &src, float threshold, float min_dist, float sensitivity, int gradient_size, int block_size, BorderMode border_mode, - uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/HarrisCornerDetector.h b/tests/validation/reference/HarrisCornerDetector.h deleted file mode 100644 index 2f464749f6..0000000000 --- a/tests/validation/reference/HarrisCornerDetector.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2017-2019 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_HARRIS_CORNER_DETECTOR_H -#define ARM_COMPUTE_TEST_HARRIS_CORNER_DETECTOR_H - -#include "arm_compute/core/Types.h" -#include "tests/SimpleTensor.h" - -#include <vector> - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -std::vector<KeyPoint> harris_corner_detector(const SimpleTensor<T> &src, - float threshold, float min_dist, float sensitivity, int gradient_size, int block_size, - BorderMode border_mode, T constant_border_value = 0); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_HARRIS_CORNER_DETECTOR_H */ diff --git a/tests/validation/reference/Histogram.cpp b/tests/validation/reference/Histogram.cpp deleted file mode 100644 index f9c77108e1..0000000000 --- a/tests/validation/reference/Histogram.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2017 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. - */ -#include "Histogram.h" - -#include "Utils.h" -#include "arm_compute/core/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<uint32_t> histogram(const SimpleTensor<T> &src, size_t num_bins, int32_t offset, uint32_t range) -{ - SimpleTensor<uint32_t> dst(TensorShape(num_bins), DataType::U32); - - // Clear the distribution - for(size_t element_idx = 0; element_idx < num_bins; ++element_idx) - { - dst[element_idx] = 0; - } - - // Create the histogram - for(int element_idx = 0; element_idx < src.num_elements(); ++element_idx) - { - if((offset <= src[element_idx]) && (src[element_idx] < (offset + range))) - { - const int index = (src[element_idx] - offset) * num_bins / range; - dst[index]++; - } - } - - return dst; -} - -template SimpleTensor<uint32_t> histogram(const SimpleTensor<uint8_t> &src, size_t num_bins, int32_t offset, uint32_t range); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/Histogram.h b/tests/validation/reference/Histogram.h deleted file mode 100644 index 5f6c7d27a2..0000000000 --- a/tests/validation/reference/Histogram.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017-2019 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_HISTOGRAM_H -#define ARM_COMPUTE_TEST_HISTOGRAM_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<uint32_t> histogram(const SimpleTensor<T> &src, size_t num_bins, int32_t offset, uint32_t range); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_HISTOGRAM_H */ diff --git a/tests/validation/reference/IntegralImage.cpp b/tests/validation/reference/IntegralImage.cpp deleted file mode 100644 index 0f6a7504fe..0000000000 --- a/tests/validation/reference/IntegralImage.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2017 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. - */ -#include "IntegralImage.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<uint32_t> integral_image(const SimpleTensor<T> &src) -{ - SimpleTensor<uint32_t> dst(src.shape(), DataType::U32); - - // Length of dimensions - const size_t width = src.shape().x(); - const size_t height = src.shape().y(); - const size_t depth = src.shape().total_size_upper(2); - - const size_t image_size = width * height; - - for(size_t z = 0; z < depth; ++z) - { - size_t current_image = z * image_size; - - //First element of each image - dst[current_image] = src[current_image]; - - // First row of each image (add only pixel on the left) - for(size_t x = 1; x < width; ++x) - { - dst[current_image + x] = static_cast<uint32_t>(src[current_image + x]) + dst[current_image + x - 1]; - } - - // Subsequent rows - for(size_t y = 1; y < height; ++y) - { - size_t current_row = current_image + (width * y); - - // First element of each row (add only pixel up) - dst[current_row] = static_cast<uint32_t>(src[current_row]) + dst[current_row - width]; - - // Following row elements - for(size_t x = 1; x < width; ++x) - { - size_t current_pixel = current_row + x; - - // out = in + up(out) + left(out) - up_left(out) - dst[current_pixel] = static_cast<uint32_t>(src[current_pixel]) + dst[current_pixel - 1] - + dst[current_pixel - width] - dst[current_pixel - width - 1]; - } - } - } - - return dst; -} - -template SimpleTensor<uint32_t> integral_image(const SimpleTensor<uint8_t> &src); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/IntegralImage.h b/tests/validation/reference/IntegralImage.h deleted file mode 100644 index 2c9b96a1d6..0000000000 --- a/tests/validation/reference/IntegralImage.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017-2019 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_INTEGRAL_IMAGE_H -#define ARM_COMPUTE_TEST_INTEGRAL_IMAGE_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<uint32_t> integral_image(const SimpleTensor<T> &src); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_INTEGRAL_IMAGE_H */ diff --git a/tests/validation/reference/LaplacianPyramid.cpp b/tests/validation/reference/LaplacianPyramid.cpp deleted file mode 100644 index 904b8403b3..0000000000 --- a/tests/validation/reference/LaplacianPyramid.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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. - */ -#include "LaplacianPyramid.h" - -#include "tests/validation/reference/ArithmeticOperations.h" -#include "tests/validation/reference/DepthConvertLayer.h" -#include "tests/validation/reference/Gaussian5x5.h" -#include "tests/validation/reference/GaussianPyramidHalf.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T, typename U> -std::vector<SimpleTensor<U>> laplacian_pyramid(const SimpleTensor<T> &src, SimpleTensor<U> &dst, size_t num_levels, BorderMode border_mode, uint8_t constant_border_value) -{ - std::vector<SimpleTensor<T>> pyramid_conv; - std::vector<SimpleTensor<U>> pyramid_dst; - - // First, a Gaussian pyramid with SCALE_PYRAMID_HALF is created - std::vector<SimpleTensor<T>> gaussian_level_pyramid = reference::gaussian_pyramid_half(src, border_mode, constant_border_value, num_levels); - - // For each level i, the corresponding image Ii is blurred with Gaussian 5x5 - // filter, and the difference between the two images is the corresponding - // level Li of the Laplacian pyramid - for(size_t i = 0; i < num_levels; ++i) - { - const SimpleTensor<T> level_filtered = reference::gaussian5x5(gaussian_level_pyramid[i], border_mode, constant_border_value); - pyramid_conv.push_back(level_filtered); - - const SimpleTensor<U> level_filtered_converted = depth_convert<T, U>(level_filtered, DataType::S16, ConvertPolicy::WRAP, 0); - const SimpleTensor<U> gaussian_level_converted = depth_convert<T, U>(gaussian_level_pyramid[i], DataType::S16, ConvertPolicy::WRAP, 0); - - const SimpleTensor<U> level_sub = reference::arithmetic_operation<U>(reference::ArithmeticOperation::SUB, gaussian_level_converted, level_filtered_converted, dst.data_type(), ConvertPolicy::WRAP); - pyramid_dst.push_back(level_sub); - } - - // Return the lowest resolution image and the pyramid - dst = depth_convert<T, U>(pyramid_conv[num_levels - 1], DataType::S16, ConvertPolicy::WRAP, 0); - - return pyramid_dst; -} - -template std::vector<SimpleTensor<int16_t>> laplacian_pyramid(const SimpleTensor<uint8_t> &src, SimpleTensor<int16_t> &dst, size_t num_levels, BorderMode border_mode, uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/LaplacianPyramid.h b/tests/validation/reference/LaplacianPyramid.h deleted file mode 100644 index 0596b81648..0000000000 --- a/tests/validation/reference/LaplacianPyramid.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2018-2019 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_LAPLACIAN_PYRAMID_H -#define ARM_COMPUTE_TEST_LAPLACIAN_PYRAMID_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T, typename U> -std::vector<SimpleTensor<U>> laplacian_pyramid(const SimpleTensor<T> &src, SimpleTensor<U> &dst, size_t num_levels, BorderMode border_mode, uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_LAPLACIAN_PYRAMID_H */ diff --git a/tests/validation/reference/LaplacianReconstruct.cpp b/tests/validation/reference/LaplacianReconstruct.cpp deleted file mode 100644 index 2a0fcc2a65..0000000000 --- a/tests/validation/reference/LaplacianReconstruct.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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. - */ -#include "LaplacianReconstruct.h" - -#include "arm_compute/core/Types.h" -#include "tests/validation/reference/ArithmeticOperations.h" -#include "tests/validation/reference/DepthConvertLayer.h" -#include "tests/validation/reference/Scale.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T, typename U> -SimpleTensor<U> laplacian_reconstruct(const std::vector<SimpleTensor<T>> &pyramid, const SimpleTensor<T> &low_res, BorderMode border_mode, T constant_border_value) -{ - std::vector<SimpleTensor<T>> tmp_pyramid(pyramid); - - const size_t last_level = pyramid.size() - 1; - const DataType data_type = low_res.data_type(); - - // input + L(n-1) - tmp_pyramid[last_level] = reference::arithmetic_operation(reference::ArithmeticOperation::ADD, low_res, pyramid[last_level], data_type, ConvertPolicy::SATURATE); - - // Scale levels n-1 to 1, and add levels n-2 to 0 - for(size_t i = last_level; i-- > 0;) - { - const float scale_x = static_cast<float>(tmp_pyramid[i].shape().x()) / tmp_pyramid[i + 1].shape().x(); - const float scale_y = static_cast<float>(tmp_pyramid[i].shape().y()) / tmp_pyramid[i + 1].shape().y(); - - tmp_pyramid[i] = reference::scale(tmp_pyramid[i + 1], scale_x, scale_y, InterpolationPolicy::NEAREST_NEIGHBOR, - border_mode, constant_border_value, SamplingPolicy::CENTER, false); - - tmp_pyramid[i] = reference::arithmetic_operation(reference::ArithmeticOperation::ADD, tmp_pyramid[i], pyramid[i], data_type, ConvertPolicy::SATURATE); - } - - return reference::depth_convert<T, U>(tmp_pyramid[0], DataType::U8, ConvertPolicy::SATURATE, 0); -} - -template SimpleTensor<uint8_t> laplacian_reconstruct(const std::vector<SimpleTensor<int16_t>> &pyramid, const SimpleTensor<int16_t> &low_res, BorderMode border_mode, int16_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/LaplacianReconstruct.h b/tests/validation/reference/LaplacianReconstruct.h deleted file mode 100644 index 8820c92983..0000000000 --- a/tests/validation/reference/LaplacianReconstruct.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2018-2019 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_LAPLACIAN_RECONSTRUCT_H -#define ARM_COMPUTE_TEST_LAPLACIAN_RECONSTRUCT_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T, typename U> -SimpleTensor<U> laplacian_reconstruct(const std::vector<SimpleTensor<T>> &pyramid, const SimpleTensor<T> &low_res, BorderMode border_mode, T constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_LAPLACIAN_RECONSTRUCT_H */ diff --git a/tests/validation/reference/Magnitude.cpp b/tests/validation/reference/Magnitude.cpp deleted file mode 100644 index 390aaa5d48..0000000000 --- a/tests/validation/reference/Magnitude.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2017 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. - */ -#include "Magnitude.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> magnitude(const SimpleTensor<T> &gx, const SimpleTensor<T> &gy, MagnitudeType magnitude_type) -{ - SimpleTensor<T> mag(gx.shape(), gx.data_type()); - - using intermediate_type = typename common_promoted_unsigned_type<T>::intermediate_type; - - for(int i = 0; i < gx.num_elements(); ++i) - { - double val = 0.f; - - if(magnitude_type == MagnitudeType::L1NORM) - { - val = static_cast<intermediate_type>(std::abs(gx[i])) + static_cast<intermediate_type>(std::abs(gy[i])); - } - else // MagnitudeType::L2NORM - { - // Note: kernel saturates to uint32_t instead of intermediate_type for S32 format - auto sum = static_cast<uint32_t>(gx[i] * gx[i]) + static_cast<uint32_t>(gy[i] * gy[i]); - val = std::sqrt(sum) + 0.5f; - } - - mag[i] = saturate_cast<T>(val); - } - - return mag; -} - -template SimpleTensor<int16_t> magnitude(const SimpleTensor<int16_t> &gx, const SimpleTensor<int16_t> &gy, MagnitudeType magnitude_type); -template SimpleTensor<int32_t> magnitude(const SimpleTensor<int32_t> &gx, const SimpleTensor<int32_t> &gy, MagnitudeType magnitude_type); -template SimpleTensor<half_float::half> magnitude(const SimpleTensor<half_float::half> &gx, const SimpleTensor<half_float::half> &gy, MagnitudeType magnitude_type); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/Magnitude.h b/tests/validation/reference/Magnitude.h deleted file mode 100644 index 81db27de20..0000000000 --- a/tests/validation/reference/Magnitude.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017-2019 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_MAGNITUDE_H -#define ARM_COMPUTE_TEST_MAGNITUDE_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> magnitude(const SimpleTensor<T> &gx, const SimpleTensor<T> &gy, MagnitudeType magnitude_type); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_MAGNITUDE_H */ diff --git a/tests/validation/reference/Median3x3.cpp b/tests/validation/reference/Median3x3.cpp deleted file mode 100644 index 55f5f62292..0000000000 --- a/tests/validation/reference/Median3x3.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2017-2019 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. - */ -#include "arm_compute/core/Helpers.h" - -#include "Median3x3.h" -#include "Utils.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -namespace -{ -constexpr unsigned int filter_size = 3; /* Size of the kernel/filter in number of elements. */ -constexpr BorderSize border_size(filter_size / 2); /* Border size of the kernel/filter around its central element. */ -} // namespace - -template <typename T> -SimpleTensor<T> median3x3(const SimpleTensor<T> &src, BorderMode border_mode, T constant_border_value) -{ - SimpleTensor<T> dst(src.shape(), src.data_type()); - const int size_tot_filter = filter_size * filter_size; - const uint32_t num_elements = src.num_elements(); - - for(uint32_t src_idx = 0; src_idx < num_elements; ++src_idx) - { - std::array<T, size_tot_filter> filter_elems = { { 0 } }; - Coordinates id = index2coord(src.shape(), src_idx); - const int x = id.x(); - const int y = id.y(); - - for(int j = y - static_cast<int>(border_size.top), index = 0; j <= y + static_cast<int>(border_size.bottom); ++j) - { - for(int i = x - static_cast<int>(border_size.left); i <= x + static_cast<int>(border_size.right); ++i, ++index) - { - id.set(0, i); - id.set(1, j); - filter_elems[index] = tensor_elem_at(src, id, border_mode, constant_border_value); - } - } - std::sort(filter_elems.begin(), filter_elems.end()); - dst[src_idx] = filter_elems[size_tot_filter / 2]; - } - - return dst; -} - -template SimpleTensor<uint8_t> median3x3(const SimpleTensor<uint8_t> &src, BorderMode border_mode, uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/Median3x3.h b/tests/validation/reference/Median3x3.h deleted file mode 100644 index a10f428d0c..0000000000 --- a/tests/validation/reference/Median3x3.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017-2019 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_MEDIAN3X3_H -#define ARM_COMPUTE_TEST_MEDIAN3X3_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> median3x3(const SimpleTensor<T> &src, BorderMode border_mode, T constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_MEDIAN3X3_H */ diff --git a/tests/validation/reference/NonLinearFilter.cpp b/tests/validation/reference/NonLinearFilter.cpp deleted file mode 100644 index ada8286927..0000000000 --- a/tests/validation/reference/NonLinearFilter.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2017-2019 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. - */ -#include "NonLinearFilter.h" -#include "Utils.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> non_linear_filter(const SimpleTensor<T> &src, NonLinearFilterFunction function, unsigned int mask_size, MatrixPattern pattern, const uint8_t *mask, BorderMode border_mode, - uint8_t constant_border_value) -{ - SimpleTensor<T> dst(src.shape(), src.data_type()); - - ARM_COMPUTE_ERROR_ON(pattern == MatrixPattern::OTHER && mask == nullptr); - ARM_COMPUTE_UNUSED(pattern); - - using intermediate_type = typename common_promoted_signed_type<T>::intermediate_type; - - const int sq_mask_size = mask_size * mask_size; - const int half_mask_size = mask_size / 2; - std::vector<intermediate_type> vals(sq_mask_size); - intermediate_type current_value = 0; - - const ValidRegion valid_region = shape_to_valid_region(src.shape(), border_mode == BorderMode::UNDEFINED, BorderSize(half_mask_size)); - const uint32_t num_elements = src.num_elements(); - - for(uint32_t element_idx = 0, count = 0, index = 0; element_idx < num_elements; ++element_idx, count = 0, index = 0) - { - Coordinates id = index2coord(src.shape(), element_idx); - if(is_in_valid_region(valid_region, id)) - { - int idx = id.x(); - int idy = id.y(); - for(int y = idy - half_mask_size; y <= idy + half_mask_size; ++y) - { - for(int x = idx - half_mask_size; x <= idx + half_mask_size; ++x, ++index) - { - id.set(0, x); - id.set(1, y); - current_value = tensor_elem_at(src, id, border_mode, constant_border_value); - - if(mask[index] == 255) - { - vals[count] = static_cast<intermediate_type>(current_value); - ++count; - } - } - } - std::sort(vals.begin(), vals.begin() + count); - - ARM_COMPUTE_ERROR_ON(count == 0); - - switch(function) - { - case NonLinearFilterFunction::MIN: - dst[element_idx] = saturate_cast<T>(vals[0]); - break; - case NonLinearFilterFunction::MAX: - dst[element_idx] = saturate_cast<T>(vals[count - 1]); - break; - case NonLinearFilterFunction::MEDIAN: - dst[element_idx] = saturate_cast<T>(vals[count / 2]); - break; - default: - ARM_COMPUTE_ERROR("Unsupported NonLinearFilter function."); - } - } - } - - return dst; -} - -template SimpleTensor<uint8_t> non_linear_filter(const SimpleTensor<uint8_t> &src, NonLinearFilterFunction function, unsigned int mask_size, MatrixPattern pattern, const uint8_t *mask, - BorderMode border_mode, uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/NonLinearFilter.h b/tests/validation/reference/NonLinearFilter.h deleted file mode 100644 index ecf6563a15..0000000000 --- a/tests/validation/reference/NonLinearFilter.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2017-2019 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_BITWISE_NOT_H -#define ARM_COMPUTE_TEST_BITWISE_NOT_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> non_linear_filter(const SimpleTensor<T> &src, NonLinearFilterFunction function, unsigned int mask_size, MatrixPattern pattern, const uint8_t *mask, BorderMode border_mode, - uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_BITWISE_NOT_H */ diff --git a/tests/validation/reference/OpticalFlow.cpp b/tests/validation/reference/OpticalFlow.cpp deleted file mode 100644 index 0a04214045..0000000000 --- a/tests/validation/reference/OpticalFlow.cpp +++ /dev/null @@ -1,404 +0,0 @@ -/* - * 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. - */ -#include "OpticalFlow.h" - -#include "GaussianPyramidHalf.h" -#include "Scharr.h" -#include "Utils.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -namespace -{ -using KeyPointArray = std::vector<KeyPoint>; -using InternalKeyPointArray = std::vector<InternalKeyPoint>; - -// Constants used for Lucas-Kanade Algorithm -constexpr int W_BITS = 14; -constexpr float D0 = 1 << W_BITS; -constexpr float DETERMINANT_THRESHOLD = 1.0e-07f; -constexpr float EIGENVALUE_THRESHOLD = 1.0e-04f; -constexpr float FLT_SCALE = 1.0f / (1 << 20); - -// Creates an InternalKeyPointArray for tracking non-integral pixel coordinates -InternalKeyPointArray create_internal_keypoints(const KeyPointArray &keypoints) -{ - InternalKeyPointArray internal_keypoints; - - for(auto keypoint : keypoints) - { - InternalKeyPoint internal_keypoint; - - internal_keypoint.x = static_cast<float>(keypoint.x); - internal_keypoint.y = static_cast<float>(keypoint.y); - internal_keypoint.tracking_status = static_cast<bool>(keypoint.tracking_status); - - internal_keypoints.push_back(internal_keypoint); - } - - return internal_keypoints; -} - -// Scale tracked points based on Pyramid level -void scale_tracked_points(size_t level, size_t num_levels, bool use_initial_estimate, - InternalKeyPointArray &old_points_internal, InternalKeyPointArray &new_points_internal, - const KeyPointArray &old_points, const KeyPointArray &new_points_estimates) -{ - if(level == num_levels - 1) // lowest resolution - { - const float scale = std::pow(SCALE_PYRAMID_HALF, level); - - for(size_t i = 0; i < old_points.size(); ++i) - { - old_points_internal.at(i).x = old_points.at(i).x * scale; - old_points_internal.at(i).y = old_points.at(i).y * scale; - old_points_internal.at(i).tracking_status = true; - - InternalKeyPoint keypoint_to_track; - - if(use_initial_estimate) - { - keypoint_to_track.x = new_points_estimates.at(i).x * scale; - keypoint_to_track.y = new_points_estimates.at(i).y * scale; - keypoint_to_track.tracking_status = (new_points_estimates.at(i).tracking_status == 1); - } - else - { - keypoint_to_track.x = old_points_internal.at(i).x; - keypoint_to_track.y = old_points_internal.at(i).y; - keypoint_to_track.tracking_status = true; - } - - new_points_internal.at(i) = keypoint_to_track; - } - } - else - { - for(size_t i = 0; i < old_points.size(); ++i) - { - old_points_internal.at(i).x /= SCALE_PYRAMID_HALF; - old_points_internal.at(i).y /= SCALE_PYRAMID_HALF; - new_points_internal.at(i).x /= SCALE_PYRAMID_HALF; - new_points_internal.at(i).y /= SCALE_PYRAMID_HALF; - } - } -} - -bool is_invalid_keypoint(const InternalKeyPoint &keypoint, const ValidRegion &valid_region, size_t window_dimension) -{ - const int half_window = window_dimension / 2; - const int x = std::floor(keypoint.x); - const int y = std::floor(keypoint.y); - - return (x - half_window < valid_region.start(0)) || (x + half_window >= valid_region.end(0) - 1) || (y - half_window < valid_region.start(1)) || (y + half_window >= valid_region.end(1) - 1); -} - -template <typename T> -constexpr int INT_ROUND(T x, int n) -{ - return (x + (1 << (n - 1))) >> n; -} - -// Return the bilinear value at a specified coordinate with different border modes -template <typename T> -int bilinear_interpolate(const SimpleTensor<T> &in, Coordinates id, float wx, float wy, BorderMode border_mode, T constant_border_value, int scale) -{ - const int level = id.x(); - const int idy = id.y(); - - const float dx = wx; - const float dy = wy; - const float dx_1 = 1.0f - dx; - const float dy_1 = 1.0f - dy; - - const T border_value = constant_border_value; - - id.set(0, level); - id.set(1, idy); - const T tl = tensor_elem_at(in, id, border_mode, border_value); - id.set(0, level + 1); - id.set(1, idy); - const T tr = tensor_elem_at(in, id, border_mode, border_value); - id.set(0, level); - id.set(1, idy + 1); - const T bl = tensor_elem_at(in, id, border_mode, border_value); - id.set(0, level + 1); - id.set(1, idy + 1); - const T br = tensor_elem_at(in, id, border_mode, border_value); - - // weights - const int w00 = roundf(dx_1 * dy_1 * D0); - const int w01 = roundf(dx * dy_1 * D0); - const int w10 = roundf(dx_1 * dy * D0); - const int w11 = D0 - w00 - w01 - w10; - - return static_cast<int>(INT_ROUND(tl * w00 + tr * w01 + bl * w10 + br * w11, scale)); -} - -template <typename T> -std::vector<int> compute_derivative(const SimpleTensor<T> &input, const InternalKeyPoint &keypoint, - BorderMode border_mode, uint8_t constant_border_value, size_t window_dimension, int scale) -{ - std::vector<int> bilinear_values; - - const int half_window = window_dimension / 2; - - float keypoint_int_x = 0; - float keypoint_int_y = 0; - - const float wx = std::modf(keypoint.x, &keypoint_int_x); - const float wy = std::modf(keypoint.y, &keypoint_int_y); - - Coordinates tl_window(static_cast<int>(keypoint_int_x) - half_window, static_cast<int>(keypoint_int_y) - half_window); - Coordinates br_window(static_cast<int>(keypoint_int_x) + half_window, static_cast<int>(keypoint_int_y) + half_window); - - for(int y = tl_window.y(); y <= br_window.y(); ++y) - { - for(int x = tl_window.x(); x <= br_window.x(); ++x) - { - bilinear_values.push_back(bilinear_interpolate(input, Coordinates(x, y), wx, wy, border_mode, static_cast<T>(constant_border_value), scale)); - } - } - - return bilinear_values; -} - -std::tuple<float, float, float> compute_spatial_gradient_matrix(const std::vector<int> &bilinear_ix, const std::vector<int> &bilinear_iy) -{ - ARM_COMPUTE_ERROR_ON(bilinear_ix.size() != bilinear_iy.size()); - - int iA11 = 0; - int iA12 = 0; - int iA22 = 0; - - for(size_t i = 0; i < bilinear_ix.size(); ++i) - { - int ixval = bilinear_ix[i]; - int iyval = bilinear_iy[i]; - - iA11 += ixval * ixval; - iA12 += ixval * iyval; - iA22 += iyval * iyval; - } - - return std::make_tuple(iA11 * FLT_SCALE, iA12 * FLT_SCALE, iA22 * FLT_SCALE); -} - -std::tuple<double, double> compute_temporal_gradient_vector(const std::vector<int> &bilinear_it_old, - const std::vector<int> &bilinear_it_new, - const std::vector<int> &bilinear_ix, - const std::vector<int> &bilinear_iy) -{ - ARM_COMPUTE_ERROR_ON(bilinear_ix.size() != bilinear_iy.size()); - ARM_COMPUTE_ERROR_ON(bilinear_it_old.size() != bilinear_it_new.size()); - - int ib1 = 0; - int ib2 = 0; - - for(size_t i = 0; i < bilinear_ix.size(); ++i) - { - int ixval = bilinear_ix[i]; - int iyval = bilinear_iy[i]; - int ival = bilinear_it_old[i]; - int jval = bilinear_it_new[i]; - - const int diff = jval - ival; - - ib1 += diff * ixval; - ib2 += diff * iyval; - } - - const double b1 = ib1 * FLT_SCALE; - const double b2 = ib2 * FLT_SCALE; - - return std::make_tuple(b1, b2); -} -} // namespace - -template <typename T> -std::vector<KeyPoint> optical_flow(const SimpleTensor<T> &old_input, const SimpleTensor<T> &new_input, - const OpticalFlowParameters ¶ms, size_t num_levels, - const std::vector<KeyPoint> &old_points, const std::vector<KeyPoint> &new_points_estimates, - BorderMode border_mode, uint8_t constant_border_value) -{ - const int filter_size = 3; // scharr filter size - const size_t max_iterations = 1000; // fixed by kernel - const size_t window_dimension = params.window_dimension; - const size_t num_iterations = (params.termination == Termination::TERM_CRITERIA_EPSILON) ? max_iterations : params.num_iterations; - - KeyPointArray new_points(old_points.size()); - - InternalKeyPointArray old_points_internal = create_internal_keypoints(old_points); - InternalKeyPointArray new_points_internal = create_internal_keypoints(new_points_estimates); - - SimpleTensor<int16_t> scharr_gx; - SimpleTensor<int16_t> scharr_gy; - - // Create pyramids - std::vector<SimpleTensor<T>> old_pyramid = gaussian_pyramid_half(old_input, border_mode, constant_border_value, num_levels); - std::vector<SimpleTensor<T>> new_pyramid = gaussian_pyramid_half(new_input, border_mode, constant_border_value, num_levels); - - // Iterate over each level of the pyramid - for(size_t idx = num_levels; idx > 0; --idx) - { - const size_t level = idx - 1; - - // Calculate scharr gradients - std::tie(scharr_gx, scharr_gy) = scharr<int16_t, T>(old_pyramid[level], filter_size, border_mode, constant_border_value, GradientDimension::GRAD_XY); - - scale_tracked_points(level, num_levels, params.use_initial_estimate, old_points_internal, new_points_internal, old_points, new_points_estimates); - - // Calculate valid region based on image dimensions of current pyramid level - const ValidRegion valid_region = shape_to_valid_region(old_pyramid[level].shape(), (border_mode == BorderMode::UNDEFINED), BorderSize(filter_size / 2)); - - for(size_t i = 0; i < old_points.size(); ++i) - { - InternalKeyPoint &old_keypoint = old_points_internal.at(i); - InternalKeyPoint &new_keypoint = new_points_internal.at(i); - - // Helper function for untracking keypoints when on the lowest pyramid level (high resolution) - const auto untrack_keypoint = [&](bool predicate) - { - if(predicate && (level == 0)) - { - new_keypoint.tracking_status = false; - return true; - } - return predicate; - }; - - if(!old_keypoint.tracking_status) - { - continue; - } - - // Check if tracked coordinate is outside image coordinate - if(untrack_keypoint(is_invalid_keypoint(old_keypoint, valid_region, window_dimension))) - { - continue; - } - - // Compute spatial derivative - std::vector<int> bilinear_ix = compute_derivative(scharr_gx, old_keypoint, border_mode, constant_border_value, window_dimension, W_BITS); - std::vector<int> bilinear_iy = compute_derivative(scharr_gy, old_keypoint, border_mode, constant_border_value, window_dimension, W_BITS); - - float A11 = 0.f; - float A12 = 0.f; - float A22 = 0.f; - std::tie(A11, A12, A22) = compute_spatial_gradient_matrix(bilinear_ix, bilinear_iy); - - // Calculate criteria for lost tracking : Matrix A is invertible - // 1. The determinant of the matrix is less than DETERMINANT_THRESHOLD - // 2. The minimum eigenvalue of the matrix is less than EIGENVALUE_THRESHOLD - const float trace_A = A11 + A22; - const float determinant = A11 * A22 - A12 * A12; - const float discriminant = (trace_A * trace_A) - 4.0f * (determinant); - const float eigenvalue_A = (trace_A - std::sqrt(discriminant)) / 2.0f; - - // Divide by window_dimension squared to reduce the floating point accummulation error - const float eigenvalue = eigenvalue_A / (window_dimension * window_dimension); - - // Check if it is a good point to track - if(untrack_keypoint(eigenvalue < EIGENVALUE_THRESHOLD || determinant < DETERMINANT_THRESHOLD)) - { - continue; - } - - float prev_delta_x = 0.f; - float prev_delta_y = 0.f; - - for(size_t j = 0; j < num_iterations; ++j) - { - // Check if tracked coordinate is outside image coordinate - if(untrack_keypoint(is_invalid_keypoint(new_keypoint, valid_region, window_dimension))) - { - break; - } - - // Compute temporal derivative - std::vector<int> bilinear_it_old = compute_derivative(old_pyramid[level], old_keypoint, border_mode, constant_border_value, window_dimension, W_BITS - 5); - std::vector<int> bilinear_it_new = compute_derivative(new_pyramid[level], new_keypoint, border_mode, constant_border_value, window_dimension, W_BITS - 5); - - double b1 = 0.f; - double b2 = 0.f; - std::tie(b1, b2) = compute_temporal_gradient_vector(bilinear_it_old, bilinear_it_new, bilinear_ix, bilinear_iy); - - // Compute motion vector -> A^-1 * -b - const float delta_x = (A12 * b2 - A22 * b1) / determinant; - const float delta_y = (A12 * b1 - A11 * b2) / determinant; - - // Update the new position - new_keypoint.x += delta_x; - new_keypoint.y += delta_y; - - const float magnitude_squared = delta_x * delta_x + delta_y * delta_y; - - // Check if termination criteria is EPSILON and if it is satisfied - if(magnitude_squared <= params.epsilon && (params.termination == Termination::TERM_CRITERIA_EPSILON || params.termination == Termination::TERM_CRITERIA_BOTH)) - { - break; - } - - // Check convergence analyzing the previous delta - if(j > 0 && (std::fabs(delta_x + prev_delta_x) < 0.01f && std::fabs(delta_y + prev_delta_y) < 0.01f)) - { - new_keypoint.x -= delta_x * SCALE_PYRAMID_HALF; - new_keypoint.y -= delta_y * SCALE_PYRAMID_HALF; - - break; - } - - prev_delta_x = delta_x; - prev_delta_y = delta_y; - } - } - } - - // Copy optical flow coordinates to output vector - for(size_t i = 0; i < old_points.size(); ++i) - { - const InternalKeyPoint &new_keypoint = new_points_internal.at(i); - - new_points.at(i).x = roundf(new_keypoint.x); - new_points.at(i).y = roundf(new_keypoint.y); - new_points.at(i).tracking_status = new_keypoint.tracking_status ? 1 : 0; - } - - return new_points; -} - -template std::vector<KeyPoint> optical_flow(const SimpleTensor<uint8_t> &old_input, const SimpleTensor<uint8_t> &new_input, - const OpticalFlowParameters ¶ms, size_t num_levels, - const std::vector<KeyPoint> &old_points, const std::vector<KeyPoint> &new_points_estimates, - BorderMode border_mode, uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/OpticalFlow.h b/tests/validation/reference/OpticalFlow.h deleted file mode 100644 index 1bc367ab6a..0000000000 --- a/tests/validation/reference/OpticalFlow.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2018-2019 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_H -#define ARM_COMPUTE_TEST_OPTICAL_FLOW_H - -#include "tests/SimpleTensor.h" -#include "tests/Types.h" - -#include <vector> - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -std::vector<KeyPoint> optical_flow(const SimpleTensor<T> &old_input, const SimpleTensor<T> &new_input, - const OpticalFlowParameters ¶ms, size_t num_levels, - const std::vector<KeyPoint> &old_points, const std::vector<KeyPoint> &new_points_estimates, - BorderMode border_mode, uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_OPTICAL_FLOW_H */ diff --git a/tests/validation/reference/Phase.cpp b/tests/validation/reference/Phase.cpp deleted file mode 100644 index 228f73bb37..0000000000 --- a/tests/validation/reference/Phase.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2017 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. - */ -#include "Phase.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<uint8_t> phase(const SimpleTensor<T> &gx, const SimpleTensor<T> &gy, PhaseType phase_type) -{ - const float PI = std::atan(1) * 4; - SimpleTensor<uint8_t> phase(gx.shape(), DataType::U8); - - if(phase_type == PhaseType::UNSIGNED) // unsigned: map to [0-255) - { - for(int i = 0; i < gx.num_elements(); ++i) - { - float angle_deg = (std::atan2(float(gy[i]), float(gx[i])) / PI) * 180.0f; - phase[i] = (angle_deg < 0.0f) ? 180.f + angle_deg : angle_deg; - } - } - else // signed: map to [0-180) degrees - { - for(int i = 0; i < gx.num_elements(); ++i) - { - float angle_pi = std::atan2(gy[i], gx[i]) / PI; - angle_pi = (angle_pi < 0.0f) ? 2 + angle_pi : angle_pi; - phase[i] = lround(angle_pi * 128) & 0xFFu; - } - } - - return phase; -} - -template SimpleTensor<uint8_t> phase(const SimpleTensor<int16_t> &gx, const SimpleTensor<int16_t> &gy, PhaseType phase_type); -template SimpleTensor<uint8_t> phase(const SimpleTensor<int32_t> &gx, const SimpleTensor<int32_t> &gy, PhaseType phase_type); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/Phase.h b/tests/validation/reference/Phase.h deleted file mode 100644 index 436c280f0a..0000000000 --- a/tests/validation/reference/Phase.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017-2019 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_PHASE_H -#define ARM_COMPUTE_TEST_PHASE_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<uint8_t> phase(const SimpleTensor<T> &gx, const SimpleTensor<T> &gy, PhaseType phase_type); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_PHASE_H */ diff --git a/tests/validation/reference/Scharr.cpp b/tests/validation/reference/Scharr.cpp deleted file mode 100644 index e9fbb73d49..0000000000 --- a/tests/validation/reference/Scharr.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2017-2019 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. - */ -#include "Scharr.h" - -#include "Utils.h" -#include "tests/validation/Helpers.h" - -#include <array> -#include <map> -#include <utility> - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -namespace -{ -const std::array<int8_t, 9> scharr_3_x{ { -3, 0, 3, -10, 0, 10, -3, 0, 3 } }; -const std::array<int8_t, 9> scharr_3_y{ { -3, -10, -3, 0, 0, 0, 3, 10, 3 } }; - -const std::map<int, std::pair<const int8_t *, const int8_t *>> masks -{ - { 3, { scharr_3_x.data(), scharr_3_y.data() } } -}; - -template <typename T> -struct data_type; - -template <> -struct data_type<int16_t> -{ - const static DataType value = DataType::S16; -}; -} // namespace - -template <typename T, typename U> -std::pair<SimpleTensor<T>, SimpleTensor<T>> scharr(const SimpleTensor<U> &src, int filter_size, BorderMode border_mode, uint8_t constant_border_value, GradientDimension gradient_dimension) -{ - const auto shape_size = static_cast<unsigned int>(filter_size); - - SimpleTensor<T> dst_x(src.shape(), data_type<T>::value, src.num_channels()); - SimpleTensor<T> dst_y(src.shape(), data_type<T>::value, src.num_channels()); - - ValidRegion valid_region = shape_to_valid_region(src.shape(), border_mode == BorderMode::UNDEFINED, BorderSize(filter_size / 2)); - - const uint32_t num_elements = src.num_elements(); - for(uint32_t i = 0; i < num_elements; ++i) - { - Coordinates coord = index2coord(src.shape(), i); - - if(!is_in_valid_region(valid_region, coord)) - { - continue; - } - - switch(gradient_dimension) - { - case GradientDimension::GRAD_X: - apply_2d_spatial_filter(coord, src, dst_x, TensorShape{ shape_size, shape_size }, masks.at(filter_size).first, 1.f, border_mode, constant_border_value); - break; - case GradientDimension::GRAD_Y: - apply_2d_spatial_filter(coord, src, dst_y, TensorShape{ shape_size, shape_size }, masks.at(filter_size).second, 1.f, border_mode, constant_border_value); - break; - case GradientDimension::GRAD_XY: - apply_2d_spatial_filter(coord, src, dst_x, TensorShape{ shape_size, shape_size }, masks.at(filter_size).first, 1.f, border_mode, constant_border_value); - apply_2d_spatial_filter(coord, src, dst_y, TensorShape{ shape_size, shape_size }, masks.at(filter_size).second, 1.f, border_mode, constant_border_value); - break; - default: - ARM_COMPUTE_ERROR("Gradient dimension not supported"); - } - } - - return std::make_pair(dst_x, dst_y); -} - -template std::pair<SimpleTensor<int16_t>, SimpleTensor<int16_t>> scharr(const SimpleTensor<uint8_t> &src, int filter_size, BorderMode border_mode, uint8_t constant_border_value, - GradientDimension gradient_dimension); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/Scharr.h b/tests/validation/reference/Scharr.h deleted file mode 100644 index 42b3202d64..0000000000 --- a/tests/validation/reference/Scharr.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2017-2019 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_SCHARR_H -#define ARM_COMPUTE_TEST_SCHARR_H - -#include "tests/SimpleTensor.h" -#include "tests/Types.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T, typename U> -std::pair<SimpleTensor<T>, SimpleTensor<T>> scharr(const SimpleTensor<U> &src, int filter_size, BorderMode border_mode, uint8_t constant_border_value, GradientDimension gradient_dimension); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_SCHARR_H */ diff --git a/tests/validation/reference/Sobel.cpp b/tests/validation/reference/Sobel.cpp deleted file mode 100644 index d9c2532add..0000000000 --- a/tests/validation/reference/Sobel.cpp +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright (c) 2017-2019 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. - */ -#include "Sobel.h" - -#include "Utils.h" -#include "tests/validation/Helpers.h" - -#include <array> -#include <map> -#include <utility> - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -namespace -{ -const std::array<int8_t, 9> sobel_3_x{ { -1, 0, 1, -2, 0, 2, -1, 0, 1 } }; -const std::array<int8_t, 9> sobel_3_y{ { -1, -2, -1, 0, 0, 0, 1, 2, 1 } }; - -const std::array<int8_t, 25> sobel_5_x{ { - -1, -2, 0, 2, 1, - -4, -8, 0, 8, 4, - -6, -12, 0, 12, 6, - -4, -8, 0, 8, 4, - -1, -2, 0, 2, 1 - } }; - -const std::array<int8_t, 25> sobel_5_y{ { - -1, -4, -6, -4, -1, - -2, -8, -12, -8, -2, - 0, 0, 0, 0, 0, - 2, 8, 12, 8, 2, - 1, 4, 6, 4, 1 - } }; - -const std::array<int8_t, 49> sobel_7_x{ { - -1, -4, -5, 0, 5, 4, 1, - -6, -24, -30, 0, 30, 24, 6, - -15, -60, -75, 0, 75, 60, 15, - -20, -80, -100, 0, 100, 80, 20, - -15, -60, -75, 0, 75, 60, 15, - -6, -24, -30, 0, 30, 24, 6, - -1, -4, -5, 0, 5, 4, 1 - } }; - -const std::array<int8_t, 49> sobel_7_y{ { - -1, -6, -15, -20, -15, -6, -1, - -4, -24, -60, -80, -60, -24, -4, - -5, -30, -75, -100, -75, -30, -5, - 0, 0, 0, 0, 0, 0, 0, - 5, 30, 75, 100, 75, 30, 5, - 4, 24, 60, 80, 60, 24, 4, - 1, 6, 15, 20, 15, 6, 1 - } }; - -const std::map<int, std::pair<const int8_t *, const int8_t *>> masks -{ - { 3, { sobel_3_x.data(), sobel_3_y.data() } }, - { 5, { sobel_5_x.data(), sobel_5_y.data() } }, - { 7, { sobel_7_x.data(), sobel_7_y.data() } }, -}; - -template <typename T> -struct data_type; - -template <> -struct data_type<int16_t> -{ - const static DataType value = DataType::S16; -}; - -template <> -struct data_type<int> -{ - const static DataType value = DataType::S32; -}; -} // namespace - -template <typename T, typename U> -std::pair<SimpleTensor<T>, SimpleTensor<T>> sobel(const SimpleTensor<U> &src, int filter_size, BorderMode border_mode, uint8_t constant_border_value, GradientDimension gradient_dimension) -{ - SimpleTensor<T> dst_x(src.shape(), data_type<T>::value, src.num_channels()); - SimpleTensor<T> dst_y(src.shape(), data_type<T>::value, src.num_channels()); - - ValidRegion valid_region = shape_to_valid_region(src.shape(), border_mode == BorderMode::UNDEFINED, BorderSize(filter_size / 2)); - - const uint32_t num_elements = src.num_elements(); - for(uint32_t i = 0; i < num_elements; ++i) - { - Coordinates coord = index2coord(src.shape(), i); - - if(!is_in_valid_region(valid_region, coord)) - { - continue; - } - switch(gradient_dimension) - { - case GradientDimension::GRAD_X: - apply_2d_spatial_filter(coord, src, dst_x, TensorShape{ static_cast<unsigned int>(filter_size), static_cast<unsigned int>(filter_size) }, masks.at(filter_size).first, 1.f, border_mode, - constant_border_value); - break; - case GradientDimension::GRAD_Y: - apply_2d_spatial_filter(coord, src, dst_y, TensorShape{ static_cast<unsigned int>(filter_size), static_cast<unsigned int>(filter_size) }, masks.at(filter_size).second, 1.f, border_mode, - constant_border_value); - break; - case GradientDimension::GRAD_XY: - apply_2d_spatial_filter(coord, src, dst_x, TensorShape{ static_cast<unsigned int>(filter_size), static_cast<unsigned int>(filter_size) }, masks.at(filter_size).first, 1.f, border_mode, - constant_border_value); - apply_2d_spatial_filter(coord, src, dst_y, TensorShape{ static_cast<unsigned int>(filter_size), static_cast<unsigned int>(filter_size) }, masks.at(filter_size).second, 1.f, border_mode, - constant_border_value); - break; - default: - ARM_COMPUTE_ERROR("Gradient dimension not supported"); - } - } - - return std::make_pair(dst_x, dst_y); -} - -template std::pair<SimpleTensor<int16_t>, SimpleTensor<int16_t>> sobel(const SimpleTensor<uint8_t> &src, int filter_size, BorderMode border_mode, uint8_t constant_border_value, - GradientDimension gradient_dimension); -template std::pair<SimpleTensor<int>, SimpleTensor<int>> sobel(const SimpleTensor<uint8_t> &src, int filter_size, BorderMode border_mode, uint8_t constant_border_value, - GradientDimension gradient_dimension); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/Sobel.h b/tests/validation/reference/Sobel.h deleted file mode 100644 index 86d6d0bc11..0000000000 --- a/tests/validation/reference/Sobel.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2017-2019 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_SOBEL_H -#define ARM_COMPUTE_TEST_SOBEL_H - -#include "arm_compute/core/Types.h" -#include "tests/SimpleTensor.h" -#include "tests/Types.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T, typename U> -std::pair<SimpleTensor<T>, SimpleTensor<T>> sobel(const SimpleTensor<U> &src, int filter_size, BorderMode border_mode, uint8_t constant_border_value, GradientDimension gradient_dimension); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_SOBEL_H */ diff --git a/tests/validation/reference/Threshold.cpp b/tests/validation/reference/Threshold.cpp deleted file mode 100644 index 6bc6cf0b4a..0000000000 --- a/tests/validation/reference/Threshold.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2017 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 src 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 src 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. src NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER src AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * dst OF OR src CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS src THE - * SOFTWARE. - */ -#include "Threshold.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> threshold(const SimpleTensor<T> &src, T threshold, T false_value, T true_value, ThresholdType type, T upper) -{ - SimpleTensor<T> dst(src.shape(), src.data_type()); - - switch(type) - { - case ThresholdType::BINARY: - for(int i = 0; i < src.num_elements(); ++i) - { - dst[i] = ((src[i] > threshold) ? true_value : false_value); - } - break; - case ThresholdType::RANGE: - for(int i = 0; i < src.num_elements(); ++i) - { - if(src[i] > upper) - { - dst[i] = false_value; - } - else if(src[i] < threshold) - { - dst[i] = false_value; - } - else - { - dst[i] = true_value; - } - } - break; - default: - ARM_COMPUTE_ERROR("Thresholding type not recognised"); - break; - } - - return dst; -} - -template SimpleTensor<uint8_t> threshold(const SimpleTensor<uint8_t> &src, uint8_t threshold, uint8_t false_value, uint8_t true_value, ThresholdType type, uint8_t upper); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/Threshold.h b/tests/validation/reference/Threshold.h deleted file mode 100644 index bee9531351..0000000000 --- a/tests/validation/reference/Threshold.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017-2019 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_THRESHOLD_H -#define ARM_COMPUTE_TEST_THRESHOLD_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> threshold(const SimpleTensor<T> &src, T threshold, T false_value, T true_value, ThresholdType type, T upper); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_THRESHOLD_H */ diff --git a/tests/validation/reference/Utils.h b/tests/validation/reference/Utils.h index 8e15faab8f..c83c6ea4b3 100644 --- a/tests/validation/reference/Utils.h +++ b/tests/validation/reference/Utils.h @@ -26,7 +26,6 @@ #include "arm_compute/core/Types.h" #include "tests/Globals.h" -#include "tests/ILutAccessor.h" #include "tests/Types.h" #include <array> @@ -123,26 +122,6 @@ void apply_2d_spatial_filter(Coordinates coord, const SimpleTensor<T> &src, Simp RawTensor transpose(const RawTensor &src, int chunk_width = 1); -/** Fill matrix random. - * - * @param[in,out] matrix Matrix - */ -template <std::size_t SIZE> -inline void fill_warp_matrix(std::array<float, SIZE> &matrix) -{ - std::mt19937 gen(library.get()->seed()); - std::uniform_real_distribution<float> dist(-1, 1); - for(auto &x : matrix) - { - x = dist(gen); - } - if(SIZE == 9) - { - // This is only used in Warp Perspective, we set M[3][3] = 1 so that Z0 is not 0 and we avoid division by 0. - matrix[8] = 1.f; - } -} - bool valid_bilinear_policy(float xn, float yn, int width, int height, BorderMode border_mode); } // namespace validation } // namespace test diff --git a/tests/validation/reference/WarpAffine.cpp b/tests/validation/reference/WarpAffine.cpp deleted file mode 100644 index 3580b75d43..0000000000 --- a/tests/validation/reference/WarpAffine.cpp +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (c) 2017-2019 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. - */ -#include "WarpAffine.h" - -#include "Utils.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -bool valid_bilinear_policy(float xn, float yn, int width, int height, BorderMode border_mode) -{ - if(border_mode != BorderMode::UNDEFINED) - { - return true; - } - if((0 <= yn + 1) && (yn + 1 < height) && (0 <= xn + 1) && (xn + 1 < width)) - { - return true; - } - return false; -} - -template <typename T> -SimpleTensor<T> warp_affine(const SimpleTensor<T> &src, SimpleTensor<T> &valid_mask, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, uint8_t constant_border_value) -{ - SimpleTensor<T> dst(src.shape(), src.data_type()); - - // x0 = M00 * x + M01 * y + M02 - // y0 = M10 * x + M11 * y + M12 - const float M00 = matrix[0]; - const float M10 = matrix[1]; - const float M01 = matrix[0 + 1 * 2]; - const float M11 = matrix[1 + 1 * 2]; - const float M02 = matrix[0 + 2 * 2]; - const float M12 = matrix[1 + 2 * 2]; - - const int width = src.shape().x(); - const int height = src.shape().y(); - - const uint32_t num_elements = src.num_elements(); - for(uint32_t element_idx = 0; element_idx < num_elements; ++element_idx) - { - valid_mask[element_idx] = 1; - Coordinates id = index2coord(src.shape(), element_idx); - int idx = id.x(); - int idy = id.y(); - - float x0 = M00 * idx + M01 * idy + M02; - float y0 = M10 * idx + M11 * idy + M12; - - id.set(0, static_cast<int>(std::floor(x0))); - id.set(1, static_cast<int>(std::floor(y0))); - if((0 <= y0) && (y0 < height) && (0 <= x0) && (x0 < width)) - { - switch(policy) - { - case InterpolationPolicy::NEAREST_NEIGHBOR: - dst[element_idx] = tensor_elem_at(src, id, border_mode, constant_border_value); - break; - case InterpolationPolicy::BILINEAR: - (valid_bilinear_policy(x0, y0, width, height, border_mode)) ? dst[element_idx] = bilinear_policy(src, id, x0, y0, border_mode, constant_border_value) : - valid_mask[element_idx] = 0; - break; - case InterpolationPolicy::AREA: - default: - ARM_COMPUTE_ERROR("Interpolation not supported"); - } - } - else - { - if(border_mode == BorderMode::UNDEFINED) - { - valid_mask[element_idx] = 0; - } - else - { - switch(policy) - { - case InterpolationPolicy::NEAREST_NEIGHBOR: - if(border_mode == BorderMode::CONSTANT) - { - dst[element_idx] = constant_border_value; - } - else if(border_mode == BorderMode::REPLICATE) - { - id.set(0, std::max(0, std::min(static_cast<int>(x0), width - 1))); - id.set(1, std::max(0, std::min(static_cast<int>(y0), height - 1))); - dst[element_idx] = src[coord2index(src.shape(), id)]; - } - break; - case InterpolationPolicy::BILINEAR: - dst[element_idx] = bilinear_policy(src, id, x0, y0, border_mode, constant_border_value); - break; - case InterpolationPolicy::AREA: - default: - ARM_COMPUTE_ERROR("Interpolation not supported"); - } - } - } - } - - return dst; -} - -template SimpleTensor<uint8_t> warp_affine(const SimpleTensor<uint8_t> &src, SimpleTensor<uint8_t> &valid_mask, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, - uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute
\ No newline at end of file diff --git a/tests/validation/reference/WarpAffine.h b/tests/validation/reference/WarpAffine.h deleted file mode 100644 index 90f765c283..0000000000 --- a/tests/validation/reference/WarpAffine.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017-2019 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_WARP_AFFINE_H -#define ARM_COMPUTE_TEST_WARP_AFFINE_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> warp_affine(const SimpleTensor<T> &src, SimpleTensor<T> &valid_mask, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_WARP_AFFINE_H */ diff --git a/tests/validation/reference/WarpPerspective.cpp b/tests/validation/reference/WarpPerspective.cpp deleted file mode 100644 index e35d75e6e2..0000000000 --- a/tests/validation/reference/WarpPerspective.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (c) 2017-2019 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. - */ -#include "arm_compute/core/Helpers.h" - -#include "Utils.h" -#include "WarpPerspective.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> warp_perspective(const SimpleTensor<T> &src, SimpleTensor<T> &valid_mask, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, uint8_t constant_border_value) -{ - SimpleTensor<T> dst(src.shape(), src.data_type()); - - // x0 = M00 * x + M01 * y + M02 - // y0 = M10 * x + M11 * y + M12 - // z0 = M20 * x + M21 * y + M22 - // xn = x0 / z0 - // yn = y0 / z0 - const float M00 = matrix[0]; - const float M10 = matrix[1]; - const float M20 = matrix[2]; - const float M01 = matrix[0 + 1 * 3]; - const float M11 = matrix[1 + 1 * 3]; - const float M21 = matrix[2 + 1 * 3]; - const float M02 = matrix[0 + 2 * 3]; - const float M12 = matrix[1 + 2 * 3]; - const float M22 = matrix[2 + 2 * 3]; - - const int width = src.shape().x(); - const int height = src.shape().y(); - - const uint32_t num_elements = src.num_elements(); - for(uint32_t element_idx = 0; element_idx < num_elements; ++element_idx) - { - valid_mask[element_idx] = 1; - Coordinates id = index2coord(src.shape(), element_idx); - const int idx = id.x(); - const int idy = id.y(); - const float z0 = M20 * idx + M21 * idy + M22; - - const float x0 = (M00 * idx + M01 * idy + M02); - const float y0 = (M10 * idx + M11 * idy + M12); - - const float xn = x0 / z0; - const float yn = y0 / z0; - id.set(0, static_cast<int>(std::floor(xn))); - id.set(1, static_cast<int>(std::floor(yn))); - if((0 <= yn) && (yn < height) && (0 <= xn) && (xn < width)) - { - switch(policy) - { - case InterpolationPolicy::NEAREST_NEIGHBOR: - dst[element_idx] = tensor_elem_at(src, id, border_mode, constant_border_value); - break; - case InterpolationPolicy::BILINEAR: - (valid_bilinear_policy(xn, yn, width, height, border_mode)) ? dst[element_idx] = bilinear_policy(src, id, xn, yn, border_mode, constant_border_value) : valid_mask[element_idx] = 0; - break; - case InterpolationPolicy::AREA: - default: - ARM_COMPUTE_ERROR("Interpolation not supported"); - break; - } - } - else - { - if(border_mode == BorderMode::UNDEFINED) - { - valid_mask[element_idx] = 0; - } - else - { - switch(policy) - { - case InterpolationPolicy::NEAREST_NEIGHBOR: - if(border_mode == BorderMode::CONSTANT) - { - dst[element_idx] = constant_border_value; - } - else if(border_mode == BorderMode::REPLICATE) - { - id.set(0, std::max(0, std::min(static_cast<int>(xn), width - 1))); - id.set(1, std::max(0, std::min(static_cast<int>(yn), height - 1))); - dst[element_idx] = src[coord2index(src.shape(), id)]; - } - break; - case InterpolationPolicy::BILINEAR: - dst[element_idx] = bilinear_policy(src, id, xn, yn, border_mode, constant_border_value); - break; - case InterpolationPolicy::AREA: - default: - ARM_COMPUTE_ERROR("Interpolation not supported"); - break; - } - } - } - } - return dst; -} - -template SimpleTensor<uint8_t> warp_perspective(const SimpleTensor<uint8_t> &src, SimpleTensor<uint8_t> &valid_mask, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, - uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/WarpPerspective.h b/tests/validation/reference/WarpPerspective.h deleted file mode 100644 index 7fcd5ddf7b..0000000000 --- a/tests/validation/reference/WarpPerspective.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017-2019 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_WARP_PERSPECTIVE_H -#define ARM_COMPUTE_TEST_WARP_PERSPECTIVE_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> warp_perspective(const SimpleTensor<T> &src, SimpleTensor<T> &valid_mask, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_WARP_PERSPECTIVE_H */ diff --git a/tests/validation/reference/YOLOLayer.cpp b/tests/validation/reference/YOLOLayer.cpp deleted file mode 100644 index fbc81f1af9..0000000000 --- a/tests/validation/reference/YOLOLayer.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2018-2020 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. - */ -#include "YOLOLayer.h" - -#include "ActivationLayer.h" - -#include "arm_compute/core/Types.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T, typename std::enable_if<is_floating_point<T>::value, int>::type> -SimpleTensor<T> yolo_layer(const SimpleTensor<T> &src, const ActivationLayerInfo &info, int32_t num_classes) -{ - // Create reference - SimpleTensor<T> dst{ src.shape(), src.data_type() }; - - // Compute reference - const T a(info.a()); - const T b(info.b()); - - const uint32_t num_elements = src.num_elements(); -#if defined(_OPENMP) - #pragma omp parallel for -#endif /* _OPENMP */ - for(uint32_t i = 0; i < num_elements; ++i) - { - const size_t z = index2coord(dst.shape(), i).z() % (num_classes + 5); - - if(z != 2 && z != 3) - { - dst[i] = activate_float<T>(src[i], a, b, info.activation()); - } - else - { - dst[i] = src[i]; - } - } - - return dst; -} - -template <> -SimpleTensor<uint8_t> yolo_layer<uint8_t>(const SimpleTensor<uint8_t> &src, const ActivationLayerInfo &info, int32_t num_classes) -{ - SimpleTensor<float> src_tmp = convert_from_asymmetric(src); - SimpleTensor<float> dst_tmp = yolo_layer<float>(src_tmp, info, num_classes); - SimpleTensor<uint8_t> dst = convert_to_asymmetric<uint8_t>(dst_tmp, src.quantization_info()); - return dst; -} - -template SimpleTensor<float> yolo_layer(const SimpleTensor<float> &src, const ActivationLayerInfo &info, int32_t num_classes); -template SimpleTensor<half> yolo_layer(const SimpleTensor<half> &src, const ActivationLayerInfo &info, int32_t num_classes); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/YOLOLayer.h b/tests/validation/reference/YOLOLayer.h deleted file mode 100644 index 33cf630aca..0000000000 --- a/tests/validation/reference/YOLOLayer.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2018-2019 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_YOLO_LAYER_H -#define ARM_COMPUTE_TEST_YOLO_LAYER_H - -#include "tests/SimpleTensor.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T, typename std::enable_if<is_floating_point<T>::value, int>::type = 0> -SimpleTensor<T> yolo_layer(const SimpleTensor<T> &src, const ActivationLayerInfo &info, int32_t num_classes); - -template <typename T, typename std::enable_if<std::is_integral<T>::value, int>::type = 0> -SimpleTensor<T> yolo_layer(const SimpleTensor<T> &src, const ActivationLayerInfo &info, int32_t num_classes); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_YOLO_LAYER_H */ |