
    6biv                        S r SSKrSSKrSSKrSSKrSSKrSSKrSSKJ	s  J
r  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  \\\\4r\R<                  " 5       r\R<                  " 5       r S	r!S
r" " S S5      r# " S S5      r$\" S5      S 5       r%S r& " S S5      r'S r(S r)S r*\" SS5      S 5       r+S r,S#S jr-S#S jr.S r/S r0\" SS 5       S$S! j5       r1 S#S" jr2g)%z6Object config serialization and deserialization logic.    N)object_registration)serialization)in_tf_saved_model_scope)generic_utils)	tf_export)keras_export)z%tensorflow.python.ops.custom_gradient)activationsconstraintsinitializerslossesmetrics
optimizersregularizersc                        \ rS rSrS rS rSrg)Config6   c                     Xl         g Nconfig)selfr   s     _/home/james-whalen/.local/lib/python3.13/site-packages/tf_keras/src/saving/serialization_lib.py__init__Config.__init__7   s        c                 ,    [        U R                  5      $ r   )serialize_keras_objectr   r   s    r   	serializeConfig.serialize:   s    %dkk22r   r   N)__name__
__module____qualname____firstlineno__r   r   __static_attributes__ r   r   r   r   6   s    3r   r   c                   .    \ rS rSrSrSS jrS rS rSrg)	SafeModeScope>   zBScope to propagate safe mode flag to nested deserialization calls.c                     Xl         g r   )	safe_mode)r   r+   s     r   r   SafeModeScope.__init__A   s    "r   c                 L    [        5       U l        U R                  [        l        g r   )in_safe_modeoriginal_valuer+   	SAFE_MODEr   s    r   	__enter__SafeModeScope.__enter__D   s    *n"nn	r   c                 .    U R                   [        l        g r   )r/   r0   r+   r   argskwargss      r   __exit__SafeModeScope.__exit__H   s    "11	r   )r/   r+   N)T)	r!   r"   r#   r$   __doc__r   r1   r7   r%   r&   r   r   r(   r(   >   s    L#-2r   r(   z0keras.__internal__.enable_unsafe_deserializationc                      S[         l        g)zADisables safe mode globally, allowing deserialization of lambdas.FN)r0   r+   r&   r   r   enable_unsafe_deserializationr;   L   s      Ir   c                  $    [        [        SS 5      $ )Nr+   )getattrr0   r&   r   r   r.   r.   R   s    9k400r   c                   $    \ rS rSrSrS rS rSrg)ObjectSharingScopeV   z?Scope to enable detection and reuse of previously seen objects.c                 F    S[         l        0 [         l        0 [         l        g NTSHARED_OBJECTSenabledid_to_obj_mapid_to_config_mapr   s    r   r1   ObjectSharingScope.__enter__Y   s    !%')$*,'r   c                 F    S[         l        0 [         l        0 [         l        g )NFrC   r4   s      r   r7   ObjectSharingScope.__exit__^   s    !&')$*,'r   r&   N)r!   r"   r#   r$   r9   r1   r7   r%   r&   r   r   r?   r?   V   s    I-
-r   r?   c                 p    [        [        SS5      (       a   [        R                  R                  U S5      $ g)z:Retrieve an object previously seen during deserialization.rE   FN)r=   rD   rF   get)obj_ids    r   get_shared_objectrN   d   s/    ~y%00++//== 1r   c                     US   S:X  a  SUS'   [        [        SS5      (       d  g[        [        U 5      5      nU[        R                  ;  a  U[        R                  U'   gX!S'   [        R                  U   nX#S'   g)z>Call after serializing an object, to keep track of its config.module__main__NrE   Fshared_object_id)r=   rD   intidrG   )objr   rM   prev_configs       r   !record_object_after_serializationrW   j   sx    h:%x>9e44C\F^44428''/%+!"$55f=*0&'r   c                 X    [        [        SS5      (       d  gU [        R                  U'   g)zFCall after deserializing an object, to keep track of it in the future.rE   FN)r=   rD   rF   )rU   rM   s     r   #record_object_after_deserializationrY   y   s$    >9e44+.N  (r   z#keras.saving.serialize_keras_objectz"keras.utils.serialize_keras_objectc                 
  ^
 [         R                  R                  R                  5       (       a  [	        5       (       a  [
        R                  " U 5      $ U c  U $ [        U [        5      (       a  U $ [        U [        [        45      (       a=  U  Vs/ s H  n[        U5      PM     nn[        U [        5      (       a  [        U5      $ U$ [        U [        5      (       a  [        U 5      $ [        U [        5      (       a  SSU R                  S5      0S.$ [        U [         R                  5      (       a  U R                   b  U R#                  5       $ S$ [        U [         R$                  5      (       a8  SU R'                  5       R)                  5       U R*                  R,                  S.S.$ [/        U 5      R0                  [2        R4                  :X  ai  [        U [2        R6                  5      (       a:  U R8                  S:  a*  S	U R)                  5       U R*                  R,                  S.S.$ U R;                  5       $ [        U [         R<                  5      (       a  U R,                  $ [        U [         R>                  R@                  RB                  5      (       a  U RD                  $ [        U [F        RH                  5      (       aW  U R4                  S
:X  aG  [J        RL                  " S[N        RP                  " U 5       3SS9  SS[R        RT                  " U 5      0S.$ [        U [         RV                  5      (       a  U RY                  5       n[        [[        S U5      5      nU R\                  R4                  nSn[_        U S5      (       aT  [         R`                  Rb                  Re                  U 5      n[        U5      n[f        Rh                  " U R\                  5      nSUU R\                  R0                  UUS.$ [k        U 5      n[m        U R\                  U5      m
[        U[n        5      (       a  US:X  a  U $ T
b:  [q        U
4S j[r         5       5      (       a  U $ [u        U T
5        [w        U T
5        T
$ [        U [F        RH                  5      (       a  U R0                  nOU R\                  R0                  nU R\                  R4                  nUS:X  a  SnOV[        U [F        RH                  5      (       a  [f        Rh                  " U 5      nO [f        Rh                  " U R\                  5      nUUUUS.n	[u        X	5        [w        X	5        U	$ s  snf )a  Retrieve the config dict by serializing the TF-Keras object.

`serialize_keras_object()` serializes a TF-Keras object to a python
dictionary that represents the object, and is a reciprocal function of
`deserialize_keras_object()`. See `deserialize_keras_object()` for more
information about the config format.

Args:
  obj: the TF-Keras object to serialize.

Returns:
  A python dict that represents the object. The python dict can be
  deserialized via `deserialize_keras_object()`.
N	__bytes__valueutf-8)
class_namer   
__tensor__)r\   dtyper   	__numpy__z<lambda>a  The object being serialized includes a `lambda`. This is unsafe. In order to reload the object, you will have to pass `safe_mode=False` to the loading function. Please avoid using `lambda` in the future, and use named Python functions instead. This is the `lambda` being serialized:    )
stacklevel
__lambda__c                     [        U [        R                  5      (       a  U R                  5       $ [        U [        R                  5      (       a  U R
                  $ U $ r   )
isinstancetfTensorShapeas_listDTypenamexs    r   <lambda>(serialize_keras_object.<locals>.<lambda>   sJ    a00 ))+ @ *1bhh 7 7aff@=>@r   _tf_extension_type_fields__typespec__)r^   	spec_namerP   r   registered_nameop_dispatch_handlerc              3   4   >#    U  H  nUTS    ;   v   M     g7f)rP   Nr&   ).0modconfig_with_public_classs     r   	<genexpr>)serialize_keras_object.<locals>.<genexpr>   s#      
5 +H555s   builtinsrP   r^   r   rs   )<rg   __internal__tf2rE   r   legacy_serializationr   rf   PLAIN_TYPESlisttupledictserialize_dictbytesdecoderh   _dimsri   Tensornumpytolistr`   rk   typer"   npr!   ndarrayndimitemrj   compatv1	Dimensionr\   typesFunctionTypewarningswarninspect	getsourcer   	func_dumpTypeSpec
_serializemap	__class__hasattrexperimentalextension_typeas_dictr   get_registered_name_get_class_or_fn_configserialize_with_public_classstranyNON_SERIALIZABLE_CLASS_MODULESget_build_and_compile_configrW   )rU   rm   
config_arr	ts_configrr   rs   inner_configrP   r^   r   rx   s             @r   r   r      sX   * ??&&((,C,E,E#::3??
{
#{##
#e}%%9<=A,Q/
=$.sE$:$:uZ J
J#tc"" #u%

7 34
 	
 #r~~&& #		 5s{{}?4?#ryy!!&++-
 	
 Cyr{{*c2::&&388a<) ZZ\ YY^^  88:#rxx  xx#ryy||--..yy#u))**s||z/I6
 7>6G6G6L5MO 	
 '005
 	
 #r{{##NN$	@ 	
	 MM**	334466>>sCI&y1I1EEO )"mm...
 	
 +3/L:|  ,$$9N)N
+ 
5
 
 
 J$S*BC)#/GH'' #u))**))''Jc5--..1EEcJO1EEO
  *	F !-%c2MC >s   Uc                     [        U S5      (       a!  U R                  5       nUb  [        U5      US'   [        U S5      (       a!  U R                  5       nUb  [        U5      US'   g )Nget_build_configbuild_configget_compile_configcompile_config)r   r   r   r   )rU   r   r   r   s       r   r   r   #  sh    s&''++-#%3L%AF>"s())//1%'5n'EF#$
r   c                     [         R                  " U SS9nUc5  [        R                  " U 5      nUc  gU R                  U R
                  UUS.$ UR                  S5      nSR                  USS 5      US   USS.$ )zSerializes classes from public TF-Keras API or object registration.

Called to check and retrieve the config of any class that has a public
TF-Keras API or has been registered as serializable via
`keras.saving.register_keras_serializable()`.
kerasapi_nameNr|   .)r   get_canonical_name_for_symbolr   r   r"   r!   splitjoin)clsr   keras_api_namers   partss        r   r   r   /  s     <<gN
 -AA#F" nn,,".	
 	
   %E((5":&Bi	 r   c                 (   U(       a  USUUS.$ [         R                  " U SS9nU(       a*  UR                  S5      nSR                  USS 5      SUUS.$ [        R
                  " U 5      nU(       d  U R                  S:X  d  gU R                  SUUS.$ )	aA  Serializes functions from public TF-Keras API or object registration.

Called to check and retrieve the config of any function that has a public
TF-Keras API or has been registered as serializable via
`keras.saving.register_keras_serializable()`. If function's module name is
already known, returns corresponding config.
functionr|   r   r   r   Nr   r{   )r   r   r   r   r   r   r"   )fnr   fn_module_namer   r   rs   s         r   serialize_with_public_fnr   S  s     $$%	
 	
 <<
WN $$S)hhuSbz*$%	
 	
 .AA"Er}}
'Bmm$.	
 	
r   c                    [        U [        R                  5      (       a  U R                  $ [	        U S5      (       aA  U R                  5       n[        U[        5      (       d  [        SU  SU 35      e[        U5      $ [	        U S5      (       a  [        R                  " U 5      $ [        SU  S[        U 5       S35      e)z1Return the object's config depending on its type.
get_configzThe `get_config()` method of z$ should return a dict. It returned: r!   zCannot serialize object z	 of type zG. To be serializable, a class must implement the `get_config()` method.)rf   r   r   r!   r   r   r   	TypeErrorr   r   r   r   )rU   r   s     r   r   r   y  s     #u))**||sL!!!&$''/u 5((.x1  f%%	j	!	!"66s;;&se9T#YK @@ @
 	
r   c                 l    U R                  5        VVs0 s H  u  pU[        U5      _M     snn$ s  snnf r   )itemsr   )rU   keyr\   s      r   r   r     s-    ADM:3C'..MMMs   0z%keras.saving.deserialize_keras_objectz$keras.utils.deserialize_keras_objectc                    [        5       nUb  UOUnUR                  SS5      nU=(       d    0 n[        R                  R                  n[        R
                  n0 UEUEUEnUR                  SS5      nU(       a%  [        S[        UR                  5       5       35      e[        R                  R                  R                  5       (       a  [        5       (       a  [        R                  " XX5      $ U c  g[!        U ["        5      (       a  U(       a  UR%                  U 5      b  X   $ [!        U [        [&        45      (       a  U  V	s/ s H  n	[        XUS9PM     sn	$ UGb$  Su  pn[!        U [(        5      (       a  SU ;   a  U S   n
S	U ;  a  [        S
U  35      eU(       a;  U S	   U;   d/  U R%                  S5      U;   d  [!        U
["        5      (       a  X;   a  SnOPU S	   S:X  a  U S   nUS:X  a  U S   n O6U S   n O0U R%                  SS5      c  [+        SU S	    SU S	    S35      eU S	   n U(       dR  X;  a  U $ [!        XP   [,        R.                  5      (       a  [        [1        XP   X5      US9$ [        [3        XP   U
S9US9$ [!        U [4        5      (       a  U $ [!        U [(        5      (       d  [+        SU  35      eS	U ;  d  SU ;  a.  U R7                  5        VVs0 s H  u  pU[        XUS9_M     snn$ U S	   nU S   =(       d    0 n
U=(       d    0 nUS:X  a  [        R8                  " U
S   U
S   S9$ US:X  a  [:        R<                  " U
S   U
S   S9$ U S	   S:X  a  U
S   R?                  S5      $ U S	   S:X  a+  U(       a  [        S5      e[@        RB                  " U
S   5      $ U S	   S :X  a  [E        U S!   U S   U S   S"U US#9n[G        US$5      (       a5  U
R7                  5        VVs0 s H  u  pU[        XUS9_M     n
nnU" S,0 U
D6$ U S   b  URI                  U
5      $ [K        S% U
5      n
URM                  ['        U
5      5      $ U R%                  SS5      nU R%                  SU5      nUS:X  a  U
n[E        UUUSU US#9$ S&U ;   a  [O        U S&   5      nUb  U$ [E        UUUS"U US#9n[!        U[,        R.                  5      (       a  U$ [G        US'5      (       d  [+        S(U S)U  35      e[        RP                  " U5      n[S        U5      nU   U   URI                  U
5      nU R%                  S*S5      nU(       a  URU                  U5        U R%                  S+S5      nU(       a  URW                  U5        SSS5        SSS5        S&U ;   a  [Y        WU S&   5        W$ s  sn	f s  snnf s  snnf ! , (       d  f       N>= f! , (       d  f       NG= f)-a_  Retrieve the object by deserializing the config dict.

The config dict is a Python dictionary that consists of a set of key-value
pairs, and represents a TF-Keras object, such as an `Optimizer`, `Layer`,
`Metrics`, etc. The saving and loading library uses the following keys to
record information of a TF-Keras object:

- `class_name`: String. This is the name of the class,
  as exactly defined in the source
  code, such as "LossesContainer".
- `config`: Dict. Library-defined or user-defined key-value pairs that store
  the configuration of the object, as obtained by `object.get_config()`.
- `module`: String. The path of the python module, such as
  "keras.engine.compile_utils". Built-in TF-Keras classes
  expect to have prefix `keras`.
- `registered_name`: String. The key the class is registered under via
  `keras.saving.register_keras_serializable(package, name)` API. The key has
  the format of '{package}>{name}', where `package` and `name` are the
  arguments passed to `register_keras_serializable()`. If `name` is not
  provided, it uses the class name. If `registered_name` successfully
  resolves to a class (that was registered), the `class_name` and `config`
  values in the dict will not be used. `registered_name` is only used for
  non-built-in classes.

For example, the following dictionary represents the built-in Adam optimizer
with the relevant config:

```python
dict_structure = {
    "class_name": "Adam",
    "config": {
        "amsgrad": false,
        "beta_1": 0.8999999761581421,
        "beta_2": 0.9990000128746033,
        "decay": 0.0,
        "epsilon": 1e-07,
        "learning_rate": 0.0010000000474974513,
        "name": "Adam"
    },
    "module": "keras.optimizers",
    "registered_name": None
}
# Returns an `Adam` instance identical to the original one.
deserialize_keras_object(dict_structure)
```

If the class does not have an exported TF-Keras namespace, the library
tracks it by its `module` and `class_name`. For example:

```python
dict_structure = {
  "class_name": "LossesContainer",
  "config": {
      "losses": [...],
      "total_loss_mean": {...},
  },
  "module": "keras.engine.compile_utils",
  "registered_name": "LossesContainer"
}

# Returns a `LossesContainer` instance identical to the original one.
deserialize_keras_object(dict_structure)
```

And the following dictionary represents a user-customized `MeanSquaredError`
loss:

```python
@keras.saving.register_keras_serializable(package='my_package')
class ModifiedMeanSquaredError(keras.losses.MeanSquaredError):
  ...

dict_structure = {
    "class_name": "ModifiedMeanSquaredError",
    "config": {
        "fn": "mean_squared_error",
        "name": "mean_squared_error",
        "reduction": "auto"
    },
    "registered_name": "my_package>ModifiedMeanSquaredError"
}
# Returns the `ModifiedMeanSquaredError` object
deserialize_keras_object(dict_structure)
```

Args:
    config: Python dict describing the object.
    custom_objects: Python dict containing a mapping between custom
        object names the corresponding classes or functions.
    safe_mode: Boolean, whether to disallow unsafe `lambda` deserialization.
        When `safe_mode=False`, loading an object has the potential to
        trigger arbitrary code execution. This argument is only
        applicable to the TF-Keras v3 model format. Defaults to `True`.

Returns:
  The object described by the `config` dictionary.

Nmodule_objectsprintable_module_nameobjectz-The following argument(s) are not supported: )custom_objectsr+   )NNFr   r^   z%Unknown `config` as a `dict`, config=rs   Tr   rP   r{   _z#Cannot deserialize object of type `z`. If `zj` is a custom class, please register it using the `@keras.saving.register_keras_serializable()` decorator.r   )r   zCould not parse config: r_   r\   r`   )r`   ra   r[   r]   rd   a  Requested the deserialization of a `lambda` object. This carries a potential risk of arbitrary code execution and thus it is disallowed by default. If you trust the source of the saved model, you can pass `safe_mode=False` to the loading function in order to allow `lambda` loading.rq   rr   class)obj_typefull_configr   rp   c                     [        U [        5      (       a  [        R                  " U 5      $ [	        [        R
                  [        U 5      5      (       a  [        [        U 5      $ U $ r   )rf   r   rg   rh   r   dtypesr   r=   rl   s    r   rn   *deserialize_keras_object.<locals>.<lambda>  sO    !T"" nnQ' G$+BIIs1v$>$>'"a.GDEGr   rR   from_configz&Unable to reconstruct an instance of 'zM' because the class is missing a `from_config()` method. Full object config: r   r   r&   )-r.   popr   _THREAD_LOCAL_CUSTOM_OBJECTS__dict___GLOBAL_CUSTOM_OBJECTS
ValueErrorr   keysrg   r}   r~   rE   r   r   deserialize_keras_objectrf   r   rL   r   r   r   r   r   r   r   r   r   constantr   arrayencoder   	func_load_retrieve_class_or_fnr   r   r   _deserializerN   custom_object_scoper(   build_from_configcompile_from_configrY   )r   r   r+   r6   safe_scope_argr   tlcogcor   rm   r   r   has_custom_objectr   r\   r^   r   rP   rs   fn_namerU   custom_obj_scopesafe_mode_scopeinstancer   r   s                             r   r   r     s   R "^N"0"<)IZZ 0$7N#)rN;;DDD

4
4C66$6#6N #JJ'>I;FKKM"#%
 	
 ??&&((,C,E,E#<<N
 	
 ~ 	63v&2 %%&4-((
 	
  %I 	
 	
 !:K7&7fd##6!%h/6) ;F8D 
 |$6::/0NB|S11$6 %)! %3!'!1!Z/#H-F#$56F ::h,4#"<01 2"<01 2%%   - +.0%2D2DEE/,&. $2	  ,+"*  .	  &+&&fd##26(;<<6!XV%;
 %lln	
 -
 )	  -	
 	
 %J(#)rL#)rN \!{{<0W8MNN[ xxW-\'5JKKl{*G$++G44l|+K  &&|G'<==l~-#;$%8)
 3344
 #/"4"4"6	 #7JC -I  #7	   &&&#$0??<00 G 	
 l 344 ZZ$'Fjj!2J?OZ$)
 	
 V#'9 :;?J
%C #u))**
3&&4ZL A##)(,
 	
 +>>~N#I.O	???<0zz.$7&&|4$4d;((8 +	 V#+f/0	
 O
R
R@ +?		s7   V&V+/V1WA&V7?W7
W	W
Wc                    US:X  a  [         R                  " XS9nO[         R                  " XS9nUb  U$ U(       Ga  US:X  d2  US:X  d,  UR                  S5      (       d  UR                  S5      (       a.  US-   U -   nSU;   a  S	U-   n[        R                  " U5      nUb  U$ US:X  a  US
:X  a  [
         H)  n	[        R                  " SU	-   S-   U -   5      nUc  M'  Us  $    UR                  5        V
Vs0 s H"  u  pU
R                  US   5      (       d  M   X_M$     nn
nU(       a"  [        [        UR                  5       5      5      $  UR                  S5      (       a  SU-   n[        R                  " U5      n	[        U	5      R!                  U S 5      nUcr  Ub  [        U	5      R!                  US 5      nU R#                  S5      S:X  a?  U R%                  S5      u  p[        U	5      R!                  US 5      nUb  ['        XS 5      OS nUb  U$ [        SU SU  SU 35      es  snn
f ! [         a    [        SU SU  SU SU 35      ef = f)Nr   r   tf_kerasr   zkeras.z	tf_keras.r   z__internal__.legacyz
compat.v1.r{   r   tf_zCould not deserialize z 'z' because its parent module z) cannot be imported. Full object config:    zCould not locate zr'. Make sure custom classes are decorated with `@keras.saving.register_keras_serializable()`. Full object config: )r   get_registered_object
startswithr   get_symbol_from_nameBUILTIN_MODULESr   endswithnextitervalues	importlibimport_moduleModuleNotFoundErrorr   varsrL   countr   r=   )rk   rs   rP   r   r   r   
custom_objr   rU   rw   kvfiltered_dict
outer_name
inner_name	outer_objs                   r   r   r     s   
 :(>>

 )>>

  j    **  --|d*H %0'(200:C
 z!f
&:&44sNS(4/ ?J ' +0022DA::k(34 2  
 D!5!5!7899
	  ))))&1C 3immD$';*3immOT: zz#!#)-C&
 IMM*d;	 !, I48  ?J

H:Rv .  +m	- S # 	(
"TF ;%%+H -''2m5 	s   5H%H%1H+ +"Ir   rB   )3r9   r   r   	threadingr   r   r   r   tensorflow.compat.v2r   v2rg   tf_keras.src.savingr   tf_keras.src.saving.legacyr   r   ,tf_keras.src.saving.legacy.saved_model.utilsr   tf_keras.src.utilsr   tensorflow.python.utilr    tensorflow.python.util.tf_exportr   r   rS   floatboolr   localrD   r0   r   r   r   r(   r;   r.   r?   rN   rW   rY   r   r   r   r   r   r   r   r   r&   r   r   <module>r     s+   =       ! ! 3 L P , - 9C%"OO	 "L 3 32 2 @A  B 
1- ->1/ )+O]]@	!H#
L
0N +*
 ,0J	J\
 JNar   