o
    ?e                     @   s\   d Z ddlmZ ddlmZ ddlmZ edg dG dd deZ	ed	g dd
d Z
dS )z{Methods for SavedModel fingerprinting.

This module contains classes and functions for reading the SavedModel
fingerprint.
    )fingerprint_pb2)fingerprinting)	tf_exportz$saved_model.experimental.Fingerprint)v1c                   @   sR   e Zd ZdZ						dddZedd Zdd Zd	d
 Zdd Z	dd Z
dS )Fingerprintay  The SavedModel fingerprint.

  Each attribute of this class is named after a field name in the
  FingerprintDef proto and contains the value of the respective field in the
  protobuf.

  Attributes:
    saved_model_checksum: A uint64 containing the `saved_model_checksum`.
    graph_def_program_hash: A uint64 containing `graph_def_program_hash`.
    signature_def_hash: A uint64 containing the `signature_def_hash`.
    saved_object_graph_hash: A uint64 containing the `saved_object_graph_hash`.
    checkpoint_hash: A uint64 containing the`checkpoint_hash`.
    version: An int32 containing the producer field of the VersionDef.
  Nc                 C   s(   || _ || _|| _|| _|| _|| _dS )a  Initializes the instance based on values in the SavedModel fingerprint.

    Args:
      saved_model_checksum: Value of the`saved_model_checksum`.
      graph_def_program_hash: Value of the `graph_def_program_hash`.
      signature_def_hash: Value of the `signature_def_hash`.
      saved_object_graph_hash: Value of the `saved_object_graph_hash`.
      checkpoint_hash: Value of the `checkpoint_hash`.
      version: Value of the producer field of the VersionDef.
    N)saved_model_checksumgraph_def_program_hashsignature_def_hashsaved_object_graph_hashcheckpoint_hashversion)selfr   r   r	   r
   r   r    r   m/home/www/facesmatcher.com/pyenv/lib/python3.10/site-packages/tensorflow/python/saved_model/fingerprinting.py__init__+   s   
zFingerprint.__init__c              
   C   s`   t |trtj|}zt|j|j|j|j	|j
|jW S  ty/ } ztd| dd}~ww )z;Constructs Fingerprint object from protocol buffer message.z5Given proto could not be deserialized as fingerprint.N)
isinstancebytesr   FingerprintDef
FromStringr   r   r   r	   r
   r   r   AttributeError
ValueError)clsprotoer   r   r   
from_protoE   s*   
zFingerprint.from_protoc                 C   sn   t |tst |tjr5z| j|jko)| j|jko)| j|jko)| j|jko)| j|jkW S  t	y4   Y dS w dS )NF)
r   r   r   r   r   r   r	   r
   r   r   )r   otherr   r   r   __eq__W   s$   





zFingerprint.__eq__c              	   C   s>   d dd| j d| j d| j d| j d| j gS )N
zSavedModel Fingerprintz  saved_model_checksum: z  graph_def_program_hash: z  signature_def_hash: z  saved_object_graph_hash: z  checkpoint_hash: )joinr   r   r	   r
   r   r   r   r   r   __str__e   s   




zFingerprint.__str__c                 C   s.   d| j  d| j d| j d| j d| j dS )NzFingerprint(z, ))r   r   r	   r
   r   r   r   r   r   __repr__o   s   
zFingerprint.__repr__c                 C   sh   zt | j| j| j| jW S  tt jfy3 } ztd| j d| j d| j d| j | 	dd}~ww )a  Canonical fingerprinting ID for a SavedModel.

    Uniquely identifies a SavedModel based on the regularized fingerprint
    attributes. (saved_model_checksum is sensitive to immaterial changes and
    thus non-deterministic.)

    Returns:
      The string concatenation of `graph_def_program_hash`,
      `signature_def_hash`, `saved_object_graph_hash`, and `checkpoint_hash`
      fingerprint attributes (separated by '/').

    Raises:
      ValueError: If the fingerprint fields cannot be used to construct the
      singleprint.
    z[Encounted invalid fingerprint values when constructing singleprint.graph_def_program_hash: zsignature_def_hash: zsaved_object_graph_hash: zcheckpoint_hash: N)	fingerprinting_pywrapZSingleprintr   r	   r
   r   	TypeErrorFingerprintExceptionr   )r   r   r   r   r   singleprintv   s0   zFingerprint.singleprint)NNNNNN)__name__
__module____qualname____doc__r   classmethodr   r   r    r"   r&   r   r   r   r   r      s    


r   z)saved_model.experimental.read_fingerprintc              
   C   sv   zt | }W n) t jy } ztd| dd}~w t jy0 } ztd| dd}~ww tt	 
|S )a9  Reads the fingerprint of a SavedModel in `export_dir`.

  Returns a `tf.saved_model.experimental.Fingerprint` object that contains
  the values of the SavedModel fingerprint, which is persisted on disk in the
  `fingerprint.pb` file in the `export_dir`.

  Read more about fingerprints in the SavedModel guide at
  https://www.tensorflow.org/guide/saved_model.

  Args:
    export_dir: The directory that contains the SavedModel.

  Returns:
    A `tf.saved_model.experimental.Fingerprint`.

  Raises:
    FileNotFoundError: If no or an invalid fingerprint is found.
  zSavedModel Fingerprint Error: N)r#   ZReadSavedModelFingerprintZFileNotFoundExceptionFileNotFoundErrorr%   RuntimeErrorr   r   r   r   r   )Z
export_dirfingerprintr   r   r   r   read_fingerprint   s   r/   N)r*   Ztensorflow.core.protobufr   Z0tensorflow.python.saved_model.pywrap_saved_modelr   r#   Z tensorflow.python.util.tf_exportr   objectr   r/   r   r   r   r   <module>   s   

z