From adaa5a0a291c380a9ecf001588f9c2c026075f10 Mon Sep 17 00:00:00 2001 From: mamingjie-China Date: Tue, 15 Oct 2019 09:49:49 +0800 Subject: [PATCH] support for Python2 --- x2paddle/decoder/tf_decoder.py | 6 +++++- x2paddle/optimizer/tf_optimizer.py | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/x2paddle/decoder/tf_decoder.py b/x2paddle/decoder/tf_decoder.py index 25f11a9..06c3052 100644 --- a/x2paddle/decoder/tf_decoder.py +++ b/x2paddle/decoder/tf_decoder.py @@ -312,7 +312,11 @@ class TFDecoder(object): right_shape_been_input = False while not right_shape_been_input: - shape = input("Shape of Input(e.g. None,224,224,3): ") + try: + shape = raw_input( + "Shape of Input(e.g. None,224,224,3): ") + except: + shape = input("Shape of Input(e.g. None,224,224,3): ") if shape.count("None") > 1: print("Only 1 dimension can be None, type again:)") else: diff --git a/x2paddle/optimizer/tf_optimizer.py b/x2paddle/optimizer/tf_optimizer.py index 08f7b08..6431e43 100644 --- a/x2paddle/optimizer/tf_optimizer.py +++ b/x2paddle/optimizer/tf_optimizer.py @@ -517,7 +517,7 @@ class TFOptimizer(object): l.op = 'transpose' l.inputs = true_node.fluid_code.layers[3].output l.param_attr = {'perm': [0, 3, 1, 2]} - if type(l.inputs) == str: + if isinstance(l.inputs, six.string_types): l.output = l.inputs else: l.output = l.inputs.layer_name @@ -550,7 +550,7 @@ class TFOptimizer(object): node = self.graph.get_node(name) if len(node.out_shapes[0]) == 4 and node.tf_data_format == "NHWC": shape = node.fluid_code.layers[0].param_attr["shape"] - shape = [shape[i] for i in [0, 3, 1, 2]] + shape = [shape[j] for j in [0, 3, 1, 2]] node.fluid_code.layers[0].param_attr["shape"] = shape node.fluid_code.layers[0].output = "nhwc_" + name attr = {"perm": [0, 2, 3, 1]} -- GitLab