
    ~Wha^                        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
Zddlmc m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 dd	lmZ dd
lmZ 	 ddlZn# e$ r dZY nw xY wdZdZ dZ!dZ" ej#                    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,dZ/d Z0d Z1 G d d          Z2 G d d           Z3 G d! d"          Z4d# Z5d$ Z6d% Z7d-d'Z8d( Z9dS ).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assetsF>+   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_self_saveable_object_factories_unconditional_dependency_names$_self_unconditional_dependency_names&_unconditional_checkpoint_dependencies)_self_unconditional_deferred_dependencies+_self_unconditional_checkpoint_dependenciesh5c           	         t          |          }|                    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           n# 1 swxY w Y   t          j        |          }t          j        t          j        t"          j                                                            d          d          }t)          j        d|          r/d}t,          j                            t3                      d          }nd
}|}	 t5          j        |d          5 }	|	                    t:          d          5 }
|
                    |                                           ddd           n# 1 swxY w Y   |	                    t@          d          5 }
|
                    |                                           ddd           n# 1 swxY w Y   |dk    rtC          tD          dz   |	d          }n3|dk    rtG          tD          dz   |	d          }nt          d|           tI          tJ          |	d          }tM          | ||dtO                                 |(                                 |(                                 ddd           n# 1 swxY w Y   |r;tR          j*        j+        ,                    ||d           t-          j-        |           n# t\          $ r}|d}~ww xY w|t          _
        dS # |t          _
        w xY w)a  Save a zip-archive representing a 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 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=r7   Nz0h5py 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_savedz^(/cns|/cfs|.*://).*$ztmp_model.kerasw.h5archivemodenpz.npzzTUnknown `weights_format` argument. Expected 'h5' or 'npz'. Received: weights_format= weights_storeassets_store
inner_pathvisited_trackables)	overwrite)/strendswith
ValueErrorh5pyImportErrorbuiltwarningswarngetattr_SAVING_V3_ENABLEDr=   r   r   jsondumpskeras__version__datetimenowstrftimerematchospathjoin_get_temp_dirzipfileZipFileopen_METADATA_FILENAMEwriteencode_CONFIG_FILENAME	H5IOStore_VARS_FNAME
NpzIOStoreDiskIOStore_ASSETS_DIRNAME_save_statesetclosetfiogfilecopyremove	Exception)modelfilepathweights_formatsaving_v3_enabled_valueserialized_model_dictconfig_jsonmetadata_jsonis_remote_pathzip_filepathzffrI   asset_storees                 ]/var/www/html/movieo_spanner_bot/venv/lib/python3.11/site-packages/keras/saving/saving_lib.py
save_modelr   j   s   0 8}}HX&& 
-"*- -
 
 	
 $,LMMM; 
 	
 	
 	
 	
 &&8'5II#			 > > 6u = => > > > > > > > > > > > > > >*233KJ"."+//11::;NOO	
 	
 M 
x((33  w||MOO5FGG+;_\3//  	 2+S11 0Q,,..///0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)3// .1**,,---. . . . . . . . . . . . . . . %% )%'#! ! !  5(( *&("3! ! ! !A0>A A   &orLLLK+(#&55    !!!A 	   	   	   	   	   	   	   	   	   	   	   	   	   	   	 D  	$ EK\8tDDDIl###    $;   #: ::::s    B<<C C 4M 	K=%(GK=G	K= G	!K=?(H3'K=3H7	7K=:H7	;B6K=1M =LM LA M M( 
MMMM( (M6Tc           
         t          |           } |                     d          st          d|            t          t          dd          }dt          _        	 t          j        j        	                    | d          5 }t          j        |d          5 }|                    t          d          5 }|                                }d	d	d	           n# 1 swxY w Y   t          j        |          }	|sd	|	d
