a
    SicӤ                     @   sf  d Z ddlZddlZddlm  mZ ddlmZ ddl	m
Z
 ddlmZ dZdZdZeeegZed	G d
d dZeddg dG dd deZeddg dG dd deZeddg dG dd deZeddg dG dd deZeddg dG dd  d eZed!d"g dG d#d$ d$eZed%d&g dG d'd( d(eZed)d*g dG d+d, d,eZed-d.g dG d/d0 d0eZed1d2g dG d3d4 d4eZed5d6g dG d7d8 d8eZed9d:g dG d;d< d<eZed=d>g dG d?d@ d@eZedAdBg dG dCdD dDeZedEdFg dG dGdH dHeZ dIdJ Z!dKdL Z"dMdN Z#dTdPdQZ$dRdS Z%dS )UzKeras initializers for TF 2.    N)backend)utils)keras_exportpartition_shapepartition_offsetlayoutzkeras.initializers.Initializerc                   @   s6   e Zd ZdZdddZdd Zedd Zd	d
 ZdS )Initializera9  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
    import tensorflow as tf

    class ExampleRandomNormal(tf.keras.initializers.Initializer):

      def __init__(self, mean, stddev):
        self.mean = mean
        self.stddev = stddev

      def __call__(self, shape, dtype=None, **kwargs):
        return tf.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.
    Nc                 K   s   t ddS )zReturns a tensor object initialized as specified by the initializer.

        Args:
          shape: Shape of the tensor.
          dtype: Optional dtype of the tensor.
          **kwargs: Additional keyword arguments.
        z>Initializer subclasses must implement the `__call__()` method.N)NotImplementedError)selfshapedtypekwargs r   ^/var/www/html/django/DPS/env/lib/python3.9/site-packages/keras/initializers/initializers_v2.py__call__L   s    zInitializer.__call__c                 C   s   i S )zReturns the configuration of the initializer as a JSON-serializable dict.

        Returns:
          A JSON-serializable Python dict.
        r   r
   r   r   r   
