diff --git a/x2paddle/op_mapper/paddle2onnx/opset11/opset.py b/x2paddle/op_mapper/paddle2onnx/opset11/opset.py index 839fd4f48f86d14f3dd1e3a4e132a4b6263a6706..4ec88b5b7d8544f41f545e6758f0803f47b8ebac 100644 --- a/x2paddle/op_mapper/paddle2onnx/opset11/opset.py +++ b/x2paddle/op_mapper/paddle2onnx/opset11/opset.py @@ -41,6 +41,33 @@ class OpSet11(OpSet10): outputs=op.output('Out'), ) return [min_node, max_node, node] + def pad2d(self, op, block): + x_shape = block.var(op.input('X')[0]).shape + paddings = op.attr('paddings') + onnx_pads = [] + #TODO support pads is Variable + if op.attr('data_format') == 'NCHW': + pads = [ + 0, 0, paddings[0], paddings[2], 0, 0, paddings[1], paddings[3] + ] + else: + pads = [ + 0, paddings[0], paddings[2], 0, 0, paddings[1], paddings[3], 0 + ] + pads_name = self.get_name(op.type, 'pads') + pads_node = self.make_constant_node(pads_name, + onnx_pb.TensorProto.INT64, pads) + constant_value_name = self.get_name(op.type, 'constant_value') + constant_value_node = self.make_constant_node(constant_value_name, + onnx_pb.TensorProto.FLOAT, + op.attr('pad_value')) + node = helper.make_node( + 'Pad', + inputs=op.input('X') + [pads_name, constant_value_name], + outputs=op.output('Out'), + mode=op.attr('mode')) + return [pads_node, constant_value_node, node] + def bilinear_interp(self, op, block): input_names = op.input_names coordinate_transformation_mode = '' diff --git a/x2paddle/op_mapper/paddle2onnx/opset9/opset.py b/x2paddle/op_mapper/paddle2onnx/opset9/opset.py index 75988fae22d97f134ee826a7b5ce5ace93e08d0a..850e3d0430d8bcb05c209560765b29d61a022edf 100644 --- a/x2paddle/op_mapper/paddle2onnx/opset9/opset.py +++ b/x2paddle/op_mapper/paddle2onnx/opset9/opset.py @@ -215,6 +215,28 @@ class OpSet9(object): pads=op.attr('paddings') + op.attr('paddings')) return node + def pad2d(self, op, block): + x_shape = block.var(op.input('X')[0]).shape + paddings = op.attr('paddings') + onnx_pads = [] + if op.attr('data_format') == 'NCHW': + pads = [ + 0, 0, paddings[0], paddings[2], 0, 0, paddings[1], paddings[3] + ] + else: + pads = [ + 0, paddings[0], paddings[2], 0, 0, paddings[1], paddings[3], 0 + ] + #TODO support pads is Variable + node = helper.make_node( + 'Pad', + inputs=op.input('X'), + outputs=op.output('Out'), + mode=op.attr('mode'), + value=op.attr('pad_value'), + pads=pads) + return node + def softmax(self, op, block): axis = op.attr('axis') shape = block.var(op.output('Out')[0]).shape