initializer base class all keras initializers inherit from this class initializers should implement a call method with the following signature python def callself shape dtypenone kwargs returns a tensor of shape shape and dtype dtype containing values drawn from a distribution of your choice optionally you an also implement the method getconfig and the class method fromconfig in order to support serialization just like with any keras object here s a simple example a random normal initializer python class examplerandomnormalinitializer def initself mean stddev self mean mean self stddev stddev def callself shape dtypenone kwargs return keras random normal shape meanself mean stddevself stddev dtypedtype def getconfigself to support serialization return mean self mean stddev self stddev note that we don t have to implement fromconfig in the example above since the constructor arguments of the class the keys in the config returned by getconfig are the same in this case the default fromconfig works fine returns a tensor object initialized as specified by the initializer args shape shape of the tensor dtype optional dtype of the tensor returns the initializer s configuration as a jsonserializable dict returns a jsonserializable python dict instantiates an initializer from a configuration dictionary example python initializer randomuniform1 1 config initializer getconfig initializer randomuniform fromconfigconfig args config a python dictionary the output of getconfig returns an initializer instance initializer base class all keras initializers inherit from this class initializers should implement a __call__ method with the following signature python def __call__ self shape dtype none kwargs returns a tensor of shape shape and dtype dtype containing values drawn from a distribution of your choice 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 python class examplerandomnormal initializer def __init__ self mean stddev self mean mean self stddev stddev def __call__ self shape dtype none kwargs return keras random normal shape mean self mean stddev self stddev dtype dtype def get_config self to support serialization return mean self mean stddev self stddev 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 returns a tensor object initialized as specified by the initializer args shape shape of the tensor dtype optional dtype of the tensor returns the initializer s configuration as a json serializable dict returns a json serializable python dict instantiates an initializer from a configuration dictionary example python initializer randomuniform 1 1 config initializer get_config initializer randomuniform from_config config args config a python dictionary the output of get_config returns an initializer instance
from keras.api_export import keras_export


@keras_export(["keras.Initializer", "keras.initializers.Initializer"])
class Initializer:
    

    def __call__(self, shape, dtype=None):
        
        raise NotImplementedError(
            "Initializer subclasses must implement the `__call__()` method."
        )

    def get_config(self):
        
        return {}

    @classmethod
    def from_config(cls, config):
        
        return cls(**config)