From 37268dbd33e04d4ab5b2fc8318f0f83506836def Mon Sep 17 00:00:00 2001 From: tensor-tang Date: Mon, 18 Sep 2017 23:38:00 +0800 Subject: [PATCH] update using exclusive padding for avg-pool --- paddle/gserver/layers/MKLDNNPoolLayer.cpp | 13 ++----------- paddle/gserver/tests/test_MKLDNN.cpp | 6 +----- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/paddle/gserver/layers/MKLDNNPoolLayer.cpp b/paddle/gserver/layers/MKLDNNPoolLayer.cpp index 26cc50bb53e..48b2f5a4cb3 100644 --- a/paddle/gserver/layers/MKLDNNPoolLayer.cpp +++ b/paddle/gserver/layers/MKLDNNPoolLayer.cpp @@ -49,11 +49,8 @@ bool MKLDNNPoolLayer::init(const LayerMap& layerMap, if (type == "max-projection") { poolAlgo_ = algorithm::pooling_max; } else if (type == "avg-projection") { - // TODO(TJ): support choosing exclusive or inclusive when paddle support it - // only can make sure that paddle use exclude when ph==pw==0 - // otherwise, paddle may used mixed or only include. - poolAlgo_ = (ph_ == 0 && pw_ == 0) ? algorithm::pooling_avg_exclude_padding - : algorithm::pooling_avg_include_padding; + // paddle only use exclude_padding + poolAlgo_ = algorithm::pooling_avg_exclude_padding; } else { LOG(FATAL) << "unknow pooling type!"; } @@ -178,12 +175,6 @@ void MKLDNNPoolLayer::resetFwdPD(std::shared_ptr& pd, padR, padKind); 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 workspace_ = diff --git a/paddle/gserver/tests/test_MKLDNN.cpp b/paddle/gserver/tests/test_MKLDNN.cpp index c3e2545e083..b593f65fe49 100644 --- a/paddle/gserver/tests/test_MKLDNN.cpp +++ b/paddle/gserver/tests/test_MKLDNN.cpp @@ -192,11 +192,6 @@ void testPoolLayer(const testPoolDesc& pm) { } 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*/ 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}); @@ -205,6 +200,7 @@ TEST(MkldnnLayer, PoolLayer) { 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, 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 -- GitLab