提交 ee1d08ab 编写于 作者: M minqiyang

Fix CI issues

上级 46a26946
...@@ -27,6 +27,8 @@ import paddle.dataset.common ...@@ -27,6 +27,8 @@ import paddle.dataset.common
import re import re
import random import random
import functools import functools
import six
import paddle.fluid.compat as cpt
__all__ = [ __all__ = [
'train', 'test', 'get_movie_title_dict', 'max_movie_id', 'max_user_id', 'train', 'test', 'get_movie_title_dict', 'max_movie_id', 'max_user_id',
...@@ -112,6 +114,7 @@ def __initialize_meta_info__(): ...@@ -112,6 +114,7 @@ def __initialize_meta_info__():
categories_set = set() categories_set = set()
with package.open('ml-1m/movies.dat') as movie_file: with package.open('ml-1m/movies.dat') as movie_file:
for i, line in enumerate(movie_file): for i, line in enumerate(movie_file):
line = cpt.to_literal_str(line, encoding='latin')
movie_id, title, categories = line.strip().split('::') movie_id, title, categories = line.strip().split('::')
categories = categories.split('|') categories = categories.split('|')
for c in categories: for c in categories:
...@@ -136,6 +139,7 @@ def __initialize_meta_info__(): ...@@ -136,6 +139,7 @@ def __initialize_meta_info__():
USER_INFO = dict() USER_INFO = dict()
with package.open('ml-1m/users.dat') as user_file: with package.open('ml-1m/users.dat') as user_file:
for line in user_file: for line in user_file:
line = cpt.to_literal_str(line, encoding='latin')
uid, gender, age, job, _ = line.strip().split("::") uid, gender, age, job, _ = line.strip().split("::")
USER_INFO[int(uid)] = UserInfo( USER_INFO[int(uid)] = UserInfo(
index=uid, gender=gender, age=age, job_id=job) index=uid, gender=gender, age=age, job_id=job)
...@@ -148,6 +152,7 @@ def __reader__(rand_seed=0, test_ratio=0.1, is_test=False): ...@@ -148,6 +152,7 @@ def __reader__(rand_seed=0, test_ratio=0.1, is_test=False):
with zipfile.ZipFile(file=fn) as package: with zipfile.ZipFile(file=fn) as package:
with package.open('ml-1m/ratings.dat') as rating: with package.open('ml-1m/ratings.dat') as rating:
for line in rating: for line in rating:
line = cpt.to_literal_str(line, encoding='latin')
if (rand.random() < test_ratio) == is_test: if (rand.random() < test_ratio) == is_test:
uid, mov_id, rating, _ = line.strip().split("::") uid, mov_id, rating, _ = line.strip().split("::")
uid = int(uid) uid = int(uid)
...@@ -187,7 +192,7 @@ def max_movie_id(): ...@@ -187,7 +192,7 @@ def max_movie_id():
Get the maximum value of movie id. Get the maximum value of movie id.
""" """
__initialize_meta_info__() __initialize_meta_info__()
return reduce(__max_index_info__, list(MOVIE_INFO.values())).index return six.moves.reduce(__max_index_info__, list(MOVIE_INFO.values())).index
def max_user_id(): def max_user_id():
...@@ -195,7 +200,7 @@ def max_user_id(): ...@@ -195,7 +200,7 @@ def max_user_id():
Get the maximum value of user id. Get the maximum value of user id.
""" """
__initialize_meta_info__() __initialize_meta_info__()
return reduce(__max_index_info__, list(USER_INFO.values())).index return six.moves.reduce(__max_index_info__, list(USER_INFO.values())).index
def __max_job_id_impl__(a, b): def __max_job_id_impl__(a, b):
...@@ -210,7 +215,7 @@ def max_job_id(): ...@@ -210,7 +215,7 @@ def max_job_id():
Get the maximum value of job id. Get the maximum value of job id.
""" """
__initialize_meta_info__() __initialize_meta_info__()
return reduce(__max_job_id_impl__, list(USER_INFO.values())).job_id return six.moves.reduce(__max_job_id_impl__, list(USER_INFO.values())).job_id
def movie_categories(): def movie_categories():
......
...@@ -62,7 +62,7 @@ def __build_dict(tar_file, dict_size, save_path, lang): ...@@ -62,7 +62,7 @@ def __build_dict(tar_file, dict_size, save_path, lang):
word_dict = defaultdict(int) word_dict = defaultdict(int)
with tarfile.open(tar_file, mode="r") as f: with tarfile.open(tar_file, mode="r") as f:
for line in f.extractfile("wmt16/train"): for line in f.extractfile("wmt16/train"):
line_split = line.strip().split("\t") line_split = line.strip().split(six.b("\t"))
if len(line_split) != 2: continue if len(line_split) != 2: continue
sen = line_split[0] if lang == "en" else line_split[1] sen = line_split[0] if lang == "en" else line_split[1]
for w in sen.split(): for w in sen.split():
......
...@@ -13,39 +13,40 @@ ...@@ -13,39 +13,40 @@
# limitations under the License. # limitations under the License.
import six import six
import math
# str and bytes related functions # str and bytes related functions
def to_literal_str(obj): def to_literal_str(obj, encoding='utf-8'):
if isinstance(obj, list): if isinstance(obj, list):
return [_to_literal_str(item) for item in obj] return [_to_literal_str(item, encoding) for item in obj]
elif isinstance(obj, set): elif isinstance(obj, set):
return set([_to_literal_str(item) for item in obj]) return set([_to_literal_str(item, encoding) for item in obj])
else: else:
return _to_literal_str(obj) return _to_literal_str(obj, encoding)
def _to_literal_str(obj): def _to_literal_str(obj, encoding):
if isinstance(obj, six.binary_type): if isinstance(obj, six.binary_type):
return obj.decode('utf-8') return obj.decode(encoding)
elif isinstance(obj, six.text_type): elif isinstance(obj, six.text_type):
return obj return obj
else: else:
return six.u(obj) return six.u(obj)
def to_bytes(obj): def to_bytes(obj, encoding='utf-8'):
if isinstance(obj, list): if isinstance(obj, list):
return [_to_bytes(item) for item in obj] return [_to_bytes(item, encoding) for item in obj]
elif isinstance(obj, set): elif isinstance(obj, set):
return set([_to_bytes(item) for item in obj]) return set([_to_bytes(item, encoding) for item in obj])
else: else:
return _to_bytes(obj) return _to_bytes(obj, encoding)
def _to_bytes(obj): def _to_bytes(obj, encoding):
if isinstance(obj, six.text_type): if isinstance(obj, six.text_type):
return obj.encode('utf-8') return obj.encode(encoding)
elif isinstance(obj, six.binary_type): elif isinstance(obj, six.binary_type):
return obj return obj
else: else:
...@@ -53,9 +54,6 @@ def _to_bytes(obj): ...@@ -53,9 +54,6 @@ def _to_bytes(obj):
# math related functions # math related functions
import math
def round(x, d=0): def round(x, d=0):
""" """
Compatible round which act the same behaviour in Python3. Compatible round which act the same behaviour in Python3.
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import numpy as np
import six import six
import paddle.fluid.core as core import paddle.fluid.core as core
...@@ -99,6 +100,8 @@ class OpDescCreationMethod(object): ...@@ -99,6 +100,8 @@ class OpDescCreationMethod(object):
new_attr = op_desc.attrs.add() new_attr = op_desc.attrs.add()
new_attr.name = attr.name new_attr.name = attr.name
new_attr.type = attr.type new_attr.type = attr.type
if isinstance(user_defined_attr, np.ndarray):
user_defined_attr = user_defined_attr.tolist()
if attr.type == framework_pb2.INT: if attr.type == framework_pb2.INT:
new_attr.i = user_defined_attr new_attr.i = user_defined_attr
elif attr.type == framework_pb2.FLOAT: elif attr.type == framework_pb2.FLOAT:
......
...@@ -25,7 +25,7 @@ def conv3dtranspose_forward_naive(input_, filter_, attrs): ...@@ -25,7 +25,7 @@ def conv3dtranspose_forward_naive(input_, filter_, attrs):
groups = attrs['groups'] groups = attrs['groups']
assert in_c == f_c assert in_c == f_c
out_c = f_out_c * groups out_c = f_out_c * groups
sub_in_c = in_c / groups sub_in_c = in_c // groups
stride, pad, dilations = attrs['strides'], attrs['paddings'], attrs[ stride, pad, dilations = attrs['strides'], attrs['paddings'], attrs[
'dilations'] 'dilations']
......
...@@ -19,7 +19,7 @@ from op_test import OpTest ...@@ -19,7 +19,7 @@ from op_test import OpTest
def maxout_forward_naive(input, groups): def maxout_forward_naive(input, groups):
s0, s1, s2, s3 = input.shape s0, s1, s2, s3 = input.shape
return np.ndarray([s0, s1 / groups, groups, s2, s3], \ return np.ndarray([s0, s1 // groups, groups, s2, s3], \
buffer = input, dtype=input.dtype).max(axis=(2)) buffer = input, dtype=input.dtype).max(axis=(2))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册