diff --git a/example/tutorial_cifar10_tfrecord.py b/example/tutorial_cifar10_tfrecord.py index 55e6834b0..720c47bfc 100644 --- a/example/tutorial_cifar10_tfrecord.py +++ b/example/tutorial_cifar10_tfrecord.py @@ -45,7 +45,6 @@ # import numpy as np import tensorflow as tf import tensorlayer as tl -# from PIL import Image from tensorlayer.layers import * model_file_name = "model_cifar10_tfrecord.ckpt" diff --git a/example/tutorial_frozenlake_dqn.py b/example/tutorial_frozenlake_dqn.py index ef323e3dc..f27306c9b 100644 --- a/example/tutorial_frozenlake_dqn.py +++ b/example/tutorial_frozenlake_dqn.py @@ -26,10 +26,6 @@ """ -import time -import gym -import numpy as np -import tensorflow as tf import tensorlayer as tl from tensorlayer.layers import * diff --git a/example/tutorial_vgg16.py b/example/tutorial_vgg16.py index 933732de0..551fc4cc5 100644 --- a/example/tutorial_vgg16.py +++ b/example/tutorial_vgg16.py @@ -166,11 +166,9 @@ def conv_layers(net_in): def conv_layers_simple_api(net_in): with tf.name_scope('preprocess'): - """ - Notice that we include a preprocessing layer that takes the RGB image - with pixels values in the range of 0-255 and subtracts the mean image - values (calculated over the entire ImageNet training set). - """ + # Notice that we include a preprocessing layer that takes the RGB image + # with pixels values in the range of 0-255 and subtracts the mean image + # values (calculated over the entire ImageNet training set). mean = tf.constant([123.68, 116.779, 103.939], dtype=tf.float32, shape=[1, 1, 1, 3], name='img_mean') net_in.outputs = net_in.outputs - mean diff --git a/tensorlayer/files.py b/tensorlayer/files.py index d88099557..afd3c96b1 100644 --- a/tensorlayer/files.py +++ b/tensorlayer/files.py @@ -802,7 +802,6 @@ def load_celebA_dataset(path='data'): The path that the data is downloaded to, defaults is ``data/celebA/``. """ - import zipfile, os data_dir = 'celebA' filename, drive_id = "img_align_celeba.zip", "0B7EVK8r0v71pZjFTYXZWM3FlRnM" save_path = os.path.join(path, filename) @@ -1496,14 +1495,10 @@ def load_npy_to_any(path='', name='file.npy'): """ file_path = os.path.join(path, name) try: - npy = np.load(file_path).item() + return np.load(file_path).item() except Exception: - npy = np.load(file_path) - finally: - try: - return npy - except Exception: - raise Exception("[!] Fail to load %s" % file_path) + return np.load(file_path) + raise Exception("[!] Fail to load %s" % file_path) def file_exists(filepath): diff --git a/tensorlayer/layers/convolution.py b/tensorlayer/layers/convolution.py index ab109798a..ce14ac931 100644 --- a/tensorlayer/layers/convolution.py +++ b/tensorlayer/layers/convolution.py @@ -64,7 +64,7 @@ def __init__( self.inputs = layer.outputs logging.info("Conv1dLayer %s: shape:%s stride:%s pad:%s act:%s" % (self.name, str(shape), str(stride), padding, act.__name__)) - with tf.variable_scope(name): # as vs: + with tf.variable_scope(name): W = tf.get_variable(name='W_conv1d', shape=shape, initializer=W_init, dtype=D_TYPE, **W_init_args) self.outputs = tf.nn.convolution( self.inputs, W, strides=(stride, ), padding=padding, dilation_rate=(dilation_rate, ), data_format=data_format) # 1.2 @@ -447,7 +447,7 @@ def __init__( logging.info("DeConv3dLayer %s: shape:%s out_shape:%s strides:%s pad:%s act:%s" % (self.name, str(shape), str(output_shape), str(strides), padding, act.__name__)) - with tf.variable_scope(name) as vs: + with tf.variable_scope(name): W = tf.get_variable(name='W_deconv3d', shape=shape, initializer=W_init, dtype=D_TYPE, **W_init_args) b = tf.get_variable(name='b_deconv3d', shape=(shape[-2]), initializer=b_init, dtype=D_TYPE, **b_init_args) diff --git a/tensorlayer/layers/core.py b/tensorlayer/layers/core.py index 5d3a6608f..3bcf70173 100644 --- a/tensorlayer/layers/core.py +++ b/tensorlayer/layers/core.py @@ -1245,7 +1245,7 @@ def __init__( else: self.inputs = layer.outputs logging.info("GaussianNoiseLayer %s: mean:%f stddev:%f" % (self.name, mean, stddev)) - with tf.variable_scope(name) as vs: + with tf.variable_scope(name): # noise = np.random.normal(0.0 , sigma , tf.to_int64(self.inputs).get_shape()) noise = tf.random_normal(shape=self.inputs.get_shape(), mean=mean, stddev=stddev, seed=seed) self.outputs = self.inputs + noise diff --git a/tensorlayer/layers/recurrent.py b/tensorlayer/layers/recurrent.py index d7936b8bf..5269aff54 100644 --- a/tensorlayer/layers/recurrent.py +++ b/tensorlayer/layers/recurrent.py @@ -367,7 +367,7 @@ def __init__( rnn_creator = lambda: cell_fn(num_units=n_hidden, **cell_init_args) # Apply dropout if dropout: - if type(dropout) in [tuple, list]: + if isinstance(dropout, (tuple, list)): # type(dropout) in [tuple, list]: in_keep_prob = dropout[0] out_keep_prob = dropout[1] elif isinstance(dropout, float): @@ -1256,7 +1256,7 @@ def __init__( self, layer, 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), sequence_length=None, @@ -1269,6 +1269,8 @@ def __init__( dynamic_rnn_init_args=None, name='bi_dyrnn_layer', ): + if cell_init_args is None: + cell_init_args = {'state_is_tuple': True} if dynamic_rnn_init_args is None: dynamic_rnn_init_args = {} diff --git a/tensorlayer/prepro.py b/tensorlayer/prepro.py index 133ed4a36..af4d5d423 100644 --- a/tensorlayer/prepro.py +++ b/tensorlayer/prepro.py @@ -2511,7 +2511,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: @@ -2915,7 +2915,7 @@ def remove_pad_sequences(sequences, pad_id=0): """ import copy sequences_out = copy.deepcopy(sequences) - for i in range(len(sequences)): + for i, _ in enumerate(sequences): # for j in range(len(sequences[i])): # if sequences[i][j] == pad_id: # sequences_out[i] = sequences_out[i][:j]