I want to have the same weights for layer initializations in all my networks, so that when I'm comparing their first epoch loss they all start from the same value. Is there a way in keras to do this?

I have set the random seed for the numpy and tensorflow, but still I get different results in initializations.

  • $\begingroup$ Have a look at this keras.io/initializers $\endgroup$ – Ankit Seth Aug 19 '19 at 6:04
  • $\begingroup$ @Ankit Seth yes i have set the seed for my initializer as well $\endgroup$ – Moeinh77 Aug 19 '19 at 6:47
  • 1
    $\begingroup$ hi - answered a similar question a little while back, it's a little trickier than you might think! datascience.stackexchange.com/a/37418/32697 $\endgroup$ – redhqs Aug 19 '19 at 10:43
  • $\begingroup$ @redhqs hi,i followed your instructions but i couldn't get it to work $\endgroup$ – Moeinh77 Aug 20 '19 at 13:08
  • 1
    $\begingroup$ @redhqs no errors,the only problem is the cost function value of first epoch is different in each run $\endgroup$ – Moeinh77 Aug 24 '19 at 5:27

You need to specify the seed in the initializer, e.g:

from keras.initializers import RandomUniform

seed = 0

model.add(Dense(64, kernel_initializer = RandomUniform(minval = -0.05, 
                                                       maxval =  0.05, 
                                                       seed = seed)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.