From e1358945d11a681f19870d4282b33f649c312e01 Mon Sep 17 00:00:00 2001 From: guosheng Date: Thu, 30 Nov 2017 23:46:21 +0800 Subject: [PATCH] Refine AvgPooling with excludeMode to make it compatible with the raw prototxt --- proto/ModelConfig.proto | 2 +- python/paddle/trainer/config_parser.py | 6 +++--- python/paddle/trainer_config_helpers/layers.py | 7 ++++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/proto/ModelConfig.proto b/proto/ModelConfig.proto index 2c131338c0..1fbdd5bbd8 100644 --- a/proto/ModelConfig.proto +++ b/proto/ModelConfig.proto @@ -140,7 +140,7 @@ message PoolConfig { optional uint32 img_size_z = 17 [ default = 1 ]; optional uint32 padding_z = 18 [ default = 1 ]; - optional bool exclude_mode = 19 [ default = true ]; + optional bool exclude_mode = 19; } message SppConfig { diff --git a/python/paddle/trainer/config_parser.py b/python/paddle/trainer/config_parser.py index ca4a66d30d..3fe844b883 100644 --- a/python/paddle/trainer/config_parser.py +++ b/python/paddle/trainer/config_parser.py @@ -1262,8 +1262,8 @@ def parse_pool(pool, input_layer_name, pool_conf, ceil_mode, exclude_mode): pool_conf.output_y = cnn_output_size(pool_conf.img_size_y, pool_conf.size_y, pool_conf.padding_y, pool_conf.stride_y, not ceil_mode) - - pool_conf.exclude_mode = exclude_mode + if exclude_mode != None: + pool_conf.exclude_mode = exclude_mode def parse_pool3d(pool, input_layer_name, pool_conf, ceil_mode): @@ -2305,7 +2305,7 @@ class NormLayer(LayerBase): class PoolLayer(LayerBase): layer_type = 'pool' - def __init__(self, name, inputs, ceil_mode=True, exclude_mode=True, + def __init__(self, name, inputs, ceil_mode=True, exclude_mode=None, **xargs): use_mkldnn = int(g_command_config_args.get("use_mkldnn", 0)) if self.layer_type == "mkldnn_pool": diff --git a/python/paddle/trainer_config_helpers/layers.py b/python/paddle/trainer_config_helpers/layers.py index 46fe09b947..8c5cc25d6c 100644 --- a/python/paddle/trainer_config_helpers/layers.py +++ b/python/paddle/trainer_config_helpers/layers.py @@ -2710,7 +2710,7 @@ def img_pool_layer(input, stride_y=None, padding_y=None, ceil_mode=True, - exclude_mode=True): + exclude_mode=None): """ Image pooling Layer. @@ -2779,8 +2779,9 @@ def img_pool_layer(input, be used. :type ceil_mode: bool :param exclude_mode: Whether to exclude the padding cells when calculating, but only - work when pool_type is AvgPooling. If use cudnn, use CudnnAvgPooling - or CudnnAvgInclPadPooling as pool_type to identify. + work when pool_type is AvgPooling. If None, also exclude the padding + cells. If use cudnn, use CudnnAvgPooling or CudnnAvgInclPadPooling + as pool_type to identify the mode. :type exclude_mode: bool :return: LayerOutput object. :rtype: LayerOutput -- GitLab