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

add caffe memory data

上级 174c5436
...@@ -258,7 +258,7 @@ class CaffeGraph(Graph): ...@@ -258,7 +258,7 @@ class CaffeGraph(Graph):
assert input_node_name in self.node_map, 'The {} isn\'t a valid node'.format( assert input_node_name in self.node_map, 'The {} isn\'t a valid node'.format(
name) name)
input_node = self.node_map[input_node_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]) need_idx = list(input_node.layer.top).index(node.layer.bottom[idx])
name = input_node_name + ':' + str(need_idx) name = input_node_name + ':' + str(need_idx)
else: else:
......
...@@ -198,6 +198,26 @@ class CaffeOpMapper(OpMapper): ...@@ -198,6 +198,26 @@ class CaffeOpMapper(OpMapper):
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, "float32"] self.inputs_info["x{}".format(self.input_index)] = [[-1] + shape, "float32"]
self.input_index += 1 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): def Convolution(self, node):
conv2d_name = name_generator("conv", self.nn_name2id) conv2d_name = name_generator("conv", self.nn_name2id)
......
...@@ -124,6 +124,8 @@ class CaffeOpMapper(OpMapper): ...@@ -124,6 +124,8 @@ class CaffeOpMapper(OpMapper):
def __init__(self, decoder): def __init__(self, decoder):
super(CaffeOpMapper, self).__init__() super(CaffeOpMapper, self).__init__()
self.graph = decoder.caffe_graph self.graph = decoder.caffe_graph
if not self.op_checker():
raise Exception("Model is not supported yet.")
self.params = dict() self.params = dict()
resolver = decoder.resolver resolver = decoder.resolver
self.used_custom_layers = {} self.used_custom_layers = {}
...@@ -190,7 +192,32 @@ class CaffeOpMapper(OpMapper): ...@@ -190,7 +192,32 @@ class CaffeOpMapper(OpMapper):
inputs={}, inputs={},
outputs=[node.name], outputs=[node.name],
**layer_attrs) **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): def Convolution(self, node):
data = node.data data = node.data
params = node.layer.convolution_param params = node.layer.convolution_param
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册