o
    i eD#                     @   s   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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dZeddddZ eddd Z!dS )z2Keras initializer serialization / deserialization.    N)initializers)initializers_v1)serialization_lib)serialization)generic_utils)
tf_inspect)tf2)init_ops)keras_exportc                     sv  t tdsi t_dt_tjrtjtjj krd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 |  D ]\}}|tj|< |tjt|< qnIt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}| D ]\}}|tj|< |tjt|< q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_OBJECTSN
ConstantV2GlorotNormalV2GlorotUniformV2
HeNormalV2HeUniformV2
IdentityV2LecunNormalV2LecunUniformV2OnesV2OrthogonalV2RandomNormalV2RandomUniformV2TruncatedNormalV2VarianceScalingV2ZerosV2glorot_normalV2glorot_uniformV2he_normalV2he_uniformV2lecun_normalV2lecun_uniformV2c                    s   t | o	t|  S )N)inspectisclass
issubclass)xbase_cls N/var/www/myenv/lib/python3.10/site-packages/keras/src/initializers/__init__.py<lambda>\   s    z1populate_deserializable_objects.<locals>.<lambda>)
obj_filter)ConstantGlorotNormalGlorotUniformIdentityOnes
OrthogonalVarianceScalingZerosHeNormal	HeUniformLecunNormalLecunUniformRandomNormalRandomUniformTruncatedNormalrandom_normalnormalrandom_uniformuniformonesonezeroszero)(hasattrLOCALr   GENERATED_WITH_V2tf__internal__r   enabledr   r+   r,   r-   r3   r4   r.   r5   r6   r/   r0   r7   r8   r9   r1   r2   Initializerr   !populate_dict_with_module_objectsitemsto_snake_casecompatv1constant_initializerglorot_normal_initializerglorot_uniform_initializeridentityones_initializerorthogonal_initializervariance_scaling_initializerzeros_initializerr   )v2_objskeyvaluev1_objsr'   r%   r(   populate_deserializable_objects'   s   




rZ   zkeras.initializers.serializeFc                 C   sT   t   | d u r	d S t| ttj stdt|  d |r%t	
| S t
| S )NzThe `keras.initializers.serialize()` API should only be used for objects of type `keras.initializers.Initializer`. Found an instance of type z+, which may lead to improper serialization.)rZ   
isinstancetuplerC   r   valueswarningswarntypelegacy_serializationserialize_keras_objectr   )initializeruse_legacy_formatr'   r'   r(   	serialize   s   

re   zkeras.initializers.deserializec                 C   s2   t   |rtj| tj|ddS tj| tj|ddS )z/Return an `Initializer` object from its config.rc   )module_objectscustom_objectsprintable_module_name)rZ   ra   deserialize_keras_objectrC   r   r   )configrg   rd   r'   r'   r(   deserialize   s   rk   zkeras.initializers.getc                 C   sv   | du rdS t | trd| v}t| |dS t | tr%t| i d}t|S t| r3t| r1|  } | S tdt|  )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.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.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.
    Nmodule)rd   )
class_namerj   z,Could not interpret initializer identifier: )	r[   dictrk   strgetcallabler!   r"   
ValueError)
identifierrd   rj   r'   r'   r(   rp      s   "



rp   )F)NF)"__doc__	threadingr^   tensorflow.compat.v2rL   v2rE   keras.src.initializersr   r   keras.src.savingr   keras.src.saving.legacyr   ra   keras.src.utilsr   r   r!   tensorflow.pythonr   tensorflow.python.opsr	    tensorflow.python.util.tf_exportr
   localrC   rZ   globalsupdater   re   rk   rp   r'   r'   r'   r(   <module>   s.   ]