Issue
In a general tensorflow setup like
model = construct_model()
with tf.Session() as sess:
train_model(sess)
Where construct_model()
contains the model definition including random initialization of weights (tf.truncated_normal
) and train_model(sess)
executes the training of the model -
Which seeds do I have to set where to ensure 100% reproducibility between repeated runs of the code snippet above? The documentation for tf.random.set_random_seed
may be concise, but left me a bit confused. I tried:
tf.set_random_seed(1234)
model = construct_model()
with tf.Session() as sess:
train_model(sess)
But got different results each time.
Solution
The best solution which works as of today with GPU is to install tensorflow-determinism with the following:
pip install tensorflow-determinism
Then include the following code to your code
import tensorflow as tf
import os
os.environ['TF_DETERMINISTIC_OPS'] = '1'
source: https://github.com/NVIDIA/tensorflow-determinism
Answered By - eugen
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.