From 6db1dde26ba8ee60a973d7afacc9e88bc2ed4167 Mon Sep 17 00:00:00 2001 From: WJJ1995 Date: Tue, 17 Jan 2023 21:57:41 +0800 Subject: [PATCH] Support YOLOv8 for dynamic shape (#931) * fixed Gemm bug * re-lint * fixed typo error * support fmod=1 * fixed nonzero bug * add nonzero test case * Support yolov8 for onnx * re-lint --- x2paddle/decoder/onnx_decoder.py | 9 ++++++++- x2paddle/op_mapper/onnx2paddle/opset13.py | 3 ++- x2paddle/op_mapper/onnx2paddle/opset_legacy.py | 12 ++++++++++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/x2paddle/decoder/onnx_decoder.py b/x2paddle/decoder/onnx_decoder.py index a0a4bd1..f51be83 100755 --- a/x2paddle/decoder/onnx_decoder.py +++ b/x2paddle/decoder/onnx_decoder.py @@ -308,7 +308,14 @@ class ONNXGraph(Graph): break else: first_i = node.inputs.index(nd.name) - node.which_child[nd.name] = idx + # deal with Multiple outputs correspond to one node + if self.node_map[nd.name].outputs.count( + layer_name) > 1: + new_child_name = "{}/{}".format(nd.name, + idx) + node.which_child[new_child_name] = idx + else: + node.which_child[nd.name] = idx self.node_map[nd.name].index = 0 break if flag == 1: diff --git a/x2paddle/op_mapper/onnx2paddle/opset13.py b/x2paddle/op_mapper/onnx2paddle/opset13.py index 0a1f1a1..59407bf 100644 --- a/x2paddle/op_mapper/onnx2paddle/opset13.py +++ b/x2paddle/op_mapper/onnx2paddle/opset13.py @@ -38,7 +38,8 @@ class OpSet13(OpSet12): val_x = self.graph.get_input_node(node, idx=0, copy=True) axes = self.graph.get_input_node(node, idx=1, copy=True) # deal with scalar(0D) tensor - if len(val_x.out_shapes[0]) == 0 and len(axes.out_shapes[0]) == 1: + if len(val_x.out_shapes[0]) == 0 and len(axes.out_shapes[ + 0]) == 1 and len(node.out_shapes[0]) == 1: self.paddle_graph.add_layer( 'paddle.reshape', inputs={"x": val_x.name}, diff --git a/x2paddle/op_mapper/onnx2paddle/opset_legacy.py b/x2paddle/op_mapper/onnx2paddle/opset_legacy.py index cac210d..bdf532a 100644 --- a/x2paddle/op_mapper/onnx2paddle/opset_legacy.py +++ b/x2paddle/op_mapper/onnx2paddle/opset_legacy.py @@ -2309,8 +2309,16 @@ class OpSet(): rename_mapper=self.rename_mapper) else: layer_attrs["bias_attr"] = False - if reduce(lambda x, y: x * y, - input_shape) in [1, -1] and 1 not in input_shape: + # deal with dynamic shape + if len(input_shape) == 0: + self.paddle_graph.add_layer( + "paddle.reshape", + inputs=layer_inputs, + outputs=[layer_inputs["x"]], + shape=[0, num_in_channels * num_groups, 0, -1]) + if len(input_shape) != 0 and reduce( + lambda x, y: x * y, + input_shape) in [1, -1] and 1 not in input_shape: input_shape[1] = num_in_channels * num_groups input_shape[0] = 0 input_shape[2] = 0 -- GitLab