未验证 提交 ca424e73 编写于 作者: Z zhupengyang 提交者: GitHub

fix bilinear-interp arm compute (#2029)

fix bilinear-interp unit test for more cases

test=develop
上级 b6379fed
...@@ -83,8 +83,8 @@ void bilinear_interp(const float* src, ...@@ -83,8 +83,8 @@ void bilinear_interp(const float* src,
beta[dy * 2 + 1] = fy; beta[dy * 2 + 1] = fy;
} }
} else { } else {
scale_x = static_cast<float>(w_in / w_out); scale_x = static_cast<float>(w_in) / w_out;
scale_y = static_cast<float>(h_in / h_out); scale_y = static_cast<float>(h_in) / h_out;
// calculate x axis coordinate // calculate x axis coordinate
for (int dx = 0; dx < w_out; dx++) { for (int dx = 0; dx < w_out; dx++) {
fx = scale_x * (dx + 0.5f) - 0.5f; fx = scale_x * (dx + 0.5f) - 0.5f;
......
...@@ -156,26 +156,30 @@ class BilinearInterpComputeTester : public arena::TestCase { ...@@ -156,26 +156,30 @@ class BilinearInterpComputeTester : public arena::TestCase {
float width_scale_ = 0.f; float width_scale_ = 0.f;
int out_height_ = -1; int out_height_ = -1;
int out_width_ = -1; int out_width_ = -1;
int outsize_height_ = -1;
int outsize_width_ = -1;
bool align_corners_ = true; bool align_corners_ = true;
std::string interp_method_ = "Bilinear"; std::string interp_method_ = "Bilinear";
DDim dims_{{1, 1}};
DDim _dims0_{{1, 1, 16, 16}}; DDim _dims0_{{1, 1, 16, 16}};
DDim _dims1_{{2}}; DDim _dims1_{{2}};
public: public:
BilinearInterpComputeTester(const Place& place, BilinearInterpComputeTester(const Place& place,
const std::string& alias, const std::string& alias,
float height_scale, float scale,
float width_scale,
int out_height, int out_height,
int out_width, int out_width,
int outsize_height,
int outsize_width,
bool align_corners, bool align_corners,
std::string interp_method) std::string interp_method)
: TestCase(place, alias), : TestCase(place, alias),
height_scale_(height_scale), height_scale_(scale),
width_scale_(width_scale), width_scale_(scale),
out_height_(out_height), out_height_(out_height),
out_width_(out_width), out_width_(out_width),
outsize_height_(outsize_height),
outsize_width_(outsize_width),
align_corners_(align_corners), align_corners_(align_corners),
interp_method_(interp_method) {} interp_method_(interp_method) {}
...@@ -183,8 +187,9 @@ class BilinearInterpComputeTester : public arena::TestCase { ...@@ -183,8 +187,9 @@ class BilinearInterpComputeTester : public arena::TestCase {
width_scale_ = height_scale_; width_scale_ = height_scale_;
std::vector<const lite::Tensor*> inputs; std::vector<const lite::Tensor*> inputs;
inputs.emplace_back(scope->FindTensor(input0_)); inputs.emplace_back(scope->FindTensor(input0_));
if (outsize_height_ > 0 && outsize_width_ > 0) {
inputs.emplace_back(scope->FindTensor(input1_)); inputs.emplace_back(scope->FindTensor(input1_));
auto outsize_data = inputs[1]->data<int>(); }
if (out_width_ != -1 && out_height_ != -1) { if (out_width_ != -1 && out_height_ != -1) {
height_scale_ = static_cast<float>(out_height_ / inputs[0]->dims()[2]); height_scale_ = static_cast<float>(out_height_ / inputs[0]->dims()[2]);
width_scale_ = static_cast<float>(out_width_ / inputs[0]->dims()[3]); width_scale_ = static_cast<float>(out_width_ / inputs[0]->dims()[3]);
...@@ -192,6 +197,7 @@ class BilinearInterpComputeTester : public arena::TestCase { ...@@ -192,6 +197,7 @@ class BilinearInterpComputeTester : public arena::TestCase {
auto* outputs = scope->NewTensor(output_); auto* outputs = scope->NewTensor(output_);
CHECK(outputs); CHECK(outputs);
if (inputs.size() > 1) { if (inputs.size() > 1) {
auto outsize_data = inputs[1]->data<int>();
int h_out = outsize_data[0]; // HW int h_out = outsize_data[0]; // HW
int w_out = outsize_data[1]; // HW int w_out = outsize_data[1]; // HW
int num_cout = inputs[0]->dims()[0]; int num_cout = inputs[0]->dims()[0];
...@@ -221,7 +227,9 @@ class BilinearInterpComputeTester : public arena::TestCase { ...@@ -221,7 +227,9 @@ class BilinearInterpComputeTester : public arena::TestCase {
void PrepareOpDesc(cpp::OpDesc* op_desc) { void PrepareOpDesc(cpp::OpDesc* op_desc) {
op_desc->SetType("bilinear_interp"); op_desc->SetType("bilinear_interp");
op_desc->SetInput("X", {input0_}); op_desc->SetInput("X", {input0_});
if (outsize_height_ > 0 && outsize_width_ > 0) {
op_desc->SetInput("OutSize", {input1_}); op_desc->SetInput("OutSize", {input1_});
}
op_desc->SetOutput("Out", {output_}); op_desc->SetOutput("Out", {output_});
op_desc->SetAttr("scale", height_scale_); op_desc->SetAttr("scale", height_scale_);
op_desc->SetAttr("out_h", out_height_); op_desc->SetAttr("out_h", out_height_);
...@@ -237,34 +245,60 @@ class BilinearInterpComputeTester : public arena::TestCase { ...@@ -237,34 +245,60 @@ class BilinearInterpComputeTester : public arena::TestCase {
} }
SetCommonTensor(input0_, _dims0_, data0.data()); SetCommonTensor(input0_, _dims0_, data0.data());
std::vector<int> data1(_dims1_.production()); if (outsize_height_ > 0 && outsize_width_ > 0) {
for (int i = 0; i < _dims1_.production(); i++) { std::vector<int> data1(2);
data1[i] = 16; data1[0] = outsize_height_;
} data1[1] = outsize_width_;
SetCommonTensor(input1_, _dims1_, data1.data()); SetCommonTensor(input1_, _dims1_, data1.data());
} }
}
}; };
void test_bilinear_interp(Place place) { void test_bilinear_interp(Place place) {
std::string interp_method = "Bilinear"; std::string interp_method = "Bilinear";
for (float scale : {1., 0.5, 0.3}) { for (float scale : {2., 1., 0.3}) {
for (int out_height : {8, 16}) { for (bool align_corners : {true, false}) {
for (int out_width : {8, 16}) { std::unique_ptr<arena::TestCase> tester(new BilinearInterpComputeTester(
place, "def", scale, -1, -1, -1, -1, align_corners, interp_method));
arena::Arena arena(std::move(tester), place, 5e-5);
arena.TestPrecision();
}
}
for (int out_height : {8, 16, 24}) {
for (int out_width : {8, 16, 24}) {
for (bool align_corners : {true, false}) { for (bool align_corners : {true, false}) {
std::unique_ptr<arena::TestCase> tester( std::unique_ptr<arena::TestCase> tester(
new BilinearInterpComputeTester(place, new BilinearInterpComputeTester(place,
"def", "def",
scale, 0,
scale,
out_height, out_height,
out_width, out_width,
-1,
-1,
align_corners, align_corners,
interp_method)); interp_method));
arena::Arena arena(std::move(tester), place, 2e-5); arena::Arena arena(std::move(tester), place, 5e-5);
arena.TestPrecision(); arena.TestPrecision();
} }
} }
} }
for (int outsize_height : {8, 16, 24}) {
for (int outsize_width : {8, 16, 24}) {
for (bool align_corners : {true, false}) {
std::unique_ptr<arena::TestCase> tester(
new BilinearInterpComputeTester(place,
"def",
0,
-1,
-1,
outsize_height,
outsize_width,
align_corners,
interp_method));
arena::Arena arena(std::move(tester), place, 5e-5);
arena.TestPrecision();
}
}
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册