提交 0c3d8fe5 编写于 作者: S SunAhong1993

add caffe memory data

上级 174c5436
......@@ -258,7 +258,7 @@ class CaffeGraph(Graph):
assert input_node_name in self.node_map, 'The {} isn\'t a valid node'.format(
name)
input_node = self.node_map[input_node_name]
if len(input_node.layer.top) > 1 and input_node.layer_type != "Input":
if len(input_node.layer.top) > 1 and input_node.layer_type not in ["Input", "MemoryData"]:
need_idx = list(input_node.layer.top).index(node.layer.bottom[idx])
name = input_node_name + ':' + str(need_idx)
else:
......
......@@ -199,6 +199,26 @@ class CaffeOpMapper(OpMapper):
self.inputs_info["x{}".format(self.input_index)] = [[-1] + shape, "float32"]
self.input_index += 1
def MemoryData(self, node):
params = node.layer.memory_data_param
transform_params = node.layer.transform_param
self.paddle_graph.add_layer(
"paddle.to_tensor",
inputs={},
outputs=[node.layer_name],
data="x{}".format(self.input_index))
shape = list()
shape.append(params.batch_size)
shape.append(params.channels)
if hasattr(transform_params, "crop_size"):
shape.append(transform_params.crop_size)
shape.append(transform_params.crop_size)
else:
shape.append(params.width)
shape.append(params.height)
self.inputs_info["x{}".format(self.input_index)] = [shape, "float32"]
self.input_index += 1
def Convolution(self, node):
conv2d_name = name_generator("conv", self.nn_name2id)
output_name = node.layer_name
......
......@@ -124,6 +124,8 @@ class CaffeOpMapper(OpMapper):
def __init__(self, decoder):
super(CaffeOpMapper, self).__init__()
self.graph = decoder.caffe_graph
if not self.op_checker():
raise Exception("Model is not supported yet.")
self.params = dict()
resolver = decoder.resolver
self.used_custom_layers = {}
......@@ -191,6 +193,31 @@ class CaffeOpMapper(OpMapper):
outputs=[node.name],
**layer_attrs)
def MemoryData(self, node):
params = node.layer.memory_data_param
transform_params = node.layer.transform_param
shape = list()
shape.append(params.batch_size)
shape.append(params.channels)
if hasattr(transform_params, "crop_size"):
shape.append(transform_params.crop_size)
shape.append(transform_params.crop_size)
else:
shape.append(params.width)
shape.append(params.height)
dtype = 'float32'
layer_attrs = {
"dtype": string(dtype),
"shape": shape,
"name": string(node.name)
}
self.paddle_graph.add_layer(
kernel="paddle.static.data",
inputs={},
outputs=[node.name],
**layer_attrs)
def Convolution(self, node):
data = node.data
params = node.layer.convolution_param
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册