未验证 提交 32eaafe0 编写于 作者: S SunAhong1993 提交者: GitHub

Update models inputs (#630)

* Update stargan.md

* fix the paddle_type

* add docs

* add docs

* add acknowledge

* fix the docs

* fix the docs

* add docs

* fix

* add docs

* add docs

* Update README.md

* fix onnx inputs

* fix

* fix

* remove

* remove numpy input
上级 f9da3dcb
...@@ -220,6 +220,7 @@ class PaddleGraph(object): ...@@ -220,6 +220,7 @@ class PaddleGraph(object):
self.layers.pop(layer_id) self.layers.pop(layer_id)
self.get_inputs() self.get_inputs()
if len(self.outputs) == 0: if len(self.outputs) == 0:
self.get_outputs() self.get_outputs()
...@@ -293,8 +294,13 @@ class PaddleGraph(object): ...@@ -293,8 +294,13 @@ class PaddleGraph(object):
self.inputs.extend(block.inputs) self.inputs.extend(block.inputs)
update(self.layers) update(self.layers)
self.inputs = list(set(self.inputs)) new_inputs = list()
if self.inputs is not None: for input_name in self.inputs:
if input_name in new_inputs:
continue
new_inputs.append(input_name)
self.inputs = new_inputs
if self.source_type == "pytorch" and self.inputs is not None:
self.inputs.sort() self.inputs.sort()
def get_outputs(self): def get_outputs(self):
...@@ -313,6 +319,15 @@ class PaddleGraph(object): ...@@ -313,6 +319,15 @@ class PaddleGraph(object):
self.outputs.append(output_name) self.outputs.append(output_name)
def gen_code(self, code_dir=None, indent=2): def gen_code(self, code_dir=None, indent=2):
# 去除to_tensor的layer
invalid_list = list()
for layer_id, layer in self.layers.items():
if layer.kernel == "paddle.to_tensor":
if layer.attrs["data"] in self.inputs:
invalid_list.append(layer_id)
for layer_id in invalid_list:
self.layers.pop(layer_id)
def gen_codes(code_list, indent=0): def gen_codes(code_list, indent=0):
indent_blank = " " * indent indent_blank = " " * indent
codes = [] codes = []
......
...@@ -128,7 +128,6 @@ class CaffeOpMapper(): ...@@ -128,7 +128,6 @@ class CaffeOpMapper():
self.params = dict() self.params = dict()
self.paddle_graph = PaddleGraph(parent_layer=None, source_type="caffe") self.paddle_graph = PaddleGraph(parent_layer=None, source_type="caffe")
self.paddle_graph.outputs = self.graph.output_nodes self.paddle_graph.outputs = self.graph.output_nodes
self.input_index = 0
self.inputs_info = {} self.inputs_info = {}
self.nn_name2id = {} self.nn_name2id = {}
print("Total nodes: {}".format( print("Total nodes: {}".format(
...@@ -193,11 +192,10 @@ class CaffeOpMapper(): ...@@ -193,11 +192,10 @@ class CaffeOpMapper():
"paddle.to_tensor", "paddle.to_tensor",
inputs={}, inputs={},
outputs=[node.layer_name], outputs=[node.layer_name],
data="x{}".format(self.input_index)) data=node.name)
shape = list(node.layer.input_param.shape[0].dim)[1:] shape = list(node.layer.input_param.shape[0].dim)[1:]
self.inputs_info["x{}".format(self.input_index)] = [[-1] + shape, self.inputs_info[node.name] = [[-1] + shape,
"float32"] "float32"]
self.input_index += 1
def MemoryData(self, node): def MemoryData(self, node):
params = node.layer.memory_data_param params = node.layer.memory_data_param
...@@ -206,7 +204,7 @@ class CaffeOpMapper(): ...@@ -206,7 +204,7 @@ class CaffeOpMapper():
"paddle.to_tensor", "paddle.to_tensor",
inputs={}, inputs={},
outputs=[node.layer_name], outputs=[node.layer_name],
data="x{}".format(self.input_index)) data=node.layer_name)
shape = list() shape = list()
shape.append(params.batch_size) shape.append(params.batch_size)
shape.append(params.channels) shape.append(params.channels)
...@@ -216,8 +214,7 @@ class CaffeOpMapper(): ...@@ -216,8 +214,7 @@ class CaffeOpMapper():
else: else:
shape.append(params.width) shape.append(params.width)
shape.append(params.height) shape.append(params.height)
self.inputs_info["x{}".format(self.input_index)] = [shape, "float32"] self.inputs_info[node.layer_name] = [shape, "float32"]
self.input_index += 1
def Convolution(self, node): def Convolution(self, node):
conv2d_name = name_generator("conv", self.nn_name2id) conv2d_name = name_generator("conv", self.nn_name2id)
......
...@@ -180,7 +180,6 @@ class OpSet9(): ...@@ -180,7 +180,6 @@ class OpSet9():
super(OpSet9, self).__init__() super(OpSet9, self).__init__()
self.graph = decoder.graph self.graph = decoder.graph
self.paddle_graph = paddle_graph self.paddle_graph = paddle_graph
self.input_index = 0
self.inputs_info = dict() self.inputs_info = dict()
self.weights = dict() self.weights = dict()
self.nn_name2id = dict() self.nn_name2id = dict()
...@@ -245,9 +244,8 @@ class OpSet9(): ...@@ -245,9 +244,8 @@ class OpSet9():
kernel="paddle.to_tensor", kernel="paddle.to_tensor",
inputs={}, inputs={},
outputs=[node.name], outputs=[node.name],
data="x{}".format(self.input_index)) data=node.name)
self.inputs_info["x{}".format(self.input_index)] = [shape, node.dtype] self.inputs_info[node.name] = [shape, node.dtype]
self.input_index += 1
@print_mapping_info @print_mapping_info
def create_parameter(self, node, parameter=None): def create_parameter(self, node, parameter=None):
......
...@@ -91,7 +91,6 @@ class TFOpMapper(): ...@@ -91,7 +91,6 @@ class TFOpMapper():
raise Exception("Model is not supported yet.") raise Exception("Model is not supported yet.")
self.params = dict() self.params = dict()
self.nn_name2id = dict() self.nn_name2id = dict()
self.input_index = 0
self.inputs_info = dict() self.inputs_info = dict()
self.paddle_graph = PaddleGraph(parent_layer=None, source_type="tf") self.paddle_graph = PaddleGraph(parent_layer=None, source_type="tf")
self.paddle_graph.outputs = self.graph.output_nodes self.paddle_graph.outputs = self.graph.output_nodes
...@@ -213,9 +212,8 @@ class TFOpMapper(): ...@@ -213,9 +212,8 @@ class TFOpMapper():
kernel="paddle.to_tensor", kernel="paddle.to_tensor",
inputs={}, inputs={},
outputs=[node.name], outputs=[node.name],
data="x{}".format(self.input_index)) data=node.name)
self.inputs_info["x{}".format(self.input_index)] = [shape, node.dtype] self.inputs_info[node.name] = [shape, node.dtype]
self.input_index += 1
def Const(self, node): def Const(self, node):
shape = node.out_shapes[0] shape = node.out_shapes[0]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册