gpt4 book ai didi

tensorflow - 将 Tensorboard 嵌入元数据链接到检查点

转载 作者:行者123 更新时间:2023-12-04 21:07:38 26 4
gpt4 key购买 nike

我在 tensorflow 上使用 tflearn 包装器来构建模型,并希望将元数据(标签)添加到结果嵌入可视化中。在运行它之后,有没有办法将 metadata.tsv 文件链接到保存的检查点?

我在检查点摘要的 logdir 中创建了一个projector_config.pbtxt 文件,metadata.tsv 位于同一文件夹中。配置如下所示:

embeddings {
tensor_name: "Embedding/W"
metadata_path: "C:/tmp/tflearn_logs/shallow_lstm/"
}

并使用文档中的代码创建 - https://www.tensorflow.org/how_tos/embedding_viz/

我已经注释掉了 tf.Session 部分,希望无需直接在 Session 对象中创建元数据链接,但我不确定这是否可能。
from tensorflow.contrib.tensorboard.plugins import projector
#with tf.Session() as sess:
config = projector.ProjectorConfig()
# One can add multiple embeddings.
embedding = config.embeddings.add()
embedding.tensor_name = 'Embedding/W'
# Link this tensor to its metadata file (e.g. labels).
embedding.metadata_path = 'C:/tmp/tflearn_logs/shallow_lstm/'
# Saves a config file that TensorBoard will read during startup.
projector.visualize_embeddings(tf.summary.FileWriter('/tmp/tflearn_logs/shallow_lstm/'), config)

下面是当前嵌入可视化的快照。请注意空的元数据。有没有办法将所需的元文件直接附加到这个嵌入?

Embedding Visualization

最佳答案

我遇到了同样的问题,现在已经解决了:)

基本上,您需要做的就是执行以下 3 个步骤:

  • 保存模型检查点,假设ckeckpoint的目录是ckp_dir ;
  • 将projector_config.pbtxt 和metadata.tsv 放入ckp_dir ;
  • 运行 tensorboard --logdir=ckp_dir并单击嵌入选项卡

  • project_config.pbtxt 的内容是:
        embeddings {
    tensor_name: "embedding_name"
    metadata_path: "metatdata.tsv"
    }

    这是将嵌入链接到 metadata.tsv 的关键。在 tf.Session() 中,我们经常得到嵌入的值,如 sess.run('embedding_name:0') .但是在projector_config.pbtxt中,我们只需输入 tensor_name: "embedding_name" .

    一般我们可以在projector_config.pbtxt中指定checkpoint路径和metadata_path,这样我们就可以将checkpoint、projector_config.pbtxt和metadata.tsv放在不同的目录下。但我觉得太复杂了。我刚刚解决了上面的问题。

    the result shown here

    关于tensorflow - 将 Tensorboard 嵌入元数据链接到检查点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41708106/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com