未验证 提交 f179d302 编写于 作者: X xiebaiyuan 提交者: GitHub

[MOBILE]Fix mobile bilinear (#3446)

* [mobile] wrap_shape in mobile loader.

* [mobile] fix mobile bilinear compatibility ,test=mobile

ONLY FIX MOBILE FOR OLD PROJECT ,DONOT NEED CHECK LITE COMPILE >>> MREGE DIRECT
上级 c7049ee4
......@@ -30,7 +30,10 @@ void BilinearOp<DeviceType, T>::InferShape() const {
int out_h = this->param_.OutH();
int out_w = this->param_.OutW();
PADDLE_MOBILE_ENFORCE(dim_x.size() == 4, "X's dimension must be 4");
bool ignore_scale = false;
if (out_h > 0 && out_w > 0) {
ignore_scale = true;
}
if (this->param_.InputOutPutSize() != nullptr) {
auto out_size_dim = this->param_.InputOutPutSize()->dims();
......@@ -38,8 +41,21 @@ void BilinearOp<DeviceType, T>::InferShape() const {
"OutSize's dimension size must be 1");
PADDLE_MOBILE_ENFORCE(out_size_dim[0] == 2, "OutSize's dim[0] must be 2");
}
std::vector<int64_t> dim_out({dim_x[0], dim_x[1], out_h, out_w});
this->param_.Out()->Resize(framework::make_ddim(dim_out));
if (this->param_.HasScale() && !ignore_scale) {
const float scale = this->param_.Scale();
DLOG << "scale_: " << scale;
std::vector<int64_t> dim_out({dim_x[0], dim_x[1],
static_cast<int>(dim_x[2] * scale),
static_cast<int>(dim_x[3] * scale)});
this->param_.Out()->Resize(framework::make_ddim(dim_out));
DLOG << "interp -- dim_out: " << dim_out;
} else {
std::vector<int64_t> dim_out({dim_x[0], dim_x[1], out_h, out_w});
this->param_.Out()->Resize(framework::make_ddim(dim_out));
DLOG << "interp -- dim_out: " << dim_out;
}
}
} // namespace operators
......
......@@ -3083,6 +3083,12 @@ class BilinearInterpParam : public OpParam {
out_w_ = GetAttr<int>("out_w", attrs);
align_corners = GetAttr<bool>("align_corners", attrs);
align_mode = GetAttr<int>("align_mode", attrs);
if (HasAttr("scale", attrs)) {
has_scale_ = true;
scale_ = GetAttr<float>("scale", attrs);
}
LOG(kLOG_DEBUG1) << "has_scale_: " << has_scale_;
LOG(kLOG_DEBUG1) << "scale_: " << scale_;
}
const GType *InputX() const { return input_x_; }
const GType *InputOutPutSize() const { return input_outsize_; }
......@@ -3091,6 +3097,8 @@ class BilinearInterpParam : public OpParam {
int OutW() const { return out_w_; }
bool AlignCorners() const { return align_corners; }
int AlignMode() const { return align_mode; }
float Scale() const { return scale_; }
bool HasScale() const { return has_scale_; }
private:
GType *input_x_;
......@@ -3100,6 +3108,8 @@ class BilinearInterpParam : public OpParam {
int out_w_;
bool align_corners;
int align_mode;
float scale_;
bool has_scale_;
};
#endif
......
......@@ -38,8 +38,7 @@ int main(int argc, char **argv) {
<< " <input_w>\n"
<< " <repeats>\n"
<< " <warmup>\n"
<< " <print_output>"
<< std::endl;
<< " <print_output>" << std::endl;
return 0;
}
......@@ -54,11 +53,8 @@ int main(int argc, char **argv) {
print_output_elem = atoi(argv[8]);
}
std::cout << "input shape(NCHW):"
<< N << " "
<< C << " "
<< H << " "
<< W << std::endl;
std::cout << "input shape(NCHW):" << N << " " << C << " " << H << " " << W
<< std::endl;
std::cout << "repeats:" << repeats << std::endl;
std::cout << "model_dir:" << model_dir << std::endl;
......@@ -76,9 +72,8 @@ int main(int argc, char **argv) {
}
auto load_end = paddle_mobile::time();
std::cout << "load cost:"
<< paddle_mobile::time_diff(load_start, load_end)
<< " ms" << std::endl;
std::cout << "load cost:" << paddle_mobile::time_diff(load_start, load_end)
<< " ms" << std::endl;
// input tensor
std::vector<float> input;
......@@ -104,8 +99,8 @@ int main(int argc, char **argv) {
sum_duration += duration;
min_duration = (duration > min_duration) ? min_duration : duration;
max_duration = (duration < max_duration) ? max_duration : duration;
std::cout << "ridx:" << ridx + 1 << "/" << repeats
<< " " << duration << " ms" << std::endl;
std::cout << "ridx:" << ridx + 1 << "/" << repeats << " " << duration
<< " ms" << std::endl;
}
// benchmark result
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册