提交 4fe0b4d2 编写于 作者: S sunyanfang01

compatible with python2 and python3

上级 32375eeb
...@@ -42,7 +42,6 @@ def convert(def_path, caffemodel_path, data_output_path, code_output_path, ...@@ -42,7 +42,6 @@ def convert(def_path, caffemodel_path, data_output_path, code_output_path,
if code_output_path: if code_output_path:
print_stderr('Saving source...') print_stderr('Saving source...')
with open(code_output_path, 'wb') as src_out: with open(code_output_path, 'wb') as src_out:
# print(type(transformer.transform_source()))
src_out.write(str.encode(transformer.transform_source())) src_out.write(str.encode(transformer.transform_source()))
print_stderr('set env variable before using converted model '\ print_stderr('set env variable before using converted model '\
'if used custom_layers:') 'if used custom_layers:')
......
...@@ -55,7 +55,7 @@ def compare(path1, path2, no_exception): ...@@ -55,7 +55,7 @@ def compare(path1, path2, no_exception):
print('[max_df:%.4e, sq_df:%.4e] when compare %s <=> %s' % print('[max_df:%.4e, sq_df:%.4e] when compare %s <=> %s' %
(max_df, sq_df, os.path.basename(f1), os.path.basename(f2))) (max_df, sq_df, os.path.basename(f1), os.path.basename(f2)))
if no_exception is False: 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) 'max_df is too large with value[%.6e]' % (max_df)
assert (sq_df < 1e-10), \ assert (sq_df < 1e-10), \
'sq_df is too large with value[%.6e]' % (sq_df) 'sq_df is too large with value[%.6e]' % (sq_df)
......
...@@ -22,7 +22,7 @@ def crop_shape(input_shape, shape=None): ...@@ -22,7 +22,7 @@ def crop_shape(input_shape, shape=None):
input_shape.shape), "input_shape is diff with output_shape" input_shape.shape), "input_shape is diff with output_shape"
return shape return shape
else: else:
raise Exception, "crop_shape input error" raise Exception("crop_shape input error")
return None return None
...@@ -54,7 +54,7 @@ def crop_layer(input, name, shape=None, axis=2, offset=None): ...@@ -54,7 +54,7 @@ def crop_layer(input, name, shape=None, axis=2, offset=None):
output_shape = shape output_shape = shape
input_tensor = input input_tensor = input
else: else:
raise Exception, "crop_layer input error" raise Exception("crop_layer input error")
assert len(output_shape) == len( assert len(output_shape) == len(
input_shape), "input_shape is diff with output_shape" input_shape), "input_shape is diff with output_shape"
......
...@@ -2,7 +2,6 @@ import re ...@@ -2,7 +2,6 @@ import re
import numbers import numbers
from collections import namedtuple from collections import namedtuple
import sys import sys
sys.path.append('~/paddlepaddle/X2Paddle_v2.0/caffe2fluid/kaffe/custom_layers')
from . import custom_layers from . import custom_layers
from .shapes import * from .shapes import *
......
...@@ -42,7 +42,7 @@ class MyNet(object): ...@@ -42,7 +42,7 @@ class MyNet(object):
def convert(cls, npy_model, fluid_path, outputs=None): def convert(cls, npy_model, fluid_path, outputs=None):
fluid = import_fluid() fluid = import_fluid()
shapes = cls.input_shapes() shapes = cls.input_shapes()
input_name = list(shapes.keys())[0] #need to review input_name = list(shapes.keys())[0]
feed_data = {} feed_data = {}
for name, shape in shapes.items(): for name, shape in shapes.items():
data_layer = fluid.layers.data( data_layer = fluid.layers.data(
......
...@@ -110,7 +110,7 @@ class Network(object): ...@@ -110,7 +110,7 @@ class Network(object):
continue continue
layer = self.layers[op_name] 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: try:
name = '%s_%s' % (op_name, param_name) name = '%s_%s' % (op_name, param_name)
v = fluid.global_scope().find_var(name) v = fluid.global_scope().find_var(name)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册