【问题标题】:Inspecting tensorflow's .data, .meta, and .index检查 tensorflow 的 .data、.meta 和 .index
【发布时间】:2020-04-10 11:12:01
【问题描述】:

几周以来,我一直在尝试使用我在 GitHub 上找到的多个神经网络。大多数时候,这些 repos 包含一个包含 .meta、.index 和 .data 文件的文件夹。我首先想使用 TensorBoard(或任何其他工具)检查这些神经网络,然后正确使用它们。

到目前为止,我已经尝试将这些文件转换为 .pb,然后在张量板上使用这个文件。但是,这种方法当然没有奏效。

我在这个过程中做了一些假设: 1) 我在 macOS 上运行最新的 TensorFlow (py3) docker 容器。 2) 我假设仅检查文件我不需要网络可能需要的必要硬件。

为了将这些文件转换为 .pb,我使用了以下代码:

import tensorflow as tf

meta_path = '/Users/emiliovazquez/Documents/Fall2019/cs594/Final/models/triviaqa-unfiltered-shared-norm/best-weights/best-202000.meta' # Your .meta file
output_node_names = [n.name for n in tf.get_default_graph().as_graph_def().node]   # Output nodes

with tf.Session() as sess:
 # Restore the graph
 saver = tf.train.import_meta_graph(meta_path)

 # Load weights
 saver.restore(sess,tf.train.latest_checkpoint('/Users/emiliovazquez/Documents/Fall2019/cs594/Final/models/triviaqa-unfiltered-shared-norm/best-weights/best-202000'))

 # Freeze the graph
 frozen_graph_def = tf.graph_util.convert_variables_to_constants(
    sess,
    sess.graph_def,
    output_node_names)

 # Save the frozen graph
 with open('./output_graph.pb', 'wb') as f:
  f.write(frozen_graph_def.SerializeToString())

为了检查生成的 .pb 文件,我使用了 this repo 并进行了适当的更改以在最新的 TensorFlow 版本上运行。

但是,在正确运行第二个 python 文件后,进程退出并出现错误。操作系统没有找到指定的文件。但是,我尝试使用容器内的相对路径和绝对路径。

请让我知道我遗漏了哪些信息,我应该使用什么工具,或者给定的方法是否正确

【问题讨论】:

    标签: python-3.x docker tensorflow tensorboard


    【解决方案1】:

    如果您显示您的 Docker 文件会更好,但从您的问题显示,您还没有将 Python 文件发送到 Docker 机器。如果 Python 文件已发送,则说明您没有正确指定输出文件的路径。由于这是在 Docker 中运行的,因此您不能为您的计算机使用绝对路径,您必须使用相对路径才能在您的计算机和 Docker 中运行。

    【讨论】:

    • 我实际上已将文件包含在我的 docker 容器中。我将编辑问题以添加对我的 docker 容器的引用。
    猜你喜欢
    • 2019-06-18
    • 2018-02-02
    • 2015-07-17
    • 1970-01-01
    • 1970-01-01
    • 2018-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多