当TensorFlow找不到tools属性时,如何检查TensorFlow中检查点文件中的变量?

2024-05-31 15:48:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着用inspect_checkpoint.py的代码检查检查点。然而,我不能让它工作,因为他们没有真正提供一个例子。我尝试了我认为最简单的方法:

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

但是我发现python没有属性tools

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

这似乎是一个(令人尴尬的)微不足道的错误/问题。有人知道怎么回事吗?为什么它找不到工具?另外,即使找到了它,如何运行该文件中提供的函数?


不幸的是,这个非常相关的问题并没有真正提供如何绕过这个问题的答案。问题就在这里How can find the variable names that saved in tensorflow checkpoint?


Tags: 方法代码nameinpytftensorflowtools
3条回答

那么,inspect_checkpoint.py不是二进制文件吗?

类似的事情可能会奏效:

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

编辑:

或者不带火箭筒:

查找tensorflow的安装位置并使用python运行命令:

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

有关所有选项,请参见文件本身:https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/tools/inspect_checkpoint.py

从最新的稳定TensorFlow版本1.13开始,在即将到来的TF 2.0中,检查检查点最直接的方法是:

path = './tmp/mdl_ckpt' 
get_checkpoint = tf.train.latest_checkpoint(path) 
#this retrieves the latest checkpoin file form path, but it also can be set manually

inspect_list = tf.train.list_variables(get_checkpoint) 

这将创建给定检查点中所有变量名的列表

试试这个:

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)

all_tensors参数是从Tensorflow 0.12.0-rc0开始添加的。

相关问题 更多 >