get_configX   s    zInitializer.get_configc                 C   s   | dd | f i |S )a  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:
          A `tf.keras.initializers.Initializer` instance.
        r   N)pop)clsconfigr   r   r   from_config`   s    zInitializer.from_configc                 C   s>   t | ddr4t | dd d u r:td| jj d nd| _d S )N_usedFseedzThe initializer z is unseeded and being called multiple times, which will return identical values  each time (even if the initializer is unseeded). Please update your code to provide a seed to the initializer, or avoid using the same initalizer instance more than once.T)getattrwarningswarn	__class____name__r   r   r   r   r   _warn_reuseu   s    	zInitializer._warn_reuse)N)	r   
__module____qualname____doc__r   r   classmethodr   r   r   r   r   r   r   "   s   (

r   zkeras.initializers.Zeroszkeras.initializers.zeros)v1c                   @   s   e Zd ZdZdddZdS )Zerosa  Initializer that generates tensors initialized to 0.

    Also available via the shortcut function `tf.keras.initializers.zeros`.

    Examples:

    >>> # Standalone usage:
    >>> initializer = tf.keras.initializers.Zeros()
    >>> values = initializer(shape=(2, 2))

    >>> # Usage in a Keras layer:
    >>> initializer = tf.keras.initializers.Zeros()
    >>> layer = tf.keras.layers.Dense(3, kernel_initializer=initializer)
    Nc                 K   sv   t | jj| t|}|jr&|tjkr6td| dt|v rF|t }|	dd}|rjt
jtj|||dS t||S a  Returns a tensor object initialized as specified by the initializer.

        Args:
          shape: Shape of the tensor.
          dtype: Optional dtype of the tensor. Only numeric or boolean dtypes
            are supported. If not specified, `tf.keras.backend.floatx()` is
            used, which default to `float32` unless you configured it otherwise
            (via `tf.keras.backend.set_floatx(float_dtype)`).
          **kwargs: Additional keyword arguments.
        z'Expected numeric or boolean dtype, got .r   Nr   r   )_validate_kwargsr   r   
_get_dtypeis_numpy_compatibletfstring
ValueError_PARTITION_SHAPEr   r   call_with_layoutzerosr
   r   r   r   r   r   r   r   r      s    
zZeros.__call__)Nr   r   r    r!   r   r   r   r   r   r$      s   r$   zkeras.initializers.Oneszkeras.initializers.onesc                   @   s   e Zd ZdZdddZdS )Onesa  Initializer that generates tensors initialized to 1.

    Also available via the shortcut function `tf.keras.initializers.ones`.

    Examples:

    >>> # Standalone usage:
    >>> initializer = tf.keras.initializers.Ones()
    >>> values = initializer(shape=(2, 2))

    >>> # Usage in a Keras layer:
    >>> initializer = tf.keras.initializers.Ones()
    >>> layer = tf.keras.layers.Dense(3, kernel_initializer=initializer)
    Nc                 K   sv   t | jj| t|}|jr&|tjkr6td| dt|v rF|t }|	dd}|rjt
jtj|||dS t||S r%   )r(   r   r   r)   r*   r+   r,   r-   r.   r   r   r/   onesr1   r   r   r   r      s    
zOnes.__call__)Nr2   r   r   r   r   r3      s   r3   zkeras.initializers.Constantzkeras.initializers.constantc                   @   s,   e Zd ZdZd
ddZdddZdd	 ZdS )Constanta}  Initializer that generates tensors with constant values.

    Also available via the shortcut function `tf.keras.initializers.constant`.

    Only scalar values are allowed.
    The constant value provided must be convertible to the dtype requested
    when calling the initializer.

    Examples:

    >>> # Standalone usage:
    >>> initializer = tf.keras.initializers.Constant(3.)
    >>> values = initializer(shape=(2, 2))

    >>> # Usage in a Keras layer:
    >>> initializer = tf.keras.initializers.Constant(3.)
    >>> layer = tf.keras.layers.Dense(3, kernel_initializer=initializer)

    Args:
      value: A Python scalar.
    r   c                 C   s
   || _ d S Nvalue)r
   r8   r   r   r   __init__   s    zConstant.__init__Nc                 K   sd   t | jj| t|}t|v r&|t }|dd}|rNtjtj	|| j
||dS tj	| j
t||dS )a  Returns a tensor object initialized to `self.value`.

        Args:
          shape: Shape of the tensor.
          dtype: Optional dtype of the tensor. If not specified,
           `tf.keras.backend.floatx()` is used,
           which default to `float32` unless you configured it otherwise
           (via `tf.keras.backend.set_floatx(float_dtype)`).
          **kwargs: Additional keyword arguments.
        r   Nr'   )r   r   )r(   r   r   r)   r.   r   r   r/   r+   constantr8   r1   r   r   r   r      s    zConstant.__call__c                 C   s
   d| j iS )Nr8   r7   r   r   r   r   r     s    zConstant.get_config)r   )Nr   r   r    r!   r9   r   r   r   r   r   r   r5      s   

r5   z keras.initializers.RandomUniformz!keras.initializers.random_uniformc                   @   s,   e Zd ZdZdddZdddZd	d
 ZdS )RandomUniforma  Initializer that generates tensors with a uniform distribution.

    Also available via the shortcut function
    `tf.keras.initializers.random_uniform`.

    Examples:

    >>> # Standalone usage:
    >>> initializer = tf.keras.initializers.RandomUniform(minval=0., maxval=1.)
    >>> values = initializer(shape=(2, 2))

    >>> # Usage in a Keras layer:
    >>> initializer = tf.keras.initializers.RandomUniform(minval=0., maxval=1.)
    >>> layer = tf.keras.layers.Dense(3, kernel_initializer=initializer)

    Args:
      minval: A python scalar or a scalar tensor. Lower bound of the range of
        random values to generate (inclusive).
      maxval: A python scalar or a scalar tensor. Upper bound of the range of
        random values to generate (exclusive).
      seed: A Python integer. Used to make the behavior of the initializer
        deterministic. Note that a seeded initializer will produce the same
        random values across multiple calls.
    皙皙?Nc                 C   s&   || _ || _|| _tj|dd| _d S N	statelessrng_type)minvalmaxvalr   r   RandomGenerator_random_generator)r
   rC   rD   r   r   r   r   r9   .  s    zRandomUniform.__init__c              	   K   s   t | jj| t|}|js2|js2td| dt|v rB|t }|t	d}|du r^| 
  |rjt|nd}|dd}|rt  t| jj||| j| j||S | j|| j| j||S )a  Returns a tensor object initialized as specified by the initializer.

        Args:
          shape: Shape of the tensor.
          dtype: Optional dtype of the tensor. Only floating point and integer
          types are supported. If not specified,
            `tf.keras.backend.floatx()` is used,
           which default to `float32` unless you configured it otherwise
           (via `tf.keras.backend.set_floatx(float_dtype)`).
          **kwargs: Additional keyword arguments.
        z%Expected float or integer dtype, got r&   Nr   )r(   r   r   r)   is_floating
is_integerr-   r.   get_PARTITION_OFFSETr   hashr   _ensure_keras_seededr   r/   rF   random_uniformrC   rD   r
   r   r   r   r   noncer   r   r   r   r   6  s2    	zRandomUniform.__call__c                 C   s   | j | j| jdS )NrC   rD   r   rP   r   r   r   r   r   ^  s    zRandomUniform.get_config)r=   r>   N)Nr;   r   r   r   r   r<     s   

(r<   zkeras.initializers.RandomNormalz keras.initializers.random_normalc                   @   s,   e Zd ZdZdddZdddZd	d
 ZdS )RandomNormala  Initializer that generates tensors with a normal distribution.

    Also available via the shortcut function
    `tf.keras.initializers.random_normal`.

    Examples:

    >>> # Standalone usage:
    >>> initializer = tf.keras.initializers.RandomNormal(mean=0., stddev=1.)
    >>> values = initializer(shape=(2, 2))

    >>> # Usage in a Keras layer:
    >>> initializer = tf.keras.initializers.RandomNormal(mean=0., stddev=1.)
    >>> layer = tf.keras.layers.Dense(3, kernel_initializer=initializer)

    Args:
      mean: a python scalar or a scalar tensor. Mean of the random values to
        generate.
      stddev: a python scalar or a scalar tensor. Standard deviation of the
        random values to generate.
      seed: A Python integer. Used to make the behavior of the initializer
        deterministic. Note that a seeded initializer will produce the same
        random values across multiple calls.
            r>   Nc                 C   s&   || _ || _|| _tj|dd| _d S r?   meanstddevr   r   rE   rF   r
   rT   rU   r   r   r   r   r9     s    zRandomNormal.__init__c              	   K   s   t | jj| tt|}t|v r*|t }|td}|du rF|   |rRt	|nd}|
dd}|rt  t| jj||| j| j||S | j|| j| j||S )a  Returns a tensor object initialized to random normal values.

        Args:
          shape: Shape of the tensor.
          dtype: Optional dtype of the tensor. Only floating point types are
            supported. If not specified, `tf.keras.backend.floatx()` is used,
            which default to `float32` unless you configured it otherwise (via
            `tf.keras.backend.set_floatx(float_dtype)`)
          **kwargs: Additional keyword arguments.
        Nr   )r(   r   r   _assert_float_dtyper)   r.   rI   rJ   r   rK   r   rL   r   r/   rF   random_normalrT   rU   rN   r   r   r   r     s.    	zRandomNormal.__call__c                 C   s   | j | j| jdS NrT   rU   r   rZ   r   r   r   r   r     s    zRandomNormal.get_config)rR   r>   N)Nr;   r   r   r   r   rQ   b  s   

%rQ   z"keras.initializers.TruncatedNormalz#keras.initializers.truncated_normalc                   @   s,   e Zd ZdZdddZdddZd	d
 ZdS )TruncatedNormala  Initializer that generates a truncated normal distribution.

    Also available via the shortcut function
    `tf.keras.initializers.truncated_normal`.

    The values generated are similar to values from a
    `tf.keras.initializers.RandomNormal` initializer except that values more
    than two standard deviations from the mean are
    discarded and re-drawn.

    Examples:

    >>> # Standalone usage:
    >>> initializer = tf.keras.initializers.TruncatedNormal(mean=0., stddev=1.)
    >>> values = initializer(shape=(2, 2))

    >>> # Usage in a Keras layer:
    >>> initializer = tf.keras.initializers.TruncatedNormal(mean=0., stddev=1.)
    >>> layer = tf.keras.layers.Dense(3, kernel_initializer=initializer)

    Args:
      mean: a python scalar or a scalar tensor. Mean of the random values
        to generate.
      stddev: a python scalar or a scalar tensor. Standard deviation of the
        random values to generate before truncation.
      seed: A Python integer. Used to make the behavior of the initializer
        deterministic. Note that a seeded initializer will produce the same
        random values across multiple calls.
    rR   r>   Nc                 C   s&   || _ || _|| _tj|dd| _d S r?   rS   rV   r   r   r   r9     s    zTruncatedNormal.__init__c              	   K   s   t | jj| tt|}t|v r*|t }|td}|du rF|   |rRt	|nd}|
dd}|r| jj| j_t  t| jj||| j| j||S | j|| j| j||S )a  Returns a tensor object initialized to random normal values (truncated).

        Args:
          shape: Shape of the tensor.
          dtype: Optional dtype of the tensor. Only floating point types are
            supported. If not specified, `tf.keras.backend.floatx()` is used,
            which default to `float32` unless you configured it otherwise (via
            `tf.keras.backend.set_floatx(float_dtype)`)
          **kwargs: Additional keyword arguments.
        Nr   )r(   r   r   rW   r)   r.   rI   rJ   r   rK   r   rF   RNG_STATEFUL	_rng_typerL   r   r/   truncated_normalrT   rU   rN   r   r   r   r     s2    	zTruncatedNormal.__call__c                 C   s   | j | j| jdS rY   rZ   r   r   r   r   r     s    zTruncatedNormal.get_config)rR   r>   N)Nr;   r   r   r   r   r[     s   

*r[   z"keras.initializers.VarianceScalingz#keras.initializers.variance_scalingc                   @   s4   e Zd ZdZdddZddd	Zd
d Zdd ZdS )VarianceScalingad  Initializer capable of adapting its scale to the shape of weights tensors.

    Also available via the shortcut function
    `tf.keras.initializers.variance_scaling`.

    With `distribution="truncated_normal" or "untruncated_normal"`, samples are
    drawn from a truncated/untruncated normal distribution with a mean of zero
    and a standard deviation (after truncation, if used) `stddev = sqrt(scale /
    n)`, where `n` is:

    - number of input units in the weight tensor, if `mode="fan_in"`
    - number of output units, if `mode="fan_out"`
    - average of the numbers of input and output units, if `mode="fan_avg"`

    With `distribution="uniform"`, samples are drawn from a uniform distribution
    within `[-limit, limit]`, where `limit = sqrt(3 * scale / n)`.

    Examples:

    >>> # Standalone usage:
    >>> initializer = tf.keras.initializers.VarianceScaling(
    ... scale=0.1, mode='fan_in', distribution='uniform')
    >>> values = initializer(shape=(2, 2))

    >>> # Usage in a Keras layer:
    >>> initializer = tf.keras.initializers.VarianceScaling(
    ... scale=0.1, mode='fan_in', distribution='uniform')
    >>> layer = tf.keras.layers.Dense(3, kernel_initializer=initializer)

    Args:
      scale: Scaling factor (positive float).
      mode: One of "fan_in", "fan_out", "fan_avg".
      distribution: Random distribution to use. One of "truncated_normal",
        "untruncated_normal" and  "uniform".
      seed: A Python integer. Used to make the behavior of the initializer
        deterministic. Note that a seeded initializer will produce the same
        random values across multiple calls.
          ?fan_inr^   Nc                 C   s   |dkrt d| dh d}||vr>t d| d| d| }|dkrRd}h d	}||vrxt d
| d| d|| _|| _|| _|| _tj|dd| _d S )NrR   z0`scale` must be positive float. Received: scale=r&   >   ra   fan_avgfan_outzInvalid `mode` argument: z. Please use one of the normalr^   >   untruncated_normaluniformr^   z!Invalid `distribution` argument: z.Allowed distributions: r@   rA   )	r-   lowerscalemodedistributionr   r   rE   rF   )r
   rh   ri   rj   r   Zallowed_modesZallowed_distributionsr   r   r   r9   7  s8    
zVarianceScaling.__init__c                 K   s   t | jj| tt|}t|v r*|t }|td}|du rF|   |rRt	|nd}|
dd}|rt  tj| j||||dS | j|||dS )a  Returns a tensor object initialized as specified by the initializer.

        Args:
          shape: Shape of the tensor.
          dtype: Optional dtype of the tensor. Only floating point types are
            supported. If not specified, `tf.keras.backend.floatx()` is used,
            which default to `float32` unless you configured it otherwise (via
            `tf.keras.backend.set_floatx(float_dtype)`)
          **kwargs: Additional keyword arguments.
        Nr   )r   r   rO   )r(   r   r   rW   r)   r.   rI   rJ   r   rK   r   rL   r   r/   _generate_init_valrN   r   r   r   r   ^  s&    zVarianceScaling.__call__c           	      C   s   | j }t|\}}| jdkr,|td| }n0| jdkrF|td| }n|td|| d  }| jdkrt|d }| j|d|||S | jdkrt|}| j	|d|||S td	| }| j
|| |||S d S )
Nra   r`   rc          @r^   g۶%?rR   re   g      @)rh   _compute_fansri   maxrj   mathsqrtrF   r^   rX   rM   )	r
   r   r   rO   rh   ra   rc   rU   limitr   r   r   rk     s*    






