diff --git a/x2paddle/decoder/caffe_decoder.py b/x2paddle/decoder/caffe_decoder.py index 99f3853a4d8aefc41035523141983c234fa7f000..dc125fa4326417bfbed5b6b1ebc93604db2afa26 100644 --- a/x2paddle/decoder/caffe_decoder.py +++ b/x2paddle/decoder/caffe_decoder.py @@ -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: diff --git a/x2paddle/op_mapper/dygraph/caffe2paddle/caffe_op_mapper.py b/x2paddle/op_mapper/dygraph/caffe2paddle/caffe_op_mapper.py index 888d8095cc9c3ea9f6ef4a046520de563a370727..25bfce58efe3be01721cdf0d7672c0f737d3e0e7 100644 --- a/x2paddle/op_mapper/dygraph/caffe2paddle/caffe_op_mapper.py +++ b/x2paddle/op_mapper/dygraph/caffe2paddle/caffe_op_mapper.py @@ -198,6 +198,26 @@ class CaffeOpMapper(OpMapper): shape = list(node.layer.input_param.shape[0].dim)[1:] 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) diff --git a/x2paddle/op_mapper/static/caffe2paddle/caffe_op_mapper.py b/x2paddle/op_mapper/static/caffe2paddle/caffe_op_mapper.py index 68ce95c71dc7124c5fce71d8338abd0730605f98..0a4119ae54104d50df54d8f7e073bcd0dcdabd49 100644 --- a/x2paddle/op_mapper/static/caffe2paddle/caffe_op_mapper.py +++ b/x2paddle/op_mapper/static/caffe2paddle/caffe_op_mapper.py @@ -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 = {} @@ -190,7 +192,32 @@ class CaffeOpMapper(OpMapper): inputs={}, 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