提交 1f618c4f 编写于 作者: M minqiyang

Fix the overfix of 2to3 in xrange

上级 5656f64b
......@@ -24,7 +24,7 @@ import tarfile
import gzip
import itertools
import paddle.dataset.common
from six.moves import zip
from six.moves import zip, range
__all__ = ['test, get_dict', 'get_embedding', 'convert']
......
......@@ -25,6 +25,7 @@ import collections
import tarfile
import re
import string
from six.moves import range
__all__ = ['build_dict', 'train', 'test', 'convert']
......@@ -66,7 +67,7 @@ def build_dict(pattern, cutoff):
dictionary = sorted(word_freq, key=lambda x: (-x[1], x[0]))
words, _ = list(zip(*dictionary))
word_idx = dict(list(zip(words, list(range(len(words))))))
word_idx = dict(list(zip(words, range(len(words)))))
word_idx['<unk>'] = len(words)
return word_idx
......
......@@ -14,13 +14,14 @@
"""
imikolov's simple dataset.
This module will download dataset from
This module will download dataset from
http://www.fit.vutbr.cz/~imikolov/rnnlm/ and parse training set and test set
into paddle reader creators.
"""
import paddle.dataset.common
import collections
import tarfile
from six.moves import range
__all__ = ['train', 'test', 'build_dict', 'convert']
......@@ -68,7 +69,7 @@ def build_dict(min_word_freq=50):
word_freq_sorted = sorted(word_freq, key=lambda x: (-x[1], x[0]))
words, _ = list(zip(*word_freq_sorted))
word_idx = dict(list(zip(words, list(range(len(words))))))
word_idx = dict(list(zip(words, range(len(words)))))
word_idx['<unk>'] = len(words)
return word_idx
......
......@@ -21,6 +21,7 @@ import paddle.dataset.common
import subprocess
import numpy
import platform
from six.moves import range
__all__ = ['train', 'test', 'convert']
URL_PREFIX = 'http://yann.lecun.com/exdb/mnist/'
......
......@@ -16,6 +16,7 @@ import paddle.dataset.common
import unittest
import tempfile
import glob
from six.moves import range
class TestCommon(unittest.TestCase):
......
......@@ -22,6 +22,7 @@ parse training set and test set into paddle reader creators.
import os
import numpy as np
import six
import tempfile
import tarfile
import os
......@@ -74,7 +75,7 @@ def load_data(filename, feature_num=14, ratio=0.8):
maximums, minimums, avgs = data.max(axis=0), data.min(axis=0), data.sum(
axis=0) / data.shape[0]
feature_range(maximums[:-1], minimums[:-1])
for i in range(feature_num - 1):
for i in six.moves.range(feature_num - 1):
data[:, i] = (data[:, i] - avgs[i]) / (maximums[i] - minimums[i])
offset = int(data.shape[0] * ratio)
UCI_TRAIN_DATA = data[:offset]
......@@ -137,7 +138,7 @@ def predict_reader():
It returns just one tuple data to do inference.
:return: one tuple data
:rtype: tuple
:rtype: tuple
"""
global UCI_TEST_DATA
load_data(paddle.dataset.common.download(URL, 'uci_housing', MD5))
......
......@@ -346,7 +346,7 @@ class Executor(object):
def _fetch_data(self, fetch_list, fetch_var_name, scope):
outs = [
core.get_fetch_variable(scope, fetch_var_name, i)
for i in range(len(fetch_list))
for i in six.moves.range(len(fetch_list))
]
return outs
......
......@@ -1497,7 +1497,9 @@ class Program(object):
else:
p = Program()
p.desc = core.ProgramDesc(self.desc)
p.blocks = [Block(p, i) for i in range(self.desc.num_blocks())]
p.blocks = [
Block(p, i) for i in six.moves.range(self.desc.num_blocks())
]
p._sync_with_cpp()
p._copy_param_info_from(self)
......@@ -1549,7 +1551,9 @@ class Program(object):
targets_idx.append([t.block.idx, t.idx])
res = Program()
res.desc = core.prune(self.desc, targets_idx)
res.blocks = [Block(res, i) for i in range(res.desc.num_blocks())]
res.blocks = [
Block(res, i) for i in six.moves.range(res.desc.num_blocks())
]
res._sync_with_cpp()
return res
......@@ -1590,13 +1594,15 @@ class Program(object):
root_block._remove_var(var.name())
# change all `is_test` attributes to True
for i in range(res.desc.num_blocks()):
for i in six.moves.range(res.desc.num_blocks()):
block = res.desc.block(i)
for j in range(block.op_size()):
for j in six.moves.range(block.op_size()):
op = block.op(j)
if op.has_attr('is_test'):
op.set_attr('is_test', True)
res.blocks = [Block(res, i) for i in range(res.desc.num_blocks())]
res.blocks = [
Block(res, i) for i in six.moves.range(res.desc.num_blocks())
]
res._sync_with_cpp()
return res
......@@ -1616,7 +1622,7 @@ class Program(object):
"""
p = Program()
p.desc = core.ProgramDesc(binary_str)
p.blocks = [Block(p, i) for i in range(p.desc.num_blocks())]
p.blocks = [Block(p, i) for i in six.moves.range(p.desc.num_blocks())]
p._sync_with_cpp()
return p
......
......@@ -85,7 +85,7 @@ class LayerHelper(object):
raise ValueError("parameter number mismatch")
elif len(param_attr) == 1 and length != 1:
tmp = [None] * length
for i in range(length):
for i in six.moves.range(length):
tmp[i] = copy.deepcopy(param_attr[0])
param_attr = tmp
return param_attr
......
......@@ -21,6 +21,7 @@ from ..layer_helper import LayerHelper
from . import tensor
from . import nn
import math
import six
from functools import reduce
__all__ = [
......@@ -102,7 +103,7 @@ def rpn_target_assign(loc,
examples.
Returns:
tuple:
tuple:
A tuple(predicted_scores, predicted_location, target_label,
target_bbox) is returned. The predicted_scores and
predicted_location is the predicted result of the RPN.
......@@ -113,7 +114,7 @@ def rpn_target_assign(loc,
anchors. The predicted_scores is a 2D Tensor with shape
[F + B, 1], and the shape of target_label is same as the shape
of the predicted_scores, B is the number of the background
anchors, the F and B is depends on the input of this operator.
anchors, the F and B is depends on the input of this operator.
Examples:
.. code-block:: python
......@@ -230,8 +231,8 @@ def detection_output(loc,
nms_eta(float): The parameter for adaptive NMS.
Returns:
Variable:
Variable:
The detection outputs is a LoDTensor with shape [No, 6].
Each row has six values: [label, confidence, xmin, ymin, xmax, ymax].
`No` is the total number of detections in this mini-batch. For each
......@@ -501,7 +502,7 @@ def target_assign(input,
Assumed that the row offset for each instance in `neg_indices` is called neg_lod,
for i-th instance and each `id` of neg_indices in this instance:
.. code-block:: text
out[i][id][0 : K] = {mismatch_value, mismatch_value, ...}
......@@ -519,11 +520,11 @@ def target_assign(input,
mismatch_value (float32): Fill this value to the mismatched location.
Returns:
tuple:
A tuple(out, out_weight) is returned. out is a 3D Tensor with
shape [N, P, K], N and P is the same as they are in
`neg_indices`, K is the same as it in input of X. If
`match_indices[i][j]`. out_weight is the weight for output with
tuple:
A tuple(out, out_weight) is returned. out is a 3D Tensor with
shape [N, P, K], N and P is the same as they are in
`neg_indices`, K is the same as it in input of X. If
`match_indices[i][j]`. out_weight is the weight for output with
the shape of [N, P, 1].
Examples:
......@@ -822,7 +823,7 @@ def prior_box(input,
offset(float): Prior boxes center offset. Default: 0.5
name(str): Name of the prior box op. Default: None.
min_max_aspect_ratios_order(bool): If set True, the output prior box is
in order of [min, max, aspect_ratios], which is consistent with
in order of [min, max, aspect_ratios], which is consistent with
Caffe. Please note, this order affects the weights order of
convolution layer followed by and does not affect the final
detection results. Default: False.
......@@ -965,7 +966,7 @@ def multi_box_head(inputs,
stride(int|list|tuple): The stride of conv2d. Default:1,
name(str): Name of the prior box layer. Default: None.
min_max_aspect_ratios_order(bool): If set True, the output prior box is
in order of [min, max, aspect_ratios], which is consistent with
in order of [min, max, aspect_ratios], which is consistent with
Caffe. Please note, this order affects the weights order of
convolution layer followed by and does not affect the fininal
detection results. Default: False.
......@@ -1033,7 +1034,7 @@ def multi_box_head(inputs,
min_sizes = []
max_sizes = []
step = int(math.floor(((max_ratio - min_ratio)) / (num_layer - 2)))
for ratio in range(min_ratio, max_ratio + 1, step):
for ratio in six.moves.range(min_ratio, max_ratio + 1, step):
min_sizes.append(base_size * ratio / 100.)
max_sizes.append(base_size * (ratio + step) / 100.)
min_sizes = [base_size * .10] + min_sizes
......
......@@ -13,6 +13,7 @@
# limitations under the License.
import contextlib
import multiprocessing
import six
import threading
from ..data_feeder import DataFeeder
......@@ -69,7 +70,7 @@ def data(name,
"""
helper = LayerHelper('data', **locals())
shape = list(shape)
for i in range(len(shape)):
for i in six.moves.range(len(shape)):
if shape[i] is None:
shape[i] = -1
append_batch_size = False
......@@ -674,7 +675,7 @@ def py_reader(capacity,
def __tensor_provider__():
for slots in paddle_reader():
yield [slots[str(idx)] for idx in xrange(counter)]
yield [slots[str(idx)] for idx in six.moves.xrange(counter)]
__set_tensor_provider__(__tensor_provider__)
......@@ -1005,7 +1006,7 @@ class Preprocessor(object):
source_lod_levels = self.underlying_reader.desc.lod_levels()
self.source_var_names = [
unique_name("preprocessor_source")
for _ in range(len(source_shapes))
for _ in six.moves.range(len(source_shapes))
]
source_vars = []
for var_name, shape, dtype, lod_level in zip(
......
......@@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import six
from . import layers
__all__ = [
......@@ -210,7 +211,7 @@ def img_conv_group(input,
conv_with_batchnorm = __extend_list__(conv_with_batchnorm)
conv_batchnorm_drop_rate = __extend_list__(conv_batchnorm_drop_rate)
for i in range(len(conv_num_filter)):
for i in six.moves.range(len(conv_num_filter)):
local_conv_act = conv_act
if conv_with_batchnorm[i]:
local_conv_act = None
......
......@@ -19,6 +19,7 @@ from . import framework
from . import executor
import warnings
import sys
import six
import os
__all__ = ['ParallelExecutor', 'ExecutionStrategy', 'BuildStrategy']
......@@ -95,7 +96,7 @@ class ParallelExecutor(object):
self._places = []
self._act_places = []
if use_cuda:
for i in range(core.get_cuda_device_count()):
for i in six.moves.range(core.get_cuda_device_count()):
p = core.Place()
self._act_places.append(core.CUDAPlace(i))
p.set_place(self._act_places[-1])
......@@ -103,7 +104,7 @@ class ParallelExecutor(object):
else:
cpu_num = int(
os.environ.get('CPU_NUM', multiprocessing.cpu_count()))
for i in range(cpu_num):
for i in six.moves.range(cpu_num):
p = core.Place()
self._act_places.append(core.CPUPlace())
p.set_place(self._act_places[-1])
......
......@@ -13,6 +13,7 @@
# limitations under the License.
import numpy
import six
import paddle
import paddle.dataset.mnist as mnist
......@@ -31,7 +32,7 @@ def network(is_train):
hidden = img
for i in xrange(2):
for i in six.moves.xrange(2):
hidden = fluid.layers.fc(input=hidden, size=100, act='tanh')
hidden = fluid.layers.dropout(
hidden, dropout_prob=0.5, is_test=not is_train)
......@@ -74,7 +75,7 @@ def main():
test_reader.decorate_paddle_reader(paddle.batch(mnist.test(), 512))
for epoch_id in xrange(10):
for epoch_id in six.moves.xrange(10):
train_reader.start()
try:
while True:
......
......@@ -22,6 +22,7 @@ import paddle.fluid as fluid
from paddle.fluid import core
import os
import sys
import six
import transformer_model
import paddle.dataset.wmt16 as wmt16
......@@ -222,7 +223,7 @@ class DistTransformer2x2(object):
first_loss, = exe.run(fetch_list=[avg_cost.name])
print(first_loss)
for i in xrange(5):
for i in six.moves.xrange(5):
_ = exe.run(fetch_list=[avg_cost.name])
last_loss, = exe.run(fetch_list=[avg_cost.name])
print(last_loss)
......
......@@ -14,6 +14,7 @@
import unittest
import numpy as np
import six
from op_test import OpTest
import paddle.fluid.core as core
from paddle.fluid.op import Operator
......@@ -59,7 +60,7 @@ class TestSpliteIds(unittest.TestCase):
x_tensor = x.get_tensor()
x_tensor.set(np_array, place)
outs_name = ["out%d" % i for i in xrange(3)]
outs_name = ["out%d" % i for i in six.moves.xrange(3)]
outs = [
scope.var(var_name).get_selected_rows() for var_name in outs_name
]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册