
    0h^                        d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z
ddlmc 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 	 ddlZdZ dZ!dZ"dZ# ejH                         Z%de%_&         e'h d      Z(d'dZ)d(dZ*d Z+d)dZ,d Z-d Z.d Z/d Z0	 	 d*dZ1d Z2d Z3 G d d      Z4 G d d      Z5 G d  d!      Z6d" Z7d# Z8d$ Z9d+d%Z:d& Z;y# e$ r dZY w xY w),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           	         t        |      }|j                  d      st        d|       |dk(  rt        t	        d      | j
                  st        j                  dd       t        t        d	d
      }dt        _
        t               5  t        |       }ddd       t        j                        }t        j                  t        j                   t"        j"                  j%                         j'                  d      d      }	 t)        j*                  |d      5 }|j-                  t.        d      5 }|j1                  |j3                                ddd       |j-                  t4        d      5 }|j1                  |j3                                ddd       |dk(  rt7        t8        dz   |d      }	n)|dk(  rt;        t8        dz   |d      }	nt        d|       t=        t>        |d      }
tA        | |	|
dtC                      |	jE                          |
jE                          ddd       |t        _
        y# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   :xY w# tF        $ r}|d}~ww xY w# |t        _
        w xY w)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)$strendswith
ValueErrorh5pyImportErrorbuiltwarningswarngetattr_SAVING_V3_ENABLEDr>   r   r   jsondumpskeras__version__datetimenowstrftimezipfileZipFileopen_METADATA_FILENAMEwriteencode_CONFIG_FILENAME	H5IOStore_VARS_FNAME
NpzIOStoreDiskIOStore_ASSETS_DIRNAME_save_statesetclose	Exception)modelfilepathweights_formatsaving_v3_enabled_valueserialized_model_dictconfig_jsonmetadata_jsonzffrJ   asset_storees               X/var/www/html/engine/venv/lib/python3.12/site-packages/tf_keras/src/saving/saving_lib.py
save_modelr{   i   sk   2 8}HX&""*-
 	
 $,LMM;; 	
 &&8'5I#		 > 6u =>**23KJJ".."++//1::;NO	
M$;__Xs+ 	 r+S1 0Q,,./0)3/ .1**,-. % )%'#!  5( *&("3! !00>/?A  &orLK+(#&5 !?	 F $; [> >0 0. .	  	 @   $; sy   
H:I+ I2 II0 IBI&I+ :II	II	II($I+ +	I;4I66I;;I> >Jc           
      b   t        |       } | j                  d      st        d|        t        t        dd      }dt        _        	 t        j                  j                  j                  | d      5 }t        j                  |d      5 }|j                  t        d      5 }|j                         }d	d	d	       t        j                         }	|sd	|	d
<   t#               5  t%        |	||      }
d	d	d	       |j'                         }t(        dz   |v rt+        t(        dz   |d      }n;t(        dz   |v rt-        t(        dz   |d      }nt        dt(         dt(         d      t/        |      dkD  rt1        t2        |d      }nd	}t5        
||dt7                      |j9                          |r|j9                          d	d	d	       d	d	d	       
|t        _        S # 1 sw Y   -xY w# 1 sw Y   xY w# 1 sw Y   7xY w# 1 sw Y   ;xY w# t:        $ r}|d	}~ww xY w# |t        _        w xY w)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   )rN   rO   rP   rV   rW   r>   tfiogfileGFiler_   r`   ra   re   readrX   loadsr   r   namelistrg   rf   rh   lenri   rj   _load_staterl   rm   rn   )rp   custom_objectscompiler   rr   gfile_handlerv   rw   rt   config_dictro   all_filenamesrJ   rx   ry   s                  rz   
load_modelr      s1    8}HX&""*-
 	

 &&8'5I#6;UU[[5  
 .	$7??<=.	$AC)3/ '1ffh'
 **[1K04,-#% 09
 KKMMU"m3 )%'#! v%6 *&("3! !!+gk]*M  =!A%)/2CP"+(#&5 !!!#].	$ .	$f #: e' ' .	$ .	$ .	$ .	$`  
 $; s   +H 3H
