必须设置哪些种子才能在 tensorflow 中实现 100% 的训练结果可重复性? [英] Which seeds have to be set where to realize 100% reproducibility of training results in tensorflow?
问题描述
在一般的 tensorflow 设置中,如
model =construct_model()使用 tf.Session() 作为 sess:train_model(sess)
其中 construct_model()
包含模型定义,包括权重的随机初始化 (tf.truncated_normal
) 和 train_model(sess)
执行训练模型的-
在重复运行上述代码片段之间,我必须设置哪些种子以确保 100% 的可重复性?文档 tf.random.set_random_seed
可能简洁,但让我有点困惑.我试过了:
tf.set_random_seed(1234)模型 = 构造模型()使用 tf.Session() 作为 sess:train_model(sess)
但每次都得到不同的结果.
目前适用于 GPU 的最佳解决方案是使用以下内容安装 tensorflow-determinism:
pip install tensorflow-determinism
然后在您的代码中包含以下代码
将 tensorflow 导入为 tf导入操作系统os.environ['TF_DETERMINISTIC_OPS'] = '1'
来源:https://github.com/NVIDIA/tensorflow-determinism>
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.
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
这篇关于必须设置哪些种子才能在 tensorflow 中实现 100% 的训练结果可重复性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!