
    6bia`                        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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  SSKJr  SS	KJr  SS
KJr   SSKrSr Sr!Sr"Sr#\RH                  " 5       r%S\%l&        \'" 1 Sk5      r(S'S jr)S(S jr*S r+S)S jr,S r-S r.S r/S r0  S*S jr1S r2S r3 " S S5      r4 " S S5      r5 " S  S!5      r6S" r7S# r8S$ r9S+S% jr:S& r;g! \ a    Sr Nf = f),z3Python-based idempotent model-saving functionality.    N)losses)
base_layer)	optimizer)ObjectSharingScope)deserialize_keras_object)serialize_keras_object)generic_utils)io_utilszconfig.jsonzmetadata.jsonzmodel.weightsassetsT>,   updatesweights_updates	variables
submodulesinput_shapeoutput_shape_eager_losses_input_layers_tf_api_namesinbound_nodesstate_updates_inbound_nodes_output_layersoutbound_nodes_outbound_nodes_callable_losses_keras_api_names_tf_api_names_v1trainable_weights_trainable_weights_keras_api_names_v1trainable_variables_inbound_nodes_value_layer_call_argspecs_name_based_restores_outbound_nodes_value_saved_model_arg_specnon_trainable_weights_deferred_dependencies_non_trainable_weightsnon_trainable_variables_checkpoint_dependencies_saved_model_inputs_spec_self_tracked_trackables_self_name_based_restores_captured_weight_regularizer_layer_checkpoint_dependencies_self_saveable_object_factories_unconditional_dependency_names$_self_unconditional_dependency_names&_unconditional_checkpoint_dependencies)_self_unconditional_deferred_dependencies+_self_unconditional_checkpoint_dependenciesc           	         [        U5      nUR                  S5      (       d  [        SU 35      eUS:X  a  [        c  [	        S5      eU R
                  (       d  [        R                  " SSS9  [        [        S	S
5      nS[        l
        [        5          [        U 5      nSSS5        [        R                  " W5      n[        R                  " [        R                   ["        R"                  R%                  5       R'                  S5      S.5      n[)        U5      (       a  [*        R,                  " 5       nOUn [.        R0                  " US5       nUR3                  [4        S5       n	U	R7                  UR9                  5       5        SSS5        UR3                  [:        S5       n	U	R7                  UR9                  5       5        SSS5        US:X  a  [=        [>        S-   USS9n
O'US:X  a  [A        [>        S-   USS9n
O[        SU 35      e[C        [D        USS9n[G        U U
US[I        5       S9  U
RK                  5         URK                  5         SSS5        [)        U5      (       aS  [L        R*                  RN                  RQ                  US5       n	U	R7                  URS                  5       5        SSS5        O U[        l
        g! , (       d  f       GN0= f! , (       d  f       GN[= f! , (       d  f       GN/= f! , (       d  f       N= f! , (       d  f       Na= f! [T         a  nUeSnAff = f! U[        l
        f = f)a@  Save a zip-archive representing a TF-Keras model to the given filepath.

The zip-based archive contains the following structure:

- JSON-based configuration file (config.json): Records of model, layer, and
    other trackables' configuration.
- NPZ-based trackable state files, found in respective directories, such as
    model/states.npz, model/dense_layer/states.npz, etc.
- Metadata file.

The states of TF-Keras trackables (layers, optimizers, loss, and metrics)
are automatically saved as long as they can be discovered through the
attributes returned by `dir(Model)`. Typically, the state includes the
variables associated with the trackable, but some specially purposed layers
may contain more such as the vocabularies stored in the hashmaps. The
trackables define how their states are saved by exposing `save_state()` and
`load_state()` APIs.

For the case of layer states, the variables will be visited as long as
they are either 1) referenced via layer attributes, or 2) referenced via a
container (list, tuple, or dict), and the container is referenced via a
layer attribute.
.keraszOInvalid `filepath` argument: expected a `.keras` extension. Received: filepath=h5Nz0h5py must be installed in order to save a model.zYou are saving a model that has not yet been built. It might not contain any weights yet. Consider building the model first by calling it on some data.   
stacklevelvalueFTz%Y-%m-%d@%H:%M:%S)keras_version
date_savedw.h5archivemodenpz.npzzTUnknown `weights_format` argument. Expected 'h5' or 'npz'. Received: weights_format= weights_storeassets_store
inner_pathvisited_trackableswb)+strendswith
ValueErrorh5pyImportErrorbuiltwarningswarngetattr_SAVING_V3_ENABLEDr>   r   r   jsondumpskeras__version__datetimenowstrftimeis_remote_pathioBytesIOzipfileZipFileopen_METADATA_FILENAMEwriteencode_CONFIG_FILENAME	H5IOStore_VARS_FNAME
NpzIOStoreDiskIOStore_ASSETS_DIRNAME_save_statesetclosetfgfileGFilegetvalue	Exception)modelfilepathweights_formatsaving_v3_enabled_valueserialized_model_dictconfig_jsonmetadata_jsonzip_filepathzffrJ   asset_storees                X/home/james-whalen/.local/lib/python3.13/site-packages/tf_keras/src/saving/saving_lib.py
save_modelr   i   s   2 8}HX&&""*-
 	
 $,LMM;; 	
 &&8'5I#		 6u = 
**23KJJ".."++//1::;NO	
M hzz|(;__\3/2+S1Q,,./ 2)3/1**,- 0 % )%'#!  5( *&("3! !00>/?A  &orLK+(#&5 !? 0B (##""8T2a--/0 32 $ $; o 
	" 21// 0/D 32  $; s   K	9L! K?' KK?% K-BK?AL!  L3L! ;L5 	
K
K*	%K?-
K<	7K??
L	L! 
LL! L5 L! !
L2+L--L22L5 5Mc           
         [        U 5      n U R                  S5      (       d  [        SU  35      e[        [        SS5      nS[        l         [        R                  R                  R                  U SS9 n[        R                  " US5       nUR                  [        S5       nUR                  5       nS	S	S	5        [        R                   " W5      n	U(       d  S	U	S
'   [#        5          [%        XUS9n
S	S	S	5        UR'                  5       n[(        S-   U;   a  [+        [(        S-   USS9nO:[(        S-   U;   a  [-        [(        S-   USS9nO[        S[(         S[(         S35      e[/        U5      S:  a  [1        [2        USS9nOS	n[5        W
UUS[7        5       S9  UR9                  5         U(       a  UR9                  5         S	S	S	5        S	S	S	5        W
U[        l        $ ! , (       d  f       GN2= f! , (       d  f       GN= f! , (       d  f       NG= f! , (       d  f       NP= f! [:         a  nUeS	nAff = f! U[        l        f = f)z1Load a zip archive representing a TF-Keras model.r9   zDInvalid filename: expected a `.keras` extension. Received: filepath=r>   FTzr+brE   rNcompile_config)	safe_moderB   rC   rG   zExpected a z.h5 or z
.npz file.   rH   rI   )rO   rP   rQ   rW   rX   r>   rr   ra   rs   rt   rc   rd   re   ri   readrY   loadsr   r   namelistrk   rj   rl   lenrm   rn   _load_staterp   rq   rv   )rx   custom_objectscompiler   rz   gfile_handler   r   r|   config_dictrw   all_filenamesrJ   r   r   s                  r   
load_modelr      s    8}HX&&""*-
 	

 &&8'5I#6;UU[[5  
7??<=)3/1ffh 0
 **[1K04,-#%09 &
 KKMMU"m3 )%'#! v%6 *&("3! !!+gk]*M  =!A%)/2CP"+(#&5 !!!#Y >
f #: e 0/ &% >=
 
`  
 $; s   (H& 5HH$G 54H)G24CHHH& H:  
