o
    i e                     @   s   d Z ddlZddlm  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mZ ddlmZ ddlmZ ede dZede dZ			dddZdd ZdS )zKeras legacy SavedModel saving.    N)logging)backend)saved_metadata_pb2)versions_pb2)saving_utilsserialization)	constants)	save_impl)utils)
LazyLoader)ask_to_proceed_with_overwrite)save
base_layerzkeras.src.engine.base_layertraining_libzkeras.src.engine.trainingTc              
   C   sN  |st j|rt|}|sdS |rt| rt|  |s)| j}d| _| 	d t
 A td, t| t| |||\}	}
W d   n1 sNw   Y  t|	|
}W d   n1 sbw   Y  W d   n1 sqw   Y  tjjtjj|tjd}||jdd W d   n1 sw   Y  |s|| _dS dS )aJ  Saves a model as a SavedModel to the filepath.

    Args:
      model: Keras model instance to be saved.
      filepath: String path to save the model.
      overwrite: whether to overwrite the existing filepath.
      include_optimizer: If True, save the model's optimizer state.
      signatures: Signatures to save with the SavedModel. Applicable to the 'tf'
        format only. Please see the `signatures` argument in
        `tf.saved_model.save` for details.
      options: (only applies to SavedModel format) `tf.saved_model.SaveOptions`
        object that specifies options for saving to SavedModel.
      save_traces: (only applies to SavedModel format) When enabled, the
        SavedModel will store the function traces for each layer. This
        can be disabled, so that only the configs of each layer are stored.
        Disabling this will decrease serialization time and file size, but
        it requires that all custom layers/models implement a
        `get_config()` method. Defaults to `True`.

    Raises:
      ValueError: if the model's inputs have not been defined.
    N	optimizerr   wbT)deterministic)ospathexistsr   r
   should_skip_serializationr   raise_model_input_errorr   _delete_trackingr   SharedObjectSavingScoper   (deprecated_internal_learning_phase_scoper   keras_option_scopesave_libsave_and_return_nodesgenerate_keras_metadatatfiogfileGFilejoinr	   SAVED_METADATA_PATHwriteSerializeToString)modelfilepath	overwriteinclude_optimizer
signaturesoptionssave_tracesproceedorig_optimizersaved_nodes
node_pathsmetadataw r5   W/var/www/myenv/lib/python3.10/site-packages/keras/src/saving/legacy/saved_model/save.pyr   +   s>    






r   c           
   	   C   s   t  }t| D ]R\}}t|tjrZ|| }|sd}ndddd |D  }|jj||t	j
ddg d|j|jd	 |jj}d
dlm} ||}	|	rZt||	sZtd|||j q|S )zBConstructs a KerasMetadata proto with the metadata of each object.rootzroot..c                 S   s   g | ]}|j qS r5   )name).0refr5   r5   r6   
<listcomp>{   s    z+generate_keras_metadata.<locals>.<listcomp>      )producermin_consumerbad_consumers)node_id	node_pathversion
identifierr3   r   r   z%s has the same name '%s' as a built-in Keras object. Consider renaming %s to avoid naming conflicts when loading with `tf.keras.models.load_model`. If renaming is not possible, pass the object in the `custom_objects` parameter of the load function.)r   SavedMetadata	enumerate
isinstancer   Layerr$   nodesaddr   
VersionDef_object_identifier_tracking_metadata	__class____name__keras.src.layersr   get_builtin_layerr   warning)
r1   r2   r3   rB   noder   rC   
class_namelayers_serializationbuiltin_layerr5   r5   r6   r   r   s:   

r   )NNT)__doc__r   tensorflow.compat.v2compatv2r    abslr   	keras.srcr   keras.protobufr   r   keras.src.saving.legacyr   r   #keras.src.saving.legacy.saved_modelr	   r
   r   keras.src.utils.generic_utilsr   keras.src.utils.io_utilsr   tensorflow.python.saved_modelr   r   globalsr   r   r   r5   r5   r5   r6   <module>   s,   
G