How to set seed value of kernel initializer (gloro

2019-08-03 18:12发布

问题:

I'd like to set seed value of glorot_uniform kernel initializer in Keras.

model.add(Dense(50, input_dim=self.state_size, activation='relu', kernel_initializer='glorot_uniform(seed=0)'))

When I use above code, error message is below.

ValueError: Unknown initializer: glorot_uniform(seed=0)

If I remove "(seed=0)" like as below

 model.add(Dense(50, input_dim=self.state_size, activation='relu', kernel_initializer='glorot_uniform'))

It works well without setting a seed value.

How can I set a seed value?

回答1:

Keras can use strings and functions as arguments for initilizers. The strings just use the default options for initializers. Try this line of code for your FC layer:

from keras import initializers
model.add(Dense(50, input_dim=self.state_size, activation='relu', kernel_initializer=initializers.glorot_uniform(seed=0)))

Here you have the documentation for the initializers: https://keras.io/initializers