未验证 提交 d04514cc 编写于 作者: J Jason 提交者: GitHub

Merge pull request #757 from wjj19950828/support_for_SegFlow

Fixed scale and crop op
...@@ -346,7 +346,15 @@ def shape_argmax(layer, input_shape): ...@@ -346,7 +346,15 @@ def shape_argmax(layer, input_shape):
def shape_crop(layer, input_shape): def shape_crop(layer, input_shape):
assert len(input_shape) == 2, "the number of crop's inputs must be 2" assert len(input_shape) == 2, "the number of crop's inputs must be 2"
return [input_shape[1]] params = layer.crop_param
axis = params.axis
if axis < 0:
axis += len(input_shape[0])
if axis > 0:
crop_shape = input_shape[0][:axis] + input_shape[1][axis:]
else:
crop_shape = input_shape[1]
return [crop_shape]
def shape_flatten(layer, input_shape): def shape_flatten(layer, input_shape):
......
...@@ -768,7 +768,8 @@ class CaffeOpMapper(): ...@@ -768,7 +768,8 @@ class CaffeOpMapper():
node.data[1]).astype("float32") node.data[1]).astype("float32")
params = node.layer.scale_param params = node.layer.scale_param
axis = params.axis axis = params.axis
inputs = [] if axis < 0:
axis += len(node.in_shapes[0])
if len(node.inputs) == 2: if len(node.inputs) == 2:
input0 = self.graph.get_input_node(node, idx=0, copy=True) input0 = self.graph.get_input_node(node, idx=0, copy=True)
input1 = self.graph.get_input_node(node, idx=1, copy=True) input1 = self.graph.get_input_node(node, idx=1, copy=True)
...@@ -777,11 +778,6 @@ class CaffeOpMapper(): ...@@ -777,11 +778,6 @@ class CaffeOpMapper():
inputs_dict = {} inputs_dict = {}
inputs_dict['x'] = input0_name inputs_dict['x'] = input0_name
inputs_dict['y'] = input1_name inputs_dict['y'] = input1_name
self.paddle_graph.add_layer(
"paddle.multiply",
inputs=inputs_dict,
outputs=[node.layer_name + "_mul"],
axis=1)
else: else:
self.paddle_graph.add_layer( self.paddle_graph.add_layer(
"self.create_parameter", "self.create_parameter",
...@@ -794,17 +790,17 @@ class CaffeOpMapper(): ...@@ -794,17 +790,17 @@ class CaffeOpMapper():
inputs_dict = {} inputs_dict = {}
inputs_dict['x'] = input0_name inputs_dict['x'] = input0_name
inputs_dict['y'] = node.layer_name + "_cparam1" inputs_dict['y'] = node.layer_name + "_cparam1"
if len(node.in_shapes[0]) == 2: if axis == len(node.in_shapes[0]) - 1:
self.paddle_graph.add_layer( self.paddle_graph.add_layer(
"paddle.multiply", "paddle.multiply",
inputs=inputs_dict, inputs=inputs_dict,
outputs=[node.layer_name + "_mul"]) outputs=[node.layer_name + "_mul"])
else: else:
self.paddle_graph.add_layer( self.paddle_graph.add_layer(
"paddle.multiply", "paddle.fluid.layers.elementwise_mul",
inputs=inputs_dict, inputs=inputs_dict,
outputs=[node.layer_name + "_mul"], outputs=[node.layer_name + "_mul"],
axis=axis) axis=axis)
self.paddle_graph.add_layer( self.paddle_graph.add_layer(
"self.create_parameter", "self.create_parameter",
inputs={}, inputs={},
...@@ -815,12 +811,10 @@ class CaffeOpMapper(): ...@@ -815,12 +811,10 @@ class CaffeOpMapper():
inputs_dict['x'] = node.layer_name + "_mul" inputs_dict['x'] = node.layer_name + "_mul"
inputs_dict['y'] = node.layer_name + "_cparam2" inputs_dict['y'] = node.layer_name + "_cparam2"
output_shape = node.out_shapes[0] output_shape = node.out_shapes[0]
if axis == -1: if axis == len(output_shape) - 1:
self.paddle_graph.add_layer( self.paddle_graph.add_layer(
"paddle.add", inputs=inputs_dict, outputs=[node.layer_name]) "paddle.add", inputs=inputs_dict, outputs=[node.layer_name])
else: else:
if axis < 0:
axis = axis + len(output_shape)
param2_shape = self.params[node.layer_name + "_cparam2"].shape param2_shape = self.params[node.layer_name + "_cparam2"].shape
param2_shape_len = len(param2_shape) param2_shape_len = len(param2_shape)
diff_len = len(output_shape) - axis - param2_shape_len diff_len = len(output_shape) - axis - param2_shape_len
...@@ -933,11 +927,15 @@ class CaffeOpMapper(): ...@@ -933,11 +927,15 @@ class CaffeOpMapper():
) == len(offset), "invalid offset[%s] in crop layer" % ( ) == len(offset), "invalid offset[%s] in crop layer" % (
str(offset)) str(offset))
offset_real = [0] * axis + offset offset_real = [0] * axis + offset
if axis > 0:
crop_shape = node.in_shapes[0][:axis] + node.in_shapes[1][axis:]
else:
crop_shape = node.in_shapes[1]
self.paddle_graph.add_layer( self.paddle_graph.add_layer(
"paddle.crop", "paddle.crop",
inputs={"x": input.name}, inputs={"x": input.name},
outputs=[node.layer_name], outputs=[node.layer_name],
shape=node.in_shapes[1], shape=crop_shape,
offsets=list(offset_real)) offsets=list(offset_real))
def Flatten(self, node): def Flatten(self, node):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册