G/*H2
H<H
H	H
H#H& &
H70H22H77H: :Ic                     [        U5      nUR                  S5      (       d  [        SU 35      e[        USS9n[	        U USS[        5       S9  UR                  5         g)zfSave only the weights of a model to a target filepath (.weights.h5).

Note: only supports h5 for now.
.weights.h5zTInvalid `filepath` argument: expected a `.weights.h5` extension. Received: filepath=rA   r   NrH   rI   )rO   rP   rQ   rj   ro   rp   rq   )rw   rx   rJ   s      r   save_weights_onlyr     so     8}H]++""*-
 	
 hS1M#5     c           	         SnSn[        U5      nUR                  S5      (       a  [        USS9nO?UR                  S5      (       a)  [        R                  " US5      n[        [
        S-   USS9n[        U WSSU[        5       S	9  UR                  5         U(       aW  [        R                  R                  R                  U5      (       a)  [        R                  R                  R                  U5        U(       a  UR                  5         gg)
zfLoad the weights of a model from a filepath (.keras or .weights.h5).

Note: only supports h5 for now.
Nr   r   r   r9   rB   rC   rH   )rJ   rK   rL   skip_mismatchrM   )rO   rP   rj   rc   rd   rk   r   rp   rq   rr   ra   rs   existsrmtree)rw   rx   r   temp_dirrD   rJ   s         r   load_weights_onlyr   /  s    
 HG8}H''!(5			8	$	$//(C0!%s
 ##5 BEEKK&&x00
8$ r   c                 P    [         R                  " S[        U 5      5      (       a  gg)Nz^(/cns|/cfs|/gcs|.*://).*$TF)rematchrO   )rx   s    r   r`   r`   O  s    	xx-s8}==r   c                    [         R                  R                  R                  U5      (       d  U R	                  X5        g [         R                  R                  R                  U5       Ha  n[         R                  R                  R                  X5      n[         R                  R                  R                  X#5      n[        XU5        Mc     g N)rr   ra   rs   isdirrg   listdirjoin_write_to_zip_recursively)zipfile_to_savesystem_pathzip_path	file_namesystem_file_pathzip_file_paths         r   r   r   U  s    55;;[))k4,,[9I!uu{{//GEEKK,,XAM%= :r   c              #      #    [        [        U 5      SS9 H6  nUR                  S5      (       d
  U[        ;   a  M%   [	        X5      nX4v   M8     g ! [
         a     MH  f = f7f)NT)reverse__)sorteddir
startswithATTR_SKIPLISTrW   rv   )	trackable
child_attr	child_objs      r   _walk_trackabler   a  sb     S^T:
  &&**E		6I ## ;
  		s(   9A"A
A"
AA"AA"c           
         [        U 5      U;   a  g [        U S5      (       a'  U(       a   U R                  UR                  U5      5        [        U S5      (       a'  U(       a   U R	                  UR                  U5      5        UR                  [        U 5      5        [        U 5       H  u  pV[        U5      (       a6  [        UUU[        R                  R                  R                  X55      US9  MK  [        U[        [        [         ["        45      (       d  Mr  [%        UUU[        R                  R                  R                  X55      US9  M     g )Nsave_own_variablessave_assetsrL   rM   )idhasattrr   maker   addr   _is_keras_trackablero   rr   ra   rs   r   
isinstancelistdicttuplerp   _save_container_state)r   rJ   rK   rL   rM   r   r   s          r   ro   ro   m  s    
)}**y.//M$$]%7%7
%CDy-((\l//
;<2i=) "1!;
y))55;;++JC#5 	D$s#;<<!55;;++JC#5 "<r   c           
      *   U(       a  [        U 5      U;   a  g [        U S5      (       aP  U(       aI  U(       a"   U R                  UR                  U5      5        O U R                  UR                  U5      5        [        U S5      (       aP  U(       aI  U(       a"   U R                  UR                  U5      5        O U R                  UR                  U5      5        Ub  UR                  [        U 5      5        [        U 5       H  u  px[        U5      (       a7  [        UUU[        R                  R                  R                  X75      UUS9  ML  [!        U["        [$        [&        [(        45      (       d  Ms  [+        UUU[        R                  R                  R                  X75      UUS9  M     g ! [         a&  n[
        R                  " SU  SU 3SS9   S nAGNaS nAff = f! [         a&  n[
        R                  " SU  SU 3SS9   S nAGN3S nAff = f)	Nload_own_variablesz!Could not load weights in object z*. Skipping object. Exception encountered: r;   r<   load_assetsz Could not load assets in object rL   r   rM   )r   r   r   getrv   rU   rV   r   r   r   r   r   rr   ra   rs   r   r   r   r   r   rp   _load_container_state)	r   rJ   rK   rL   r   rM   r   r   r   s	            r   r   r     s    bm/AAy.//M,,]->->z-JK (():)::)FGy-((\%%l&6&6z&BC !!,"2"2:">?%r)}- "1!;
y))55;;++JC+#5 	D$s#;<<!55;;++JC+#5 "<9  7	{ C../S2  !	   6yk B../S2  !	 s/    F/  G" /
G9GG"
H,HHc           
         0 n[        U [        5      (       a  [        U R                  5       5      n U  H  n[	        U5      (       d  M  [        U5      U;   a  M&  [        R                  " UR                  R                  5      nXu;   a  XW==   S-  ss'   U SXW    3nOSXW'   [        UUU[        R                  R                  R                  X75      US9  M     g )N   _r   r   )r   r   r   valuesr   r   r	   to_snake_case	__class____name__ro   rr   ra   rs   r   )	containerrJ   rK   rL   rM   
used_namesr   names           r   r   r     s     J)T""))+,		y)) )} 22 !..y/B/B/K/KLD! A% q!1 23#$
 55;;++J=#5 r   c           
         0 n[        U [        5      (       a  [        U R                  5       5      n U  H  n[	        U5      (       d  M  U(       a  [        U5      U;   a  M-  [        R                  " UR                  R                  5      nX;   a  Xh==   S-  ss'   U SXh    3nOSXh'   [        UUU[        R                  R                  R                  X85      UUS9  M     g )Nr   r   r   r   )r   r   r   r   r   r   r	   r   r   r   r   rr   ra   rs   r   )	r   rJ   rK   rL   r   rM   r   r   r   s	            r   r   r     s     J)T""))+,		y)) "bm7I&I !..y/B/B/K/KLD! A% q!1 23#$
 55;;++J=+#5 r   c                   4    \ rS rSrSrS	S jrS rS rS rSr	g)
rm   i  zAsset store backed by disk storage.

If `archive` is specified, then `root_path` refers to the filename
inside the archive.

If `archive` is not specified, then `root_path` refers to the full path of
the target directory.
Nc                    X0l         Xl        X l        S U l        U R                  (       a  [	        5       U l        U R                   S:X  a#  U R                  R                  U R                  S9  [        R                  R                  R                  U R                  U R                  5      U l
        U R                   S:X  a4  [        R                  R                  R                  U R                  5        g g US:X  a  Xl
        g [	        5       U l        [        R                  R                  R                  U R                  U R                  5      U l
        [        R                  R                  R                  U R                  5        g )Nr   )pathrA   )rE   	root_pathrD   tmp_dirget_temp_dir
extractallrr   ra   rs   r   working_dirmakedirsselfr   rD   rE   s       r   __init__DiskIOStore.__init__  s    	"<<'>DLyyC''T\\':!uu{{//dnnMDyyC$$T%5%56   s{#, +~#%55;;#3#3LL$..$  $$T%5%56r   c                 B   U(       d  U R                   $ [        R                  R                  R	                  U R                   U5      n[        R                  R                  R                  U5      (       d)  [        R                  R                  R                  U5        U$ r   )r   rr   ra   rs   r   r   r   r   r   s     r   r   DiskIOStore.make3  se    ###uu{{ 0 0$7uu{{!!$''EEKK  &r   c                     U(       d  U R                   $ [        R                  R                  R	                  U R                   U5      n[        R                  R                  R                  U5      (       a  U$ g r   )r   rr   ra   rs   r   r   r   s     r   r   DiskIOStore.get;  sR    ###uu{{ 0 0$755;;d##Kr   c                    U R                   S:X  a<  U R                  (       a+  [        U R                  U R                  U R                  5        U R
                  (       am  [        R                  R                  R                  U R
                  5      (       a4  [        R                  R                  R                  U R
                  5        g g g NrA   )rE   rD   r   r   r   r   rr   ra   rs   r   r   r   s    r   rq   DiskIOStore.closeC  sw    99%d.. <<BEEKK..t||<<EEKKt||, =<r   )rD   rE   r   r   r   )NN)
r   
__module____qualname____firstlineno____doc__r   r   r   rq   __static_attributes__ r   r   rm   rm     s    7,-r   rm   c                   0    \ rS rSrSS jrS rS rS rSrg)	rj   iL  Nc                    Xl         X0l        X l        SU l        U R                  (       a  U R                  S:X  a  [        R
                  " 5       U l        O+U R                  R                  U R                   S5      U l        [        R                  " U R                  U R                  S9U l	        g[        R                  " XR                  S9U l	        g)zNumerical variable store backed by HDF5.

If `archive` is specified, then `root_path` refers to the filename
inside the archive.

If `archive` is not specified, then `root_path` refers to the path of
the h5 file on disk.
NrA   r   r   )
r   rE   rD   io_filera   rb   re   rR   Fileh5_filer   s       r   r   H5IOStore.__init__M  s     #	<<yyC!zz|#||00E99T\\		BDL99YYY?DLr   c                     U(       d  U R                   R                  S5      $ U R                   R                  U5      R                  S5      $ Nvars)r   create_groupr   s     r   r   H5IOStore.maked  s:    <<,,V44||((.;;FCCr   c                     U(       d  U R                   S   $ XR                   ;   a%  SU R                   U   ;   a  U R                   U   S   $ 0 $ r   )r   r   s     r   r   H5IOStore.geti  sG    <<''<<Fdll4.@$@<<%f--	r   c                 N   U R                   R                  5         U R                  S:X  aO  U R                  (       a>  U R                  R	                  U R
                  U R                  R                  5       5        U R                  (       a  U R                  R                  5         g g r   )r   rq   rE   rD   writestrr   r   ru   r   s    r   rq   H5IOStore.closep  se    99LL!!$..$,,2G2G2IJ<<LL  r   )rD   r   r   rE   r   Nr   	r   r   r   r   r   r   r   rq   r   r   r   r   rj   rj   L  s    @.D
!r   rj   c                   0    \ rS rSrSS jrS rS rS rSrg)	rl   ix  Nc                     Xl         X0l        X l        US:X  a  0 U l        gU R                  (       a  UR	                  USS9U l        O[	        USS9U l        [        R                  " U R
                  SS9U l        g)zNumerical variable store backed by NumPy.savez/load.

 If `archive` is specified, then `root_path` refers to the filename
inside the archive.

If `archive` is not specified, then `root_path` refers to the path of
the npz file on disk.
rA   r   r   rbT)allow_pickleN)r   rE   rD   contentsre   r   nploadr   s       r   r   NpzIOStore.__init__y  s`     #	3;DM|| ic:id3GGDFF>DMr   c                     U(       d  0 U R                   S'   U R                   S   $ 0 U R                   U'   U R                   U   $ N__root__)r  r   s     r   r   NpzIOStore.make  s?    (*DMM*%==,, d}}T""r   c                     U(       d*  SU R                   ;   a  [        U R                   S   5      $ 0 $ XR                   ;   a  U R                   U   R                  5       $ 0 $ r  )r  r   tolistr   s     r   r   NpzIOStore.get  sQ    T]]*DMM*566I== ==&--//	r   c                 X   U R                   S:X  a  U R                  (       a+  U R                  R                  U R                  SSS9U l        O[        U R                  SS9U l        [
        R                  " U R                  40 U R                  D6  U R                  R                  5         g )NrA   T)rE   force_zip64rN   r   )	rE   rD   re   r   r   r  savezr  rq   r   s    r   rq   NpzIOStore.close  su    99||**NN$ +  dnn48HHTVV-t}}-r   )rD   r  r   rE   r   r  r  r   r   r   rl   rl   x  s    ?*#	r   rl   c                  x    [         R                  " 5       n [         R                  " U S9nUR                  5         U $ )N)r   )tempfilemkdtempTemporaryFilerq   )r   testfiles     r   r   r     s/    !H%%(3HNNOr   c                     SSK Jn  [        U [        R                  [
        R                  UR                  [        R                  45      $ )Nr   )base_metric)
tf_keras.src.metricsr   r   r   Layerr   	OptimizerMetricr   Loss)objr   s     r   r   r     s<    0KK		
 r   c                  $    [        [        SS5      $ )Nr>   T)rW   rX   r   r   r   saving_v3_enabledr(    s    %w55r   c                     U(       d  [        SU  SU S35        [        U S5      (       d  g U R                  5        H"  n[        SU U 35        [        X   US-   S9  M$     g )NzKeras weights file (z) :keysz...)prefix)printr   r+  _print_h5_file)r   r,  actionkeys       r   r.  r.    s`    $WIRxq9:7F##||~F8C5!"w|FUN; r   c                    [         R                  " SU S35        [         R                  " SS-  5        U R                   HD  nSUR                  S S -  n[         R                  " SUR                  X2R
                  4-  5        MF     g )NzKeras model archive r*  z%-46s %19s %12s)z	File NamezModified    Sizez%d-%02d-%02d %02d:%02d:%02d   z%-46s %s %12d)r
   	print_msgfilelist	date_timefilename	file_size)rc   r/  zinfodates       r   _print_zip_filer;    s{    -fXQ78AA !!,ur/BBu~~t__EE	
 "r   )r:   )NTT)F)FN)rH   N)<r   r]   ra   rY   r   r  	threadingrU   rc   numpyr  tensorflow.compat.v2compatv2rr   tf_keras.srcsrcr[   r   tf_keras.src.enginer   tf_keras.src.optimizersr   %tf_keras.src.saving.serialization_libr   r   r   tf_keras.src.utilsr	   r
   rR   rS   ri   rf   rk   rn   localrX   r>   	frozensetr   r   r   r   r   r`   r   r   ro   r   r   r   rm   rj   rl   r   r   r(  r.  r;  r   r   r   <module>rI     s&   :  	  	      ! !   * - D J H , ' ! $  __&   -/dd;NC;L2@		$N =@>"J6- 6-r)! )!X/ /d6<

O  Ds   'C0 0C;:C;