From 6dbc2f297704e038b851ab56b307157db5395de5 Mon Sep 17 00:00:00 2001 From: liu zhengxi <380185688@qq.com> Date: Fri, 30 Aug 2019 20:40:54 +0800 Subject: [PATCH] Modify the slice op, stack op, reduce_mean op (#1921) * add stack op and add reduce_mean op and their unit tests * modify stack op output name and modify the for loop in reduce_mean op * add HasAttr for slice op --- lite/arm/math/reduce_mean.cc | 8 ++++---- lite/kernels/arm/stack_compute.cc | 2 +- lite/operators/slice_op.cc | 4 +++- lite/operators/stack_op.cc | 2 +- lite/tests/kernels/reduce_mean_compute_test.cc | 8 ++++---- lite/tests/kernels/stack_compute_test.cc | 2 +- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lite/arm/math/reduce_mean.cc b/lite/arm/math/reduce_mean.cc index 786f8320ee..a139d825b7 100644 --- a/lite/arm/math/reduce_mean.cc +++ b/lite/arm/math/reduce_mean.cc @@ -36,7 +36,7 @@ void reduce_mean_n(const float* src, for (int w = 0; w < width_in; ++w) { data_index = c * hw_size + h * width_in + w; dst[data_index] = 0.0; - for (int n = 1; n < num_in; ++n) { + for (int n = 0; n < num_in; ++n) { src_index = n * chw_size + data_index; dst[data_index] += static_cast(src[src_index]) / num_in; } @@ -61,7 +61,7 @@ void reduce_mean_c(const float* src, data_index = n * hw_size + h * width_in + w; src_index0 = n * chw_size + h * width_in + w; dst[data_index] = 0.0; - for (int c = 1; c < channel_in; ++c) { + for (int c = 0; c < channel_in; ++c) { src_index = src_index0 + c * hw_size; dst[data_index] += static_cast(src[src_index]) / channel_in; } @@ -87,7 +87,7 @@ void reduce_mean_h(const float* src, data_index = n * cw_size + c * width_in + w; src_index0 = n * chw_size + c * hw_size + w; dst[data_index] = 0.0; - for (int h = 1; h < height_in; ++h) { + for (int h = 0; h < height_in; ++h) { src_index = src_index0 + h * width_in; dst[data_index] += static_cast(src[src_index]) / height_in; } @@ -115,7 +115,7 @@ void reduce_mean_w(const float* src, data_index = n * ch_size + c * height_in + h; src_index0 = n * chw_size + c * hw_size + h * width_in; dst[data_index] = 0.0; - for (int w = 1; w < width_in; ++w) { + for (int w = 0; w < width_in; ++w) { src_index = src_index0 + w; dst[data_index] += static_cast(src[src_index]) / width_in; } diff --git a/lite/kernels/arm/stack_compute.cc b/lite/kernels/arm/stack_compute.cc index fb9fa85211..12d04b2d60 100644 --- a/lite/kernels/arm/stack_compute.cc +++ b/lite/kernels/arm/stack_compute.cc @@ -38,5 +38,5 @@ void StackCompute::Run() { REGISTER_LITE_KERNEL( stack, kARM, kFloat, kNCHW, paddle::lite::kernels::arm::StackCompute, def) .BindInput("X", {LiteType::GetTensorTy(TARGET(kARM))}) - .BindOutput("Out", {LiteType::GetTensorTy(TARGET(kARM))}) + .BindOutput("Y", {LiteType::GetTensorTy(TARGET(kARM))}) .Finalize(); diff --git a/lite/operators/slice_op.cc b/lite/operators/slice_op.cc index d919a6db4f..ec4267e7d2 100644 --- a/lite/operators/slice_op.cc +++ b/lite/operators/slice_op.cc @@ -79,7 +79,9 @@ bool SliceOp::AttachImpl(const cpp::OpDesc &opdesc, lite::Scope *scope) { param_.axes = opdesc.GetAttr>("axes"); param_.starts = opdesc.GetAttr>("starts"); param_.ends = opdesc.GetAttr>("ends"); - param_.decrease_axis = opdesc.GetAttr>("decrease_axis"); + if (opdesc.HasAttr("decrease_axis")) { + param_.decrease_axis = opdesc.GetAttr>("decrease_axis"); + } return true; } diff --git a/lite/operators/stack_op.cc b/lite/operators/stack_op.cc index bc8537117e..8fdf61e822 100644 --- a/lite/operators/stack_op.cc +++ b/lite/operators/stack_op.cc @@ -46,7 +46,7 @@ bool StackOp::InferShape() const { bool StackOp::AttachImpl(const cpp::OpDesc &op_desc, lite::Scope *scope) { auto X = op_desc.Input("X"); - auto Out = op_desc.Output("Out").front(); + auto Out = op_desc.Output("Y").front(); for (auto var : X) { param_.X.emplace_back(scope->FindVar(var)->GetMutable()); } diff --git a/lite/tests/kernels/reduce_mean_compute_test.cc b/lite/tests/kernels/reduce_mean_compute_test.cc index e8733ef3ea..cda273239d 100644 --- a/lite/tests/kernels/reduce_mean_compute_test.cc +++ b/lite/tests/kernels/reduce_mean_compute_test.cc @@ -34,7 +34,7 @@ void reduce_mean_n(const float* src, for (int w = 0; w < width_in; ++w) { data_index = c * hw_size + h * width_in + w; dst[data_index] = 0.0; - for (int n = 1; n < num_in; ++n) { + for (int n = 0; n < num_in; ++n) { src_index = n * chw_size + data_index; dst[data_index] += static_cast(src[src_index]) / num_in; } @@ -58,7 +58,7 @@ void reduce_mean_c(const float* src, data_index = n * hw_size + h * width_in + w; src_index0 = n * chw_size + h * width_in + w; dst[data_index] = 0.0; - for (int c = 1; c < channel_in; ++c) { + for (int c = 0; c < channel_in; ++c) { src_index = src_index0 + c * hw_size; dst[data_index] += static_cast(src[src_index]) / channel_in; } @@ -83,7 +83,7 @@ void reduce_mean_h(const float* src, data_index = n * cw_size + c * width_in + w; src_index0 = n * chw_size + c * hw_size + w; dst[data_index] = 0.0; - for (int h = 1; h < height_in; ++h) { + for (int h = 0; h < height_in; ++h) { src_index = src_index0 + h * width_in; dst[data_index] += static_cast(src[src_index]) / height_in; } @@ -110,7 +110,7 @@ void reduce_mean_w(const float* src, data_index = n * ch_size + c * height_in + h; src_index0 = n * chw_size + c * hw_size + h * width_in; dst[data_index] = 0.0; - for (int w = 1; w < width_in; ++w) { + for (int w = 0; w < width_in; ++w) { src_index = src_index0 + w; dst[data_index] += static_cast(src[src_index]) / width_in; } diff --git a/lite/tests/kernels/stack_compute_test.cc b/lite/tests/kernels/stack_compute_test.cc index 7fcefad65e..543409d4ba 100644 --- a/lite/tests/kernels/stack_compute_test.cc +++ b/lite/tests/kernels/stack_compute_test.cc @@ -77,7 +77,7 @@ class StackComputeTester : public arena::TestCase { void PrepareOpDesc(cpp::OpDesc* op_desc) { op_desc->SetType("stack"); op_desc->SetInput("X", {input1_, input2_}); - op_desc->SetOutput("Out", {output_}); + op_desc->SetOutput("Y", {output_}); op_desc->SetAttr("axis", axis_); } -- GitLab