Tensorboard - 向数据点添加多个元数据标签

时间:2018-04-11 15:34:32

标签: python tensorflow machine-learning visualization tensorboard

我创建了一组图像嵌入,我在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)

1 个答案:

答案 0 :(得分:0)

您可以使用.tsv文件。例如:

Word\tFrequency
Airplane\t345
Car\t241
...

Ref