aboutsummaryrefslogtreecommitdiff
path: root/src/core/NEON/kernels/NEROIPoolingLayerKernel.cpp
diff options
context:
space:
mode:
authorManuel Bottini <manuel.bottini@arm.com>2019-01-09 17:04:39 +0000
committerGeorgios Pinitas <georgios.pinitas@arm.com>2019-01-11 15:17:31 +0000
commitcc5171b85654b9f19a5f52bbe8abea0572ee0163 (patch)
tree032999b06aeced4f5e2963ab60c833acb951c3c8 /src/core/NEON/kernels/NEROIPoolingLayerKernel.cpp
parent587708b05ca63fa88118daec82e2c39d63e60086 (diff)
downloadComputeLibrary-cc5171b85654b9f19a5f52bbe8abea0572ee0163.tar.gz
COMPMID-1677: Change ROIPooling layer interface to accept ROIs as tensors
Change-Id: If16b572a4d906187b77f32133a72a44316fa74e4 Reviewed-on: https://review.mlplatform.org/490 Tested-by: Arm Jenkins <bsgcomp@arm.com> Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com>
Diffstat (limited to 'src/core/NEON/kernels/NEROIPoolingLayerKernel.cpp')
-rw-r--r--src/core/NEON/kernels/NEROIPoolingLayerKernel.cpp53
1 files changed, 37 insertions, 16 deletions
diff --git a/src/core/NEON/kernels/NEROIPoolingLayerKernel.cpp b/src/core/NEON/kernels/NEROIPoolingLayerKernel.cpp
index 4d908db77b..6fd6792ff8 100644
--- a/src/core/NEON/kernels/NEROIPoolingLayerKernel.cpp
+++ b/src/core/NEON/kernels/NEROIPoolingLayerKernel.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2018 ARM Limited.
+ * Copyright (c) 2017-2019 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -35,22 +35,35 @@
#include <cfloat>
#include <cmath>
-using namespace arm_compute;
-
+namespace arm_compute
+{
NEROIPoolingLayerKernel::NEROIPoolingLayerKernel()
: _input(nullptr), _rois(nullptr), _output(nullptr), _pool_info(0, 0, 0.f)
{
}
-void NEROIPoolingLayerKernel::configure(const ITensor *input, const IROIArray *rois, ITensor *output, const ROIPoolingLayerInfo &pool_info)
+void NEROIPoolingLayerKernel::configure(const ITensor *input, const ITensor *rois, ITensor *output, const ROIPoolingLayerInfo &pool_info)
{
- ARM_COMPUTE_ERROR_ON_NULLPTR(input, rois, output);
- ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F32);
+ ARM_COMPUTE_ERROR_ON_NULLPTR(input, output, rois);
+
+ //Validate arguments
+ ARM_COMPUTE_ERROR_ON_NULLPTR(input->info(), rois->info(), output->info());
+ ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(rois, 1, DataType::U16);
+ ARM_COMPUTE_ERROR_ON(rois->info()->dimension(0) != 5);
+ ARM_COMPUTE_ERROR_ON(rois->info()->num_dimensions() > 2);
+ ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F32, DataType::F16);
ARM_COMPUTE_ERROR_ON((pool_info.pooled_width() == 0) || (pool_info.pooled_height() == 0));
- ARM_COMPUTE_ERROR_ON(rois->num_values() == 0);
- // Output auto inizialitation if not yet initialized
- TensorShape output_shape(pool_info.pooled_width(), pool_info.pooled_height(), input->info()->dimension(2), rois->num_values());
+ if(output->info()->total_size() != 0)
+ {
+ ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
+ ARM_COMPUTE_ERROR_ON((output->info()->dimension(0) != pool_info.pooled_width()) || (output->info()->dimension(1) != pool_info.pooled_height()));
+ ARM_COMPUTE_ERROR_ON(input->info()->dimension(2) != output->info()->dimension(2));
+ ARM_COMPUTE_ERROR_ON(rois->info()->dimension(1) != output->info()->dimension(3));
+ }
+
+ // Output auto initialization if not yet initialized
+ TensorShape output_shape(pool_info.pooled_width(), pool_info.pooled_height(), input->info()->dimension(2), rois->info()->dimension(1));
auto_init_if_empty(*output->info(), output_shape, 1, input->info()->data_type());
ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
@@ -64,7 +77,7 @@ void NEROIPoolingLayerKernel::configure(const ITensor *input, const IROIArray *r
// Configure kernel window
Window window;
- window.set(Window::DimX, Window::Dimension(0, rois->num_values()));
+ window.set(Window::DimX, Window::Dimension(0, rois->info()->dimension(1)));
window.set(Window::DimY, Window::Dimension(0, 1));
AccessWindowStatic input_access(input->info(),
@@ -85,6 +98,8 @@ void NEROIPoolingLayerKernel::run(const Window &window, const ThreadInfo &info)
ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
+ const size_t values_per_roi = _rois->info()->dimension(0);
+
const int roi_list_start = window.x().start();
const int roi_list_end = window.x().end();
const int width = _input->info()->dimension(Window::DimX);
@@ -94,16 +109,21 @@ void NEROIPoolingLayerKernel::run(const Window &window, const ThreadInfo &info)
const int pooled_h = _pool_info.pooled_height();
const float spatial_scale = _pool_info.spatial_scale();
+ const auto *rois_ptr = reinterpret_cast<const uint16_t *>(_rois->buffer());
+
for(int roi_indx = roi_list_start; roi_indx < roi_list_end; ++roi_indx)
{
- const ROI &curr_roi = _rois->at(roi_indx);
+ const unsigned int roi_batch = rois_ptr[values_per_roi * roi_indx];
+ const auto x1 = rois_ptr[values_per_roi * roi_indx + 1];
+ const auto y1 = rois_ptr[values_per_roi * roi_indx + 2];
+ const auto x2 = rois_ptr[values_per_roi * roi_indx + 3];
+ const auto y2 = rois_ptr[values_per_roi * roi_indx + 4];
// Scale ROI
- const int roi_batch = curr_roi.batch_idx;
- const int roi_anchor_x = support::cpp11::round(curr_roi.rect.x * spatial_scale);
- const int roi_anchor_y = support::cpp11::round(curr_roi.rect.y * spatial_scale);
- const int roi_width = std::max(support::cpp11::round(curr_roi.rect.width * spatial_scale), 1.f);
- const int roi_height = std::max(support::cpp11::round(curr_roi.rect.height * spatial_scale), 1.f);
+ const int roi_anchor_x = support::cpp11::round(x1 * spatial_scale);
+ const int roi_anchor_y = support::cpp11::round(y1 * spatial_scale);
+ const int roi_width = std::max(support::cpp11::round((x2 - x1) * spatial_scale), 1.f);
+ const int roi_height = std::max(support::cpp11::round((y2 - y1) * spatial_scale), 1.f);
// Iterate through all feature maps
for(int fm = 0; fm < fms; ++fm)
@@ -146,3 +166,4 @@ void NEROIPoolingLayerKernel::run(const Window &window, const ThreadInfo &info)
}
}
}
+} // namespace arm_compute \ No newline at end of file