
    &Vf	&                     4   d dl 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Zn# e$ r dZY nw xY w edd	g          dd            Z eddg          dd            Z ed          dd            Z ed          dd            ZdS )    N)logging)keras_export)legacy_h5_format)
saving_lib)
file_utils)io_utilszkeras.saving.save_modelzkeras.models.save_modelTc                    |                     dd          }|                     dd          }|rnt          |                              d          s"t          |                              d          rt          j        d|            nt          d|           |r1t          d	t          |                                                     t          |                              d          rt          j        d
           	 t          j	        
                    |          }n# t          $ r d}Y nw xY w|r|st          j        |          }|sdS t          |                              d          rt          j        | |           dS t          |                              d          rt!          j        | |||           dS t          d| d          )a  Saves a model as a `.keras` file.

    Args:
        model: Keras model instance to be saved.
        filepath: `str` or `pathlib.Path` object. Path where to save the model.
        overwrite: Whether we should overwrite any existing model at the target
            location, or instead ask the user via an interactive prompt.

    Example:

    ```python
    model = keras.Sequential(
        [
            keras.layers.Dense(5, input_shape=(3,)),
            keras.layers.Softmax(),
        ],
    )
    model.save("model.keras")
    loaded_model = keras.saving.load_model("model.keras")
    x = keras.random.uniform((10, 3))
    assert np.allclose(model.predict(x), loaded_model.predict(x))
    ```

    Note that `model.save()` is an alias for `keras.saving.save_model()`.

    The saved `.keras` file contains:

    - The model's configuration (architecture)
    - The model's weights
    - The model's optimizer's state (if any)

    Thus models can be reinstantiated in the exact same state.
    include_optimizerTsave_formatF.h5.hdf5.keraszThe `save_format` argument is deprecated in Keras 3. We recommend removing this argument as it can be inferred from the file path. Received: save_format=zThe `save_format` argument is deprecated in Keras 3. Please remove this argument and pass a file path with either `.keras` or `.h5` extension.Received: save_format=z-The following argument(s) are not supported: a  You are saving your model as an HDF5 file via `model.save()` or `keras.saving.save_model(model)`. This file format is considered legacy. We recommend using instead the native Keras format, e.g. `model.save('my_model.keras')` or `keras.saving.save_model(model, 'my_model.keras')`. Na  Invalid filepath extension for saving. Please add either a `.keras` extension for the native Keras format (recommended) or a `.h5` extension. Use `model.export(filepath)` if you want to export a SavedModel for use with TFLite/TFServing/etc. Received: filepath=.)popstrendswithr   warning
ValueErrorlistkeysospathexists	TypeErrorr   ask_to_proceed_with_overwriter   
save_modelr   save_model_to_hdf5)modelfilepath	overwritekwargsr
   r   r   proceeds           X/var/www/html/software/conda/lib/python3.11/site-packages/keras/src/saving/saving_api.pyr   r      sR   F 

#6==**]E22K x==!!"233 	s8}}7M7M8
 8
 	 O7 *57 7    7 *57 7    
%FKKMM""% %
 
 	
 8}}.// 
C	
 	
 	
))    i 8BB 	F
8}}h'' 
eX.....	X		 0	1	1 
+8Y(9	
 	
 	
 	
 	
 .
 #+. . .
 
 	
s   D' 'D65D6zkeras.saving.load_modelzkeras.models.load_modelc                    t          |                               d          ot          j        |           }t	          j        |           rt	          j        |           s}|s{t          j        	                    t          j                    t          j                            |                     }t	          j        | |           t          j        |          r|} d}|rt          j        | |||          S t          |                               d          rt          j        | ||          S t          |                               d          rt#          d|  d          t#          d|  d	|  d
          )a  Loads a model saved via `model.save()`.

    Args:
        filepath: `str` or `pathlib.Path` object, path to the saved model file.
        custom_objects: Optional dictionary mapping names
            (strings) to custom classes or functions to be
            considered during deserialization.
        compile: Boolean, whether to compile the model after loading.
        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 Keras v3 model format. Defaults to `True`.

    Returns:
        A Keras model instance. If the original model was compiled,
        and the argument `compile=True` is set, then the returned model
        will be compiled. Otherwise, the model will be left uncompiled.

    Example:

    ```python
    model = keras.Sequential([
        keras.layers.Dense(5, input_shape=(3,)),
        keras.layers.Softmax()])
    model.save("model.keras")
    loaded_model = keras.saving.load_model("model.keras")
    x = np.random.random((10, 3))
    assert np.allclose(model.predict(x), loaded_model.predict(x))
    ```

    Note that the model variables may have different name values
    (`var.name` property, e.g. `"dense_1/kernel:0"`) after being reloaded.
    It is recommended that you use layer attributes to
    access specific variables, e.g. `model.get_layer("dense_1").kernel`.
    r   T)custom_objectscompile	safe_moder   )r&   r'   zFile not found: filepath=z<. Please ensure the file is an accessible `.keras` zip file.$File format not supported: filepath=a  . Keras 3 only supports V3 `.keras` files and legacy H5 format files (`.h5` extension). Note that the legacy SavedModel format is not supported by `load_model()` in Keras 3. In order to reload a TensorFlow SavedModel as an inference-only layer in Keras 3, use `keras.layers.TFSMLayer(za, call_endpoint='serving_default')` (note that your `call_endpoint` might have a different name).)r   r   zipfile
