提交 4bf3c8c5 编写于 作者: M minqiyang

Use six.moves to migrate zip, map, reduce and pickle in Python2 to Python3

上级 91f0573b
...@@ -28,11 +28,12 @@ images per class. ...@@ -28,11 +28,12 @@ images per class.
""" """
import pickle
import itertools import itertools
import numpy import numpy
import paddle.dataset.common import paddle.dataset.common
import tarfile import tarfile
from six.moves import zip
from six.moves import cPickle as pickle
__all__ = ['train100', 'test100', 'train10', 'test10', 'convert'] __all__ = ['train100', 'test100', 'train10', 'test10', 'convert']
......
...@@ -20,9 +20,8 @@ import shutil ...@@ -20,9 +20,8 @@ import shutil
import sys import sys
import importlib import importlib
import paddle.dataset import paddle.dataset
import pickle import six.moves.cPickle as pickle
import glob import glob
import pickle as pickle
__all__ = [ __all__ = [
'DATA_HOME', 'DATA_HOME',
......
...@@ -24,6 +24,7 @@ import tarfile ...@@ -24,6 +24,7 @@ import tarfile
import gzip import gzip
import itertools import itertools
import paddle.dataset.common import paddle.dataset.common
from six.moves import zip
__all__ = ['test, get_dict', 'get_embedding', 'convert'] __all__ = ['test, get_dict', 'get_embedding', 'convert']
......
...@@ -28,7 +28,6 @@ Graphics and Image Processing (2008) ...@@ -28,7 +28,6 @@ Graphics and Image Processing (2008)
http://www.robots.ox.ac.uk/~vgg/publications/papers/nilsback08.{pdf,ps.gz}. http://www.robots.ox.ac.uk/~vgg/publications/papers/nilsback08.{pdf,ps.gz}.
""" """
import pickle
import itertools import itertools
import functools import functools
from .common import download from .common import download
...@@ -39,6 +38,8 @@ from paddle.reader import * ...@@ -39,6 +38,8 @@ from paddle.reader import *
import os import os
import numpy as np import numpy as np
from multiprocessing import cpu_count from multiprocessing import cpu_count
from six.moves import cPickle as pickle
from six.moves import zip
__all__ = ['train', 'test', 'valid'] __all__ = ['train', 'test', 'valid']
DATA_URL = 'http://www.robots.ox.ac.uk/~vgg/data/flowers/102/102flowers.tgz' DATA_URL = 'http://www.robots.ox.ac.uk/~vgg/data/flowers/102/102flowers.tgz'
......
...@@ -36,7 +36,7 @@ except ImportError: ...@@ -36,7 +36,7 @@ except ImportError:
cv2 = None cv2 = None
import os import os
import tarfile import tarfile
import pickle import six.moves.cPickle as pickle
__all__ = [ __all__ = [
"load_image_bytes", "load_image", "resize_short", "to_chw", "center_crop", "load_image_bytes", "load_image", "resize_short", "to_chw", "center_crop",
......
...@@ -963,9 +963,9 @@ class Block(object): ...@@ -963,9 +963,9 @@ class Block(object):
raise ValueError("Var {0} is not found recursively".format(name)) raise ValueError("Var {0} is not found recursively".format(name))
def all_parameters(self): def all_parameters(self):
return list(self.iter_parameters()) return list(self._iter_parameters())
def iter_parameters(self): def _iter_parameters(self):
return (item[1] for item in list(self.vars.items()) return (item[1] for item in list(self.vars.items())
if isinstance(item[1], Parameter)) if isinstance(item[1], Parameter))
...@@ -1199,7 +1199,7 @@ class Block(object): ...@@ -1199,7 +1199,7 @@ class Block(object):
if not isinstance(other, Block): if not isinstance(other, Block):
raise TypeError( raise TypeError(
"_copy_param_info_from should be invoked with Block") "_copy_param_info_from should be invoked with Block")
for p in other.iter_parameters(): for p in other._iter_parameters():
assert isinstance(p, Parameter) assert isinstance(p, Parameter)
v = self.vars.get(p.name, None) v = self.vars.get(p.name, None)
if v is None: if v is None:
......
...@@ -20,6 +20,7 @@ from . import unique_name ...@@ -20,6 +20,7 @@ from . import unique_name
from paddle.fluid.initializer import Constant, Xavier from paddle.fluid.initializer import Constant, Xavier
from .param_attr import ParamAttr, WeightNormParamAttr from .param_attr import ParamAttr, WeightNormParamAttr
from . import core from . import core
from six.moves import zip
class LayerHelper(object): class LayerHelper(object):
......
...@@ -28,11 +28,12 @@ images per class. ...@@ -28,11 +28,12 @@ images per class.
""" """
import pickle
import itertools import itertools
import numpy import numpy
import paddle.v2.dataset.common import paddle.v2.dataset.common
import tarfile import tarfile
from six.moves import cPickle as pickle
from six.moves import zip
__all__ = ['train10'] __all__ = ['train10']
......
...@@ -17,6 +17,7 @@ from .. import core ...@@ -17,6 +17,7 @@ from .. import core
from ..framework import Program, default_main_program, Parameter from ..framework import Program, default_main_program, Parameter
from ..backward import _rename_arg_ from ..backward import _rename_arg_
from functools import reduce from functools import reduce
from six.moves import range
dtype_to_size = { dtype_to_size = {
core.VarDesc.VarType.FP16: 2, core.VarDesc.VarType.FP16: 2,
......
...@@ -67,7 +67,7 @@ def recordio(paths, buf_size=100): ...@@ -67,7 +67,7 @@ def recordio(paths, buf_size=100):
import recordio as rec import recordio as rec
import paddle.reader.decorator as dec import paddle.reader.decorator as dec
import pickle as pickle import six.moves.cPickle as pickle
def reader(): def reader():
if isinstance(paths, str): if isinstance(paths, str):
......
...@@ -22,6 +22,8 @@ import subprocess ...@@ -22,6 +22,8 @@ import subprocess
from six.moves.queue import Queue from six.moves.queue import Queue
from six.moves import zip_longest from six.moves import zip_longest
from six.moves import map
from six.moves import zip
import itertools import itertools
import random import random
import zlib import zlib
......
...@@ -42,7 +42,7 @@ except ImportError: ...@@ -42,7 +42,7 @@ except ImportError:
try: try:
import cPickle as pickle import cPickle as pickle
except ImportError: except ImportError:
import pickle import six.moves.cPickle as pickle
import io import io
......
...@@ -20,7 +20,7 @@ from .utils import deprecated ...@@ -20,7 +20,7 @@ from .utils import deprecated
try: try:
import cPickle as pickle import cPickle as pickle
except ImportError: except ImportError:
import pickle import six.moves.cPickle as pickle
__all__ = ['define_py_data_sources2'] __all__ = ['define_py_data_sources2']
......
...@@ -28,7 +28,7 @@ from .default_decorators import * ...@@ -28,7 +28,7 @@ from .default_decorators import *
try: try:
import cPickle as pickle import cPickle as pickle
except ImportError: except ImportError:
import pickle import six.moves.cPickle as pickle
import copy import copy
__all__ = [ __all__ = [
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册