
    BVhJ                         d Z ddl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j                         ad	 Z e         e       j#                  t        j$                         d
 ZddZd Zy)z2Keras initializer serialization / deserialization.    N)tf2)initializers_v1)initializers_v2)generic_utils)
tf_inspect)init_opsc                  4   t        t        d      si t        _        dt        _        t        j                  r&t        j                  t	        j
                         k(  ryi t        _        t	        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
                         ri } t        j,                  t/        j0                  | t        gfd       | j3                         D ]>  \  }}|t        j                  |<   |t        j                  t/        j4                  |      <   @ n5t6        j                  t6        j                  t6        j                  t6        j                  t6        j                  t6        j                   t6        j(                  t6        j*                  t8        j                  t8        j                  t8        j                  t8        j                  t8        j"                  t8        j$                  t8        j&                  d}|j3                         D ]>  \  }}|t        j                  |<   |t        j                  t/        j4                  |      <   @ t        j                  d   t        j                  d<   t        j                  d   t        j                  d<   t        j                  d   t        j                  d <   t        j                  d!   t        j                  d"<   y)#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                 J    t        j                  |       xr t        |       S N)inspectisclass
issubclass)xbase_clss    ]/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/keras/initializers/__init__.py<lambda>z1populate_deserializable_objects.<locals>.<lambda>R   s    W__Q/KJq(4K     )
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_V2r   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_caser   r   )v2_objskeyvaluev1_objsr&   s       @r'   populate_deserializable_objectsrN       s    
	&E"E
522ckkmC %KKM% %4$<$<%L!(7(D(D%$%)8)F)F%%&$3$<$<%L!%4%>%>%M"$3$<$<%L!'6'B'B%O$(7(D(D%$% / 4 4%H&5&@&@%N#(7(D(D%$%)8)F)F%%&+:+J+J%'(+:+J+J%'(!0!6!6%I *9)E)E%%&*9*G*G%&'%4%=%=%M"&5&?&?%N#(7(C(C%$%)8)E)E%%&[[] G**H33	KM mmo B
U$e<Ae33C89B %% --!//%%))#33#,,$..&22'44'44(66*::G" mmo B
U$e<Ae33C89B !& 1 1/ B%H!&!2!23C!D%I"..v6%E#//8%Fr)   c                 ,    t        j                  |       S r!   )r   serialize_keras_object)initializers    r'   	serializerR      s    		-	-k	::r)   c                 d    t                t        j                  | t        j                  |d      S )z/Return an `Initializer` object from its config.rQ   )module_objectscustom_objectsprintable_module_name)rN   r   deserialize_keras_objectrC   r
   )configrU   s     r'   deserializerY      s-    !#		/	/&&#)	
+ +r)   c                 
   | yt        | t              rt        |       S t        | t              rt        |       } t        |       S t	        |       rt        j                  |       r |        } | S t        dt        |       z         )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dictrY   strcallabler"   r#   
ValueError)
identifiers    r'   getra      s~    B 
D!z""*c"ZJz""
z"<j
C_% & &r)   r!   )__doc__	threadingtensorflow.pythonr   $tensorflow.python.keras.initializersr   r   tensorflow.python.keras.utilsr   r   r"   tensorflow.python.opsr   localrC   rN   globalsupdater
   rR   rY   ra    r)   r'   <module>rl      sc    9  ! @ @ 7 ? *
 		S9r   ! 	  "" #
;+.&r)   