Reproducible results in Tensorflow with tf.set_random_seed

后端 未结 7 1758
死守一世寂寞
死守一世寂寞 2020-11-28 13:28

I am trying to generate N sets of independent random numbers. I have a simple code that shows the problem for 3 sets of 10 random numbers. I notice that even though I use th

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-28 14:02

    I noticed that you want to have 3 different vectors containing random numbers. Every time you want to run the code you want these three vectors containing random numbers to be the same as the first time. This approach is completely explainable, why need four the same random vectors. You want to have 4 random vectors each other.

    There are two types of seeds that you can set when defining chart operations: Grain at the chart level, which is set by tf.set_random_seed, and seeds at the operational level, which are placed in the initializer variable As the grain is at the chart level, each time the result is different. You must use tf.InteractiveSession ()

    tf.set_random_seed(1234)
    
    sess = tf.InteractiveSession()
    print(sess.run(tf.random_uniform((10,), 0, 10, seed=1)))
    print(sess.run(tf.random_uniform((10,), 0, 10, seed=2)))
    print(sess.run(tf.random_uniform((10,), 0, 10, seed=3)))
    print(sess.run(tf.random_uniform((10,), 0, 10, seed=4)))
    

    You get 4 random number vectors containing numbers from 0 to 10.

提交回复
热议问题