If Keras results are not reproducible, what's the best practice for comparing models and choosing hyper parameters?

后端 未结 4 1861
日久生厌
日久生厌 2020-12-06 14:50

UPDATE: This question was for Tensorflow 1.x. I upgraded to 2.0 and (at least on the simple code below) the reproducibility issue seems fixed on 2.0. So that solves my p

4条回答
  •  心在旅途
    2020-12-06 15:26

    Putting only the code of below, it works. The KEY of the question, VERY IMPORTANT, is to call the function reset_seeds() every time before running the model. Doing that you will obtain reproducible results as I checked in the Google Collab.

    import numpy as np
    import tensorflow as tf
    import random as python_random
    
    def reset_seeds():
       np.random.seed(123) 
       python_random.seed(123)
       tf.random.set_seed(1234)
    
    reset_seeds() 
    

提交回复
热议问题