提交 0b2dad2b 编写于 作者: D dingminghui 提交者: jackzhang235

fix(pool): fix pool op wrong calculation in yolov3 and enable more

           testcase
上级 789112e8
......@@ -62,8 +62,6 @@ int PoolConverter(void* ctx, OpLite* op, KernelBase* kernel) {
paddings.insert(paddings.begin() + 2 * i + 1, copy_pad);
}
}
int pad_height = paddings[0];
int pad_width = paddings[2];
std::string padding_algorithm("");
if (op_info->HasAttr("padding_algorithm")) {
padding_algorithm = op_info->GetAttr<std::string>("padding_algorithm");
......@@ -73,12 +71,7 @@ int PoolConverter(void* ctx, OpLite* op, KernelBase* kernel) {
adaptive = op_info->GetAttr<bool>("adaptive");
}
auto input_dims = x->dims();
if (global_pooling) {
ksize.resize(static_cast<size_t>(input_dims.size()) - 2);
for (size_t i = 0; i < ksize.size(); ++i) {
ksize[i] = static_cast<int>(input_dims[i + 2]);
}
}
lite::operators::UpdatePadding(&paddings,
global_pooling,
adaptive,
......@@ -87,31 +80,31 @@ int PoolConverter(void* ctx, OpLite* op, KernelBase* kernel) {
strides,
ksize);
// std::vector<int64_t> output_shape({input_dims[0], input_dims[1]});
// for (size_t i = 0; i < 2; i++) {
// output_shape.push_back(
// (input_dims[i + 2] + paddings[2 * i] + paddings[2 * i + 1] -
// ksize[0]) /
// strides[i] +
// 1);
// }
if (global_pooling) {
ksize.resize(static_cast<size_t>(input_dims.size()) - 2);
for (size_t i = 0; i < ksize.size(); ++i) {
ksize[i] = static_cast<int>(input_dims[i + 2]);
}
}
auto output_tensor = graph->AddNode(
output_var_name, output_shape, CNML_TENSOR, CNML_NCHW, graph->FPType());
cnmlPoolOpParam_t pool_param;
CNML_CALL(
cnmlCreatePoolOpParam_V2(&pool_param,
cnmlCreatePoolOpParam_V3(&pool_param,
ksize[0],
ksize[1],
strides[0],
strides[1],
pad_height,
pad_width,
1, // dilation
1,
paddings[0],
paddings[1],
paddings[2],
paddings[3],
1, // dilation h
1, // dilation w
ToCnmlPoolMode(pooling_type),
ceil_mode ? CNML_POOL_KVALID : CNML_POOL_KFULL,
ceil_mode ? CNML_POOL_KFULL : CNML_POOL_KVALID,
true, /* real */
1 /* blend factor */));
cnmlBaseOp_t pool_op;
......
......@@ -43,6 +43,12 @@ void pool_ref(const std::shared_ptr<operators::PoolOpLite> op) {
std::string pooling_type = op_info->GetAttr<std::string>("pooling_type");
bool global_pooling = op_info->GetAttr<bool>("global_pooling");
if (pooling_type == "max") {
for (int i = 0; i < out_dims.production(); ++i) {
dst_ptr[i] = -65504.f;
}
}
int in_n = in_dims[0];
int in_c = in_dims[1];
int in_h = in_dims[2];
......@@ -203,62 +209,46 @@ void test_pool(int bs,
}
TEST(MLUBridges, pool) {
// for (auto pooling_type : {"max", "avg"}) {
// for (auto ceil_mode : {true, false}) {
// for (auto global_pooling : {/*true, */ false}) {
// for (auto exclusive : {true /*, false*/}) {
// for (auto ksize : {2, 3}) {
// for (auto stride : {1, 2}) {
// for (auto padding : {0, 1}) {
// for (auto bs : {1, 3}) {
// for (auto ic : {1, 3}) {
// for (auto ih : {3, 7}) {
// for (auto iw : {3, 7}) {
// test_pool(bs,
// ic,
// ih,
// iw,
// pooling_type,
// ceil_mode,
// global_pooling,
// exclusive,
// ksize,
// stride,
// padding);
// }
// }
// }
// }
// }
// }
// }
// }
// }
// }
// }
for (auto pooling_type : {"max", "avg"}) {
for (auto ceil_mode : {true, false}) {
bool global_pooling = false;
bool exclusive = true;
int ksize = 2;
int stride = 1;
int padding = 0;
int bs = 6;
int ic = 6;
int ih = 6;
int iw = 6;
test_pool(bs,
ic,
ih,
iw,
pooling_type,
ceil_mode,
global_pooling,
exclusive,
ksize,
stride,
padding);
for (auto global_pooling : {true, false}) {
for (auto exclusive : {true /*, false*/}) {
for (auto ksize : {2, 3}) {
for (auto stride : {1, 2}) {
for (auto padding : {0, 1}) {
for (auto bs : {1, 3}) {
for (auto ic : {1, 3}) {
for (auto ih : {3, 7}) {
for (auto iw : {3, 7}) {
LOG(INFO)
<< "shape: " << bs << ',' << ic << ',' << ih << ','
<< iw << '\t' << "pooling type: " << pooling_type
<< '\t' << "ceil model: " << ceil_mode << '\t'
<< "global_pooling: " << global_pooling << '\t'
<< "exclusive: " << exclusive << '\t'
<< "ksize: " << ksize << '\t'
<< "stride: " << stride << '\t'
<< "padding: " << padding;
test_pool(bs,
ic,
ih,
iw,
pooling_type,
ceil_mode,
global_pooling,
exclusive,
ksize,
stride,
padding);
}
}
}
}
}
}
}
}
}
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册