I want to see the variables that are saved in a TensorFlow checkpoint along with their values. How can I find the variable names that are saved in a TensorFlow checkpoint?
I used tf.train.NewCheckpointReader
which is explained here. But, it is not given in the documentation of TensorFlow. Is there any other way?
You can use the
inspect_checkpoint.py
tool.So, for example, if you stored the checkpoint in the current directory, then you can print the variables and their values as follows
Adding more parameter details to
print_tensors_in_checkpoint_file
file_name
: not a physical file, just the prefix of filenamesIf no
tensor_name
is provided, prints the tensor names and shapes in the checkpoint file. Iftensor_name
is provided, prints the content of the tensor.(inspect_checkpoint.py)If
all_tensor_names
isTrue
, Prints all the tensor namesIf
all_tensor
is 'True`, Prints all the tensor names and the corresponding content.N.B.
all_tensor
andall_tensor_names
will overridetensor_name
Example usage:
Update:
all_tensors
argument was added toprint_tensors_in_checkpoint_file
since Tensorflow 0.12.0-rc0 so you may need to addall_tensors=False
orall_tensors=True
if required.Alternative method:
Hope it helps.
A few more details.
If your model is saved using V2 format, for example, if we have the following files in the directory
/my/dir/
then the
file_name
parameter should only be the prefix, that isSee https://github.com/tensorflow/tensorflow/issues/7696 for a discussion.