How does one inspect variables in a checkpoint fil

2019-03-19 09:44发布

I was trying to inspect checkpoints using the code at inspect_checkpoint.py. However, I wasn't able to have it work because they didn't really provide an example. I tried the simplest thing I thought would work:

tf.python.tools.inspect_checkpoint.print_tensors_in_checkpoint_file(file_name='./tmp/mdl_ckpt',tensor_name='',all_tensors='')

however I get that python has no attribute tools:

AttributeError: module 'tensorflow.python' has no attribute 'tools'

it seems like a (embarrassingly) trivial bug/issue. Does someone know what is going on? Why can't it find tools? Also, even if it did find it, how would one run the function provided in that file?


Unfortunately, the very related question did not really provide an answer of how to get around this issue. The question is here How can find the variable names that saved in tensorflow checkpoint?

3条回答
Viruses.
2楼-- · 2019-03-19 10:04

Well, isn't inspect_checkpoint.py a binary?

Something like this might work:

bazel run tensorflow/python/tools:inspect_checkpoint -- --file_name=YOUR_CKPT

EDIT:

Or without bazel:

Find where tensorflow is installed and run the command with python:

python PATH_TO_VENV/lib/python3.6/site-packages/tensorflow/python/tools/inspect_checkpoint.py --file_name=YOUR_CKPT

For all options, see the file itself: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/tools/inspect_checkpoint.py

查看更多
地球回转人心会变
3楼-- · 2019-03-19 10:10

Try this:

from tensorflow.python.tools.inspect_checkpoint import print_tensors_in_checkpoint_file
print_tensors_in_checkpoint_file(file_name='./tmp/mdl_ckpt', tensor_name='', all_tensors=False)

The all_tensors argument was added since Tensorflow 0.12.0-rc0.

查看更多
Summer. ? 凉城
4楼-- · 2019-03-19 10:22

You could also use the command line interface that uses inspect_checkpoint.

查看更多
登录 后发表回答