问题
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