Skip to content

Commit 7c9d5d9

Browse files
zsdonghaoluomai
authored andcommitted
Fix remaining issues. (#359)
* fixed example * fixed dict and vs * fix issues * fix bug * format
1 parent ff89160 commit 7c9d5d9

File tree

8 files changed

+15
-25
lines changed

8 files changed

+15
-25
lines changed

example/tutorial_cifar10_tfrecord.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
# import numpy as np
4646
import tensorflow as tf
4747
import tensorlayer as tl
48-
# from PIL import Image
4948
from tensorlayer.layers import *
5049

5150
model_file_name = "model_cifar10_tfrecord.ckpt"

example/tutorial_frozenlake_dqn.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@
2626
2727
"""
2828

29-
import time
30-
import gym
31-
import numpy as np
32-
import tensorflow as tf
3329
import tensorlayer as tl
3430
from tensorlayer.layers import *
3531

example/tutorial_vgg16.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,9 @@ def conv_layers(net_in):
166166

167167
def conv_layers_simple_api(net_in):
168168
with tf.name_scope('preprocess'):
169-
"""
170-
Notice that we include a preprocessing layer that takes the RGB image
171-
with pixels values in the range of 0-255 and subtracts the mean image
172-
values (calculated over the entire ImageNet training set).
173-
"""
169+
# Notice that we include a preprocessing layer that takes the RGB image
170+
# with pixels values in the range of 0-255 and subtracts the mean image
171+
# values (calculated over the entire ImageNet training set).
174172
mean = tf.constant([123.68, 116.779, 103.939], dtype=tf.float32, shape=[1, 1, 1, 3], name='img_mean')
175173
net_in.outputs = net_in.outputs - mean
176174

tensorlayer/files.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,6 @@ def load_celebA_dataset(path='data'):
802802
The path that the data is downloaded to, defaults is ``data/celebA/``.
803803
804804
"""
805-
import zipfile, os
806805
data_dir = 'celebA'
807806
filename, drive_id = "img_align_celeba.zip", "0B7EVK8r0v71pZjFTYXZWM3FlRnM"
808807
save_path = os.path.join(path, filename)
@@ -1496,14 +1495,10 @@ def load_npy_to_any(path='', name='file.npy'):
14961495
"""
14971496
file_path = os.path.join(path, name)
14981497
try:
1499-
npy = np.load(file_path).item()
1498+
return np.load(file_path).item()
15001499
except Exception:
1501-
npy = np.load(file_path)
1502-
finally:
1503-
try:
1504-
return npy
1505-
except Exception:
1506-
raise Exception("[!] Fail to load %s" % file_path)
1500+
return np.load(file_path)
1501+
raise Exception("[!] Fail to load %s" % file_path)
15071502

15081503

15091504
def file_exists(filepath):

tensorlayer/layers/convolution.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def __init__(
6464
self.inputs = layer.outputs
6565
logging.info("Conv1dLayer %s: shape:%s stride:%s pad:%s act:%s" % (self.name, str(shape), str(stride), padding, act.__name__))
6666

67-
with tf.variable_scope(name): # as vs:
67+
with tf.variable_scope(name):
6868
W = tf.get_variable(name='W_conv1d', shape=shape, initializer=W_init, dtype=D_TYPE, **W_init_args)
6969
self.outputs = tf.nn.convolution(
7070
self.inputs, W, strides=(stride, ), padding=padding, dilation_rate=(dilation_rate, ), data_format=data_format) # 1.2
@@ -447,7 +447,7 @@ def __init__(
447447
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,
448448
act.__name__))
449449

450-
with tf.variable_scope(name) as vs:
450+
with tf.variable_scope(name):
451451
W = tf.get_variable(name='W_deconv3d', shape=shape, initializer=W_init, dtype=D_TYPE, **W_init_args)
452452
b = tf.get_variable(name='b_deconv3d', shape=(shape[-2]), initializer=b_init, dtype=D_TYPE, **b_init_args)
453453

tensorlayer/layers/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ def __init__(
12451245
else:
12461246
self.inputs = layer.outputs
12471247
logging.info("GaussianNoiseLayer %s: mean:%f stddev:%f" % (self.name, mean, stddev))
1248-
with tf.variable_scope(name) as vs:
1248+
with tf.variable_scope(name):
12491249
# noise = np.random.normal(0.0 , sigma , tf.to_int64(self.inputs).get_shape())
12501250
noise = tf.random_normal(shape=self.inputs.get_shape(), mean=mean, stddev=stddev, seed=seed)
12511251
self.outputs = self.inputs + noise

tensorlayer/layers/recurrent.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ def __init__(
367367
rnn_creator = lambda: cell_fn(num_units=n_hidden, **cell_init_args)
368368
# Apply dropout
369369
if dropout:
370-
if type(dropout) in [tuple, list]:
370+
if isinstance(dropout, (tuple, list)): # type(dropout) in [tuple, list]:
371371
in_keep_prob = dropout[0]
372372
out_keep_prob = dropout[1]
373373
elif isinstance(dropout, float):
@@ -1256,7 +1256,7 @@ def __init__(
12561256
self,
12571257
layer,
12581258
cell_fn, #tf.nn.rnn_cell.LSTMCell,
1259-
cell_init_args={'state_is_tuple': True},
1259+
cell_init_args=None,
12601260
n_hidden=256,
12611261
initializer=tf.random_uniform_initializer(-0.1, 0.1),
12621262
sequence_length=None,
@@ -1269,6 +1269,8 @@ def __init__(
12691269
dynamic_rnn_init_args=None,
12701270
name='bi_dyrnn_layer',
12711271
):
1272+
if cell_init_args is None:
1273+
cell_init_args = {'state_is_tuple': True}
12721274
if dynamic_rnn_init_args is None:
12731275
dynamic_rnn_init_args = {}
12741276

tensorlayer/prepro.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2511,7 +2511,7 @@ def _get_coord(coord):
25112511

25122512
coords_new = list()
25132513
classes_new = list()
2514-
for i in range(len(coords)):
2514+
for i, _ in enumerate(coords):
25152515
coord = coords[i]
25162516
assert len(coord) == 4, "coordinate should be 4 values : [x, y, w, h]"
25172517
if is_rescale:
@@ -2915,7 +2915,7 @@ def remove_pad_sequences(sequences, pad_id=0):
29152915
"""
29162916
import copy
29172917
sequences_out = copy.deepcopy(sequences)
2918-
for i in range(len(sequences)):
2918+
for i, _ in enumerate(sequences):
29192919
# for j in range(len(sequences[i])):
29202920
# if sequences[i][j] == pad_id:
29212921
# sequences_out[i] = sequences_out[i][:j]

0 commit comments

Comments
 (0)