
    BVh}                     F   d Z ddlZddlZddlZddlmZ ddlZddlm	Z	 ddl
mZ ddlmZ dZd$dZ	 	 d%d
Zd Zd Zedk(  r ej(                         Zej-                  ddd        ej/                  dedd       ej/                  dedd       ej/                  dedd       ej/                  ddddd	d       ej/                  ddddd	d       ej/                  dd ed!"       ej3                         \  ZZ ej6                  eej8                  d   gez   #       yy)&z-A simple script for inspect checkpoint files.    N)app)errors_impl)flags)py_checkpoint_reader c                    | j                         }|rot        j                  |      }i }d}d}|D ]<  }|j                  |      r!|dz  }|t	        j
                  ||         z  }5||   ||<   > |}t        d|||fz         |D cg c]  }t	        j
                  ||          }}t	        j                  |t              S c c}w )z Count total number of variables.r      z?# Excluding %d tensors (%d params) that match %s when counting.)dtype)	get_variable_to_shape_maprecompilesearchnpprodprintsumint)	readercount_exclude_patternvar_to_shape_mapregex_patternnew_var_to_shape_mapexclude_num_tensorsexclude_num_paramsv	var_sizess	            Z/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/tools/inspect_checkpoint.py_count_total_paramsr      s    557 JJ45M 6			a	 q bgg&6q&9::"21"5Q6 ,	
K/1FOH H I 6FFrww'*+F)F			%% Gs   CFc           	      f    	 t        j                         }|s|r|j                         }|j                         }t	        |j                               D ]D  \  }}	t        d|d||   j                  d|	       |s*	 t        |j                  |             F n|s+t        |j                         j                  dd             n~|j                  |      st        d|z         y	|j                         }|j                         }t        d|d||   j                  d||          t        |j                  |             t        d
t        ||      z         y	# t        j                  $ r t        d       Y .w xY w# t        $ r}
t        t!        |
             dt!        |
      v rt        d       dt!        |
      v r]t#         fddD              rDdj%                   j'                  d      dd       }d}t        |j)                  |             Y d	}
~
y	Y d	}
~
y	Y d	}
~
y	d	}
~
ww xY w)a#  Prints tensors in a checkpoint file.

  If no `tensor_name` is provided, prints the tensor names and shapes
  in the checkpoint file.

  If `tensor_name` is provided, prints the content of the tensor.

  Args:
    file_name: Name of the checkpoint file.
    tensor_name: Name of the tensor in the checkpoint file to print.
    all_tensors: Boolean indicating whether to print all tensors.
    all_tensor_names: Boolean indicating whether to print all tensor names.
    count_exclude_pattern: Regex string, pattern to exclude tensors from count.
  ztensor: z (z) z"<not convertible to a numpy dtype>zutf-8ignore)errorsz!Tensor %s not found in checkpointNz# Total number of params: %dr   z#corrupted compressed block contentszFIt's likely that your checkpoint file has been compressed with SNAPPY.z	Data lossc              3   &   K   | ]  }|v  
 y w)N ).0e	file_names     r   	<genexpr>z3print_tensors_in_checkpoint_file.<locals>.<genexpr>j   s     AqANAs   )z.indexz.metaz.data.r   z
It's likely that this is a V2 checkpoint and you need to provide the filename
*prefix*.  Try removing the '.' and extension.  Try:
inspect checkpoint --file_name = {})r   NewCheckpointReaderr   get_variable_to_dtype_mapsorteditemsr   name
get_tensorr   InternalErrordebug_stringdecode
has_tensorr   	Exceptionstranyjoinsplitformat)r'   tensor_nameall_tensorsall_tensor_namesr   r   r   var_to_dtype_mapkeyvaluer&   proposed_filev2_file_error_templates   `            r    print_tensors_in_checkpoint_filerC   6   s   "):!55i@F&99;99;/5578 8*#uc+;C+@+E+EuMN8&##C()	8 F!(((BC{+1K?@99;99;*;7<<k*, - Fk*+ 

(+>&;,= = ># ** 8678& 
 :	#a&M,A6  s1vA$@AAhhys3Ab9:m ' "))-899 	B 	:sE   A;F  E"AF *A7F "F F FF 	H0BH++H0c                 D   | j                  dd      }t        |      dk7  s|d   st        j                  d| z        |\  }}t	        j
                         }||vrt        j                  d|z        t        ||         }|t        d      u rt        j                  d|z        	 |t        ur ||      n"t        j                         j                  |      }t	        j                  d	i ||i y# t        $ r$}t        j                  |j                        d}~ww xY w)
a  Sets a single numpy printoption from a string of the form 'x=y'.

  See documentation on numpy.set_printoptions() for details about what values
  x and y can take. x can be any option listed there other than 'formatter'.

  Args:
    kv_str: A string of the form 'x=y', such as 'threshold=100000'

  Raises:
    argparse.ArgumentTypeError: If the string couldn't be used to set any
        numpy printoption.
  =r	      r   z'%s' is not in the form k=v.z '%s' is not a valid printoption.Nz4Setting '%s' from the command line is not supported.r$   )r9   lenargparseArgumentTypeErrorr   get_printoptionstypeboolr   BooleanParserparse
ValueErrormessageset_printoptions)kv_strk_v_strkv_strprintoptionsv_typer   r&   s           r   parse_numpy_printoptionrX   s   s    LLa '\Qgaj

$
$%Cf%L
MM(!U$$&,l

$
$%G!%K
LLQ &tDz

$
$>BD D0  	u#(#6#6#8#>#>u#E 
 A 
 0

$
$QYY
//0s   '3C2 2	D;DDc                    t         j                  s!t        d       t        j                  d       y t        t         j                  t         j                  t         j                  t         j                  t         j                         y )NzUsage: inspect_checkpoint --file_name=checkpoint_file_name [--tensor_name=tensor_to_print] [--all_tensors] [--all_tensor_names] [--count_exclude_pattern] [--printoptions]r	   r"   )
FLAGSr'   r   sysexitrC   r;   r<   r=   r   )unused_argvs    r   mainr^      sT    			 HHQK$**511#99;    __main__rK   rL   c                 (    | j                         dk(  S )Ntrue)lower)r   s    r   <lambda>rd      s    AGGI,? r_   z--file_namez}Checkpoint filename. Note, if using Checkpoint V2 format, file_name is the shared prefix between all files in the checkpoint.)rK   defaulthelpz--tensor_namezName of the tensor to inspectz--count_exclude_patternzAPattern to exclude tensors, e.g., from optimizers, when counting.z--all_tensors?Tz7If True, print the names and values of all the tensors.)nargsconstrK   re   rf   z--all_tensor_namesz,If True, print the names of all the tensors.z--printoptions*z9Argument for numpy.set_printoptions(), in the form 'k=v'.)rh   rK   rf   )r^   argv)r   )Fr   )__doc__rH   r   r[   abslr   numpyr   tensorflow.python.frameworkr   tensorflow.python.platformr   tensorflow.python.trainingr   rZ   r   rC   rX   r^   __name__ArgumentParserparserregisteradd_argumentr6   parse_known_argsunparsedrunrk   r$   r_   r   <module>rz      s~   4  	 
   3 , ;&2 7<;=::z B;$ z"8""$&//&&"?@;	  < 	*	  ,
 	N	  P
 	D  F 	9  ; 	"F	  H
 ++-/%	#''t388A;-(23Q r_   