z"VarianceScaling._generate_init_valc                 C   s   | j | j| j| jdS )Nrh   ri   rj   r   rr   r   r   r   r   r     s
    zVarianceScaling.get_config)r`   ra   r^   N)Nr   r   r    r!   r9   r   rk   r   r   r   r   r   r_   
  s   )    
'
!r_   zkeras.initializers.Orthogonalzkeras.initializers.orthogonalc                   @   s4   e Zd ZdZdddZdddZdd	 Zd
d ZdS )
Orthogonala  Initializer that generates an orthogonal matrix.

    Also available via the shortcut function `tf.keras.initializers.orthogonal`.

    If the shape of the tensor to initialize is two-dimensional, it is
    initialized with an orthogonal matrix obtained from the QR decomposition of
    a matrix of random numbers drawn from a normal distribution. If the matrix
    has fewer rows than columns then the output will have orthogonal rows.
    Otherwise, the output will have orthogonal columns.

    If the shape of the tensor to initialize is more than two-dimensional,
    a matrix of shape `(shape[0] * ... * shape[n - 2], shape[n - 1])`
    is initialized, where `n` is the length of the shape vector.
    The matrix is subsequently reshaped to give a tensor of the desired shape.

    Examples:

    >>> # Standalone usage:
    >>> initializer = tf.keras.initializers.Orthogonal()
    >>> values = initializer(shape=(2, 2))

    >>> # Usage in a Keras layer:
    >>> initializer = tf.keras.initializers.Orthogonal()
    >>> layer = tf.keras.layers.Dense(3, kernel_initializer=initializer)

    Args:
      gain: multiplicative factor to apply to the orthogonal matrix
      seed: A Python integer. Used to make the behavior of the initializer
        deterministic. Note that a seeded initializer will produce the same
        random values across multiple calls.

    References:
      - [Saxe et al., 2014](https://openreview.net/forum?id=_wzZwKpTDF_9C)
    r`   Nc                 C   s    || _ || _tj|dd| _d S r?   )gainr   r   rE   rF   )r
   ru   r   r   r   r   r9     s
    zOrthogonal.__init__c                 K   s   t | jj|dd tt|}t|dk rDtd| dt| d|   |dd}|rvt	  t
