Skip to content

Commit

Permalink
Merge pull request #361 from tensorlayer/codacy4
Browse files Browse the repository at this point in the history
fix pylint issues
  • Loading branch information
lgarithm authored Feb 24, 2018
2 parents d3c79b6 + 3086690 commit 91cc03d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
10 changes: 5 additions & 5 deletions tensorlayer/layers/convolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ def __init__(
else:
raise Exception("Donot support shape %s" % self.inputs.get_shape())
logging.info("UpSampling2dLayer %s: is_scale:%s size:%s method:%d align_corners:%s" % (name, is_scale, size, method, align_corners))
with tf.variable_scope(name) as vs:
with tf.variable_scope(name):
try:
self.outputs = tf.image.resize_images(self.inputs, size=size, method=method, align_corners=align_corners)
except Exception: # for TF 0.10
Expand Down Expand Up @@ -568,7 +568,7 @@ def __init__(
else:
raise Exception("Donot support shape %s" % self.inputs.get_shape())
logging.info("DownSampling2dLayer %s: is_scale:%s size:%s method:%d, align_corners:%s" % (name, is_scale, size, method, align_corners))
with tf.variable_scope(name) as vs:
with tf.variable_scope(name):
try:
self.outputs = tf.image.resize_images(self.inputs, size=size, method=method, align_corners=align_corners)
except Exception: # for TF 0.10
Expand Down Expand Up @@ -797,7 +797,7 @@ def _tf_batch_map_offsets(inputs, offsets, grid_offset):
logging.info("[warnings] unknow input channels, set to 1")
shape = (filter_size[0], filter_size[1], pre_channel, n_filter)

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

Expand Down Expand Up @@ -987,7 +987,7 @@ def __init__(self,
if act is None:
act = tf.identity
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__))
with tf.variable_scope(name) as vs:
with tf.variable_scope(name):
shape = [filter_size[0], filter_size[1], int(self.inputs.get_shape()[-1]), n_filter]
filters = tf.get_variable(name='filter', shape=shape, initializer=W_init, dtype=D_TYPE, **W_init_args)
if b_init:
Expand Down Expand Up @@ -1627,7 +1627,7 @@ def __init__(

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

with tf.variable_scope(name) as vs:
with tf.variable_scope(name):
W = tf.get_variable(
name='W_sepconv2d', shape=shape, initializer=W_init, dtype=D_TYPE,
**W_init_args) # [filter_height, filter_width, in_channels, channel_multiplier]
Expand Down
4 changes: 2 additions & 2 deletions tensorlayer/layers/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1323,10 +1323,10 @@ def __init__(
self.n_units = n_units
logging.info("DropconnectDenseLayer %s: %d %s" % (self.name, self.n_units, act.__name__))

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

set_keep[name] = tf.placeholder(tf.float32)
W_dropcon = tf.nn.dropout(W, set_keep[name])
Expand Down
11 changes: 7 additions & 4 deletions tensorlayer/layers/recurrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ def __init__(

# Apply dropout
if dropout:
if type(dropout) in [tuple, list]:
if isinstance(dropout, (tuple, list)):
in_keep_prob = dropout[0]
out_keep_prob = dropout[1]
elif isinstance(dropout, float):
Expand Down Expand Up @@ -1311,7 +1311,7 @@ def __init__(

# Apply dropout
if dropout:
if type(dropout) in [tuple, list]:
if isinstance(dropout, (tuple, list)):
in_keep_prob = dropout[0]
out_keep_prob = dropout[1]
elif isinstance(dropout, float):
Expand Down Expand Up @@ -1445,7 +1445,7 @@ class Seq2Seq(Layer):
A TensorFlow core RNN cell
- see `RNN Cells in TensorFlow <https://www.tensorflow.org/api_docs/python/>`__
- Note TF1.0+ and TF1.0- are different
cell_init_args : dictionary
cell_init_args : dictionary or None
The arguments for the cell initializer.
n_hidden : int
The number of hidden units in the layer.
Expand Down Expand Up @@ -1540,7 +1540,7 @@ def __init__(
net_encode_in,
net_decode_in,
cell_fn, #tf.nn.rnn_cell.LSTMCell,
cell_init_args={'state_is_tuple': True},
cell_init_args=None,
n_hidden=256,
initializer=tf.random_uniform_initializer(-0.1, 0.1),
encode_sequence_length=None,
Expand All @@ -1552,6 +1552,9 @@ def __init__(
return_seq_2d=False,
name='seq2seq',
):
if cell_init_args is None:
cell_init_args = {'state_is_tuple': True}

Layer.__init__(self, name=name)
if cell_fn is None:
raise Exception("Please put in cell_fn")
Expand Down
8 changes: 4 additions & 4 deletions tensorlayer/prepro.py
Original file line number Diff line number Diff line change
Expand Up @@ -2651,7 +2651,7 @@ def _get_coord(coord):

coords_new = list()
classes_new = list()
for i in range(len(coords)):
for i, _ in enumerate(coords):
coord = coords[i]
assert len(coord) == 4, "coordinate should be 4 values : [x, y, w, h]"
if is_rescale:
Expand Down Expand Up @@ -2794,7 +2794,7 @@ def _get_coord(coord):

coords_new = list()
classes_new = list()
for i in range(len(coords)):
for i, _ in enumerate(coords):
coord = coords[i]
assert len(coord) == 4, "coordinate should be 4 values : [x, y, w, h]"
if is_rescale:
Expand Down Expand Up @@ -3010,7 +3010,7 @@ def sequences_add_start_id(sequences, start_id=0, remove_last=False):
"""
sequences_out = [[] for _ in range(len(sequences))] #[[]] * len(sequences)
for i in range(len(sequences)):
for i, _ in enumerate(sequences):
if remove_last:
sequences_out[i] = [start_id] + sequences[i][:-1]
else:
Expand Down Expand Up @@ -3041,7 +3041,7 @@ def sequences_add_end_id(sequences, end_id=888):
"""
sequences_out = [[] for _ in range(len(sequences))] #[[]] * len(sequences)
for i in range(len(sequences)):
for i, _ in enumerate(sequences):
sequences_out[i] = sequences[i] + [end_id]
return sequences_out

Expand Down

0 comments on commit 91cc03d

Please sign in to comment.