diff --git a/x2paddle/op_mapper/__pycache__/__init__.cpython-37.pyc b/x2paddle/op_mapper/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..3c68b130e9165a7cb882733fc57bf5e7bc581c1e Binary files /dev/null and b/x2paddle/op_mapper/__pycache__/__init__.cpython-37.pyc differ diff --git a/x2paddle/op_mapper/dygraph/__pycache__/prim2code.cpython-37.pyc b/x2paddle/op_mapper/dygraph/__pycache__/prim2code.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4b7ad383ffd75fc3110bae684a3676740d5da8c0 Binary files /dev/null and b/x2paddle/op_mapper/dygraph/__pycache__/prim2code.cpython-37.pyc differ diff --git a/x2paddle/op_mapper/dygraph/caffe2paddle/__pycache__/__init__.cpython-37.pyc b/x2paddle/op_mapper/dygraph/caffe2paddle/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e84b634987b038e4553332ef566621958c6d71be Binary files /dev/null and b/x2paddle/op_mapper/dygraph/caffe2paddle/__pycache__/__init__.cpython-37.pyc differ diff --git a/x2paddle/op_mapper/dygraph/caffe2paddle/__pycache__/caffe_op_mapper.cpython-37.pyc b/x2paddle/op_mapper/dygraph/caffe2paddle/__pycache__/caffe_op_mapper.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ec931feeeff97bf01d4ce81c9907f675b828b7a5 Binary files /dev/null and b/x2paddle/op_mapper/dygraph/caffe2paddle/__pycache__/caffe_op_mapper.cpython-37.pyc differ diff --git a/x2paddle/op_mapper/dygraph/caffe2paddle/__pycache__/caffe_shape.cpython-37.pyc b/x2paddle/op_mapper/dygraph/caffe2paddle/__pycache__/caffe_shape.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8d02b27a91b9310924d16b33f0e9a16600cbddd0 Binary files /dev/null and b/x2paddle/op_mapper/dygraph/caffe2paddle/__pycache__/caffe_shape.cpython-37.pyc differ diff --git a/x2paddle/op_mapper/dygraph/caffe2paddle/caffe_op_mapper.py b/x2paddle/op_mapper/dygraph/caffe2paddle/caffe_op_mapper.py index 41f034fe6c501831b36f72049cfa69dbafc359fa..67e2018eabb42bccb0d68520ca5013bfc880b936 100644 --- a/x2paddle/op_mapper/dygraph/caffe2paddle/caffe_op_mapper.py +++ b/x2paddle/op_mapper/dygraph/caffe2paddle/caffe_op_mapper.py @@ -371,7 +371,6 @@ class CaffeOpMapper(OpMapper): params = node.layer.pooling_param ceil_mode = getattr(params, "ceil_mod", True) global_pool = getattr(params, "global_pooling", False) - assert not global_pool, "The global_pool must be False!" kernel_default = [1, 1] channel, kernel, stride, pad, dilation, group = self.get_kernel_parameters( node.layer_type, params) @@ -382,25 +381,55 @@ class CaffeOpMapper(OpMapper): assert len( node.inputs) == 1, "The count of Pooling node\'s input is not 1." input = self.graph.get_bottom_node(node, idx=0, copy=True) - layer_attrs = { - 'kernel_size': kernel, - 'stride': stride, - 'padding': pad, - 'ceil_mode': ceil_mode, - } - if params.pool == 0: - self.pd_graph.add_layer( - "paddle.nn.MaxPool2D", - inputs={"input": self.get_input_name(input)}, - outputs=layer_outputs, - **layer_attrs) + if global_pool: + if kernel[0] == 0: + kernel = [1, 1] + if params.pool == 0: + self.pd_graph.add_layer( + "paddle.nn.AdaptiveMaxPool2D", + inputs={"input": self.get_input_name(input)}, + outputs=layer_outputs, + output_size=kernel) + else: + self.pd_graph.add_layer( + "paddle.nn.AdaptiveAvgPool2D", + inputs={"input": self.get_input_name(input)}, + outputs=layer_outputs, + output_size=kernel) else: - layer_attrs["count_include_pad"] = True + layer_attrs = { + 'pool_size': kernel, + 'pool_stride': stride, + 'pool_padding': pad, + 'ceil_mode': ceil_mode, + 'pool_type': string(pool_type), + 'exclusive': False, + 'global_pooling': global_pool, + } self.pd_graph.add_layer( - "paddle.nn.AvgPool2D", + "paddle.fluid.dygraph.Pool2D", inputs={"input": self.get_input_name(input)}, outputs=layer_outputs, **layer_attrs) +# layer_attrs = { +# 'kernel_size': kernel, +# 'stride': stride, +# 'padding': pad, +# 'ceil_mode': ceil_mode, +# } +# if params.pool == 0: +# self.pd_graph.add_layer( +# "paddle.nn.MaxPool2D", +# inputs={"input": self.get_input_name(input)}, +# outputs=layer_outputs, +# **layer_attrs) +# else: +# layer_attrs["count_include_pad"] = True +# self.pd_graph.add_layer( +# "paddle.nn.AvgPool2D", +# inputs={"input": self.get_input_name(input)}, +# outputs=layer_outputs, +# **layer_attrs) def LRN(self, node): assert len(node.inputs) == 1, "The count of LRN node\'s input is not 1." @@ -532,11 +561,11 @@ class CaffeOpMapper(OpMapper): sections_list.append(s[axis]) layer_attrs = { 'num_or_sections': sections_list, - 'dim': axis, + 'axis': axis, } self.pd_graph.add_layer( "paddle.split", - inputs={"input": self.get_input_name(input)}, + inputs={"x": self.get_input_name(input)}, outputs=[node.layer_name], **layer_attrs) @@ -796,26 +825,19 @@ class CaffeOpMapper(OpMapper): inputs_dict['x'] = node.layer_name + "_mul" inputs_dict['y'] = node.layer_name + "_cparam2" self.pd_graph.add_layer( - "paddle.add", + "fluid.layers.elementwise_add", inputs=inputs_dict, outputs=[node.layer_name], axis=axis) def Reshape(self, node): input = self.graph.get_bottom_node(node, idx=0, copy=True) - top_count = len(input.layer.top) - is_inplace = False if top_count == 1 else True output_shape = node.output_shape[0] - print(output_shape) - layer_attrs = { - 'shape': output_shape, - 'inplace': is_inplace, - } self.pd_graph.add_layer( "paddle.reshape", inputs={"x": self.get_input_name(input)}, outputs=[node.layer_name], - **layer_attrs) + shape=output_shape) def ArgMax(self, node): @@ -1042,10 +1064,10 @@ class CaffeOpMapper(OpMapper): nms_param_dict = {"nms_threshold": 0.3, "top_k": 10, "eta": 1.0} self.pd_graph.add_layer( "paddle.split", - inputs={"input": inputs_list[2]}, + inputs={"x": inputs_list[2]}, outputs=[node.layer_name + "_priorbox_list"], num_or_sections=2, - dim=1) + axis=1) self.pd_graph.add_layer( "prim.getitem", inputs={"list": node.layer_name + "_priorbox_list"}, @@ -1284,8 +1306,8 @@ class CaffeOpMapper(OpMapper): "axes": [params.axis], "starts": [params.slice_point[0]]} self.pd_graph.add_layer( - "paddle.split", - inputs={"input": self.get_input_name(input), + "paddle.slice", + inputs={"x": self.get_input_name(input), "end": node.layer_name + "_end"}, outputs=[node.layer_name], **layer_attrs) diff --git a/x2paddle/op_mapper/static/__pycache__/__init__.cpython-37.pyc b/x2paddle/op_mapper/static/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..51f30da711f3c4b7d484c68502124157d201587e Binary files /dev/null and b/x2paddle/op_mapper/static/__pycache__/__init__.cpython-37.pyc differ diff --git a/x2paddle/op_mapper/static/caffe2paddle/__pycache__/__init__.cpython-37.pyc b/x2paddle/op_mapper/static/caffe2paddle/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..3b20d50c877d33e5b093373e6110969a04ef2275 Binary files /dev/null and b/x2paddle/op_mapper/static/caffe2paddle/__pycache__/__init__.cpython-37.pyc differ diff --git a/x2paddle/op_mapper/static/caffe2paddle/__pycache__/caffe_op_mapper.cpython-37.pyc b/x2paddle/op_mapper/static/caffe2paddle/__pycache__/caffe_op_mapper.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5a10891212579dbbf8abcde42ae8bcb8ea778757 Binary files /dev/null and b/x2paddle/op_mapper/static/caffe2paddle/__pycache__/caffe_op_mapper.cpython-37.pyc differ diff --git a/x2paddle/op_mapper/static/caffe2paddle/__pycache__/caffe_shape.cpython-37.pyc b/x2paddle/op_mapper/static/caffe2paddle/__pycache__/caffe_shape.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4e25ae52804b21b1532f642674d7854a9a430aba Binary files /dev/null and b/x2paddle/op_mapper/static/caffe2paddle/__pycache__/caffe_shape.cpython-37.pyc differ diff --git a/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/__init__.cpython-37.pyc b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..74b120e2a60d3db8056057aeb9b03c7438532b5b Binary files /dev/null and b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/__init__.cpython-37.pyc differ diff --git a/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/axpy.cpython-37.pyc b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/axpy.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..00a121066c6929a73cfa5e8b91353bde557b4928 Binary files /dev/null and b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/axpy.cpython-37.pyc differ diff --git a/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/convolutiondepthwise.cpython-37.pyc b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/convolutiondepthwise.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e09c7cfeeb9a9a123cf03767cf7901bb3c334a5a Binary files /dev/null and b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/convolutiondepthwise.cpython-37.pyc differ diff --git a/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/detectionoutput.cpython-37.pyc b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/detectionoutput.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..bff1983094338287c16df4abca000aa3c7dee360 Binary files /dev/null and b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/detectionoutput.cpython-37.pyc differ diff --git a/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/normalize.cpython-37.pyc b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/normalize.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ef0becbd3673c06577ce5338c219bee0bd37e7f4 Binary files /dev/null and b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/normalize.cpython-37.pyc differ diff --git a/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/permute.cpython-37.pyc b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/permute.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7ab28747db6c612d35494f3dd975bb5d70e0c5d1 Binary files /dev/null and b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/permute.cpython-37.pyc differ diff --git a/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/priorbox.cpython-37.pyc b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/priorbox.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b2627c9bd69fc8f1410851d60c91c67c91973865 Binary files /dev/null and b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/priorbox.cpython-37.pyc differ diff --git a/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/register.cpython-37.pyc b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/register.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8892acdb49ea964d607e83a2804888c2370f84a3 Binary files /dev/null and b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/register.cpython-37.pyc differ diff --git a/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/relu6.cpython-37.pyc b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/relu6.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..46a9abef065b6d89f2efdf58e2cc8b9f6d696fe0 Binary files /dev/null and b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/relu6.cpython-37.pyc differ diff --git a/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/roipooling.cpython-37.pyc b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/roipooling.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..80196bf35923937c105dfa0cf350d21ade97a865 Binary files /dev/null and b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/roipooling.cpython-37.pyc differ diff --git a/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/select.cpython-37.pyc b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/select.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..6670c51401370836f0c797657453ff23b3938981 Binary files /dev/null and b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/select.cpython-37.pyc differ diff --git a/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/shufflechannel.cpython-37.pyc b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/shufflechannel.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e367425fd46a713e62b876f3a3ba3d182c995afc Binary files /dev/null and b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/shufflechannel.cpython-37.pyc differ diff --git a/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/upsample.cpython-37.pyc b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/upsample.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..65e69365fa436bb2cbe0af95d57a7aeaf8e6ebb2 Binary files /dev/null and b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/__pycache__/upsample.cpython-37.pyc differ diff --git a/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/axpy.py b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/axpy.py index 9760b4633f1553601bb4bac5bff05d237400aecd..6e0f843398afc877e22b24a454f45c96e5369ceb 100644 --- a/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/axpy.py +++ b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/axpy.py @@ -16,8 +16,8 @@ def axpy_layer(inputs, input_shape=None, name=None): alpha = inputs[0] x = inputs[1] y = inputs[2] - out = paddle.multiply(x, alpha, axis=0) - out = paddle.add(out, y, name=name) + out = fluid.layers.elementwise_mul(x, alpha, axis=0) + out = fluid.layers.elementwise_add(out, y, name=name) return out diff --git a/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/convolutiondepthwise.py b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/convolutiondepthwise.py index 908883425ab73a4b38f84ab34e7216ab5378e2ce..670d5436af6af54bdc74dd1a79e4ef4e30f42205 100644 --- a/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/convolutiondepthwise.py +++ b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/convolutiondepthwise.py @@ -15,6 +15,15 @@ def convolutiondepthwise_shape(input_shape, kernel_w=None, stride_h=None, stride_w=None): + [k_h, k_w] = [1, 1] + if isinstance(kernel_size, numbers.Number): + [k_h, k_w] = [kernel_size] * 2 + elif len(kernel_size) > 0: + k_h = kernel_h if kernel_h > 0 else kernel_size[0] + k_w = kernel_w if kernel_w > 0 else kernel_size[len(kernel_size) - 1] + elif kernel_h > 0 or kernel_w > 0: + k_h = kernel_h + k_w = kernel_w [s_h, s_w] = [1, 1] if isinstance(stride, numbers.Number): [s_h, s_w] = [stride] * 2 @@ -70,6 +79,15 @@ def convolutiondepthwise_layer(inputs, input_shape=None, name=None): import numbers + [k_h, k_w] = [1, 1] + if isinstance(kernel_size, numbers.Number): + [k_h, k_w] = [kernel_size] * 2 + elif len(kernel_size) > 0: + k_h = kernel_h if kernel_h > 0 else kernel_size[0] + k_w = kernel_w if kernel_w > 0 else kernel_size[len(kernel_size) - 1] + elif kernel_h > 0 or kernel_w > 0: + k_h = kernel_h + k_w = kernel_w [s_h, s_w] = [1, 1] if isinstance(stride, numbers.Number): [s_h, s_w] = [stride] * 2 @@ -104,14 +122,16 @@ def convolutiondepthwise_layer(inputs, c_out = num_output if num_output is not None else input_shape[0][1] group = int(c_in / (c_in / c_out)) if c_in > c_out else int(c_in / (c_out / c_in)) - out = paddle.nn.functional.conv2d( + out = fluid.layers.conv2d( input, dilation=[dila_h, dila_w], + filter_size=[k_h, k_w], stride=[s_h, s_w], padding=[p_h, p_w], groups=group, - weight=name + '_weights', - bias=name + '_bias', + num_filters=c_out, + param_attr=name + '_weights', + bias_attr=name + '_bias', name=name) return out diff --git a/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/detectionoutput.py b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/detectionoutput.py index 7e29c31ec0416ff233ab639f19c7cec7d183e183..6f70e42b3589af4c3fae3cae6045dd7e112ed53e 100644 --- a/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/detectionoutput.py +++ b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/detectionoutput.py @@ -18,14 +18,14 @@ def detectionoutput_layer(inputs, nms_param = {"nms_threshold": 0.3, "top_k": 10, "eta": 1.0} mbox_conf_flatten = inputs[1] mbox_priorbox = inputs[2] - mbox_priorbox_list = paddle.split(mbox_priorbox, 2, dim=1) + mbox_priorbox_list = fluid.layers.split(mbox_priorbox, 2, dim=1) pb = mbox_priorbox_list[0] pbv = mbox_priorbox_list[1] - pb = paddle.reshape(x=pb, shape=[-1, 4]) - pbv = paddle.reshape(x=pbv, shape=[-1, 4]) + pb = fluid.layers.reshape(x=pb, shape=[-1, 4]) + pbv = fluid.layers.reshape(x=pbv, shape=[-1, 4]) mbox_loc = inputs[0] - mbox_loc = paddle.reshape(x=mbox_loc, shape=[-1, pb.shape[0], 4]) - mbox_conf_flatten = paddle.reshape( + mbox_loc = fluid.layers.reshape(x=mbox_loc, shape=[-1, pb.shape[0], 4]) + mbox_conf_flatten = fluid.layers.reshape( x=mbox_conf_flatten, shape=[0, pb.shape[0], -1]) default = {"nms_threshold": 0.3, "top_k": 10, "eta": 1.0} diff --git a/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/normalize.py b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/normalize.py index 806d59a2bfe30fb1ac07d176a15f1ea0589cc01f..19c583acc7ab73cd63d0bc7f373488e9437aec4c 100644 --- a/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/normalize.py +++ b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/normalize.py @@ -13,14 +13,14 @@ def normalize_layer(inputs, name=None): assert across_spatial == False, "Only support across_spatial == False for Normalize" input = inputs[0] - l2_norm = paddle.nn.functional.normalize(input, axis=1, p=2, name=name + '_l2') - scale_param = paddle.static.create_parameter( + l2_norm = fluid.layers.l2_normalize(input, axis=1, name=name + '_l2') + scale_param = fluid.layers.create_parameter( shape=[1] if channel_shared else [1, 1, 1, input_shape[0][1]], dtype=input.dtype, - attr=paddle.ParamAttr(name=name + '_scale')) - scale_param = paddle.reshape(x=scale_param, \ + attr=fluid.ParamAttr(name=name + '_scale')) + scale_param = fluid.layers.reshape(x=scale_param, \ shape=[1] if channel_shared else [input_shape[0][1]]) - out = paddle.multiply( + out = fluid.layers.elementwise_mul( x=l2_norm, y=scale_param, axis=-1 if channel_shared else 1) return out diff --git a/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/permute.py b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/permute.py index 2e6befd564aa1ffa3b951a4cdb3dcbcd24a3a568..617af1ff7fbc68bda84556deb6a86d96a01a0cf4 100644 --- a/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/permute.py +++ b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/permute.py @@ -14,7 +14,7 @@ def permute_shape(input_shape, order=None): def permute_layer(inputs, order=None, input_shape=None, name=None): input = inputs[0] order = list(order) - out = paddle.transpose(input, perm=order, name=name) + out = fluid.layers.transpose(input, perm=order, name=name) return out diff --git a/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/relu6.py b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/relu6.py index e757aa1a343219c0cbf7771c1f6f0f07cc676e20..4e94fcf1a77d730ba8552e30c1c494e966038043 100644 --- a/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/relu6.py +++ b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/relu6.py @@ -8,7 +8,7 @@ def relu6_shape(input_shape): def relu6_layer(inputs, input_shape=None, name=None): input = inputs[0] - out = paddle.nn.functional.relu6(x=input) + out = fluid.layers.relu6(x=input) return out diff --git a/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/roipooling.py b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/roipooling.py index 09a2e7282a782739c38b33d386fc1d4d94586767..5e0d459f1302bb94e99cc922379e739ce087a18e 100644 --- a/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/roipooling.py +++ b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/roipooling.py @@ -20,7 +20,7 @@ def roipooling_layer(inputs, name=None): input = inputs[0] roi = inputs[1] - roi = paddle.slice(roi, axes=[1], starts=[1], ends=[5]) + roi = fluid.layers.slice(roi, axes=[1], starts=[1], ends=[5]) out = fluid.layers.roi_pool( input, roi, diff --git a/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/select.py b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/select.py index c1c9badf2ebd2245a6329ebbbf61730d8c8e044d..497a3c24212b66d6686ff0bc8b2977195c165e28 100644 --- a/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/select.py +++ b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/select.py @@ -30,7 +30,7 @@ def select_layer(inputs, out = [] for i in range(len(slice_point)): out.append( - paddle.slice( + fluid.layers.slice( input, axes=[axis], starts=[slice_point[i]], diff --git a/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/upsample.py b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/upsample.py index a32452a040c20455d6269d0f5eabb288f5f150f0..44ce7f516bc9049bd10ea41183e676dae5692ef3 100644 --- a/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/upsample.py +++ b/x2paddle/op_mapper/static/caffe2paddle/caffe_custom_layer/upsample.py @@ -42,8 +42,8 @@ def upsample_layer(inputs, scale, input_shape=None, name=None): :return: """ x = inputs[0] - out = paddle.nn.functioanl.interpolate( - x, align_corners=False, scale_factor=scale, name=name) + out = fluid.layers.resize_nearest( + x, align_corners=False, scale=scale, name=name) return out diff --git a/x2paddle/op_mapper/static/caffe2paddle/caffe_op_mapper.py b/x2paddle/op_mapper/static/caffe2paddle/caffe_op_mapper.py index 7efea61e9d3d5b82ecb3091ba54844e677cd2a46..2fa7f441f6666fd3718f5dec811930b8495f1fd5 100644 --- a/x2paddle/op_mapper/static/caffe2paddle/caffe_op_mapper.py +++ b/x2paddle/op_mapper/static/caffe2paddle/caffe_op_mapper.py @@ -26,7 +26,7 @@ from x2paddle.core.program import PaddleGraph class CaffeOpMapper(OpMapper): directly_map_ops = { 'AbsVal': 'paddle.abs', - 'Sigmoid': 'paddle.nn.functional.sigmoid', + 'Sigmoid': 'fluid.layers.sigmoid', 'TanH': 'paddle.tanh', } @@ -51,7 +51,7 @@ class CaffeOpMapper(OpMapper): func = getattr(self, op) func(node) elif op in custom_layers: - self.set_node_shape(node, is_custom_op=True) + self.set_node_shape(node, is_fluid_op=False) self.deal_custom_layer(node) elif op in self.directly_map_ops: self.set_node_shape(node) @@ -79,7 +79,7 @@ class CaffeOpMapper(OpMapper): print(op) return False - def set_node_shape(self, node, is_custom_op=False): + def set_node_shape(self, node, is_fluid_op=True): inputs = node.inputs input_shape = [] for i, nm in enumerate(inputs): @@ -91,11 +91,11 @@ class CaffeOpMapper(OpMapper): node.input_shape = input_shape func_name = 'shape_' + node.layer_type.lower() - if is_custom_op: - node.output_shape = compute_output_shape(node) - else: + if is_fluid_op: node.output_shape = getattr(caffe_shape, func_name)(node.layer, input_shape) + else: + node.output_shape = compute_output_shape(node) def adjust_parameters(self, node): data = node.data @@ -203,7 +203,7 @@ class CaffeOpMapper(OpMapper): "name": string(node.layer_name) } self.pd_graph.add_layer( - kernel="paddle.static.data", + kernel="fluid.data", inputs={}, outputs=[node.layer_name], **layer_attrs) @@ -226,50 +226,27 @@ class CaffeOpMapper(OpMapper): data.append(np.zeros([output_c, ]).astype('float32')) else: data = self.adjust_parameters(node) - self.weights[node.layer_name + '_weight_attr'] = data[0] + self.weights[node.layer_name + '_weights'] = data[0] if len(data) == 2: - self.weights[node.layer_name + '_bias_attr'] = data[1] + self.weights[node.layer_name + '_bias'] = data[1] assert len(node.inputs ) == 1, 'The count of Convolution node\'s input is not 1.' input = self.graph.get_bottom_node(node, idx=0, copy=True) layer_attrs = { - "dtype": string("float32"), - "shape": data[0].shape, - "name": string("{}_weight".format(node.layer_name)) - } - self.pd_graph.add_layer( - kernel="paddle.static.data", - inputs={}, - outputs=["{}_weight".format(node.layer_name)], - **layer_attrs) - self.pd_graph.add_layer( - kernel="paddle.ParamAttr", - inputs={}, - outputs=["{}_weight_attr".format(node.layer_name)], - name = string("{}_weight_attr".format(node.layer_name))) - - layer_attrs = { + 'filter_size': kernel, + 'num_filters': channel, 'stride': stride, 'padding': pad, 'dilation': dilation, 'groups': group, 'name': string(node.layer_name), + 'param_attr': string(node.layer_name + '_weights'), + 'bias_attr': False + if len(data) == 1 else string(node.layer_name + '_bias'), } - inputs_dict = {"x": self.get_input_name(input), - "weight": "{}_weight".format(node.layer_name), - "weight_attr": "{}_weight_attr".format(node.layer_name)} - if len(data) == 1: - layer_attrs["bias_attr"] = False - else: - self.pd_graph.add_layer( - kernel="paddle.ParamAttr", - inputs={}, - outputs=["{}_bias_attr".format(node.layer_name)], - name = string("{}_bias_attr".format(node.layer_name))) - inputs_dict["bias_attr"] = "{}_bias_attr".format(node.layer_name) self.pd_graph.add_layer( - kernel="paddle.nn.functional.conv2d", - inputs=inputs_dict, + kernel="fluid.layers.conv2d", + inputs={"input": self.get_input_name(input)}, outputs=[node.layer_name], **layer_attrs) @@ -299,18 +276,20 @@ class CaffeOpMapper(OpMapper): input = self.graph.get_bottom_node(node, idx=0, copy=True) layer_attrs = { 'output_size': None, + 'filter_size': kernel, + 'num_filters': channel, 'stride': stride, 'padding': pad, 'dilation': dilation, 'groups': group, 'name': string(node.layer_name), - 'weight': string(node.layer_name + '_weights'), - 'bias': False + 'param_attr': string(node.layer_name + '_weights'), + 'bias_attr': False if len(data) == 1 else string(node.layer_name + '_bias') } self.pd_graph.add_layer( - kernel="paddle.nn.functional.conv_transpose2d", - inputs={"x": self.get_input_name(input)}, + kernel="fluid.layers.conv2d_transpose", + inputs={"input": self.get_input_name(input)}, outputs=[node.layer_name], **layer_attrs) @@ -318,31 +297,31 @@ class CaffeOpMapper(OpMapper): params = node.layer.pooling_param ceil_mode = getattr(params, 'ceil_mode', True) global_pool = getattr(params, 'global_pooling', False) - assert not global_pool, "The global_pool must be False!" kernel_default = [1, 1] channel, kernel, stride, pad, dilation, group = self.get_kernel_parameters( node.layer_type, params) + if params.pool == 0: + pool_type = 'max' + else: + pool_type = 'avg' assert len( node.inputs) == 1, 'The count of Pooling node\'s input is not 1.' input = self.graph.get_bottom_node(node, idx=0, copy=True) layer_attrs = { - 'kernel_size': kernel, - 'stride': stride, - 'padding': pad, + 'pool_size': kernel, + 'pool_stride': stride, + 'pool_padding': pad, 'ceil_mode': ceil_mode, + 'pool_type': string(pool_type), + 'exclusive': False, + 'global_pooling': global_pool, + 'name': string(node.layer_name) } - if params.pool == 0: - self.pd_graph.add_layer( - kernel="paddle.nn.functional.max_pool2d", - inputs={"x": self.get_input_name(input)}, - outputs=[node.layer_name], - **layer_attrs) - else: - self.pd_graph.add_layer( - kernel="paddle.nn.functional.avg_pool2d", - inputs={"x": self.get_input_name(input)}, - outputs=[node.layer_name], - **layer_attrs) + self.pd_graph.add_layer( + kernel="fluid.layers.pool2d", + inputs={"input": self.get_input_name(input)}, + outputs=[node.layer_name], + **layer_attrs) def LRN(self, node): assert len(node.inputs) == 1, 'The count of LRN node\'s input is not 1.' @@ -412,7 +391,7 @@ class CaffeOpMapper(OpMapper): if len(data) == 1 else string(node.layer_name + '_bias') } self.pd_graph.add_layer( - kernel="paddle.static.nn.fc", + kernel="fluid.layers.fc", inputs={"input": self.get_input_name(input)}, outputs=[node.layer_name], **layer_attrs) @@ -453,7 +432,7 @@ class CaffeOpMapper(OpMapper): 'name': string(node.layer_name) } self.pd_graph.add_layer( - kernel="paddle.split", + kernel="fluid.layers.split", inputs={"input": self.get_input_name(input)}, outputs=[node.layer_name], **layer_attrs) @@ -489,13 +468,13 @@ class CaffeOpMapper(OpMapper): if params.HasField('negative_slope') and params.negative_slope != 0: negative_slope = float(params.negative_slope) self.pd_graph.add_layer( - kernel="paddle.nn.functional.leaky_relu", + kernel="fluid.layers.leaky_relu", inputs={"x": self.get_input_name(input)}, outputs=[node.layer_name], - negative_slope=negative_slope) + alpha=negative_slope) else: self.pd_graph.add_layer( - kernel="paddle.nn.functional.relu", + kernel="fluid.layers.relu", inputs={"x": self.get_input_name(input)}, outputs=[node.layer_name]) @@ -519,7 +498,7 @@ class CaffeOpMapper(OpMapper): 'name': string(node.layer_name) } self.pd_graph.add_layer( - kernel="paddle.nn.functional.prelu", + kernel="fluid.layers.prelu", inputs={"x": self.get_input_name(input)}, outputs=[node.layer_name], **layer_attrs) @@ -542,7 +521,7 @@ class CaffeOpMapper(OpMapper): assert axis == 1, 'PaddlePaddle can not support the situation when the axis is not 1.' assert not ignore_label >= 0, 'PaddlePaddle can not support the situation when the model has ignore label.' self.pd_graph.add_layer( - kernel="paddle.metric.accuracy", + kernel="fluid.layers.accuracy", inputs=inputs_dict, outputs=[node.layer_name], k=top_k) @@ -562,7 +541,7 @@ class CaffeOpMapper(OpMapper): inputs_dict['x'] = self.get_input_name(inputs[0]) inputs_dict['y'] = self.get_input_name(inputs[1]) self.pd_graph.add_layer( - kernel="paddle.multiply", + kernel="fluid.layers.elementwise_mul", inputs=inputs_dict, outputs=[node.layer_name]) elif mode == 1: @@ -571,37 +550,37 @@ class CaffeOpMapper(OpMapper): input1_name = self.get_input_name(inputs[0]) layer_attrs = { 'shape': [1], - 'fill_value': coeff[0], + 'value': coeff[0], 'dtype': '{}.dtype'.format(input1_name) } self.pd_graph.add_layer( - kernel="paddle.full", + kernel="fluid.layers.fill_constant", inputs={}, outputs=["{}_const1".format(node.layer_name)], **layer_attrs) self.pd_graph.add_layer( - kernel="paddle.multiply", + kernel="fluid.layers.elementwise_mul", inputs={"x": input1_name, "y": "{}_const1".format(node.layer_name)}, outputs=["{}_mul1".format(node.layer_name)]) input2_name = self.get_input_name(inputs[1]) layer_attrs = { 'shape': [1], - 'fill_value': coeff[1], + 'value': coeff[1], 'dtype': '{}.dtype'.format(input2_name) } self.pd_graph.add_layer( - kernel="paddle.full", + kernel="fluid.layers.fill_constant", inputs={}, outputs=["{}_const2".format(node.layer_name)], **layer_attrs) self.pd_graph.add_layer( - kernel="paddle.multiply", + kernel="fluid.layers.elementwise_mul", inputs={"x": input2_name, "y": "{}_const2".format(node.layer_name)}, outputs=["{}_mul2".format(node.layer_name)]) self.pd_graph.add_layer( - kernel="paddle.add", + kernel="fluid.layers.elementwise_add", inputs={"x": "{}_mul1".format(node.layer_name), "y": "{}_mul2".format(node.layer_name)}, outputs=[node.layer_name]) @@ -610,7 +589,7 @@ class CaffeOpMapper(OpMapper): inputs_dict['x'] = self.get_input_name(inputs[0]) inputs_dict['y'] = self.get_input_name(inputs[1]) self.pd_graph.add_layer( - kernel="paddle.add", + kernel="fluid.layers.elementwise_add", inputs=inputs_dict, outputs=[node.layer_name]) else: @@ -618,7 +597,7 @@ class CaffeOpMapper(OpMapper): inputs_dict['x'] = self.get_input_name(inputs[0]) inputs_dict['y'] = self.get_input_name(inputs[1]) self.pd_graph.add_layer( - kernel="paddle.add", + kernel="fluid.layers.elementwise_max", inputs=inputs_dict, outputs=[node.layer_name]) @@ -659,7 +638,7 @@ class CaffeOpMapper(OpMapper): 'name': string(node.layer_name) } self.pd_graph.add_layer( - kernel="paddle.nn.functional.batch_norm", + kernel="fluid.layers.batch_norm", inputs={"input": self.get_input_name(input)}, outputs=[node.layer_name], **layer_attrs) @@ -695,7 +674,7 @@ class CaffeOpMapper(OpMapper): inputs_dict['x'] = self.get_input_name(input0) inputs_dict['y'] = self.get_input_name(input1) self.pd_graph.add_layer( - kernel="paddle.multiply", + kernel="fluid.layers.elementwise_mul", inputs=inputs_dict, outputs=["{}_mul".format(node.layer_name)], axis=axis) @@ -704,7 +683,7 @@ class CaffeOpMapper(OpMapper): input0 = self.graph.get_bottom_node(node, idx=0, copy=True) input0_name = self.get_input_name(input0) self.pd_graph.add_layer( - kernel="paddle.ParamAttr", + kernel="fluid.ParamAttr", inputs={}, outputs=["{}_scale".format(node.layer_name)], name = string("{}_scale".format(node.layer_name))) @@ -716,7 +695,7 @@ class CaffeOpMapper(OpMapper): 'default_initializer': 'Constant(value=1.0)' } self.pd_graph.add_layer( - kernel="paddle.static.create_parameter", + kernel="fluid.layers.create_parameter", inputs={"attr": node.layer_name + '_scale',}, outputs=["{}_cparam1".format(node.layer_name)], **layer_attrs) @@ -724,14 +703,14 @@ class CaffeOpMapper(OpMapper): inputs_dict['x'] = self.get_input_name(input0) inputs_dict['y'] = "{}_cparam1".format(node.layer_name) self.pd_graph.add_layer( - kernel="paddle.multiply", + kernel="fluid.layers.elementwise_mul", inputs=inputs_dict, outputs=["{}_mul".format(node.layer_name)], axis=axis) scale_shape = bias_shape input0_name = self.get_input_name(input0) self.pd_graph.add_layer( - kernel="paddle.ParamAttr", + kernel="fluid.ParamAttr", inputs={}, outputs=["{}_offset".format(node.layer_name)], name = string("{}_offset".format(node.layer_name))) @@ -743,7 +722,7 @@ class CaffeOpMapper(OpMapper): 'default_initializer': 'Constant(value=1.0)' } self.pd_graph.add_layer( - kernel="paddle.static.create_parameter", + kernel="fluid.layers.create_parameter", inputs={"attr": node.layer_name + '_offset'}, outputs=["{}_cparam2".format(node.layer_name)], **layer_attrs) @@ -751,7 +730,7 @@ class CaffeOpMapper(OpMapper): inputs_dict['x'] = "{}_mul".format(node.layer_name) inputs_dict['y'] = "{}_cparam2".format(node.layer_name) self.pd_graph.add_layer( - kernel="paddle.add", + kernel="fluid.layers.elementwise_add", inputs=inputs_dict, outputs=[node.layer_name], axis=axis) @@ -769,7 +748,7 @@ class CaffeOpMapper(OpMapper): 'name': string(node.layer_name) } self.pd_graph.add_layer( - kernel="paddle.reshape", + kernel="fluid.layers.reshape", inputs={"x": self.get_input_name(input)}, outputs=[node.layer_name], **layer_attrs) @@ -789,7 +768,7 @@ class CaffeOpMapper(OpMapper): axis += len(input_shape) if out_max_val is True: self.pd_graph.add_layer( - kernel="paddle.topk", + kernel="fluid.layers.topk", inputs={"input": self.get_input_name(input)}, outputs=["{}_topk_var".format(node.layer_name), "{}_index_var".format(node.layer_name)], @@ -807,7 +786,7 @@ class CaffeOpMapper(OpMapper): axis=axis) else: self.pd_graph.add_layer( - kernel="paddle.topk", + kernel="fluid.layers.topk", inputs={"input": self.get_input_name(input)}, outputs=["_", node.layer_name], k=top_k) @@ -832,7 +811,7 @@ class CaffeOpMapper(OpMapper): layer_attrs = {"offsets": list(offset_real), "shape": node.input_shape[1]} self.pd_graph.add_layer( - kernel="paddle.crop", + kernel="fluid.layers.crop_tensor", inputs={"x": self.get_input_name(input)}, outputs=[node.layer_name], **layer_attrs) @@ -843,7 +822,7 @@ class CaffeOpMapper(OpMapper): inputs) == 1, 'The count of DetectionOutput node\'s input is not 1.' input = self.graph.get_bottom_node(node, idx=0, copy=True) self.pd_graph.add_layer( - kernel="paddle.reshape", + kernel="fluid.layers.reshape", inputs={"x": self.get_input_name(input)}, outputs=[node.layer_name], shape = node.output_shape[0]) @@ -894,7 +873,7 @@ class CaffeOpMapper(OpMapper): 'name': string(node.layer_name) } self.pd_graph.add_layer( - kernel="paddle.sum", + kernel="fluid.layers.reduce_sum", inputs={"input": self.get_input_name(input)}, outputs=[node.layer_name], **layer_attrs) @@ -909,7 +888,7 @@ class CaffeOpMapper(OpMapper): 'name': string(node.layer_name) } self.pd_graph.add_layer( - kernel="paddle.sum", + kernel="fluid.layers.reduce_sum", inputs={"input": node.layer_name}, outputs=[node.layer_name], **layer_attrs) @@ -925,7 +904,7 @@ class CaffeOpMapper(OpMapper): 'name': string(node.layer_name) } self.pd_graph.add_layer( - kernel="paddle.sum", + kernel="fluid.layers.reduce_sum", inputs={"input": node.layer_name}, outputs=[node.layer_name], **layer_attrs) @@ -936,7 +915,7 @@ class CaffeOpMapper(OpMapper): 'name': string(node.layer_name) } self.pd_graph.add_layer( - kernel="paddle.mean", + kernel="fluid.layers.reduce_mean", inputs={"input": node.layer_name}, outputs=[node.layer_name], **layer_attrs)