In Tensorflow, is there a way to set a seed at the session level?

风格不统一 提交于 2019-12-10 19:30:43

问题


I'm trying to get repeatable results when running a session, but want to change the seed freely between sessions. Something like this:

a = tf.random_uniform([1])

#Set seed here to e.g. 123
with tf.Session() as sess:
   print(sess.run(a)) #Output: A1
   print(sess.run(a)) #Output: A2

#Set seed here to e.g. 42
with tf.Session() as sess:
   print(sess.run(a)) #Output: A3
   print(sess.run(a)) #Output: A4

#Set seed here to e.g. 123
with tf.Session() as sess:
   print(sess.run(a)) #Output: A1
   print(sess.run(a)) #Output: A2

If I understood the set_random_seed page correctly, the method seems to set the seed at the graph level, so between session the results will be the same. In fact, according to that page, it only seems possible to:

  • Make the run not reproducible
  • Make single operations reproducible, without possibility to change between sessions (by setting the seed of the operation directly)
  • Make all operations reproducible, without possibility to change between sessions (by using set_random_seed)

I could not find any way to flexibly change the seed without having to rebuild the graph. Any pointers to the right solution would be highly appreciated.

来源:https://stackoverflow.com/questions/55162685/in-tensorflow-is-there-a-way-to-set-a-seed-at-the-session-level

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!