From 2913eea10e5fe08cb723cc4fa11def73d448893f Mon Sep 17 00:00:00 2001 From: mamingjie-China Date: Sat, 8 Aug 2020 17:04:52 +0800 Subject: [PATCH] fix bug in paddle1.8.3 --- x2paddle/op_mapper/tf_op_mapper_nhwc.py | 21 ++++++++++++++++----- x2paddle/optimizer/tf_optimizer.py | 5 ++++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/x2paddle/op_mapper/tf_op_mapper_nhwc.py b/x2paddle/op_mapper/tf_op_mapper_nhwc.py index 2bb0ade..12c91f8 100644 --- a/x2paddle/op_mapper/tf_op_mapper_nhwc.py +++ b/x2paddle/op_mapper/tf_op_mapper_nhwc.py @@ -299,6 +299,10 @@ class TFOpMapperNHWC(OpMapper): data_format = node.get_attr("data_format").decode() pad_mode = node.get_attr("padding").decode() channel_first = data_format == "NCHW" + if data_format == "NHWC": + n, h, w, c = input.out_shapes[0] + else: + n, c, h, w = input.out_shapes[0] if kernel.layer_type == 'Const': kernel_value = kernel.value @@ -333,6 +337,12 @@ class TFOpMapperNHWC(OpMapper): if hasattr(node, 'dilation') and attr['dilation'] == [1, 1]: if len(node.dilation) == 1: attr['dilation'] = [1, node.dilation[0]] + + if c == -1: + reshape_attr = {"shape": [0, k_size[2], 0, 0]} + node.fluid_code.add_layer( + "reshape", inputs=input, output=input, param_attr=reshape_attr) + node.fluid_code.add_layer( "conv2d", inputs=input, output=node, param_attr=attr) if not channel_first: @@ -748,11 +758,11 @@ class TFOpMapperNHWC(OpMapper): self.add_omit_nodes(begin.layer_name, node.layer_name) begin = begin.value.tolist() else: - begin = begin - shape = begin.out_shapes[0] - attr = {"shape": shape} - node.fluid_code.add_layer( - "reshape", inputs=begin, output=begin, param_attr=attr) + begin = self.decoder.infer_tensor(begin).tolist() +# shape = begin.out_shapes[0] +# attr = {"shape": shape} +# node.fluid_code.add_layer( +# "reshape", inputs=begin, output=begin, param_attr=attr) if size.layer_type == "Const": self.add_omit_nodes(size.layer_name, node.layer_name) size = size.value.tolist() @@ -1091,3 +1101,4 @@ class TFOpMapperNHWC(OpMapper): output = "{}[{}]".format(node.layer_name, i) node.fluid_code.add_layer( "data", inputs=None, output=output, param_attr=attr) + diff --git a/x2paddle/optimizer/tf_optimizer.py b/x2paddle/optimizer/tf_optimizer.py index 6d3c0cd..a5bf84b 100644 --- a/x2paddle/optimizer/tf_optimizer.py +++ b/x2paddle/optimizer/tf_optimizer.py @@ -863,6 +863,9 @@ class TFOptimizer(object): weight = numpy.expand_dims(weight, 2) weight = numpy.expand_dims(weight, 3) self.op_mapper.weights[in_nodes3[0].layer_name] = weight + # fix bug in Paddle1.8.3 and may change in next version + self.op_mapper.weights[in_nodes3[0].layer_name + + '_1'] = weight.reshape(1, -1) in_nodes3[0].fluid_code.layers[0].param_attr["shape"] = [ 1, in_shape[-1], 1, 1 ] @@ -885,7 +888,7 @@ class TFOptimizer(object): node.fluid_code.clear() attr = { "mode": string(mode), - "param_attr": string(in_nodes3[0].layer_name) + "param_attr": string(in_nodes3[0].layer_name + "_1") } node.fluid_code.add_layer( -- GitLab