Tensorflow`set_random_seed`无法正常工作
发布于 2021-01-29 17:20:05
通话tf.set_random_seed(SEED)
没有影响,我可以告诉…
例如, 在IPython笔记本中 多次 在 下面运行以下代码会每次产生不同的输出:
import tensorflow as tf
tf.set_random_seed(42)
sess = tf.InteractiveSession()
a = tf.constant([1, 2, 3, 4, 5])
tf.initialize_all_variables().run()
a_shuf = tf.random_shuffle(a)
print(a.eval())
print(a_shuf.eval())
sess.close()
如果我显式设置种子:a_shuf = tf.random_shuffle(a,
seed=42)
,则每次运行后输出都是相同的。但是,如果我已经打电话,为什么还要设置种子tf.set_random_seed(42)
?
使用numpy的等效代码仅适用于:
import numpy as np
np.random.seed(42)
a = [1,2,3,4,5]
np.random.shuffle(a)
print(a)
关注者
0
被浏览
82