a
    Sic                     @   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 SavedModel serialization.    N)logging)backend)serialization)saved_metadata_pb2)versions_pb2)saving_utils)	constants)	save_impl)utils)
LazyLoader)ask_to_proceed_with_overwrite)save
base_layerzkeras.engine.base_layertraining_libzkeras.engine.trainingTc              	   C   s&  |s t j|r t|}|s dS |r8t| r8t|  |sR| j}d| _| 	d t
dX t|$ t| |||\}	}
W d   n1 s0    Y  t|	|
}W d   n1 s0    Y  tjjtjj|tjd"}||jdd W d   n1 s0    Y  |s"|| _dS )aQ  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.
        Defaults to `True`. Disabling this will decrease serialization time
        and reduce file size, but it requires that all custom layers/models
        implement a `get_config()` method.

    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   (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 r3   Y/var/www/html/django/DPS/env/lib/python3.9/site-packages/keras/saving/saved_model/save.pyr   +   s0     


&(2r   c           	   	   C   s   t  }t| D ]\}}t|tjr|| }|s6d}ndddd |D }|jj	||t
jddg d|j|jd	 |jj}t|}|rt||std
|||j q|S )zLConstructs a KerasMetadata proto with the metadata of each keras
    object.rootzroot.{}.c                 S   s   g | ]
}|j qS r3   )name).0refr3   r3   r4   
<listcomp>|       z+generate_keras_metadata.<locals>.<listcomp>      )producermin_consumerbad_consumers)node_id	node_pathversion
identifierr1   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   Layerformatr"   nodesaddr   
VersionDef_object_identifier_tracking_metadata	__class____name__r   get_builtin_layerr   warning)	r/   r0   r1   rA   noder   rB   
class_namebuiltin_layerr3   r3   r4   r   q   s:    

r   )NNT) __doc__r   tensorflow.compat.v2compatv2r   abslr   kerasr   keras.layersr   keras.protobufr   r   keras.savingr   keras.saving.saved_modelr   r	   r
   keras.utils.generic_utilsr   keras.utils.io_utilsr   Ztensorflow.python.saved_modelr   r   globalsr   r   r   r3   r3   r3   r4   <module>   s*      
F