【问题标题】:How does one inspect variables in a checkpoint file in TensorFlow when TensorFlow can't find the tools attribute?当 TensorFlow 找不到工具属性时,如何在 TensorFlow 中检查检查点文件中的变量?
【发布时间】:2017-06-11 13:18:02
【问题描述】:

我试图使用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?

【问题讨论】:

  • 为我工作。你用的是什么版本的张量流?你是通过 pip 安装还是从源安装?
  • @DomJack 我正在使用tensorflow (0.12.1),我只是使用了 pip install。还有python 3.5.1版。你呢?还有你跑的是什么,正是我写的?
  • python: 2.7.6, tensorflow: 0.12.1 代码: 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='')

标签: python machine-learning tensorflow deep-learning


【解决方案1】:
python -m tensorflow.python.tools.inspect_checkpoint --file_name bad_model/epoch-233

python -m tensorflow.python.tools.inspect_checkpoint --file_name bad_model/epoch-233 --all_tensors

python -m tensorflow.python.tools.inspect_checkpoint --file_name bad_model/epoch-233 --all_tensor_names

【讨论】:

    【解决方案2】:

    从最新的稳定版 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) 
    

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

    【讨论】:

      【解决方案3】:

      您也可以使用command line interface,它使用inspect_checkpoint

      【讨论】:

        【解决方案4】:

        试试这个:

        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 起添加。

        【讨论】:

        • 有没有办法按顺序打印图层?
        【解决方案5】:

        好吧,inspect_checkpoint.py 不是二进制文件吗?

        这样的事情可能会奏效:

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

        编辑:

        或者没有 bazel:

        找到 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

        【讨论】:

        • 啊二进制?抱歉,如果我对此感到非常困惑,但我提供的链接可以告诉我指向 python 文件的链接还是我错了?
        • 还有什么是bazel?为什么我需要 bazel?
        • 很可能 pip 安装没有安装所有工具。 Bazel 是 google 的开源构建工具——所以如果你从源代码安装,bazel 就是你所使用的。不确定如何从 pip 安装中执行您想要的操作,但我可以确认从源代码构建的版本已构建了适当的工具。
        • @DomJack 你是说我需要重新安装 tensorflow 吗?从源头?上次我尝试的时候超级痛苦。
        • Bazel 是您用来从源代码编译 tensorflow 的工具。它不需要。关键是 inspect_checkpoint 实际上是一个二进制文件而不是一个库,所以你可以直接从命令行运行它。我在答案中添加了一些代码。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-05-23
        • 1970-01-01
        • 1970-01-01
        • 2020-05-31
        • 2018-11-17
        • 1970-01-01
        • 2019-04-03
        相关资源
        最近更新 更多