o
    i e                     @   s   d 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 Zdd Zdd ZdS )zUtilities for SavedModel fingerprinting.

This module contains utility classes and functions for working with the
SavedModel fingerprint.
    )logging)flags)fingerprint_pb2)file_io)fingerprinting)	constants)metrics)compatc              
   C   s   t  j rKtt| ttj	}t
d| zt| }W n tjy3 } zt|dd}~ww t|| tj|d tj| t| d dS dS )a!  Write fingerprint protobuf, if requested.

  Writes a `tf.saved_model.experimental.Fingerprint` object to a
  `fingerprint.pb` file in the `export_dir` using the `saved_model.pb` file
  contained in `export_dir`.

  Args:
    export_dir: The directory in which to write the fingerprint.
  zWriting fingerprint to %sNfingerprint)pathsingleprint)r   configsaved_model_fingerprintingvaluer   joinr	   as_strr   FINGERPRINT_FILENAMEr   infofingerprinting_pywrapCreateFingerprintDefFingerprintException
ValueErroratomic_write_string_to_filer   SetWriteFingerprintSetWritePathAndSingleprintsingleprint_from_saved_model)
export_dirfingerprint_pathfingerprint_serializede r!   a/var/www/myenv/lib/python3.10/site-packages/tensorflow/python/saved_model/fingerprinting_utils.pywrite_fingerprint!   s.   



r#   c              
   C   s2   zt | W S  t jy } zt|dd}~ww )a2  Returns the singleprint of a SavedModel in `export_dir`.

  Args:
    export_dir: The directory that contains the SavedModel.

  Returns:
    A string containing the singleprint of the SavedModel in `export_dir`.

  Raises:
    ValueError: If a valid singleprint cannot be constructed from a SavedModel.
  N)r   SingleprintFromSMr   r   )r   r    r!   r!   r"   r   ?   s   
r   c                 C   s2   t | tjs
tdtj| j| j| j| j	| j
dS )Nz$Supplied value is not a Fingerprint.)saved_model_checksumgraph_def_program_hashsignature_def_hashsaved_object_graph_hashcheckpoint_hash)
isinstancer   Fingerprint	TypeErrorr   FingerprintDefr%   r&   r'   r(   r)   r
   r!   r!   r"   to_protoQ   s   r.   N)__doc__abslr   tensorflow.core.configr   tensorflow.core.protobufr   tensorflow.python.lib.ior   tensorflow.python.saved_modelr   0tensorflow.python.saved_model.pywrap_saved_modelr   r   r   tensorflow.python.utilr	   r#   r   r.   r!   r!   r!   r"   <module>   s   