Skip to content

Commit 6d5b199

Browse files
committed
fix many pylint issues.
1 parent e382a7f commit 6d5b199

13 files changed

+69
-123
lines changed

example/tutorial_bipedalwalker_a3c_continuous_action.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def work(self):
210210
self.AC.v_target: buffer_v_target,
211211
}
212212
# update gradients on global network
213-
test = self.AC.update_global(feed_dict)
213+
self.AC.update_global(feed_dict)
214214
buffer_s, buffer_a, buffer_r = [], [], []
215215

216216
# update local network from global network

example/tutorial_imagenet_inceptionV3_distributed.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,12 @@ def calculate_metrics(predicted_batch, real_batch, threshold=0.5, is_training=Fa
288288
def run_evaluator(task_spec, checkpoints_path, batch_size=32):
289289
with tf.Graph().as_default():
290290
# load dataset
291-
images_input, one_hot_classes, num_classes, dataset_size = \
291+
images_input, one_hot_classes, num_classes, _dataset_size = \
292292
load_data(file=VAL_FILE,
293293
task_spec=task_spec,
294294
batch_size=batch_size,
295295
epochs=1)
296-
network, predictions = build_network(images_input, num_classes=num_classes, is_training=False)
296+
_network, predictions = build_network(images_input, num_classes=num_classes, is_training=False)
297297
saver = tf.train.Saver()
298298
# metrics
299299
metrics_init_ops, _, metrics_ops = \

example/tutorial_vgg16.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949

5050
def conv_layers(net_in):
51-
with tf.name_scope('preprocess') as scope:
51+
with tf.name_scope('preprocess'):
5252
"""
5353
Notice that we include a preprocessing layer that takes the RGB image
5454
with pixels values in the range of 0-255 and subtracts the mean image

tensorlayer/db.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,8 @@ def find_one_job(self, args=None):
407407

408408
def push_job(self, margs, wargs, dargs, epoch):
409409

410-
ms, mid = self.load_model_architecture(margs)
411-
weight, wid = self.find_one_params(wargs)
410+
_ms, mid = self.load_model_architecture(margs)
411+
_weight, wid = self.find_one_params(wargs)
412412
args = {"weight": wid, "model": mid, "dargs": dargs, "epoch": epoch, "time": datetime.utcnow(), "Running": False}
413413
self.__autofill(args)
414414
self.db.JOBS.insert_one(args)

tensorlayer/files.py

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,8 +1171,8 @@ def save_npz(save_list=None, name='model.npz', sess=None):
11711171
save_list_var = sess.run(save_list)
11721172
else:
11731173
try:
1174-
for k, value in enumerate(save_list):
1175-
save_list_var.append(value.eval())
1174+
for _k, v in enumerate(save_list):
1175+
save_list_var.append(v.eval())
11761176
except Exception:
11771177
logging.info(" Fail to save model, Hint: pass the session into this function, tl.files.save_npz(network.all_params, name='model.npz', sess=sess)")
11781178
np.savez(name, params=save_list_var)
@@ -1351,60 +1351,6 @@ def load_and_assign_npz_dict(name='model.npz', sess=None):
13511351
logging.info("[*] Model restored from npz_dict %s" % name)
13521352

13531353

1354-
# def save_npz_dict(save_list=[], name='model.npz', sess=None):
1355-
# """Input parameters and the file name, save parameters as a dictionary into .npz file. Use tl.utils.load_npz_dict() to restore.
1356-
#
1357-
# Parameters
1358-
# ----------
1359-
# save_list : a list
1360-
# Parameters want to be saved.
1361-
# name : a string or None
1362-
# The name of the .npz file.
1363-
# sess : None or Session
1364-
#
1365-
# Notes
1366-
# -----
1367-
# This function tries to avoid a potential broadcasting error raised by numpy.
1368-
#
1369-
# """
1370-
# ## save params into a list
1371-
# save_list_var = []
1372-
# if sess:
1373-
# save_list_var = sess.run(save_list)
1374-
# else:
1375-
# try:
1376-
# for k, value in enumerate(save_list):
1377-
# save_list_var.append(value.eval())
1378-
# except:
1379-
# logging.info(" Fail to save model, Hint: pass the session into this function, save_npz_dict(network.all_params, name='model.npz', sess=sess)")
1380-
# save_var_dict = {str(idx):val for idx, val in enumerate(save_list_var)}
1381-
# np.savez(name, **save_var_dict)
1382-
# save_list_var = None
1383-
# save_var_dict = None
1384-
# del save_list_var
1385-
# del save_var_dict
1386-
# logging.info("[*] %s saved" % name)
1387-
#
1388-
# def load_npz_dict(path='', name='model.npz'):
1389-
# """Load the parameters of a Model saved by tl.files.save_npz_dict().
1390-
#
1391-
# Parameters
1392-
# ----------
1393-
# path : a string
1394-
# Folder path to .npz file.
1395-
# name : a string or None
1396-
# The name of the .npz file.
1397-
#
1398-
# Returns
1399-
# --------
1400-
# params : list
1401-
# A list of parameters in order.
1402-
# """
1403-
# d = np.load( path+name )
1404-
# saved_list_var = [val[1] for val in sorted(d.items(), key=lambda tup: int(tup[0]))]
1405-
# return saved_list_var
1406-
1407-
14081354
def save_ckpt(sess=None, mode_name='model.ckpt', save_dir='checkpoint', var_list=None, global_step=None, printable=False):
14091355
"""Save parameters into `ckpt` file.
14101356

tensorlayer/layers/convolution.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def __init__(
180180
act = tf.identity
181181
logging.info("Conv2dLayer %s: shape:%s strides:%s pad:%s act:%s" % (self.name, str(shape), str(strides), padding, act.__name__))
182182

183-
with tf.variable_scope(name) as vs:
183+
with tf.variable_scope(name):
184184
W = tf.get_variable(name='W_conv2d', shape=shape, initializer=W_init, dtype=D_TYPE, **W_init_args)
185185
if b_init:
186186
b = tf.get_variable(name='b_conv2d', shape=(shape[-1]), initializer=b_init, dtype=D_TYPE, **b_init_args)
@@ -511,7 +511,7 @@ def __init__(
511511
with tf.variable_scope(name) as vs:
512512
try:
513513
self.outputs = tf.image.resize_images(self.inputs, size=size, method=method, align_corners=align_corners)
514-
except: # for TF 0.10
514+
except Exception: # for TF 0.10
515515
self.outputs = tf.image.resize_images(self.inputs, new_height=size[0], new_width=size[1], method=method, align_corners=align_corners)
516516

517517
self.all_layers = list(layer.all_layers)
@@ -571,7 +571,7 @@ def __init__(
571571
with tf.variable_scope(name) as vs:
572572
try:
573573
self.outputs = tf.image.resize_images(self.inputs, size=size, method=method, align_corners=align_corners)
574-
except: # for TF 0.10
574+
except Exception: # for TF 0.10
575575
self.outputs = tf.image.resize_images(self.inputs, new_height=size[0], new_width=size[1], method=method, align_corners=align_corners)
576576

577577
self.all_layers = list(layer.all_layers)
@@ -792,7 +792,7 @@ def _tf_batch_map_offsets(inputs, offsets, grid_offset):
792792

793793
try:
794794
pre_channel = int(layer.outputs.get_shape()[-1])
795-
except: # if pre_channel is ?, it happens when using Spatial Transformer Net
795+
except Exception: # if pre_channel is ?, it happens when using Spatial Transformer Net
796796
pre_channel = 1
797797
logging.info("[warnings] unknow input channels, set to 1")
798798
shape = (filter_size[0], filter_size[1], pre_channel, n_filter)
@@ -1351,7 +1351,7 @@ def conv2d(
13511351

13521352
try:
13531353
pre_channel = int(layer.outputs.get_shape()[-1])
1354-
except: # if pre_channel is ?, it happens when using Spatial Transformer Net
1354+
except Exception: # if pre_channel is ?, it happens when using Spatial Transformer Net
13551355
pre_channel = 1
13561356
logging.info("[warnings] unknow input channels, set to 1")
13571357
return Conv2dLayer(
@@ -1616,7 +1616,7 @@ def __init__(
16161616
logging.info("DepthwiseConv2d %s: shape:%s strides:%s pad:%s act:%s" % (self.name, str(shape), str(strides), padding, act.__name__))
16171617
try:
16181618
pre_channel = int(layer.outputs.get_shape()[-1])
1619-
except: # if pre_channel is ?, it happens when using Spatial Transformer Net
1619+
except Exception: # if pre_channel is ?, it happens when using Spatial Transformer Net
16201620
pre_channel = 1
16211621
logging.info("[warnings] unknow input channels, set to 1")
16221622

tensorlayer/layers/core.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def get_variables_with_name(name=None, train_only=True, printable=False):
221221
else:
222222
try: # TF1.0+
223223
t_vars = tf.global_variables()
224-
except: # TF0.12
224+
except Exception: # TF0.12
225225
t_vars = tf.all_variables()
226226

227227
d_vars = [var for var in t_vars if name in var.name]
@@ -418,13 +418,13 @@ def print_layers(self):
418418
def count_params(self):
419419
"""Return the number of parameters in the network"""
420420
n_params = 0
421-
for i, p in enumerate(self.all_params):
421+
for _i, p in enumerate(self.all_params):
422422
n = 1
423423
# for s in p.eval().shape:
424424
for s in p.get_shape():
425425
try:
426426
s = int(s)
427-
except:
427+
except Exception:
428428
s = 1
429429
if s:
430430
n = n * s
@@ -610,14 +610,15 @@ def __init__(
610610
Layer.__init__(self, name=name)
611611
self.inputs = inputs
612612
logging.info("Word2vecEmbeddingInputlayer %s: (%d, %d)" % (self.name, vocabulary_size, embedding_size))
613+
613614
# Look up embeddings for inputs.
614615
# Note: a row of 'embeddings' is the vector representation of a word.
615616
# for the sake of speed, it is better to slice the embedding matrix
616617
# instead of transfering a word id to one-hot-format vector and then
617618
# multiply by the embedding matrix.
618619
# embed is the outputs of the hidden layer (embedding layer), it is a
619620
# row vector with 'embedding_size' values.
620-
with tf.variable_scope(name) as vs:
621+
with tf.variable_scope(name):
621622
embeddings = tf.get_variable(name='embeddings', shape=(vocabulary_size, embedding_size), initializer=E_init, dtype=D_TYPE, **E_init_args)
622623
embed = tf.nn.embedding_lookup(embeddings, self.inputs)
623624
# Construct the variables for the NCE loss (i.e. negative sampling)
@@ -878,7 +879,7 @@ def __init__(
878879
if b_init is not None:
879880
try:
880881
b = tf.get_variable(name='b', shape=(n_units), initializer=b_init, dtype=D_TYPE, **b_init_args)
881-
except: # If initializer is a constant, do not specify shape.
882+
except Exception: # If initializer is a constant, do not specify shape.
882883
b = tf.get_variable(name='b', initializer=b_init, dtype=D_TYPE, **b_init_args)
883884
self.outputs = act(tf.matmul(self.inputs, W) + b)
884885
else:
@@ -982,10 +983,11 @@ def __init__(
982983
L2_w = tf.contrib.layers.l2_regularizer(lambda_l2_w)(self.train_params[0]) \
983984
+ tf.contrib.layers.l2_regularizer(lambda_l2_w)(self.train_params[2]) # faster than the code below
984985
# L2_w = lambda_l2_w * tf.reduce_mean(tf.square(self.train_params[0])) + lambda_l2_w * tf.reduce_mean( tf.square(self.train_params[2]))
986+
985987
# DropNeuro
986-
P_o = cost.lo_regularizer(0.03)(
987-
self.train_params[0]) # + cost.lo_regularizer(0.5)(self.train_params[2]) # <haodong>: if add lo on decoder, no neuron will be broken
988-
P_i = cost.li_regularizer(0.03)(self.train_params[0]) # + cost.li_regularizer(0.001)(self.train_params[2])
988+
# P_o = cost.lo_regularizer(0.03)(
989+
# self.train_params[0]) # + cost.lo_regularizer(0.5)(self.train_params[2]) # <haodong>: if add lo on decoder, no neuron will be broken
990+
# P_i = cost.li_regularizer(0.03)(self.train_params[0]) # + cost.li_regularizer(0.001)(self.train_params[2])
989991

990992
# L1 of activation outputs
991993
activation_out = self.all_layers[-2]
@@ -1082,7 +1084,7 @@ def pretrain(self, sess, x, X_train, X_val, denoise_name=None, n_epoch=100, batc
10821084
visualize.draw_weights(
10831085
self.train_params[0].eval(), second=10, saveable=True, shape=[28, 28], name=save_name + str(epoch + 1), fig_idx=2012)
10841086
files.save_npz([self.all_params[0]], name=save_name + str(epoch + 1) + '.npz')
1085-
except:
1087+
except Exception:
10861088
raise Exception(
10871089
"You should change the visualize.W() in ReconLayer.pretrain(), if you want to save the feature images for different dataset")
10881090

tensorlayer/layers/extend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def __init__(
2929
self.inputs = layer.outputs
3030

3131
logging.info("ExpandDimsLayer %s: axis:%d" % (self.name, axis))
32-
with tf.variable_scope(name) as vs:
32+
with tf.variable_scope(name):
3333
try: # TF12 TF1.0
3434
self.outputs = tf.expand_dims(self.inputs, axis=axis)
3535
except Exception: # TF11

tensorlayer/layers/normalization.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,8 @@ def __init__(
9999
params_shape = x_shape[-1:]
100100

101101
from tensorflow.python.training import moving_averages
102-
from tensorflow.python.ops import control_flow_ops
103102

104-
with tf.variable_scope(name) as vs:
103+
with tf.variable_scope(name):
105104
axis = list(range(len(x_shape) - 1))
106105

107106
# 1. beta, gamma

0 commit comments

Comments
 (0)