o
    i e                     @   s   d 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mZ ddlmZ ddlmZ 			dddZG dd dejZdd ZdS )z(Implementation of SaveDataset in Python.    N)
checkpoint)checkpoint_management)dataset_ops)structured_function)	structure)context)dtypes)ops)gen_experimental_dataset_ops)gfile)nested_structure_coderc                 C   s   t  rL|rLt| |||}t|}d|v rtdtj|d}||d< tjdi |}|	|j
 t|D ]}	d|v rC|d jdd |jdd q5d
S t| ||\}
}}}tj|
j||j|||d	S )z:Implements the save function and checkpoint functionality.r   zV'Invalid `checkpoint_args`. `checkpoint_args` are not allowed to include 'checkpoint'.)iteratorstep_counter   )deltaT)check_interval)pathshard_func_other_argscompression
shard_funcuse_shard_funcN )r   executing_eagerly_SaveDatasetiter
ValueErrorcheckpoint_lib
Checkpointr   CheckpointManagerrestorelatest_checkpoint	enumerate
assign_addsaveset_save_dataset_attributesged_opssave_dataset_variant_tensorcaptured_inputs)input_datasetr   r   r   checkpoint_argsr&   save_iteratorr   manager_datasetr   r   r   Q/var/www/myenv/lib/python3.10/site-packages/tensorflow/python/data/ops/save_op.py_save    s6   r0   c                       s4   e Zd ZdZ fddZdd Zedd Z  ZS )r   z/"A dataset that loads previously saved dataset.c                    sb   |j | _|| _t|||\}}}}tj|j||j|||t	|j t
|j d}t || d S )N)r   r   r   r   r   output_typesoutput_shapes)element_spec_element_spec_shard_funcr$   r%   save_dataset_v2r'   r(   r   get_flat_tensor_typesget_flat_tensor_shapessuper__init__)selfr.   r   r   r   r   variant_tensor	__class__r   r/   r:   G   s    


z_SaveDataset.__init__c                 C   s   | j gS N)r5   r;   r   r   r/   
_functionsX   s   z_SaveDataset._functionsc                 C   s   | j S r?   )r4   r@   r   r   r/   r3   [   s   z_SaveDataset.element_spec)	__name__
__module____qualname____doc__r:   rA   propertyr3   __classcell__r   r   r=   r/   r   D   s    r   c                 C   s   |du rd}dd }nd}t j|d| jdd}t| j}t| ttj	
|tjd}||  W d   n1 s@w   Y  tj|tjd	d
}|j}|t  |   | |||fS )z6Sets parameters for SaveDatasetOp and SaveDatasetV2Op.NFc                  W   s   d S r?   r   )xr   r   r/   <lambda>d   s    z-set_save_dataset_attributes.<locals>.<lambda>Tzsave())input_structureadd_to_graphwbr   )dtypename)r   StructuredFunctionWrapperr3   r   encode_structurer   MakeDirsGFileosr   joinr   DATASET_SPEC_FILENAMEwriteSerializeToStringr	   convert_to_tensorr   stringfunctionrK   get_default_graph_apply_debug_options)r.   r   r   r   wrapped_funcencodedfr   r   r/   r$   `   s.   

r$   )NNN)rE   rS   tensorflow.python.checkpointr   r   r   tensorflow.python.data.opsr   r   tensorflow.python.data.utilr   tensorflow.python.eagerr   tensorflow.python.frameworkr   r	   tensorflow.python.opsr
   r%   tensorflow.python.platformr   tensorflow.python.saved_modelr   r0   UnaryDatasetr   r$   r   r   r   r/   <module>   s&   
$