深度学习调参-keras,tensorflow设置随机种子,保证结果可复现

keras,tensorflow设置随机种子,保证结果可复现

ref: https://keras.io/getting-started/faq/#how-can-i-obtain-reproducible-results-using-keras-during-development

ref: https://tensorflow.google.cn/api_docs/python/tf/random/set_seed

1
2
3
4
5
6
7
8
np.random.seed(42)

# tensorflow V1.x
tf.set_random_seed(1234)

# tensorflow V2.x
# For Tensorflow 2.0 tf.random.set_random_seed(seed) changed to tf.random.set_seed(seed).
tf.random.set_seed(1234)