Path: blob/master/templates/api/layers/initializers.md
3297 views
Layer weight initializers
Usage of initializers
Initializers define the way to set the initial random weights of Keras layers.
The keyword arguments used for passing initializers to layers depends on the layer. Usually, it is simply kernel_initializer
and bias_initializer
:
All built-in initializers can also be passed via their string identifier:
Available initializers
The following built-in initializers are available as part of the keras.initializers
module:
{{autogenerated}}
Creating custom initializers
Simple callables
You can pass a custom callable as initializer. It must take the arguments shape
(shape of the variable to initialize) and dtype
(dtype of generated values):
Initializer
subclasses
If you need to configure your initializer via various arguments (e.g. stddev
argument in RandomNormal
), you should implement it as a subclass of keras.initializers.Initializer
.
Initializers should implement a __call__
method with the following signature:
Optionally, you an also implement the method get_config
and the class method from_config
in order to support serialization -- just like with any Keras object.
Here's a simple example: a random normal initializer.
Note that we don't have to implement from_config
in the example above since the constructor arguments of the class the keys in the config returned by get_config
are the same. In this case, the default from_config
works fine.