o
    ?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)pathZsingleprint)r   configZsaved_model_fingerprintingvaluer   joinr	   Zas_strr   ZFINGERPRINT_FILENAMEr   infofingerprinting_pywrapZCreateFingerprintDefFingerprintException
ValueErrorZatomic_write_string_to_filer   ZSetWriteFingerprintZSetWritePathAndSingleprintsingleprint_from_saved_model)
export_dirZfingerprint_pathZfingerprint_serializede r   s/home/www/facesmatcher.com/pyenv/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   Z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   ZFingerprint	TypeErrorr   ZFingerprintDefr   r   r   r   r   r
   r   r   r   to_protoQ   s   r!   N)__doc__Zabslr   Ztensorflow.core.configr   Ztensorflow.core.protobufr   Ztensorflow.python.lib.ior   Ztensorflow.python.saved_modelr   Z0tensorflow.python.saved_model.pywrap_saved_modelr   r   r   Ztensorflow.python.utilr	   r   r   r!   r   r   r   r   <module>   s   