提交 edb4bde7 编写于 作者: S SunAhong1993

add pooling round_mode

上级 0c3d8fe5
...@@ -1378,6 +1378,11 @@ message PoolingParameter { ...@@ -1378,6 +1378,11 @@ message PoolingParameter {
// If global_pooling then it will pool over the size of the bottom by doing // If global_pooling then it will pool over the size of the bottom by doing
// kernel_h = bottom->height and kernel_w = bottom->width // kernel_h = bottom->height and kernel_w = bottom->width
optional bool global_pooling = 12 [default = false]; optional bool global_pooling = 12 [default = false];
enum RoundMode {
CEIL = 0;
FLOOR = 1;
}
optional RoundMode round_mode = 13 [default = CEIL];
} }
message PowerParameter { message PowerParameter {
......
此差异已折叠。
...@@ -115,6 +115,12 @@ def shape_pooling(layer, input_shape): ...@@ -115,6 +115,12 @@ def shape_pooling(layer, input_shape):
method = math.ceil method = math.ceil
else: else:
method = math.floor method = math.floor
if not hasattr(params, 'ceil_mode'):
round_mode = getattr(params, 'round_mode', 0)
if round_mode == 1:
method = math.floor
else:
method = math.ceil
return get_strided_kernel_output_shape(params, input_shape[0], method) return get_strided_kernel_output_shape(params, input_shape[0], method)
...@@ -240,7 +246,9 @@ def shape_reshape(layer, input_shape): ...@@ -240,7 +246,9 @@ def shape_reshape(layer, input_shape):
params = layer.reshape_param params = layer.reshape_param
axis = params.axis if hasattr(params, 'axis') else 0 axis = params.axis if hasattr(params, 'axis') else 0
num_axes = params.num_axes if hasattr(params, 'num_axes') else -1 num_axes = params.num_axes if hasattr(params, 'num_axes') else -1
is_unknow_batch = False
if inshape[0] == -1: if inshape[0] == -1:
is_unknow_batch = True
inshape[0] = 1 inshape[0] = 1
input_count = count(inshape) input_count = count(inshape)
...@@ -310,6 +318,7 @@ def shape_reshape(layer, input_shape): ...@@ -310,6 +318,7 @@ def shape_reshape(layer, input_shape):
output_count = count(output_shape) output_count = count(output_shape)
assert output_count == input_count, "[Reshape]output count[%d] must match input count[%d]" % ( assert output_count == input_count, "[Reshape]output count[%d] must match input count[%d]" % (
output_count, input_count) output_count, input_count)
if is_unknow_batch:
output_shape[0] = -1 output_shape[0] = -1
return [output_shape] return [output_shape]
......
...@@ -358,7 +358,9 @@ class CaffeOpMapper(OpMapper): ...@@ -358,7 +358,9 @@ class CaffeOpMapper(OpMapper):
output_name = node.layer_name output_name = node.layer_name
layer_outputs = [pool2d_name, output_name] layer_outputs = [pool2d_name, output_name]
params = node.layer.pooling_param params = node.layer.pooling_param
ceil_mode = getattr(params, "ceil_mod", True) ceil_mode = getattr(params, "ceil_mode", True)
if not hasattr(params, 'ceil_mode'):
ceil_mode = True if getattr(params, "round_mode", 0) == 0 else False
global_pool = getattr(params, "global_pooling", False) global_pool = getattr(params, "global_pooling", False)
kernel_default = [1, 1] kernel_default = [1, 1]
channel, kernel, stride, pad, dilation, group = _get_kernel_parameters( channel, kernel, stride, pad, dilation, group = _get_kernel_parameters(
...@@ -635,7 +637,7 @@ class CaffeOpMapper(OpMapper): ...@@ -635,7 +637,7 @@ class CaffeOpMapper(OpMapper):
"paddle.scale", "paddle.scale",
inputs={"x": input1_name}, inputs={"x": input1_name},
outputs=[node.layer_name + '_mul1'], outputs=[node.layer_name + '_mul1'],
scale=coeff[2]) scale=coeff[1])
inputs_dict = {} inputs_dict = {}
inputs_dict['x'] = node.layer_name + '_mul0' inputs_dict['x'] = node.layer_name + '_mul0'
inputs_dict['y'] = node.layer_name + '_mul1' inputs_dict['y'] = node.layer_name + '_mul1'
...@@ -972,12 +974,12 @@ class CaffeOpMapper(OpMapper): ...@@ -972,12 +974,12 @@ class CaffeOpMapper(OpMapper):
# operation = MEAN # operation = MEAN
else: else:
layer_attrs = { layer_attrs = {
"dim": dim[axis:], "axis": dim[axis:],
"keep_dim": False, "keepdim": False,
} }
self.paddle_graph.add_layer( self.paddle_graph.add_layer(
"paddle.mean", "paddle.mean",
inputs={"input": input.name}, inputs={"x": input.name},
outputs=[node.layer_name], outputs=[node.layer_name],
**layer_attrs) **layer_attrs)
self.paddle_graph.add_layer( self.paddle_graph.add_layer(
......
...@@ -395,6 +395,8 @@ class CaffeOpMapper(OpMapper): ...@@ -395,6 +395,8 @@ class CaffeOpMapper(OpMapper):
def Pooling(self, node): def Pooling(self, node):
params = node.layer.pooling_param params = node.layer.pooling_param
ceil_mode = getattr(params, 'ceil_mode', True) ceil_mode = getattr(params, 'ceil_mode', True)
if not hasattr(params, 'ceil_mode'):
ceil_mode = True if getattr(params, "round_mode", 0) == 0 else False
global_pool = getattr(params, 'global_pooling', False) global_pool = getattr(params, 'global_pooling', False)
kernel_default = [1, 1] kernel_default = [1, 1]
channel, kernel, stride, pad, dilation, group = _get_kernel_parameters( channel, kernel, stride, pad, dilation, group = _get_kernel_parameters(
...@@ -679,7 +681,7 @@ class CaffeOpMapper(OpMapper): ...@@ -679,7 +681,7 @@ class CaffeOpMapper(OpMapper):
"paddle.scale", "paddle.scale",
inputs={"x": input1_name}, inputs={"x": input1_name},
outputs=[node.name + '_mul1'], outputs=[node.name + '_mul1'],
scale=coeff[2]) scale=coeff[1])
inputs_dict = {} inputs_dict = {}
inputs_dict['x'] = node.name + '_mul0' inputs_dict['x'] = node.name + '_mul0'
inputs_dict['y'] = node.name + '_mul1' inputs_dict['y'] = node.name + '_mul1'
...@@ -1024,12 +1026,12 @@ class CaffeOpMapper(OpMapper): ...@@ -1024,12 +1026,12 @@ class CaffeOpMapper(OpMapper):
# operation = MEAN # operation = MEAN
else: else:
layer_attrs = { layer_attrs = {
"dim": dim[axis:], "axis": dim[axis:],
"keep_dim": False, "keepdim": False,
} }
self.paddle_graph.add_layer( self.paddle_graph.add_layer(
"paddle.mean", "paddle.mean",
inputs={"input": input.name}, inputs={"x": input.name},
outputs=[node.name], outputs=[node.name],
**layer_attrs) **layer_attrs)
self.paddle_graph.add_layer( self.paddle_graph.add_layer(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册