Tensorboard - 向数据点添加多个元数据标签
Posted
技术标签:
【中文标题】Tensorboard - 向数据点添加多个元数据标签【英文标题】:Tensorboard - Adding multiple metadata labels to data points 【发布时间】:2018-09-21 13:53:21 【问题描述】:我创建了一组图像嵌入,并在 TensorBoard 中进行可视化。我还对这些嵌入进行了聚类,并希望将它们的聚类作为元数据附加到这些点上。我目前用于编写元数据的代码如下所示 - 如何为集群添加额外的元数据标签?有可能吗?
names = data_dir_list # category names
# Create metadata file
metadata_file = open(os.path.join(LOG_DIR, 'metadata_4_classes.tsv'), 'w')
metadata_file.write('Class\tName\n')
k = num_of_samples_each_class # num of samples in each class
j = 0 # Class counter
for i in range(num_of_samples):
c = names[y[i]] # Get sample category
# if iteration has entered a new class
if i % k == 0:
j = j + 1
metadata_file.write('\t\n'.format(j, c))
# metadata_file.write('%06d\t%s\n' % (j, c))
metadata_file.close()
features = tf.Variable(feature_vectors, name='features') # Assign feature vectors to TF variable
with tf.Session() as sess:
saver = tf.train.Saver([features], save_relative_paths=True)
sess.run(features.initializer)
saver.save(sess, os.path.join(LOG_DIR, 'images_4_classes.ckpt'))
config = projector.ProjectorConfig()
# One can add multiple embeddings.
embedding = config.embeddings.add()
embedding.tensor_name = features.name
# Link this tensor to its metadata file (e.g. labels).
embedding.metadata_path = os.path.join(LOG_DIR, 'metadata_4_classes.tsv')
# Comment out if you don't want sprites
embedding.sprite.image_path = os.path.join(LOG_DIR, 'sprite_4_classes.png')
embedding.sprite.single_image_dim.extend([img_data.shape[1], img_data.shape[1]])
# Saves a config file that TensorBoard will read during startup.
projector.visualize_embeddings(tf.summary.FileWriter(LOG_DIR), config)
【问题讨论】:
见github.com/tensorflow/tensorboard/issues/61 【参考方案1】:您可以使用 .tsv 文件。例如:
Word\tFrequency
Airplane\t345
Car\t241
...
Ref
【讨论】:
以上是关于Tensorboard - 向数据点添加多个元数据标签的主要内容,如果未能解决你的问题,请参考以下文章
tensorboard显示多个event文件在一个图上!tensorboard中曲线图的数据下载且用matplotlib.pyplot来画,便于实验对比。