is_zipfiler   is_remote_pathisdirr   r   joinr   get_temp_dirbasenamecopy
load_modelr   load_model_from_hdf5r   )r    r&   r'   r(   is_keras_zip
local_paths         r$   r2   r2   t   s   J x==))(33 8J9 9L 	!(++  **   
 W\\#%%rw'7'7'A'A
 


 	*--- j)) 	 !HL 
$)	
 
 
 	
 8}}.// 
4^W
 
 
 	
 
X			)	) 
   
 
 	
 
,8 
, 
, 
, 
, 
,
 
 	
    zkeras.saving.save_weightsc                 2   t          |                              d          st          d|           	 t          j                            |          }n# t          $ r d}Y nw xY w|r|st          j        |          }|sd S t          j
        | |fi | d S )N.weights.h5z;The filename must end in `.weights.h5`. Received: filepath=F)r   r   r   r   r   r   r   r   r   r   save_weights_only)r   r    r!   r"   r   r#   s         r$   save_weightsr:      s    x==!!-00 
-"*- -
 
 	
))    i 8BB 	F ;;F;;;;;s   A A%$A%zkeras.saving.load_weightsFc                    t          |                              d          r-|rt          d|           t          j        | ||           d S t          |                              d          rD|                    dd           }|rt          d|           t          j        | |||           d S t          |                              d          s"t          |                              d          r|                    d	d
          }|rt          d|           t          st          d          t          j        |d          5 }d|j	        vrd|v r|d         }|rt          j        || |           nt          j        ||            d d d            d S # 1 swxY w Y   d S t          d| d          )Nr   zInvalid keyword arguments: )skip_mismatchr8   objects_to_skip)r<   r=   r   r   by_nameFz2Loading a H5 file requires `h5py` to be installed.rlayer_namesmodel_weightsr)   zY. Keras 3 only supports V3 `.keras` and `.weights.h5` files, or legacy V1/V2 `.h5` files.)r   r   r   r   load_weights_onlyr   h5pyImportErrorFileattrsr   $load_weights_from_hdf5_group_by_nameload_weights_from_hdf5_group)r   r    r<   r"   r=   r>   fs          r$   load_weightsrJ      s   
8}}h'' &
 	EC6CCDDD$8=	
 	
 	
 	
 	
 	
 
X			.	.  
 **%6== 	EC6CCDDD$'+		
 	
 	
 	
 	
 	
 
X			&	& 
#h--*@*@*I*I 
**Y.. 	EC6CCDDD 	D   Yx%% 	HAG++10D0Do& H Eum    !=aGGG	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 28 2 2 2
 
 	
s   AF  F$'F$)T)NTT)F)r   r*   abslr   keras.src.api_exportr   keras.src.legacy.savingr   keras.src.savingr   keras.src.utilsr   r   rC   rD   r   r2   r:   rJ    r6   r$   <module>rQ      s   				        - - - - - - 4 4 4 4 4 4 ' ' ' ' ' ' & & & & & & $ $ $ $ $ $KKKK   DDD (*CDEE^
 ^
 ^
 FE^
B (*CDEEX
 X
 X
 FEX
v )**< < < +*<" )**'
 '
 '
 +*'
 '
 '
s   3 ==