Skip to content

Commit 76fc874

Browse files
authored
Merge pull request #130 from boscotsang/patch-2
Arg seed for DropoutLayer & GaussianNoiseLayer
2 parents 3036ccd + b1a7e68 commit 76fc874

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

tensorlayer/layers.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,8 @@ class DropoutLayer(Layer):
903903
Default False, if True, the keeping probability is fixed and cannot be changed via feed_dict.
904904
is_train : boolean
905905
If False, skip this layer, default is True.
906+
seed : int or None
907+
An integer or None to create random seed.
906908
name : a string or None
907909
An optional name to attach to this layer.
908910
@@ -939,6 +941,7 @@ def __init__(
939941
keep = 0.5,
940942
is_fix = False,
941943
is_train = True,
944+
seed = None,
942945
name = 'dropout_layer',
943946
):
944947
Layer.__init__(self, name=name)
@@ -955,10 +958,10 @@ def __init__(
955958
# The name of placeholder for keep_prob is the same with the name
956959
# of the Layer.
957960
if is_fix:
958-
self.outputs = tf.nn.dropout(self.inputs, keep, name=name)
961+
self.outputs = tf.nn.dropout(self.inputs, keep, seed=seed, name=name)
959962
else:
960963
set_keep[name] = tf.placeholder(tf.float32)
961-
self.outputs = tf.nn.dropout(self.inputs, set_keep[name], name=name) # 1.2
964+
self.outputs = tf.nn.dropout(self.inputs, set_keep[name], seed=seed, name=name) # 1.2
962965

963966
self.all_layers = list(layer.all_layers)
964967
self.all_params = list(layer.all_params)
@@ -997,6 +1000,8 @@ class GaussianNoiseLayer(Layer):
9971000
stddev : float
9981001
is_train : boolean
9991002
If False, skip this layer, default is True.
1003+
seed : int or None
1004+
An integer or None to create random seed.
10001005
name : a string or None
10011006
An optional name to attach to this layer.
10021007
"""
@@ -1020,7 +1025,7 @@ def __init__(
10201025
print(" [TL] GaussianNoiseLayer %s: mean:%f stddev:%f" % (self.name, mean, stddev))
10211026
with tf.variable_scope(name) as vs:
10221027
# noise = np.random.normal(0.0 , sigma , tf.to_int64(self.inputs).get_shape())
1023-
noise = tf.random_normal(shape = self.inputs.get_shape(), mean=mean, stddev=stddev)
1028+
noise = tf.random_normal(shape = self.inputs.get_shape(), mean=mean, stddev=stddev, seed=seed)
10241029
self.outputs = self.inputs + noise
10251030
self.all_layers = list(layer.all_layers)
10261031
self.all_params = list(layer.all_params)

0 commit comments

Comments
 (0)