Tensorboard解析元数据或获取精灵图像需要永远

时间:2017-05-21 11:48:33

标签: tensorflow tensorboard

我运行了这段代码:

import os
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
from tensorflow.contrib.tensorboard.plugins import projector

LOG_DIR = 'logs'
metadata = os.path.join(LOG_DIR, 'metadata.tsv')

mnist = input_data.read_data_sets('MNIST_data')
input_1 = mnist.train.next_batch(10)
images = tf.Variable(input_1[0], name='images')

with open(metadata, 'w') as metadata_file:
    for row in input_1[1]:
        metadata_file.write('%d\n' % row)

with tf.Session() as sess:
    saver = tf.train.Saver([images])

    sess.run(images.initializer)
    saver.save(sess, os.path.join(LOG_DIR, 'images.ckpt'))

    config = projector.ProjectorConfig()
    # One can add multiple embeddings.
    # Link this tensor to its metadata file (e.g. labels).
    embedding = config.embeddings.add()
    embedding.tensor_name = images.name

    embedding.metadata_path = metadata
    # Saves a config file that TensorBoard will read during startup.
    projector.visualize_embeddings(tf.summary.FileWriter(LOG_DIR), config)

在此之后,我打开了tensorboard嵌入选项卡,它显示了解析元数据。然而,它一直无休止地加载。我尝试了另一个代码,在这种情况下,它继续加载获取spite Image。我的张量板有问题吗?

1 个答案:

答案 0 :(得分:4)

问题是TensorBoard找不到您的元数据文件,因为它会查找相对于您使用' - logdir '参数指定的目录的元数据文件em> tensorboard '命令。

因此,如果您使用' tensorboard --logdir logs '打开TensorBoard,它将在'logs / logs / metadata.tsv'中查找元数据文件。

代码的可能修复方法是替换此行

embedding.metadata_path = metadata  

这一个:

 embedding.metadata_path = 'metadata.tsv'

通常,为了调试TensorBoard错误,您必须在查看TensorBoard时查看浏览器控制台中错误消息的响应。