a
    0Sic                     @   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 ede dZedG dd dejZeedd  dS )zAsset-type Trackable object.    N)context)dtypes)ops)file_io)	array_ops)resource_variable_ops)base)lazy_loader)	tf_exportsaved_model_utilsz(tensorflow.python.saved_model.utils_implzsaved_model.Assetc                   @   s@   e Zd ZdZdd Zedd Zedd Zdd	 Z	d
d Z
dS )Asseta  Represents a file asset to hermetically include in a SavedModel.

  A SavedModel can include arbitrary files, called assets, that are needed
  for its use. For example a vocabulary file used initialize a lookup table.

  When a trackable object is exported via `tf.saved_model.save()`, all the
  `Asset`s reachable from it are copied into the SavedModel assets directory.
  Upon loading, the assets and the serialized functions that depend on them
  will refer to the correct filepaths inside the SavedModel directory.

  Example:

  ```
  filename = tf.saved_model.Asset("file.txt")

  @tf.function(input_signature=[])
  def func():
    return tf.io.read_file(filename)

  trackable_obj = tf.train.Checkpoint()
  trackable_obj.func = func
  trackable_obj.filename = filename
  tf.saved_model.save(trackable_obj, "/tmp/saved_model")

  # The created SavedModel is hermetic, it does not depend on
  # the original file and can be moved to another path.
  tf.io.gfile.remove("file.txt")
  tf.io.gfile.rename("/tmp/saved_model", "/tmp/new_location")

  reloaded_obj = tf.saved_model.load("/tmp/new_location")
  print(reloaded_obj.func())
  ```

  Attributes:
    asset_path: A path, or a 0-D `tf.string` tensor with path to the asset.
  c              	   C   s   t |tjrt|}t N td$ tj|tj	dd| _
W d   n1 sT0    Y  W d   n1 sr0    Y  dS )z"Record the full path to the asset.CPU
asset_path)dtypenameN)
isinstanceosPathLikefspathr   
init_scopedeviceconvert_to_tensorr   string_path)selfpath r   ]/var/www/html/django/DPS/env/lib/python3.9/site-packages/tensorflow/python/trackable/asset.py__init__K   s    
zAsset.__init__c                 C   s   | j S )zFetch the current asset path.)r   )r   r   r   r   r   V   s    zAsset.asset_pathc                 K   sF   |j }tt|||j j}| |}t sBt	
t	jj|j |S N)assetr   joinr   Zget_assets_dirasset_file_def_indexfilenamer   executing_eagerlyr   add_to_collection	GraphKeysASSET_FILEPATHSr   )clsobject_proto
export_dirasset_file_defunused_kwargsprotor#   r    r   r   r   _deserialize_from_proto[   s    
zAsset._deserialize_from_protoc                 C   s   t | || d S r   )setattr)r   r   valuer   r   r   _add_trackable_childg   s    zAsset._add_trackable_childc                 K   s2   t j| jjtjdd}t|}||| j< | jgS )Nasset_path_initializer)shaper   r   )r   placeholderr   r3   r   r   r   ResourceVariable)r   
tensor_mapr,   r2   Zasset_variabler   r   r   _export_to_saved_model_graphj   s    
z"Asset._export_to_saved_model_graphN)__name__
__module____qualname____doc__r   propertyr   classmethodr.   r1   r7   r   r   r   r   r   $   s   %

r   c                 K   s   t j| jfi |S r   )r   r   r   )r    kwr   r   r   <lambda>z       r?   )r;   r   tensorflow.python.eagerr   tensorflow.python.frameworkr   r   tensorflow.python.lib.ior   tensorflow.python.opsr   r   tensorflow.python.trackabler   tensorflow.python.utilr	    tensorflow.python.util.tf_exportr
   
LazyLoaderglobalsr   	Trackabler   #register_tensor_conversion_functionr   r   r   r   <module>   s&   T