j| j|||d	S | ||S )
a  Returns a tensor object initialized to an orthogonal matrix.

        Args:
          shape: Shape of the tensor.
          dtype: Optional dtype of the tensor. Only floating point types are
            supported. If not specified, `tf.keras.backend.floatx()` is used,
           which default to `float32` unless you configured it otherwise
           (via `tf.keras.backend.set_floatx(float_dtype)`)
          **kwargs: Additional keyword arguments.
        Fsupport_partition   zKThe tensor to initialize must be at least two-dimensional. Received: shape=	 of rank r&   r   Nr'   )r(   r   r   rW   r)   lenr-   r   r   rL   r   r/   rk   r1   r   r   r   r     s(    

zOrthogonal.__call__c                 C   s   d}|d d D ]}||9 }q|d }t ||t||f}| jj||d}tjj|dd\}}	tj|	}
|t|
9 }||k rtj	|}| j
t|| S )N   r   F)full_matrices)rn   minrF   rX   r+   linalgqrtensor_diag_partsignmatrix_transposeru   reshape)r
   r   r   num_rowsdimnum_cols
flat_shapeaqrdr   r   r   rk     s    
zOrthogonal._generate_init_valc                 C   s   | j | jdS )Nru   r   r   r   r   r   r   r     s    zOrthogonal.get_config)r`   N)Nrs   r   r   r   r   rt     s
   #

rt   zkeras.initializers.Identityzkeras.initializers.identityc                   @   s4   e Zd ZdZdddZdddZdd	 Zd
d ZdS )Identitya0  Initializer that generates the identity matrix.

    Also available via the shortcut function `tf.keras.initializers.identity`.

    Only usable for generating 2D matrices.

    Examples:

    >>> # Standalone usage:
    >>> initializer = tf.keras.initializers.Identity()
    >>> values = initializer(shape=(2, 2))

    >>> # Usage in a Keras layer:
    >>> initializer = tf.keras.initializers.Identity()
    >>> layer = tf.keras.layers.Dense(3, kernel_initializer=initializer)

    Args:
      gain: Multiplicative factor to apply to the identity matrix.
    r`   c                 C   s
   || _ d S r6   ru   )r
   ru   r   r   r   r9      s    zIdentity.__init__Nc                 K   st   t | jj|dd tt|}t|dkrDtd| dt| d|dd}|rhtj	| j
