提交 37268dbd 编写于 作者: T tensor-tang

update using exclusive padding for avg-pool

上级 cc28fb4b
...@@ -49,11 +49,8 @@ bool MKLDNNPoolLayer::init(const LayerMap& layerMap, ...@@ -49,11 +49,8 @@ bool MKLDNNPoolLayer::init(const LayerMap& layerMap,
if (type == "max-projection") { if (type == "max-projection") {
poolAlgo_ = algorithm::pooling_max; poolAlgo_ = algorithm::pooling_max;
} else if (type == "avg-projection") { } else if (type == "avg-projection") {
// TODO(TJ): support choosing exclusive or inclusive when paddle support it // paddle only use exclude_padding
// only can make sure that paddle use exclude when ph==pw==0 poolAlgo_ = algorithm::pooling_avg_exclude_padding;
// otherwise, paddle may used mixed or only include.
poolAlgo_ = (ph_ == 0 && pw_ == 0) ? algorithm::pooling_avg_exclude_padding
: algorithm::pooling_avg_include_padding;
} else { } else {
LOG(FATAL) << "unknow pooling type!"; LOG(FATAL) << "unknow pooling type!";
} }
...@@ -178,12 +175,6 @@ void MKLDNNPoolLayer::resetFwdPD(std::shared_ptr<pool_fwd::primitive_desc>& pd, ...@@ -178,12 +175,6 @@ void MKLDNNPoolLayer::resetFwdPD(std::shared_ptr<pool_fwd::primitive_desc>& pd,
padR, padR,
padKind); padKind);
pd.reset(new pool_fwd::primitive_desc(fwdDesc, engine_)); pd.reset(new pool_fwd::primitive_desc(fwdDesc, engine_));
if ((ph_ != 0 || pw_ != 0) && (padR[0] > padL[0] || padR[1] > padL[1])) {
LOG(WARNING)
<< "With this layer " << getName() << ", mkldnn_pool use "
<< "inclusive pooling, while paddle mix inclusice and exclusive."
<< "So they may have different results for this layer.";
}
// prepare workspace if necessary // prepare workspace if necessary
workspace_ = workspace_ =
......
...@@ -192,11 +192,6 @@ void testPoolLayer(const testPoolDesc& pm) { ...@@ -192,11 +192,6 @@ void testPoolLayer(const testPoolDesc& pm) {
} }
TEST(MkldnnLayer, PoolLayer) { TEST(MkldnnLayer, PoolLayer) {
// For max pooling, MKLDNN has the same result with Paddle.
// For avg pooling, MKLDNN use either inclusive or exclusive pooling, while
// Paddle mixes these two types. So, when encountering some
// test cases with padding>0, they may get different results.
// Then MKLDNN layer will give warnning for these cases.
/* bs, ch, ih, iw, oh, ow, fh, fw, ph, pw, sh, sw*/ /* bs, ch, ih, iw, oh, ow, fh, fw, ph, pw, sh, sw*/
testPoolLayer({2, 1, 4, 4, 2, 2, 3, 3, 0, 0, 2, 2}); testPoolLayer({2, 1, 4, 4, 2, 2, 3, 3, 0, 0, 2, 2});
testPoolLayer({10, 8, 16, 16, 8, 8, 2, 2, 0, 0, 2, 2}); testPoolLayer({10, 8, 16, 16, 8, 8, 2, 2, 0, 0, 2, 2});
...@@ -205,6 +200,7 @@ TEST(MkldnnLayer, PoolLayer) { ...@@ -205,6 +200,7 @@ TEST(MkldnnLayer, PoolLayer) {
testPoolLayer({8, 16, 14, 14, 7, 7, 3, 3, 0, 0, 2, 2}); testPoolLayer({8, 16, 14, 14, 7, 7, 3, 3, 0, 0, 2, 2});
testPoolLayer({4, 16, 7, 7, 1, 1, 7, 7, 0, 0, 1, 1}); testPoolLayer({4, 16, 7, 7, 1, 1, 7, 7, 0, 0, 1, 1});
testPoolLayer({4, 2, 5, 5, 3, 3, 5, 5, 1, 1, 1, 1}); testPoolLayer({4, 2, 5, 5, 3, 3, 5, 5, 1, 1, 1, 1});
testPoolLayer({2, 8, 56, 56, 29, 29, 3, 3, 1, 1, 2, 2});
} }
// TODO(TJ): add branch test // TODO(TJ): add branch test
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册