From 4fe0b4d293391326c04aeb1793041a93eec701bf Mon Sep 17 00:00:00 2001 From: sunyanfang01 Date: Mon, 18 Mar 2019 15:50:17 +0800 Subject: [PATCH] compatible with python2 and python3 --- caffe2fluid/convert.py | 1 - caffe2fluid/examples/imagenet/compare.py | 2 +- caffe2fluid/kaffe/custom_layers/crop.py | 4 ++-- caffe2fluid/kaffe/layers.py | 1 - caffe2fluid/kaffe/net_template.py | 2 +- caffe2fluid/kaffe/paddle/network.py | 2 +- 6 files changed, 5 insertions(+), 7 deletions(-) diff --git a/caffe2fluid/convert.py b/caffe2fluid/convert.py index 5e9ecac..95bafb8 100755 --- a/caffe2fluid/convert.py +++ b/caffe2fluid/convert.py @@ -42,7 +42,6 @@ def convert(def_path, caffemodel_path, data_output_path, code_output_path, if code_output_path: print_stderr('Saving source...') with open(code_output_path, 'wb') as src_out: -# print(type(transformer.transform_source())) src_out.write(str.encode(transformer.transform_source())) print_stderr('set env variable before using converted model '\ 'if used custom_layers:') diff --git a/caffe2fluid/examples/imagenet/compare.py b/caffe2fluid/examples/imagenet/compare.py index 18766df..6d708e8 100644 --- a/caffe2fluid/examples/imagenet/compare.py +++ b/caffe2fluid/examples/imagenet/compare.py @@ -55,7 +55,7 @@ def compare(path1, path2, no_exception): print('[max_df:%.4e, sq_df:%.4e] when compare %s <=> %s' % (max_df, sq_df, os.path.basename(f1), os.path.basename(f2))) if no_exception is False: - assert (max_df < 1e-4), \ + assert (max_df < 1e-5), \ 'max_df is too large with value[%.6e]' % (max_df) assert (sq_df < 1e-10), \ 'sq_df is too large with value[%.6e]' % (sq_df) diff --git a/caffe2fluid/kaffe/custom_layers/crop.py b/caffe2fluid/kaffe/custom_layers/crop.py index 807f65d..d146be9 100644 --- a/caffe2fluid/kaffe/custom_layers/crop.py +++ b/caffe2fluid/kaffe/custom_layers/crop.py @@ -22,7 +22,7 @@ def crop_shape(input_shape, shape=None): input_shape.shape), "input_shape is diff with output_shape" return shape else: - raise Exception, "crop_shape input error" + raise Exception("crop_shape input error") return None @@ -54,7 +54,7 @@ def crop_layer(input, name, shape=None, axis=2, offset=None): output_shape = shape input_tensor = input else: - raise Exception, "crop_layer input error" + raise Exception("crop_layer input error") assert len(output_shape) == len( input_shape), "input_shape is diff with output_shape" diff --git a/caffe2fluid/kaffe/layers.py b/caffe2fluid/kaffe/layers.py index 9205663..2e32761 100644 --- a/caffe2fluid/kaffe/layers.py +++ b/caffe2fluid/kaffe/layers.py @@ -2,7 +2,6 @@ import re import numbers from collections import namedtuple import sys -sys.path.append('~/paddlepaddle/X2Paddle_v2.0/caffe2fluid/kaffe/custom_layers') from . import custom_layers from .shapes import * diff --git a/caffe2fluid/kaffe/net_template.py b/caffe2fluid/kaffe/net_template.py index cb601bb..c3a16da 100644 --- a/caffe2fluid/kaffe/net_template.py +++ b/caffe2fluid/kaffe/net_template.py @@ -42,7 +42,7 @@ class MyNet(object): def convert(cls, npy_model, fluid_path, outputs=None): fluid = import_fluid() shapes = cls.input_shapes() - input_name = list(shapes.keys())[0] #need to review + input_name = list(shapes.keys())[0] feed_data = {} for name, shape in shapes.items(): data_layer = fluid.layers.data( diff --git a/caffe2fluid/kaffe/paddle/network.py b/caffe2fluid/kaffe/paddle/network.py index 0286bce..b1c9ca0 100644 --- a/caffe2fluid/kaffe/paddle/network.py +++ b/caffe2fluid/kaffe/paddle/network.py @@ -110,7 +110,7 @@ class Network(object): continue layer = self.layers[op_name] - for param_name, data in data_dict[op_name].items(): #need to review + for param_name, data in data_dict[op_name].items(): try: name = '%s_%s' % (op_name, param_name) v = fluid.global_scope().find_var(name) -- GitLab