Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support YOLOv8 for dynamic shape #931

Merged
merged 12 commits into from Jan 17, 2023
9 changes: 8 additions & 1 deletion x2paddle/decoder/onnx_decoder.py
Expand Up @@ -308,7 +308,14 @@ def build_connection(self, layer_name, node):
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:
Expand Down
3 changes: 2 additions & 1 deletion x2paddle/op_mapper/onnx2paddle/opset13.py
Expand Up @@ -38,7 +38,8 @@ def Unsqueeze(self, node):
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},
Expand Down
12 changes: 10 additions & 2 deletions x2paddle/op_mapper/onnx2paddle/opset_legacy.py
Expand Up @@ -2309,8 +2309,16 @@ def Conv(self, node):
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
Expand Down