<   t#                      5  t%          |	||          }
d	d	d	           n# 1 swxY w Y   |                                }t(          dz   |v rt+          t(          dz   |d          }nGt(          dz   |v rt-          t(          dz   |d          }n t          dt(           dt(           d          t/          |          dk    rt1          t2          |d          }nd	}t5          |
||dt7                                 |                                 |r|                                 d	d	d	           n# 1 swxY w Y   d	d	d	           n# 1 swxY w Y   |
|t          _        S # t:          $ r}|d	}~ww xY w# |t          _        w xY w)z.Load a zip archive representing a Keras model.r9   zDInvalid filename: expected a `.keras` extension. Received: filepath=r=   FTzr+brD   rNcompile_config)	safe_moderA   rB   rF   zExpected a z.h5 or z
.npz file.   rG   rH   )rN   rO   rP   rV   rW   r=   rt   ru   rv   GFilere   rf   rg   rk   readrX   loadsr   r   namelistrm   rl   rn   lenro   rp   _load_staterr   rs   ry   )r{   custom_objectscompiler   r}   gfile_handler   r   r   config_dictrz   all_filenamesrI   r   r   s                  r   
load_modelr      s    8}}HX&& 
-"*- -
 
 	

 &&8'5II#7;U[5  
 
 /	$7?<==/	$AC)3// '1ffhh' ' ' ' ' ' ' ' ' ' ' ' ' ' '
 *[11K 504,-#%%  09                
 KKMMMU"m33 )%'#! ! ! v%66 *&("3! ! ! !M+MMkMMM   =!!A%%)/2CPPP"+(#&55    !!! $!!###_/	$ /	$ /	$ /	$ /	$ /	$ /	$ /	$ /	$ /	$ /	$ /	$ /	$ /	$ /	$ /	$ /	$ /	$ /	$ /	$ /	$ /	$ /	$ /	$ /	$ /	$ /	$ /	$ /	$ /	$h #:      
 $; ::::s   &I&  IH62CH6CH6C,H6D&H6&D**H6-D*.C<H6*I6H:	:I=H:	>II& II& II& I: &
I70I22I77I: :Jc                     t          |          }|                    d          st          d|           t          |d          }t	          | |ddt                                 |                                 dS )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=r@   r   NrG   rH   )rN   rO   rP   rl   rq   rr   rs   )rz   r{   rI   s      r   save_weights_onlyr     s     8}}H]++ 
-"*- -
 
 	
 hS111M#55        c           	      0   d}d}t          |          }|                    d          rt          |d          }nD|                    d          r/t          j        |d          }t          t
          dz   |d          }t          | |dd|t                      	           |                                 |rHt          j
        j                            |          r$t          j
        j                            |           |r|                                 dS dS )
znLoad the weights of a model from a filepath (.keras or .weights.h5).

    Note: only supports h5 for now.
    Nr   r   r   r9   rA   rB   rG   )rI   rJ   rK   skip_mismatchrL   )rN   rO   rl   re   rf   rm   r   rr   rs   rt   ru   rv   existsrmtree)rz   r{   r   temp_dirrC   rI   s         r   load_weights_onlyr   4  s)   
 HG8}}H'' 
