Skip to content

Commit 91cc03d

Browse files
authored
Merge pull request #361 from tensorlayer/codacy4
fix pylint issues
2 parents d3c79b6 + 3086690 commit 91cc03d

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

tensorlayer/layers/convolution.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ def __init__(
508508
else:
509509
raise Exception("Donot support shape %s" % self.inputs.get_shape())
510510
logging.info("UpSampling2dLayer %s: is_scale:%s size:%s method:%d align_corners:%s" % (name, is_scale, size, method, align_corners))
511-
with tf.variable_scope(name) as vs:
511+
with tf.variable_scope(name):
512512
try:
513513
self.outputs = tf.image.resize_images(self.inputs, size=size, method=method, align_corners=align_corners)
514514
except Exception: # for TF 0.10
@@ -568,7 +568,7 @@ def __init__(
568568
else:
569569
raise Exception("Donot support shape %s" % self.inputs.get_shape())
570570
logging.info("DownSampling2dLayer %s: is_scale:%s size:%s method:%d, align_corners:%s" % (name, is_scale, size, method, align_corners))
571-
with tf.variable_scope(name) as vs:
571+
with tf.variable_scope(name):
572572
try:
573573
self.outputs = tf.image.resize_images(self.inputs, size=size, method=method, align_corners=align_corners)
574574
except Exception: # for TF 0.10
@@ -797,7 +797,7 @@ def _tf_batch_map_offsets(inputs, offsets, grid_offset):
797797
logging.info("[warnings] unknow input channels, set to 1")
798798
shape = (filter_size[0], filter_size[1], pre_channel, n_filter)
799799

800-
with tf.variable_scope(name) as vs:
800+
with tf.variable_scope(name):
801801
offset = self.offset_layer.outputs
802802
assert offset.get_shape()[-1] == 2 * shape[0] * shape[1]
803803

@@ -987,7 +987,7 @@ def __init__(self,
987987
if act is None:
988988
act = tf.identity
989989
logging.info("AtrousConv2dLayer %s: n_filter:%d filter_size:%s rate:%d pad:%s act:%s" % (self.name, n_filter, filter_size, rate, padding, act.__name__))
990-
with tf.variable_scope(name) as vs:
990+
with tf.variable_scope(name):
991991
shape = [filter_size[0], filter_size[1], int(self.inputs.get_shape()[-1]), n_filter]
992992
filters = tf.get_variable(name='filter', shape=shape, initializer=W_init, dtype=D_TYPE, **W_init_args)
993993
if b_init:
@@ -1627,7 +1627,7 @@ def __init__(
16271627

16281628
assert len(strides) == 4, "len(strides) should be 4."
16291629

1630-
with tf.variable_scope(name) as vs:
1630+
with tf.variable_scope(name):
16311631
W = tf.get_variable(
16321632
name='W_sepconv2d', shape=shape, initializer=W_init, dtype=D_TYPE,
16331633
**W_init_args) # [filter_height, filter_width, in_channels, channel_multiplier]

tensorlayer/layers/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,10 +1323,10 @@ def __init__(
13231323
self.n_units = n_units
13241324
logging.info("DropconnectDenseLayer %s: %d %s" % (self.name, self.n_units, act.__name__))
13251325

1326-
with tf.variable_scope(name) as vs:
1326+
with tf.variable_scope(name):
13271327
W = tf.get_variable(name='W', shape=(n_in, n_units), initializer=W_init, dtype=D_TYPE, **W_init_args)
13281328
b = tf.get_variable(name='b', shape=(n_units), initializer=b_init, dtype=D_TYPE, **b_init_args)
1329-
self.outputs = act(tf.matmul(self.inputs, W) + b) #, name=name) # 1.2
1329+
self.outputs = act(tf.matmul(self.inputs, W) + b)
13301330

13311331
set_keep[name] = tf.placeholder(tf.float32)
13321332
W_dropcon = tf.nn.dropout(W, set_keep[name])

tensorlayer/layers/recurrent.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ def __init__(
10621062

10631063
# Apply dropout
10641064
if dropout:
1065-
if type(dropout) in [tuple, list]:
1065+
if isinstance(dropout, (tuple, list)):
10661066
in_keep_prob = dropout[0]
10671067
out_keep_prob = dropout[1]
10681068
elif isinstance(dropout, float):
@@ -1311,7 +1311,7 @@ def __init__(
13111311

13121312
# Apply dropout
13131313
if dropout:
1314-
if type(dropout) in [tuple, list]:
1314+
if isinstance(dropout, (tuple, list)):
13151315
in_keep_prob = dropout[0]
13161316
out_keep_prob = dropout[1]
13171317
elif isinstance(dropout, float):
@@ -1445,7 +1445,7 @@ class Seq2Seq(Layer):
14451445
A TensorFlow core RNN cell
14461446
- see `RNN Cells in TensorFlow <https://www.tensorflow.org/api_docs/python/>`__
14471447
- Note TF1.0+ and TF1.0- are different
1448-
cell_init_args : dictionary
1448+
cell_init_args : dictionary or None
14491449
The arguments for the cell initializer.
14501450
n_hidden : int
14511451
The number of hidden units in the layer.
@@ -1540,7 +1540,7 @@ def __init__(
15401540
net_encode_in,
15411541
net_decode_in,
15421542
cell_fn, #tf.nn.rnn_cell.LSTMCell,
1543-
cell_init_args={'state_is_tuple': True},
1543+
cell_init_args=None,
15441544
n_hidden=256,
15451545
initializer=tf.random_uniform_initializer(-0.1, 0.1),
15461546
encode_sequence_length=None,
@@ -1552,6 +1552,9 @@ def __init__(
15521552
return_seq_2d=False,
15531553
name='seq2seq',
15541554
):
1555+
if cell_init_args is None:
1556+
cell_init_args = {'state_is_tuple': True}
1557+
15551558
Layer.__init__(self, name=name)
15561559
if cell_fn is None:
15571560
raise Exception("Please put in cell_fn")

tensorlayer/prepro.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2651,7 +2651,7 @@ def _get_coord(coord):
26512651

26522652
coords_new = list()
26532653
classes_new = list()
2654-
for i in range(len(coords)):
2654+
for i, _ in enumerate(coords):
26552655
coord = coords[i]
26562656
assert len(coord) == 4, "coordinate should be 4 values : [x, y, w, h]"
26572657
if is_rescale:
@@ -2794,7 +2794,7 @@ def _get_coord(coord):
27942794

27952795
coords_new = list()
27962796
classes_new = list()
2797-
for i in range(len(coords)):
2797+
for i, _ in enumerate(coords):
27982798
coord = coords[i]
27992799
assert len(coord) == 4, "coordinate should be 4 values : [x, y, w, h]"
28002800
if is_rescale:
@@ -3010,7 +3010,7 @@ def sequences_add_start_id(sequences, start_id=0, remove_last=False):
30103010
30113011
"""
30123012
sequences_out = [[] for _ in range(len(sequences))] #[[]] * len(sequences)
3013-
for i in range(len(sequences)):
3013+
for i, _ in enumerate(sequences):
30143014
if remove_last:
30153015
sequences_out[i] = [start_id] + sequences[i][:-1]
30163016
else:
@@ -3041,7 +3041,7 @@ def sequences_add_end_id(sequences, end_id=888):
30413041
30423042
"""
30433043
sequences_out = [[] for _ in range(len(sequences))] #[[]] * len(sequences)
3044-
for i in range(len(sequences)):
3044+
for i, _ in enumerate(sequences):
30453045
sequences_out[i] = sequences[i] + [end_id]
30463046
return sequences_out
30473047

0 commit comments

Comments
 (0)