Reproducible results in Tensorflow with tf.set_random_seed

后端 未结 7 1734
死守一世寂寞
死守一世寂寞 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:16

    Adding this answer for reference: The problem of the reproducible result might not come directly from TensorFlow but from the underlying platform. See this issue on Keras

    In case of running on an Nvidia GPU, there is a lib from Nvidia that helps to get deterministic results: tensorflow-determinism

    pip install tensorflow-determinism
    

    and you use it like this:

    import tensorflow as tf
    import os
    os.environ['TF_DETERMINISTIC_OPS'] = '1'
    

    and it's still recommended to add these fields:

    SEED = 123
    os.environ['PYTHONHASHSEED']=str(SEED)
    random.seed(SEED)
    np.random.seed(SEED)
    tf.random.set_seed(SEED)
    

    For Tensorflow < 2.1, add above and this:

    from tfdeterminism import patch
    patch()
    
    0 讨论(0)
提交回复
热议问题