!(555			8	$	$ 
/(C00!%s
 
 
 ##55     %BEK&&x00 %
8$$$  r   c                    t           j        j                            |          s|                     ||           d S t           j        j                            |          D ]]}t           j        j                            ||          }t           j        j                            ||          }t          | ||           ^d S N)rt   ru   rv   isdirri   listdirrc   _write_to_zip_recursively)zipfile_to_savesystem_pathzip_path	file_namesystem_file_pathzip_file_paths         r   r   r   T  s    5;[)) k844444,,[99 	 	I!u{//YGGEK,,XyAAM%!1=   	 	r   c              #      K   t          |           D ]I}|                    d          s	|t          v r!	 t          | |          }n# t          $ r Y ?w xY w||fV  Jd S )N__)dir
startswithATTR_SKIPLISTrV   ry   )	trackable
child_attr	child_objs      r   _walk_trackabler   `  s      )nn $ $
  && 	**E*E		:66II 	 	 	H	 )#####$ $s   A
AAc           
         t          |           |v rd S t          | d          r*|r(|                     |                    |                     t          | d          r*|r(|                     |                    |                     |                    t          |                      t          |           D ]\  }}t          |          r8t          |||t          j
        j                            ||          |           Lt          |t          t          t           t"          f          r7t%          |||t          j
        j                            ||          |           d S )N_save_own_variables_save_assetsrK   rL   )idhasattrr   maker   addr   _is_keras_trackablerq   rt   ru   rv   rc   
isinstancelistdicttuplerr   _save_container_state)r   rI   rJ   rK   rL   r   r   s          r   rq   rq   l  s    
)}}*** y/00 F] F%%m&8&8&D&DEEEy.)) >l >|00<<===2i==))) "1!;!;  
Iy)) 	5;++J
CC#5     	D$s#;<< 	!5;++J
CC#5    r   c           
      V   |rt          |           |v rd S t          | d          r|r|r]	 |                     |                    |                     n[# t          $ r&}t          j        d|  d| d           Y d }~n0d }~ww xY w|                     |                    |                     t          | d          r|r|r]	 |                     |                    |                     n[# t          $ r&}t          j        d|  d| d           Y d }~n0d }~ww xY w|                     |                    |                     |"|                    t          |                      t          |           D ]\  }}t          |          r9t          |||t          j        j                            ||          ||           Mt!          |t"          t$          t&          t(          f          r8t+          |||t          j        j                            ||          ||           d S )	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 rK   r   rL   )r   r   r   getry   rT   rU   r   r   r   r   r   rt   ru   rv   rc   r   r   r   r   rr   _load_container_state)	r   rI   rJ   rK   r   rL   r   r   r   s	            r   r   r     s     bmm/AAAy/00 I] I 	I--m.?.?
.K.KLLLL   2	 2 2./2 2  !	         ))-*;*;J*G*GHHHy.)) Al A 	A&&|'7'7
'C'CDDDD   2y 2 2./2 2  !	         ""<#3#3J#?#?@@@%r)}}--- "1!;!;  
Iy)) 	5;++J
CC+#5     	D$s#;<< 	!5;++J
CC+#5    s/   (A 
BA??B(C- -
D7DDc           
         i }t          | t                    r!t          |                                           } | D ]}t	          |          r|t          j        |j        j                  }||v r||xx         dz  cc<   | d||          }nd||<   t          |||t          j        j                            ||          |           d S )N   _r   r   )r   r   r   valuesr   r	   to_snake_case	__class____name__rq   rt   ru   rv   rc   )	containerrI   rJ   rK   rL   
used_namesr   names           r   r   r     s     J)T"" -))++,,	  	y)) 	 !.y/B/KLLDz!!4   A%   33D!133#$
4 5;++J==#5    r   c           
         i }t          | t                    r!t          |                                           } | D ]}t	          |          r}t          j        |j        j                  }||v r||xx         dz  cc<   | d||          }nd||<   t          |||t          j        j                            ||          ||           d S )Nr   r   r   r   )r   r   r   r   r   r	   r   r   r   r   rt   ru   rv   rc   )	r   rI   rJ   rK   r   rL   r   r   r   s	            r   r   r     s     J)T"" -))++,,	  	y)) 	 .y/B/KLLDz!!4   A%   33D!133#$
4 5;++J==+#5    r   c                   ,    e Zd ZdZddZd Zd Zd ZdS )ro   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                   t          j        j        	                    | j        | j                  | _
        | j         dk    r+t          j        j                            | j
                   d S d S |dk    r	|| _
        d S t	                      | _        t          j        j        	                    | j        | j                  | _
        t          j        j                            | j
                   d S )Nr   )rb   r@   )rD   	root_pathrC   tmp_dirrd   
extractallrt   ru   rv   rc   working_dirmakedirsselfr   rC   rD   s       r   __init__zDiskIOStore.__init__  s   	"< 	7(??DLyC''T\':::!u{//dnMMDyC$$T%566666   s{{#,   ,#%5;#3#3L$.$ $  $$T%566666r   c                     |s| j         S t          j        j                            | j         |          }t          j        j                            |          s$t          j        j                            |           |S r   )r   rt   ru   rv   rc   r   r   r   rb   s     r   r   zDiskIOStore.make(  sf     	$##u{ 0$77u{!!$'' 	'EK  &&&r   c                     |s| j         S t          j        j                            | j         |          }t          j        j                            |          r|S d S r   )r   rt   ru   rv   rc   r   r   s     r   r   zDiskIOStore.get0  sS     	$##u{ 0$775;d## 	Ktr   c                 $   | j         dk    r'| j        r t          | j        | j        | j                   | j        rTt          j        j        	                    | j                  r-t          j        j        
                    | j                   d S d S d S Nr@   )rD   rC   r   r   r   r   rt   ru   rv   r   r   r   s    r   rs   zDiskIOStore.close8  s    9%d.   < 	-BEK..t|<< 	-EKt|,,,,,	- 	- 	- 	-r   )NN)r   
__module____qualname____doc__r   r   r   rs    r   r   ro   ro     s_         7 7 7 7,    - - - - -r   ro   c                   (    e Zd ZddZd Zd Zd ZdS )rl   Nr   c                 l   || _         || _        || _        d| _        | j        rp| j        dk    rt	          j                    | _        n%| j                            | j         d          | _        t          j        | j        | j                  | _	        dS t          j        || j                  | _	        dS )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.
        Nr@   r   r   )
r   rD   rC   io_fileru   BytesIOrg   rQ   Fileh5_filer   s       r   r   zH5IOStore.__init__B  s     #	< 	@yC!z||#|00EE9T\	BBBDLLL9YTY???DLLLr   c                     |s| j                             d          S | j                             |                              d          S Nvars)r   create_groupr   s     r   r   zH5IOStore.makeY  sD     	5<,,V444|((..;;FCCCr   c                 z    |s| j         d         S || j         v r"d| j         |         v r| j         |         d         S i S r   )r   r   s     r   r   zH5IOStore.get^  sL     	(<''4<Fdl4.@$@$@<%f--	r   c                    | j                                          | j        dk    r>| j        r7| j                            | j        | j                                                   | j        r| j                                         d S d S r   )r   rs   rD   rC   writestrr   r   getvaluer   s    r   rs   zH5IOStore.closee  s    9L!!$.$,2G2G2I2IJJJ< 	!L     	! 	!r   Nr   r   r   r   r   r   r   rs   r   r   r   rl   rl   A  s\        @ @ @ @.D D D
  ! ! ! ! !r   rl   c                   (    e Zd ZddZd Zd Zd ZdS )rn   Nr   c                    || _         || _        || _        |dk    r	i | _        dS | j        r|                    |d          | _        nt	          |d          | _        t          j        | j        d          | _        dS )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.
        r@   r   r   rbT)allow_pickleN)r   rD   rC   contentsrg   r   nploadr   s       r   r   zNpzIOStore.__init__n  s     #	3;;DMMM| 4 ic::id333GDF>>>DMMMr   c                 b    |si | j         d<   | j         d         S i | j         |<   | j         |         S N__root__)r   r   s     r   r   zNpzIOStore.make  s<     	-(*DM*%=,, d}T""r   c                     |s%d| j         v rt          | j         d                   S i S || j         v r| j         |                                         S i S r  )r   r   tolistr   s     r   r   zNpzIOStore.get  s\     	T]**DM*5666I4=  =&--///	r   c                    | j         dk    rf| j        r(| j                            | j        dd          | _        nt          | j        d          | _        t          j        | j        fi | j         | j                                         d S )Nr@   T)rD   force_zip64wbr   )	rD   rC   rg   r   r   r  savezr   rs   r   s    r   rs   zNpzIOStore.close  s    9| 9**N$ +   dn4888HTV--t}---r   r   r   r   r   r   rn   rn   m  sU        ? ? ? ?*# # #  	 	 	 	 	r   rn   c                  ~    t          j                    } t          j        |           }|                                 | S )N)r   )tempfilemkdtempTemporaryFilers   )r   testfiles     r   rd   rd     s8    !!H%(333HNNOr   c                 |    ddl m} t          | t          j        t
          j        |j        t          j	        f          S )Nr   )base_metric)
keras.metricsr  r   r   Layerr   	OptimizerMetricr   Loss)objr  s     r   r   r     sE    ))))))K		
  r   c                  .    t          t          dd          S )Nr=   F)rV   rW   r   r   r   saving_v3_enabledr    s    %w666r   rG   c                     |st          d|  d| d           t          | d          sd S |                                 D ]0}t          d| |            t          | |         |dz              1d S )NzKeras weights file (z) :keysz...)prefix)printr   r  _print_h5_file)r   r  actionkeys       r   r   r     s     ;9W99999:::7F## ||~~ < <!F!C!!"""ws|FUN;;;;;< <r   c                     t          j        d| d           t          j        ddz             | j        D ]8}d|j        d d         z  }t          j        d|j        ||j        fz             9d S )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)re   r!  zinfodates       r   _print_zip_filer-    s    7f777888AA   ! 
 
,urr/BBu~tU_EE	
 	
 	
 	

 
r   )r7   )NTT)F)FN)rG   N):r   r\   ru   rX   ra   r_   r  	threadingrT   re   numpyr  tensorflow.compat.v2compatv2rt   rZ   r   keras.enginer   keras.optimizersr   keras.saving.serialization_libr   r   r   keras.utilsr	   r
   rQ   rR   rk   rh   rm   rp   localrW   r=   	frozensetr   r   r   r   r   r   r   rq   r   r   r   ro   rl   rn   rd   r   r  r   r-  r   r   r   <module>r9     s=   : 9  				  				 				            ! ! ! ! ! ! ! ! !        # # # # # # & & & & & & = = = = = = C C C C C C A A A A A A % % % % % %            KKKK   DDD
 ! $  %Y_&&    	- - -/ /dh; h; h; h;VD; D; D; D;N  0   @	 	 		$ 	$ 	$     P = = = =@  6  <6- 6- 6- 6- 6- 6- 6- 6-r)! )! )! )! )! )! )! )!X/ / / / / / / /d    7 7 7< < < <
 
 
 
 
s   )A. .A87A8