Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion example/tutorial_cifar10_tfrecord.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 0 additions & 4 deletions example/tutorial_frozenlake_dqn.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@

"""

import time
import gym
import numpy as np
import tensorflow as tf
import tensorlayer as tl
from tensorlayer.layers import *

Expand Down
8 changes: 3 additions & 5 deletions example/tutorial_vgg16.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 3 additions & 8 deletions tensorlayer/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions tensorlayer/layers/convolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion tensorlayer/layers/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions tensorlayer/layers/recurrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand All @@ -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 = {}

Expand Down
4 changes: 2 additions & 2 deletions tensorlayer/prepro.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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]
Expand Down