
    BVh                        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 ej"                  Zd
eddfdZd
edefdZd
edefdZd
edefdZde
j.                  dej0                  fdZy)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)compat
export_dirreturnNc                 z   t        j                         j                  j                         rt	        j
                  t        j                  |       t        j                  t        j                              }t        j                  d|       	 t        j                  |       }t	        j                   ||       t#        j$                  |       	 t#        j&                  | t)        |              yy# t        $ r}t        |      dd}~ww xY w# t"        j*                  $ r t        j                  d       Y yw xY w)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singleprintzIpath_and_singleprint metric could not be set. Model saving will continue.)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_fingerprint_protoMetricException)r   fingerprint_pathfingerprint_serializedes       b/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/saved_model/fingerprinting_utils.pywrite_fingerprintr&   #   s    \\^..446||j!i4457 LL,.>?$4II
  ''(8(>@ ,BC2((8DF! 7   $qMt#$ "" 2ll 1 22s*   C2  D 2	D;DD(D:9D:c                 h    	 t        j                  |       S # t        $ r}t        |      dd}~ww xY w)aC  Returns the singleprint of `saved_model.pb` in `export_dir`.

  Args:
    export_dir: The directory that contains `saved_model.pb`.

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

  Raises:
    ValueError: If a valid singleprint cannot be constructed from 
    `saved_model.pb`.
  N)r   SingleprintFromSMr   r   r   r$   s     r%   "singleprint_from_saved_model_protor*   E   4    " 22:>>	 "
Q-T!"    	1,1c                 h    	 t        j                  |       S # t        $ r}t        |      dd}~ww xY w)aB  Returns the singleprint of `fingerprint.pb` in `export_dir`.

  Args:
    export_dir: The directory that contains `fingerprint.pb`.

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

  Raises:
    ValueError: If a valid singleprint cannot be constructed from
    `fingerprint.pb`.
  N)r   SingleprintFromFPr   r   r)   s     r%   r    r    X   r+   r,   c                     	 t        |       S # t        $ r Y nw xY w	 t        |        t        |       S # t        $ r Y nw xY w	 t        |       S # t        $ r}t        |      dd}~ww xY w)a  Returns the singleprint of the SavedModel in `export_dir`.

  First tries to construct the singleprint from `fingerprint.pb`, then from
  `saved_model.pb`. Attempts to write the `fingerprint.pb` if not found, but
  doesn't return an error if it isn't writeable.

  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 the
    SavedModel.
  N)r    r   r&   r*   r)   s     r%   singleprint_from_saved_modelr0   k   sz    $	-j99	 			j!-j99	 		"-j99	 "
Q-T!"s0   
 	3 	??
A 	A(A##A(r   c                     t        j                  | j                  | j                  | j                  | j
                  | j                        S )N)saved_model_checksumgraph_def_program_hashsignature_def_hashsaved_object_graph_hashcheckpoint_hash)r   FingerprintDefr2   r3   r4   r5   r6   r   s    r%   to_protor8      sB    		'	'&;;(??$77)AA!11
3 3    )__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   strr&   r*   r    r0   Fingerprintr7   r8    r9   r%   <module>rE      s     ( 4 , 8 F d D ),AA 2# 2$ 2D"3 "3 "&"3 "3 "&""S ""S ""J3++30?0N0N3r9   