From c2268794ab638dd1c4f85b67b582ceb08acfe3c1 Mon Sep 17 00:00:00 2001 From: Oleg Zabluda Date: Thu, 12 Oct 2017 12:01:21 -0700 Subject: [PATCH] Remove redundant argument to range(). (#8108) * Remove redundant argument to range. All other range() invocations in this file follow this style. * Remove redundant argument to range() --- examples/conv_filter_visualization.py | 2 +- examples/image_ocr.py | 4 ++-- keras/backend/cntk_backend.py | 2 +- keras/backend/tensorflow_backend.py | 4 ++-- keras/engine/training.py | 2 +- tests/keras/backend/backend_test.py | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/conv_filter_visualization.py b/examples/conv_filter_visualization.py index b85b867974a..b235a237c34 100644 --- a/examples/conv_filter_visualization.py +++ b/examples/conv_filter_visualization.py @@ -59,7 +59,7 @@ def normalize(x): kept_filters = [] -for filter_index in range(0, 200): +for filter_index in range(200): # we only scan through the first 200 filters, # but there are actually 512 of them print('Processing filter %d' % filter_index) diff --git a/examples/image_ocr.py b/examples/image_ocr.py index 2d9e3964847..7370e5210ff 100644 --- a/examples/image_ocr.py +++ b/examples/image_ocr.py @@ -260,7 +260,7 @@ def get_batch(self, index, size, train): input_length = np.zeros([size, 1]) label_length = np.zeros([size, 1]) source_str = [] - for i in range(0, size): + for i in range(size): # Mix in some blank inputs. This seems to be important for # achieving translational invariance if train and i > size - 4: @@ -372,7 +372,7 @@ def show_edit_distance(self, num): word_batch = next(self.text_img_gen)[0] num_proc = min(word_batch['the_input'].shape[0], num_left) decoded_res = decode_batch(self.test_func, word_batch['the_input'][0:num_proc]) - for j in range(0, num_proc): + for j in range(num_proc): edit_dist = editdistance.eval(decoded_res[j], word_batch['source_str'][j]) mean_ed += float(edit_dist) mean_norm_ed += float(edit_dist) / len(word_batch['source_str'][j]) diff --git a/keras/backend/cntk_backend.py b/keras/backend/cntk_backend.py index 505f7c48f77..abba7cb8f1e 100644 --- a/keras/backend/cntk_backend.py +++ b/keras/backend/cntk_backend.py @@ -512,7 +512,7 @@ def dot(x, y): y_shape = int_shape(y) if len(y_shape) > 2: permutation = [len(y_shape) - 2] - permutation += list(range(0, len(y_shape) - 2)) + permutation += list(range(len(y_shape) - 2)) permutation += [len(y_shape) - 1] y = C.transpose(y, perm=permutation) return C.times(x, y, len(y_shape) - 1) diff --git a/keras/backend/tensorflow_backend.py b/keras/backend/tensorflow_backend.py index 70f0d699fb7..63590b4e6d3 100644 --- a/keras/backend/tensorflow_backend.py +++ b/keras/backend/tensorflow_backend.py @@ -3732,11 +3732,11 @@ def range_less_than(_, current_input): initializer=init, parallel_iterations=1) dense_mask = dense_mask[:, 0, :] - label_array = tf.reshape(tf.tile(tf.range(0, label_shape[1]), num_batches_tns), + label_array = tf.reshape(tf.tile(tf.range(label_shape[1]), num_batches_tns), label_shape) label_ind = tf.boolean_mask(label_array, dense_mask) - batch_array = tf.transpose(tf.reshape(tf.tile(tf.range(0, label_shape[0]), + batch_array = tf.transpose(tf.reshape(tf.tile(tf.range(label_shape[0]), max_num_labels_tns), reverse(label_shape, 0))) batch_ind = tf.boolean_mask(batch_array, dense_mask) indices = tf.transpose(tf.reshape(concatenate([batch_ind, label_ind], axis=0), [2, -1])) diff --git a/keras/engine/training.py b/keras/engine/training.py index ad373cc01c7..1806311dbe6 100644 --- a/keras/engine/training.py +++ b/keras/engine/training.py @@ -373,7 +373,7 @@ def _make_batches(size, batch_size): """ num_batches = int(np.ceil(size / float(batch_size))) return [(i * batch_size, min(size, (i + 1) * batch_size)) - for i in range(0, num_batches)] + for i in range(num_batches)] def _slice_arrays(arrays, start=None, stop=None): diff --git a/tests/keras/backend/backend_test.py b/tests/keras/backend/backend_test.py index 9a4bdf807d9..13d8ab916ce 100644 --- a/tests/keras/backend/backend_test.py +++ b/tests/keras/backend/backend_test.py @@ -729,7 +729,7 @@ def test_in_top_k(self): targets = np.random.randint(num_classes, size=batch_size, dtype='int32') # (k == 0 or k > num_classes) does not raise an error but just return an unmeaningful tensor. - for k in range(0, num_classes + 1): + for k in range(num_classes + 1): z_list = [b.eval(b.in_top_k(b.variable(predictions, dtype='float32'), b.variable(targets, dtype='int32'), k)) for b in [KTH, KTF]]