|||d	S | 
||S )
a  Returns a tensor object initialized to a 2D identity matrix.

        Args:
          shape: Shape of the tensor. It should have exactly rank 2.
          dtype: Optional dtype of the tensor. Only floating point types are
           supported. If not specified, `tf.keras.backend.floatx()` is used,
           which default to `float32` unless you configured it otherwise
           (via `tf.keras.backend.set_floatx(float_dtype)`)
          **kwargs: Additional keyword arguments.
        Frv   rx   zNIdentity matrix initializer can only be used for 2D matrices. Received: shape=ry   r&   r   Nr'   )r(   r   r   rW   r)   rz   r-   r   r   r/   rk   r1   r   r   r   r   #  s$    

zIdentity.__call__c                 C   s   t j|d|i}| j| S )Nr   )r+   eyeru   )r
   r   r   initializerr   r   r   rk   >  s    zIdentity._generate_init_valc                 C   s
   d| j iS )Nru   r   r   r   r   r   r   B  s    zIdentity.get_config)r`   )Nrs   r   r   r   r   r     s
   

r   z keras.initializers.GlorotUniformz!keras.initializers.glorot_uniformc                       s*   e Zd ZdZd fdd	Zdd Z  ZS )GlorotUniformag  The Glorot uniform initializer, also called Xavier uniform initializer.

    Also available via the shortcut function
    `tf.keras.initializers.glorot_uniform`.

    Draws samples from a uniform distribution within `[-limit, limit]`, where
    `limit = sqrt(6 / (fan_in + fan_out))` (`fan_in` is the number of input
    units in the weight tensor and `fan_out` is the number of output units).

    Examples:

    >>> # Standalone usage:
    >>> initializer = tf.keras.initializers.GlorotUniform()
    >>> values = initializer(shape=(2, 2))

    >>> # Usage in a Keras layer:
    >>> initializer = tf.keras.initializers.GlorotUniform()
    >>> layer = tf.keras.layers.Dense(3, kernel_initializer=initializer)

    Args:
      seed: A Python integer. Used to make the behavior of the initializer
        deterministic. Note that a seeded initializer will not produce the same
        random values across multiple calls, but multiple initializers will
        produce the same sequence when constructed with the same seed value.

    References:
      - [Glorot et al., 2010](http://proceedings.mlr.press/v9/glorot10a.html)
    Nc                    s   t  jddd|d d S )Nr`   rb   rf   rr   superr9   r
   r   r   r   r   r9   i  s    zGlorotUniform.__init__c                 C   s
   d| j iS Nr   r   r   r   r   r   r   n  s    zGlorotUniform.get_config)Nr   r   r    r!   r9   r   __classcell__r   r   r   r   r   F  s   r   zkeras.initializers.GlorotNormalz keras.initializers.glorot_normalc                       s*   e Zd ZdZd fdd	Zdd Z  ZS )GlorotNormala|  The Glorot normal initializer, also called Xavier normal initializer.

    Also available via the shortcut function
    `tf.keras.initializers.glorot_normal`.

    Draws samples from a truncated normal distribution centered on 0 with
    `stddev = sqrt(2 / (fan_in + fan_out))` where `fan_in` is the number of
    input units in the weight tensor and `fan_out` is the number of output units
    in the weight tensor.

    Examples:

    >>> # Standalone usage:
    >>> initializer = tf.keras.initializers.GlorotNormal()
    >>> values = initializer(shape=(2, 2))

    >>> # Usage in a Keras layer:
    >>> initializer = tf.keras.initializers.GlorotNormal()
    >>> layer = tf.keras.layers.Dense(3, kernel_initializer=initializer)

    Args:
      seed: A Python integer. Used to make the behavior of the initializer
        deterministic. Note that a seeded initializer will not produce the same
        random values across multiple calls, but multiple initializers will
        produce the same sequence when constructed with the same seed value.

    References:
      - [Glorot et al., 2010](http://proceedings.mlr.press/v9/glorot10a.html)
    Nc                    s   t  jddd|d d S )Nr`   rb   r^   rr   r   r   r   r   r   r9     s    zGlorotNormal.__init__c                 C   s
   d| j iS r   r   r   r   r   r   r     s    zGlorotNormal.get_config)Nr   r   r   r   r   r   r  s   r   zkeras.initializers.LecunNormalzkeras.initializers.lecun_normalc                       s*   e Zd ZdZd fdd	Zdd Z  ZS )LecunNormala  Lecun normal initializer.

     Also available via the shortcut function
    `tf.keras.initializers.lecun_normal`.

    Initializers allow you to pre-specify an initialization strategy, encoded in
    the Initializer object, without knowing the shape and dtype of the variable
    being initialized.

    Draws samples from a truncated normal distribution centered on 0 with
    `stddev = sqrt(1 / fan_in)` where `fan_in` is the number of input units in
    the weight tensor.

    Examples:

    >>> # Standalone usage:
    >>> initializer = tf.keras.initializers.LecunNormal()
    >>> values = initializer(shape=(2, 2))

    >>> # Usage in a Keras layer:
    >>> initializer = tf.keras.initializers.LecunNormal()
    >>> layer = tf.keras.layers.Dense(3, kernel_initializer=initializer)

    Args:
      seed: A Python integer. Used to make the behavior of the initializer
        deterministic. Note that a seeded initializer will not produce the same
        random values across multiple calls, but multiple initializers will
        produce the same sequence when constructed with the same seed value.

    References:
      - [Klambauer et al., 2017](https://arxiv.org/abs/1706.02515)
    Nc                    s   t  jddd|d d S )Nr`   ra   r^   rr   r   r   r   r   r   r9     s    zLecunNormal.__init__c                 C   s
   d| j iS r   r   r   r   r   r   r     s    zLecunNormal.get_config)Nr   r   r   r   r   r     s   !r   zkeras.initializers.LecunUniformz keras.initializers.lecun_uniformc                       s*   e Zd ZdZd fdd	Zdd Z  ZS )LecunUniforma  Lecun uniform initializer.

     Also available via the shortcut function
    `tf.keras.initializers.lecun_uniform`.

    Draws samples from a uniform distribution within `[-limit, limit]`, where
    `limit = sqrt(3 / fan_in)` (`fan_in` is the number of input units in the
    weight tensor).

    Examples:

    >>> # Standalone usage:
    >>> initializer = tf.keras.initializers.LecunUniform()
    >>> values = initializer(shape=(2, 2))

    >>> # Usage in a Keras layer:
    >>> initializer = tf.keras.initializers.LecunUniform()
    >>> layer = tf.keras.layers.Dense(3, kernel_initializer=initializer)

    Args:
      seed: A Python integer. Used to make the behavior of the initializer
        deterministic. Note that a seeded initializer will not produce the same
        random values across multiple calls, but multiple initializers will
        produce the same sequence when constructed with the same seed value.

    References:
      - [Klambauer et al., 2017](https://arxiv.org/abs/1706.02515)
    Nc                    s   t  jddd|d d S )Nr`   ra   rf   rr   r   r   r   r   r   r9     s    zLecunUniform.__init__c                 C   s
   d| j iS r   r   r   r   r   r   r     s    zLecunUniform.get_config)Nr   r   r   r   r   r     s   r   zkeras.initializers.HeNormalzkeras.initializers.he_normalc                       s*   e Zd ZdZd fdd	Zdd Z  ZS )HeNormala  He normal initializer.

     Also available via the shortcut function
    `tf.keras.initializers.he_normal`.

    It draws samples from a truncated normal distribution centered on 0 with
    `stddev = sqrt(2 / fan_in)` where `fan_in` is the number of input units in
    the weight tensor.

    Examples:

    >>> # Standalone usage:
    >>> initializer = tf.keras.initializers.HeNormal()
    >>> values = initializer(shape=(2, 2))

    >>> # Usage in a Keras layer:
    >>> initializer = tf.keras.initializers.HeNormal()
    >>> layer = tf.keras.layers.Dense(3, kernel_initializer=initializer)

    Args:
      seed: A Python integer. Used to make the behavior of the initializer
        deterministic. Note that a seeded initializer will not produce the same
        random values across multiple calls, but multiple initializers will
        produce the same sequence when constructed with the same seed value.

    References:
      - [He et al., 2015](https://arxiv.org/abs/1502.01852)
    Nc                    s   t  jddd|d d S )Nrl   ra   r^   rr   r   r   r   r   r   r9     s    zHeNormal.__init__c                 C   s
   d| j iS r   r   r   r   r   r   r     s    zHeNormal.get_config)Nr   r   r   r   r   r     s   r   zkeras.initializers.HeUniformzkeras.initializers.he_uniformc                       s*   e Zd ZdZd fdd	Zdd Z  ZS )	HeUniforma  He uniform variance scaling initializer.

     Also available via the shortcut function
    `tf.keras.initializers.he_uniform`.

    Draws samples from a uniform distribution within `[-limit, limit]`, where
    `limit = sqrt(6 / fan_in)` (`fan_in` is the number of input units in the
    weight tensor).

    Examples:

    >>> # Standalone usage:
    >>> initializer = tf.keras.initializers.HeUniform()
    >>> values = initializer(shape=(2, 2))

    >>> # Usage in a Keras layer:
    >>> initializer = tf.keras.initializers.HeUniform()
    >>> layer = tf.keras.layers.Dense(3, kernel_initializer=initializer)

    Args:
      seed: A Python integer. Used to make the behavior of the initializer
        deterministic. Note that a seeded initializer will not produce the same
        random values across multiple calls, but multiple initializers will
        produce the same sequence when constructed with the same seed value.

    References:
      - [He et al., 2015](https://arxiv.org/abs/1502.01852)
    Nc                    s   t  jddd|d d S )Nrl   ra   rf   rr   r   r   r   r   r   r9   C  s    zHeUniform.__init__c                 C   s
   d| j iS r   r   r   r   r   r   r   H  s    zHeUniform.get_config)Nr   r   r   r   r   r   "  s   r   c                 C   s   | d u rt  } t| S r6   )r   floatxr+   as_dtyper}   r   r   r   r)   L  s    r)   c                 C   s$   t | } | js td|  d| S )a	  Validate and return floating point type based on `dtype`.

    `dtype` must be a floating point type.

    Args:
      dtype: The data type to validate.

    Returns:
      Validated type.

    Raises:
      ValueError: if `dtype` is not a floating point type.
    z"Expected floating point type, got r&   )r+   r   rG   r-   r}   r   r   r   rW   R  s    
rW   c                 C   s   t | dk rd }}nnt | dkr0| d  }}nTt | dkrN| d }| d }n6d}| dd D ]}||9 }q^| d | }| d | }t|t|fS )zComputes the number of input and output units for a weight shape.

    Args:
      shape: Integer shape tuple or TF tensor shape.

    Returns:
      A tuple of integer scalars (fan_in, fan_out).
    r{   r   rx   Nr|   )rz   int)r   ra   rc   receptive_field_sizer   r   r   r   rm   f  s    	


rm   Tc                 C   sN   dd |D }|r(t d| dt d|sJt|v s<t|v rJt|  dd S )Nc                 S   s   g | ]}|t vr|qS r   )_ALLOWED_INITIALIZER_KWARGS).0kr   r   r   
<listcomp>      z$_validate_kwargs.<locals>.<listcomp>zUnknown keyword arguments: z. Allowed keyword arguments: r&   z9 initializer doesn't support partition-related arguments.)	TypeErrorr   r.   rJ   r-   )cls_namer   rw   invalid_kwargsr   r   r   r(     s    r(   c                   C   s   t tjddstddS )a  Make sure the keras.backend global seed generator is set.

    This is important for DTensor use case to ensure that each client are
    initialized with same seed for tf.random.Generator, so that the value
    created are in sync among all the clients.
    	generatorNzWhen using DTensor APIs, you need to set the global seed before using any Keras initializers. Please make sure to call `tf.keras.utils.set_random_seed()` in your code.)r   r   _SEED_GENERATORr-   r   r   r   r   rL     s    rL   )T)&r!   ro   r   tensorflow.compat.v2compatv2r+   kerasr   Zkeras.dtensorr    tensorflow.python.util.tf_exportr   r.   rJ   _LAYOUTr   r   r$   r3   r5   r<   rQ   r[   r_   rt   r   r   r   r   r   r   r   r)   rW   rm   r(   rL   r   r   r   r   <module>   s   
a))4NKU b;'++'''
