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