Tensorflow:如何可视化嵌入

时间:2018-07-03 16:07:29

标签: python tensorflow

在使用word2vec_basic.py从文本创建的嵌入中使用TensorBoard时遇到问题。基本上,完成脚本后,我可以进行嵌入了。但是,我不知道如何将文件传递到TensorBoard或在线投影仪。我找不到存储实际向量的文件。

使用code I found online时出现错误:

from tensorflow.contrib.tensorboard.plugins import projector


with tf.Session() as sess:
# Create summary writer.
writer = tf.summary.FileWriter('./graphs/embedding_test', sess.graph)
# Initialize embeddings
sess.run(embeddings.initializer)
# Create Projector config
config = projector.ProjectorConfig()
# Add embedding visualizer
embedding = config.embeddings.add()
# Attache the name 'embedding'
embedding.tensor_name = embeddings.name
# Metafile which is described later
embedding.metadata_path = './graphs/embedding_test/metadata.tsv'
# Add writer and config to Projector
projector.visualize_embeddings(writer, config)
# Save the model
saver_embed = tf.train.Saver([embeddings])
saver_embed.save(sess, '.graphs/embedding_test/embedding_test.ckpt', 1)
writer.close()

错误是

  

raise RuntimeError('“会话”图为空。

非常感谢您提供有关创建3D表示形式的帮助。

0 个答案:

没有答案