G6!G2.G6 G*/CG6 HH H! G'"G6*G3/G66G?	;HHH 	HHHH! !H.c                     t        |      }|j                  d      st        d|       t        |d      }t	        | |ddt                      |j                          y)znSave 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   )rN   rO   rP   rf   rk   rl   rm   )ro   rp   rJ   s      rz   save_weights_onlyr     sl     8}H]+""*-
 	
 hS1M#5     c           	         d}d}t        |      }|j                  d      rt        |d      }n<|j                  d      r+t        j                  |d      }t        t
        dz   |d      }t        | dd|t               	       |j                          |rRt        j                  j                  j                  |      r)t        j                  j                  j                  |       |r|j                          yy)
znLoad 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   )rN   rO   rf   r_   r`   rg   r   rl   rm   r   r   r   existsrmtree)ro   rp   r   temp_dirrD   rJ   s         rz   load_weights_onlyr   %  s    
 HG8}H'!(5			8	$//(C0!%s
 ##5 BEEKK&&x0
8$ r   c                 D    t        j                  dt        |             ryy)Nz^(/cns|/cfs|/gcs|.*://).*$TF)rematchrN   )rp   s    rz   is_remote_pathr   E  s    	xx-s8}=r   c                    t         j                  j                  j                  |      s| j	                  ||       y t         j                  j                  j                  |      D ]c  }t         j                  j                  j                  ||      }t         j                  j                  j                  ||      }t        | ||       e y N)r   r   r   isdirrc   listdirjoin_write_to_zip_recursively)zipfile_to_savesystem_pathzip_path	file_namesystem_file_pathzip_file_paths         rz   r   r   K  s    55;;[)k84,,[9 	I!uu{{//YGEEKK,,XyAM%!1=	r   c              #      K   t        t        |       d      D ]/  }|j                  d      s|t        v r	 t	        | |      }||f 1 y # t
        $ r Y >w xY ww)NT)reverse__)sorteddir
startswithATTR_SKIPLISTrV   rn   )	trackable
child_attr	child_objs      rz   _walk_trackabler   W  si     S^T: $
  &**E		:6I )##$
  		s(   4AA	A	AAAAc           
      l   t        |       |v ry t        | d      r"|r | j                  |j                  |             t        | d      r"|r | j	                  |j                  |             |j                  t        |              t        |       D ]  \  }}t        |      r9t        |||t        j                  j                  j                  ||      |       Jt        |t        t        t         t"        f      skt%        |||t        j                  j                  j                  ||      |        y )Nsave_own_variablessave_assetsrL   rM   )idhasattrr   maker   addr   _is_keras_trackablerk   r   r   r   r   
isinstancelistdicttuplerl   _save_container_state)r   rJ   rK   rL   rM   r   r   s          rz   rk   rk   c  s    
)}**y./M$$]%7%7
%CDy-(\l//
;<2i=) "1!; 
Iy)55;;++J
C#5 	D$s#;<!55;;++J
C#5r   c           
         |rt        |       |v ry t        | d      rF|rD|r"	 | j                  |j                  |             n | j                  |j                  |             t        | d      rF|rD|r"	 | j                  |j                  |             n | j                  |j                  |             ||j                  t        |              t        |       D ]  \  }}t        |      r:t        |||t        j                  j                  j                  ||      ||       Kt!        |t"        t$        t&        t(        f      slt+        |||t        j                  j                  j                  ||      ||        y # t        $ r(}t        j                  d|  d| d       Y d }~Md }~ww xY w# t        $ r(}t        j                  d|  d| d       Y d }~/d }~ww xY w)	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   getrn   rT   rU   r   r   r   r   r   r   r   r   r   r   r   r   r   rl   _load_container_state)	r   rJ   rK   rL   r   rM   ry   r   r   s	            rz   r   r     s    bm/AAy./M,,]->->z-JK (():)::)FGy-(\%%l&6&6z&BC !!,"2"2:">?%r)}- "1!; 
Iy)55;;++J
C+#5 	D$s#;<!55;;++J
C+#59  7	{ C../S2  !	   6yk B../S2  !	 s/    F 4 F8 	F5F00F58	G)G$$G)c           
         i }t        | t              rt        | j                               } | D ]  }t	        |      st        |      |v rt        j                  |j                  j                        }||v r||xx   dz  cc<   | d||    }nd||<   t        |||t        j                  j                  j                  ||      |        y )N   _r   r   )r   r   r   valuesr   r   r	   to_snake_case	__class____name__rk   r   r   r   r   )	containerrJ   rK   rL   rM   
used_namesr   names           rz   r   r     s     J)T"))+,	 	y) )} 22 !..y/B/B/K/KLDz!4 A% qD!1 23#$
4 55;;++J=#5r   c           
         i }t        | t              rt        | j                               } | D ]  }t	        |      s|rt        |      |v rt        j                  |j                  j                        }||v r||xx   dz  cc<   | d||    }nd||<   t        |||t        j                  j                  j                  ||      ||        y )Nr   r   r   r   )r   r   r   r   r   r   r	   r   r   r   r   r   r   r   r   )	r   rJ   rK   rL   r   rM   r   r   r   s	            rz   r   r     s     J)T"))+,	 	y) "bm7I&I !..y/B/B/K/KLDz!4 A% qD!1 23#$
4 55;;++J=+#5r   c                   *    e Zd ZdZddZd Zd Zd Zy)ri   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                    || _         || _        || _        d | _        | j                  rt	               | _        | j                   dk(  r&| j                  j                  | j                         t        j                  j                  j                  | j                  | j                        | _
        | j                   dk(  r4t        j                  j                  j                  | j                         y y |dk(  r|| _
        y t	               | _        t        j                  j                  j                  | j                  | j                        | _
        t        j                  j                  j                  | j                         y )Nr~   )pathrA   )rE   	root_pathrD   tmp_dirget_temp_dir
extractallr   r   r   r   working_dirmakedirsselfr   rD   rE   s       rz   __init__zDiskIOStore.__init__  s   	"<<'>DLyyC''T\\':!uu{{//dnnMDyyC$$T%5%56   s{#, +~#%55;;#3#3LL$..$  $$T%5%56r   c                 .   |s| j                   S t        j                  j                  j	                  | j                   |      }t        j                  j                  j                  |      s)t        j                  j                  j                  |       |S r   )r   r   r   r   r   r   r   r   r   s     rz   r   zDiskIOStore.make)  sb    ###uu{{ 0 0$7uu{{!!$'EEKK  &r   c                     |s| j                   S t        j                  j                  j	                  | j                   |      }t        j                  j                  j                  |      r|S y r   )r   r   r   r   r   r   r   s     rz   r   zDiskIOStore.get1  sO    ###uu{{ 0 0$755;;d#Kr   c                 x   | j                   dk(  r7| j                  r+t        | j                  | j                  | j                         | j
                  rht        j                  j                  j                  | j
                        r4t        j                  j                  j                  | j
                         y y y NrA   )rE   rD   r   r   r   r   r   r   r   r   r   r   s    rz   rm   zDiskIOStore.close9  st    99%d.. <<BEEKK..t||<EEKKt||, =<r   )NN)r   
__module____qualname____doc__r   r   r   rm    r   rz   ri   ri   	  s    7,-r   ri   c                   &    e Zd ZddZd Zd Zd Zy)rf   Nc                    || _         || _        || _        d| _        | j                  r| j                  dk(  rt	        j
                         | _        n+| j                  j                  | j                   d      | _        t        j                  | j                  | j                        | _	        yt        j                  || j                        | _	        y)a  Numerical 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_filer   BytesIOra   rQ   Fileh5_filer   s       rz   r   zH5IOStore.__init__C  s     #	<<yyC!zz|#||00E99T\\		BDL99YTYY?DLr   c                     |s| j                   j                  d      S | j                   j                  |      j                  d      S Nvars)r   create_groupr   s     rz   r   zH5IOStore.makeZ  s:    <<,,V44||((.;;FCCr   c                     |s| j                   d   S || j                   v r#d| j                   |   v r| j                   |   d   S i S r   )r   r   s     rz   r   zH5IOStore.get_  sI    <<''4<<Fdll4.@$@<<%f--	r   c                 8   | j                   j                          | j                  dk(  rJ| j                  r>| j                  j	                  | j
                  | j                  j                                | j                  r| j                  j                          y y r   )r   rm   rE   rD   writestrr   r   getvaluer   s    rz   rm   zH5IOStore.closef  se    99LL!!$..$,,2G2G2IJ<<LL  r   Nr~   r   r   r   r   r   r   rm   r   r   rz   rf   rf   B  s    @.D
!r   rf   c                   &    e Zd ZddZd Zd Zd Zy)rh   Nc                    || _         || _        || _        |dk(  ri | _        y| j                  r|j	                  |d      | _        nt	        |d      | _        t        j                  | j
                  d      | _        y)a  Numerical 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   contentsra   rw   nploadr   s       rz   r   zNpzIOStore.__init__o  sf     #	3;DM|| ic:id3GGDFF>DMr   c                 ~    |si | j                   d<   | j                   d   S i | j                   |<   | j                   |   S N__root__)r   r   s     rz   r   zNpzIOStore.make  s?    (*DMM*%==,, d}}T""r   c                     |s(d| j                   v rt        | j                   d         S i S || j                   v r| j                   |   j                         S i S r  )r   r   tolistr   s     rz   r   zNpzIOStore.get  sS    T]]*DMM*566I4== ==&--//	r   c                 V   | j                   dk(  r| j                  r.| j                  j                  | j                  dd      | _        nt        | j                  d      | _        t        j                  | j                  fi | j                   | j                  j                          y )NrA   T)rE   force_zip64wbr}   )	rE   rD   ra   r   rw   r   savezr   rm   r   s    rz   rm   zNpzIOStore.close  su    99||**NN$ +  dnn48HHTVV-t}}-r   r   r   r   r   rz   rh   rh   n  s    ?*#	r   rh   c                  z    t        j                         } t        j                  |       }|j                          | S )N)r   )tempfilemkdtempTemporaryFilerm   )r   testfiles     rz   r   r     s/    !H%%(3HNNOr   c                     ddl m} t        | t        j                  t
        j                  |j                  t        j                  f      S )Nr   )base_metric)
tf_keras.src.metricsr  r   r   Layerr   	OptimizerMetricr   Loss)objr  s     rz   r   r     s<    0KK		
 r   c                  $    t        t        dd      S )Nr>   T)rV   rW   r   r   rz   saving_v3_enabledr    s    %w55r   c                     |st        d|  d| d       t        | d      sy | j                         D ]%  }t        d| |        t        | |   |dz          ' y )NzKeras weights file (z) :keysz...)prefix)printr   r  _print_h5_file)r   r  actionkeys       rz   r  r    sd    $WIRxq9:7F#||~ <F8C5!"ws|FUN;<r   c                 
   t        j                  d| d       t        j                  ddz         | j                  D ]C  }d|j                  d d z  }t        j                  d|j                  ||j
                  fz         E y )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)r_   r   zinfodates       rz   _print_zip_filer,    s    -fXQ78AA !! 
,ur/BBu~~tU__EE	

r   )r:   )NTT)F)FN)rH   N)<r   r\   r   rX   r   r  	threadingrT   r_   numpyr   tensorflow.compat.v2compatv2r   tf_keras.srcsrcrZ   r   tf_keras.src.enginer   tf_keras.src.optimizersr   %tf_keras.src.saving.serialization_libr   r   r   tf_keras.src.utilsr	   r
   rQ   rR   re   rb   rg   rj   localrW   r>   	frozensetr   r{   r   r   r   r   r   r   rk   r   r   r   ri   rf   rh   r   r   r  r  r,  r   r   rz   <module>r:     s(   :  	  	      ! !   * - D J H , ' ! $  %Y__&   -/dZ;zC;L2@		$N =@>"J6- 6-r)! )!X/ /d6<

{  Ds   'C+ +C54C5