Python tf.set_random_seed不';似乎没有正确地播种
我遇到了一个问题,在python上使用Tensorflow编程时,Python tf.set_random_seed不';似乎没有正确地播种,python,tensorflow,random,Python,Tensorflow,Random,我遇到了一个问题,在python上使用Tensorflow编程时,tf.set\u random\u seed无法生成可重复的值。具体来说, import tensorflow as tf sd = 1 tf.set_random_seed(seed = sd) tf.reset_default_graph() sess = tf.InteractiveSession() print(sess.run(tf.random_normal(shape=[1], mean=0, stddev=1))
tf.set\u random\u seed
无法生成可重复的值。具体来说,
import tensorflow as tf
sd = 1
tf.set_random_seed(seed = sd)
tf.reset_default_graph()
sess = tf.InteractiveSession()
print(sess.run(tf.random_normal(shape=[1], mean=0, stddev=1)))
上述代码输出[1.3086201]
。然后我再次运行了整个代码,它没有输出预期的值[1.3086201]
,而是给出了一个新的[-2.1209881]
为什么会发生这种情况以及如何设置Tensorflow种子?定义图形操作时,可以设置两种类型的种子:
tf.set\u random\u seed
设置的图形级种子,以及tf.random\u normal
,因此它是不同的
如果希望
tf.random\u normal
生成相同的唯一序列,则无论重新初始化多少次,都应设置操作级别种子
sess = tf.InteractiveSession()
print(sess.run(tf.random_normal(shape=[1], mean=0, stddev=1, seed=1)))
# -0.8113182
print(sess.run(tf.random_normal(shape=[1], mean=0, stddev=1, seed=1)))
# -0.8113182
尚
tf.reset\u default\u graph()的可能重复项清除操作中的手动随机种子