B
    d[                 @   s   d 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dlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ e add Ze  e tj eddd ZeddddZeddd ZdS )z2Keras initializer serialization / deserialization.    N)initializers_v1)initializers_v2)serialization)generic_utils)
tf_inspect)tf2)init_ops)keras_exportc                 s  t tdsi t_dt_tjr2tjtjj kr2dS i t_tjj t_tj	tjd< tj
tjd< tjtjd< tjtjd< tjtjd< tjtjd< tjtjd	< tjtjd
< tjtjd< tjtjd< tjtjd< tjtjd< tjtjd< tjtjd< tjtjd< tj
tjd< tjtjd< tjtjd< tjtjd< tjtjd< tjtjd< tjj ri } tj tj| tg fddd x|  D ]$\}}|tj|< |tjt|< q~W ntjjjtjjj tjjj!tjjj"j#tjjj$tjjj%tjjj&tjjj't(jt(jt(jt(jt(jt(jt(jd}x0| D ]$\}}|tj|< |tjt|< qW tjd tjd< tjd tjd< tjd  tjd!< tjd" tjd#< dS )$z;Populates dict ALL_OBJECTS with every built-in initializer.ALL_OBJECTSNZ
ConstantV2ZGlorotNormalV2ZGlorotUniformV2Z
HeNormalV2ZHeUniformV2Z
IdentityV2ZLecunNormalV2ZLecunUniformV2ZOnesV2ZOrthogonalV2ZRandomNormalV2ZRandomUniformV2ZTruncatedNormalV2ZVarianceScalingV2ZZerosV2Zglorot_normalV2Zglorot_uniformV2Zhe_normalV2Zhe_uniformV2Zlecun_normalV2Zlecun_uniformV2c                s   t | ot|  S )N)inspectisclass
issubclass)x)base_cls M/var/www/html/venv/lib/python3.7/site-packages/keras/initializers/__init__.py<lambda>Z       z1populate_deserializable_objects.<locals>.<lambda>)Z
obj_filter)ConstantGlorotNormalGlorotUniformIdentityOnes
OrthogonalVarianceScalingZerosHeNormal	HeUniformLecunNormalLecunUniformRandomNormalRandomUniformTruncatedNormalZrandom_normalnormalZrandom_uniformuniformZonesoneZzeroszero))hasattrLOCALr
   ZGENERATED_WITH_V2tfZ__internal__r   enabledr   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r   r   ZInitializerr   Z!populate_dict_with_module_objectsitemsZto_snake_casecompatZv1Zconstant_initializerZglorot_normal_initializerZglorot_uniform_initializerZinitializersidentityZones_initializerZorthogonal_initializerZvariance_scaling_initializerZzeros_initializerr   )Zv2_objskeyvalueZv1_objsr   )r   r   populate_deserializable_objects%   sz    




r0   zkeras.initializers.serializec             C   s
   t | S )N)r   Zserialize_keras_object)initializerr   r   r   	serialize   s    r2   zkeras.initializers.deserializec             C   s   t   tj| tj|ddS )z/Return an `Initializer` object from its config.r1   )Zmodule_objectscustom_objectsZprintable_module_name)r0   r   Zdeserialize_keras_objectr(   r
   )configr3   r   r   r   deserialize   s    r5   zkeras.initializers.getc             C   sh   | dkrdS t | trt| S t | tr8t| } t| S t| rTt| rP|  } | S tdt|  dS )a/  Retrieve a Keras initializer by the identifier.

    The `identifier` may be the string name of a initializers function or class
    (case-sensitively).

    >>> identifier = 'Ones'
    >>> tf.keras.initializers.deserialize(identifier)
    <...keras.initializers.initializers_v2.Ones...>

    You can also specify `config` of the initializer to this function by passing
    dict containing `class_name` and `config` as an identifier. Also note that
    the `class_name` must map to a `Initializer` class.

    >>> cfg = {'class_name': 'Ones', 'config': {}}
    >>> tf.keras.initializers.deserialize(cfg)
    <...keras.initializers.initializers_v2.Ones...>

    In the case that the `identifier` is a class, this method will return a new
    instance of the class by its constructor.

    Args:
      identifier: String or dict that contains the initializer name or
        configurations.

    Returns:
      Initializer instance base on the input identifier.

    Raises:
      ValueError: If the input identifier is not a supported type or in a bad
        format.
    Nz,Could not interpret initializer identifier: )
isinstancedictr5   strcallabler   r   
ValueError)
identifierr   r   r   get   s    "


r<   )N)__doc__	threadingZtensorflow.compat.v2r,   Zv2r)   Zkeras.initializersr   r   Zkeras.saving.legacyr   Zkeras.utilsr   r   r   Ztensorflow.pythonr   Ztensorflow.python.opsr   Z tensorflow.python.util.tf_exportr	   localr(   r0   globalsupdater
   r2   r5   r<   r   r   r   r   <module>   s$   ]