From 74aecd486f9e63d6d430a0f2e5484c360fef8052 Mon Sep 17 00:00:00 2001 From: yongqiang Date: Mon, 27 Jul 2020 09:04:16 +0000 Subject: [PATCH] change priorbox. test=develop --- lite/backends/arm/math/prior_box.cc | 18 +++++++++--------- lite/backends/arm/math/prior_box.h | 8 ++++---- lite/kernels/arm/prior_box_compute.cc | 22 +++++++++++++++++++--- lite/kernels/arm/prior_box_compute.h | 7 ++++++- 4 files changed, 38 insertions(+), 17 deletions(-) mode change 100644 => 100755 lite/backends/arm/math/prior_box.cc mode change 100644 => 100755 lite/backends/arm/math/prior_box.h diff --git a/lite/backends/arm/math/prior_box.cc b/lite/backends/arm/math/prior_box.cc old mode 100644 new mode 100755 index 4ef7356e67..fd0729d8fc --- a/lite/backends/arm/math/prior_box.cc +++ b/lite/backends/arm/math/prior_box.cc @@ -21,7 +21,7 @@ namespace lite { namespace arm { namespace math { -const int MALLOC_ALIGN = 16; +const int MALLOC_ALIGN = 64; void* fast_malloc(size_t size) { size_t offset = sizeof(void*) + MALLOC_ALIGN - 1; @@ -46,8 +46,8 @@ void fast_free(void* ptr) { void density_prior_box(const lite::Tensor* input, const lite::Tensor* image, - lite::Tensor** boxes, - lite::Tensor** variances, + lite::Tensor* boxes, + lite::Tensor* variances, const std::vector& min_size_, const std::vector& fixed_size_, const std::vector& fixed_ratio_, @@ -69,11 +69,11 @@ void density_prior_box(const lite::Tensor* input, int win1 = input->dims()[3]; int hin1 = input->dims()[2]; DDim shape_out({hin1, win1, prior_num_, 4}); - (*boxes)->Resize(shape_out); - (*variances)->Resize(shape_out); + boxes->Resize(shape_out); + variances->Resize(shape_out); - float* _cpu_data = (*boxes)->mutable_data(); - float* _variance_data = (*variances)->mutable_data(); + float* _cpu_data = boxes->mutable_data(); + float* _variance_data = variances->mutable_data(); const int width = win1; const int height = hin1; @@ -329,8 +329,8 @@ void density_prior_box(const lite::Tensor* input, void prior_box(const lite::Tensor* input, const lite::Tensor* image, - lite::Tensor** boxes, - lite::Tensor** variances, + lite::Tensor* boxes, + lite::Tensor* variances, const std::vector& min_size, const std::vector& max_size, const std::vector& aspect_ratio, diff --git a/lite/backends/arm/math/prior_box.h b/lite/backends/arm/math/prior_box.h old mode 100644 new mode 100755 index 03fd627510..2a22854a61 --- a/lite/backends/arm/math/prior_box.h +++ b/lite/backends/arm/math/prior_box.h @@ -25,8 +25,8 @@ namespace math { void density_prior_box(const lite::Tensor* input, const lite::Tensor* image, - lite::Tensor** boxes, - lite::Tensor** variances, + lite::Tensor* boxes, + lite::Tensor* variances, const std::vector& min_size_, const std::vector& fixed_size_, const std::vector& fixed_ratio_, @@ -47,8 +47,8 @@ void density_prior_box(const lite::Tensor* input, void prior_box(const lite::Tensor* input, const lite::Tensor* image, - lite::Tensor** boxes, - lite::Tensor** variances, + lite::Tensor* boxes, + lite::Tensor* variances, const std::vector& min_size, const std::vector& max_size, const std::vector& aspect_ratio, diff --git a/lite/kernels/arm/prior_box_compute.cc b/lite/kernels/arm/prior_box_compute.cc index 48ae1e94dd..7ac1c5c2e0 100644 --- a/lite/kernels/arm/prior_box_compute.cc +++ b/lite/kernels/arm/prior_box_compute.cc @@ -46,7 +46,7 @@ inline void ExpandAspectRatios(const std::vector& input_aspect_ratior, } } -void PriorBoxCompute::Run() { +void PriorBoxCompute::PrepareForRun() { auto& param = Param(); bool is_flip = param.flip; @@ -69,8 +69,8 @@ void PriorBoxCompute::Run() { lite::arm::math::prior_box(param.input, param.image, - ¶m.boxes, - ¶m.variances, + &out_boxes, + &variances, min_size, max_size, aspect_ratios_vec, @@ -85,6 +85,22 @@ void PriorBoxCompute::Run() { is_clip, order, min_max_aspect_ratios_order); + this->_flag_init = true; +} + +void PriorBoxCompute::Run() { + if (!this->_flag_init) { + LOG(FATAL) << "ERROR: init priorbox first\n"; + } + auto& param = Param(); + param.boxes->Resize(out_boxes.dims()); + param.variances->Resize(out_boxes.dims()); + memcpy(param.boxes->mutable_data(), + out_boxes.data(), + param.boxes->numel()); + memcpy(param.variances->mutable_data(), + variances.data(), + param.variances->numel()); } } // namespace arm diff --git a/lite/kernels/arm/prior_box_compute.h b/lite/kernels/arm/prior_box_compute.h index d44406a98f..277c3ed37c 100644 --- a/lite/kernels/arm/prior_box_compute.h +++ b/lite/kernels/arm/prior_box_compute.h @@ -24,10 +24,15 @@ namespace arm { class PriorBoxCompute : public KernelLite { public: using param_t = operators::PriorBoxParam; - + void PrepareForRun() override; void Run() override; virtual ~PriorBoxCompute() = default; + + private: + bool _flag_init{false}; + lite::Tensor out_boxes; + lite::Tensor variances; }; } // namespace arm -- GitLab