diff --git a/x2paddle/core/program.py b/x2paddle/core/program.py index 31e0e44b5c169b27933dc8e6bceac67c191a0771..ebf0e81094cb4c6db5f8f7997aed4cba7b4a2d28 100644 --- a/x2paddle/core/program.py +++ b/x2paddle/core/program.py @@ -210,9 +210,12 @@ class PaddleGraph(object): if self.edges_in.get(layer_id, 0) == 0 and self.edges_out.get( layer_id, 0) == 0 and layer.kernel != "prim.assert" \ and layer.kernel != "prim.exception" \ - and layer.kernel != "prim.warnings" and layer.outputs[0] not in self.outputs: + and layer.kernel != "prim.warnings" \ + and layer.outputs[0] not in self.outputs: if layer.kernel == "paddle.to_tensor" and layer.outputs[0] in self.inputs_info: self.inputs_info.pop(layer.outputs[0]) + if layer.outputs[0] in self.inputs: + self.inputs.pop(self.inputs.index(layer.outputs[0])) invalid_list.append(layer_id) for layer_id in invalid_list: self.layers.pop(layer_id) @@ -355,6 +358,8 @@ class PaddleGraph(object): edges_in = self.edges_in.get(layer_id, []) edges_out = self.edges_out.get(layer_id, []) if len(edges_in) == 0 and len(edges_out) == 0 and layer.outputs[0] not in self.outputs: + if layer.outputs[0] in self.inputs: + self.inputs.pop(self.inputs.index(layer.outputs[0])) continue line = "" diff --git a/x2paddle/decoder/onnx_decoder.py b/x2paddle/decoder/onnx_decoder.py index a82c70e908048145fd54d937cdb2a6e69c0321bb..49c74200deb923ee7e007d6474ef46c43c9e5d09 100644 --- a/x2paddle/decoder/onnx_decoder.py +++ b/x2paddle/decoder/onnx_decoder.py @@ -31,6 +31,7 @@ import numpy as np from copy import deepcopy import logging as _logging import os +import copy default_op_domain = 'ai.onnx' _logger = _logging.getLogger(__name__) @@ -125,6 +126,17 @@ class ONNXGraphDataNode(GraphNode): shape.append(dim.dim_value) out_shapes.append(shape) return out_shapes + elif isinstance(self.layer, TensorProto): + values = self.layer.dims + out_shapes = list() + shape = list() + for dim in values: + if dim == 0: + shape.append(-1) + else: + shape.append(dim) + out_shapes.append(shape) + return out_shapes else: values = self.layer.dims out_shapes = list() @@ -227,8 +239,6 @@ class ONNXGraph(Graph): inner_nodes = self.get_inner_nodes() for ipt_vi in self.graph.input: if ipt_vi.name not in inner_nodes: - if len(ipt_vi.type.tensor_type.shape.dim) == 0: - continue self.check_input_shape(ipt_vi) self.place_holder_nodes.append(ipt_vi.name) @@ -289,7 +299,7 @@ class ONNXGraph(Graph): #generate topo super(ONNXGraph, self).build() - self.input_nodes = self.place_holder_nodes + self.input_nodes = copy.deepcopy(self.place_holder_nodes) def build_connection(self, layer_name, node): """ diff --git a/x2paddle/op_mapper/dygraph/onnx2paddle/opset9/opset.py b/x2paddle/op_mapper/dygraph/onnx2paddle/opset9/opset.py index 3858f789707a633870613d35972ce5d23643f1cb..e47aadb8fe8bed5b6988c0ba18efcaee9183c1b0 100644 --- a/x2paddle/op_mapper/dygraph/onnx2paddle/opset9/opset.py +++ b/x2paddle/op_mapper/dygraph/onnx2paddle/opset9/opset.py @@ -299,6 +299,9 @@ class OpSet9(): attrs.update({"align_corners": False, "mode": string(mode), "align_mode": 1}) + val_x_shape = val_x.out_shapes[0] + if mode == "linear" and len(val_x_shape) == 4: + attrs["mode"] = string("bilinear") self.paddle_graph.add_layer( kernel="paddle.nn.functional.interpolate", inputs=inputs, @@ -1386,9 +1389,7 @@ class OpSet9(): outputs=[output_name]) else: if mode == 'channel' and len(shape_slope) == 1: - # paddle params shape need be [1, channel] slope_data = _const_weight_or_none(val_slope) - slope_data = np.reshape(slope_data, [1] + shape_slope) self.weights[val_slope.name] = slope_data num_parameters = val_x.out_shapes[0][1] else: diff --git a/x2paddle/op_mapper/static/onnx2paddle/opset9/opset.py b/x2paddle/op_mapper/static/onnx2paddle/opset9/opset.py index 8ea77bdb5707164a851d7635dabc06518b1b5063..889424d9eece33fd70af4abd1909744afd602c30 100644 --- a/x2paddle/op_mapper/static/onnx2paddle/opset9/opset.py +++ b/x2paddle/op_mapper/static/onnx2paddle/opset9/opset.py @@ -289,6 +289,9 @@ class OpSet9(): attrs.update({"align_corners": False, "mode": string(mode), "align_mode": 1}) + val_x_shape = val_x.out_shapes[0] + if mode == "linear" and len(val_x_shape) == 4: + attrs["mode"] = string("bilinear") self.paddle_graph.add_layer( kernel="paddle.nn.functional.interpolate", inputs=inputs, @@ -1323,9 +1326,6 @@ class OpSet9(): @print_mapping_info def PRelu(self, node): - op_name = name_generator("prelu", self.nn_name2id) - output_name = node.name - layer_outputs = [op_name, output_name] val_x = self.graph.get_input_node(node, idx=0, copy=True) val_slope = self.graph.get_input_node(node, idx=1, copy=True) @@ -1342,12 +1342,13 @@ class OpSet9(): outputs=[node.name], mode="element") else: - if mode == 'channel' and len(shape_slope) == 1: - # paddle params shape need be [1, channel] - slope_data = _const_weight_or_none(val_slope) - slope_data = np.reshape(slope_data, [1] + shape_slope) - self.params[val_slope.name] = slope_data - + if mode == 'channel': + if len(shape_slope) > 1: + self.paddle_graph.add_layer( + "paddle.reshape", + inputs={"x": val_slope.name}, + outputs=[val_slope.name], + shape=[shape_slope[0]]) self.paddle_graph.add_layer( "paddle.nn.functional.prelu", inputs={"x": val_x.name,