Skip to content

Instantly share code, notes, and snippets.

@tnq177
Last active May 11, 2020 09:21
Show Gist options
  • Save tnq177/ce34bcf6b20243b0b5b23c78833e7945 to your computer and use it in GitHub Desktop.
Save tnq177/ce34bcf6b20243b0b5b23c78833e7945 to your computer and use it in GitHub Desktop.
Tensorflow global random seed
tf.reset_default_graph()
with tf.Graph().as_default():
    tf.set_random_seed(42)
    
    with tf.Session() as sess:
        ...define graph here...
  • Must reset default graph before defining graph & must set random seed before creating session.
  • Some GPU ops are not fully deterministic
  • Some said setting the graph seed is not enough, and op seed is also required, but so far just graph seed works for me
  • ref: http://stackoverflow.com/a/40247201/2005810
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment