From 31bbce1249138633ecd34d351e2ea237ff6d55c8 Mon Sep 17 00:00:00 2001 From: Abe Mbise Date: Tue, 19 Sep 2017 16:19:13 +0100 Subject: COMPMID-510: Port Warp Perspective to new validation Change-Id: I0d96ceb9d9d1d077bec09330cda4fbe6d81ce641 Reviewed-on: http://mpd-gerrit.cambridge.arm.com/88476 Tested-by: Kaizen Reviewed-by: Pablo Tello --- tests/validation_old/TensorOperations.h | 126 -------------------------------- 1 file changed, 126 deletions(-) (limited to 'tests/validation_old/TensorOperations.h') diff --git a/tests/validation_old/TensorOperations.h b/tests/validation_old/TensorOperations.h index bba09175ca..2b326930f6 100644 --- a/tests/validation_old/TensorOperations.h +++ b/tests/validation_old/TensorOperations.h @@ -118,46 +118,6 @@ void apply_2d_spatial_filter(Coordinates coord, const Tensor &in, Tensor } } // namespace -template -T bilinear_policy(const Tensor &in, Coordinates id, float xn, float yn, BorderMode border_mode, uint8_t constant_border_value) -{ - int idx = std::floor(xn); - int idy = std::floor(yn); - - const float dx = xn - idx; - const float dy = yn - idy; - const float dx_1 = 1.0f - dx; - const float dy_1 = 1.0f - dy; - - id.set(0, idx); - id.set(1, idy); - const T tl = tensor_elem_at(in, id, border_mode, constant_border_value); - id.set(0, idx + 1); - id.set(1, idy); - const T tr = tensor_elem_at(in, id, border_mode, constant_border_value); - id.set(0, idx); - id.set(1, idy + 1); - const T bl = tensor_elem_at(in, id, border_mode, constant_border_value); - id.set(0, idx + 1); - id.set(1, idy + 1); - const T br = tensor_elem_at(in, id, border_mode, constant_border_value); - - return tl * (dx_1 * dy_1) + tr * (dx * dy_1) + bl * (dx_1 * dy) + br * (dx * dy); -} - -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; -} - // Sobel 3x3 template void sobel_3x3(Tensor &in, Tensor &out_x, Tensor &out_y, BorderMode border_mode, uint8_t constant_border_value) @@ -677,92 +637,6 @@ void threshold(const Tensor &in, Tensor &out, uint8_t threshold, uint8_t f } } -// Warp Perspective -template -void warp_perspective(const Tensor &in, Tensor &out, Tensor &valid_mask, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, uint8_t constant_border_value) -{ - // 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 = in.shape().x(); - const int height = in.shape().y(); - - for(int element_idx = 0; element_idx < in.num_elements(); ++element_idx) - { - valid_mask[element_idx] = 1; - Coordinates id = index2coord(in.shape(), element_idx); - int idx = id.x(); - int idy = id.y(); - const float z0 = M20 * idx + M21 * idy + M22; - - float x0 = (M00 * idx + M01 * idy + M02); - float y0 = (M10 * idx + M11 * idy + M12); - - float xn = x0 / z0; - float yn = y0 / z0; - id.set(0, static_cast(std::floor(xn))); - id.set(1, static_cast(std::floor(yn))); - if((0 <= yn) && (yn < height) && (0 <= xn) && (xn < width)) - { - switch(policy) - { - case InterpolationPolicy::NEAREST_NEIGHBOR: - out[element_idx] = tensor_elem_at(in, id, border_mode, constant_border_value); - break; - case InterpolationPolicy::BILINEAR: - (valid_bilinear_policy(xn, yn, width, height, border_mode)) ? out[element_idx] = bilinear_policy(in, id, xn, yn, 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) - { - out[element_idx] = constant_border_value; - } - else if(border_mode == BorderMode::REPLICATE) - { - id.set(0, std::max(0, std::min(static_cast(xn), width - 1))); - id.set(1, std::max(0, std::min(static_cast(yn), height - 1))); - out[element_idx] = in[coord2index(in.shape(), id)]; - } - break; - case InterpolationPolicy::BILINEAR: - out[element_idx] = bilinear_policy(in, id, xn, yn, border_mode, constant_border_value); - break; - case InterpolationPolicy::AREA: - default: - ARM_COMPUTE_ERROR("Interpolation not supported"); - } - } - } - } -} - // ROI Pooling layer template void roi_pooling_layer(const Tensor &in, Tensor &out, const std::vector &rois, const ROIPoolingLayerInfo &pool_info) -- cgit v1.2.1