From c42d85e9aead392d3cf15d5ad9d0f0e2c4e5a967 Mon Sep 17 00:00:00 2001 From: mamingjie-China Date: Thu, 5 Sep 2019 20:24:15 +0800 Subject: [PATCH] support for python2 --- x2paddle/core/fluid_code.py | 11 ++++++----- x2paddle/core/graph.py | 2 ++ x2paddle/decoder/caffe_decoder.py | 4 ---- x2paddle/op_mapper/onnx_op_mapper.py | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/x2paddle/core/fluid_code.py b/x2paddle/core/fluid_code.py index 42b51f1..5619e08 100644 --- a/x2paddle/core/fluid_code.py +++ b/x2paddle/core/fluid_code.py @@ -13,8 +13,9 @@ # limitations under the License. from x2paddle.core.graph import GraphNode -import collections from x2paddle.core.util import * +import collections +import six class Layer(object): @@ -28,7 +29,7 @@ class Layer(object): def get_code(self): layer_code = "" if self.output is not None: - if isinstance(self.output, str): + if isinstance(self.output, six.string_types): layer_code = self.output + " = " else: layer_code = self.output.layer_name + " = " @@ -47,7 +48,7 @@ class Layer(object): "[{}]".format(input.index) + ", ") else: in_list += (input.layer_name + ", ") - elif isinstance(input, str): + elif isinstance(input, six.string_types): in_list += (input + ", ") else: raise Exception( @@ -72,7 +73,7 @@ class Layer(object): "[{}]".format(self.inputs.index) + ", ") else: layer_code += (self.inputs.layer_name + ", ") - elif isinstance(self.inputs, str): + elif isinstance(self.inputs, six.string_types): layer_code += (self.inputs + ", ") else: raise Exception("Unknown type of inputs.") @@ -119,6 +120,6 @@ class FluidCode(object): for layer in self.layers: if isinstance(layer, Layer): codes.append(layer.get_code()) - elif isinstance(layer, str): + elif isinstance(layer, six.string_types): codes.append(layer) return codes diff --git a/x2paddle/core/graph.py b/x2paddle/core/graph.py index 3165dcd..6ca6c47 100644 --- a/x2paddle/core/graph.py +++ b/x2paddle/core/graph.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import print_function +from __future__ import division import collections import copy as cp diff --git a/x2paddle/decoder/caffe_decoder.py b/x2paddle/decoder/caffe_decoder.py index 9573d10..ea9d3bc 100644 --- a/x2paddle/decoder/caffe_decoder.py +++ b/x2paddle/decoder/caffe_decoder.py @@ -236,11 +236,7 @@ class CaffeDecoder(object): data.MergeFromString(open(self.model_path, 'rb').read()) pair = lambda layer: (layer.name, self.normalize_pb_data(layer)) layers = data.layers or data.layer - import time - start = time.time() self.params = [pair(layer) for layer in layers if layer.blobs] - end = time.time() - print('cost:', str(end - start)) def normalize_pb_data(self, layer): transformed = [] diff --git a/x2paddle/op_mapper/onnx_op_mapper.py b/x2paddle/op_mapper/onnx_op_mapper.py index a2d8941..4dcc922 100644 --- a/x2paddle/op_mapper/onnx_op_mapper.py +++ b/x2paddle/op_mapper/onnx_op_mapper.py @@ -94,7 +94,7 @@ class ONNXOpMapper(OpMapper): print(op) return False - def directly_map(self, node, *args, name='', **kwargs): + def directly_map(self, node, name='', *args, **kwargs): inputs = node.layer.input outputs = node.layer.output op_type = node.layer_type -- GitLab