我已經接受了Tensorflow文檔的幫助。
對於如何運行TensorBoard,並確保您記錄所有必要的信息,請參閱:TensorBoard: Visualizing Learning.
可視化你的嵌入,有三件事情你需要做的:
1 )設置一個包含你的嵌入的2D張量。
embedding_var = tf.get_variable(....)
2)定期保存在LOG_DIR一個檢查站的模型變量。
saver = tf.train.Saver()
saver.save(session, os.path.join(LOG_DIR, "model.ckpt"), step)
3)(可選)與嵌入關聯的元數據。
如果你有你的嵌入相關的任何元數據(標籤,圖像),你可以告訴TensorBoard它無論是在LOG_DIR直接存儲projector_config.pbtxt,或使用我們的API的Python。
例如,以下projector_config.ptxt關聯起來的元數據的word_embedding張量存儲在$ LOG_DIR/metadata.tsv:
embeddings {
tensor_name: 'word_embedding'
metadata_path: '$LOG_DIR/metadata.tsv'
}
相同的配置可以編程方式使用下面的代碼段來生產:
from tensorflow.contrib.tensorboard.plugins import projector
# Create randomly initialized embedding weights which will be trained.
vocabulary_size = 10000
embedding_size = 200
embedding_var = tf.get_variable('word_embedding', [vocabulary_size,
embedding_size])
# Format: tensorflow/tensorboard/plugins/projector/projector_config.proto
config = projector.ProjectorConfig()
# You can add multiple embeddings. Here we add only one.
embedding = config.embeddings.add()
embedding.tensor_name = embedding_var.name
# Link this tensor to its metadata file (e.g. labels).
embedding.metadata_path = os.path.join(LOG_DIR, 'metadata.tsv')
#Use the same LOG_DIR where you stored your checkpoint.
summary_writer = tf.summary.FileWriter(LOG_DIR)
# The next line writes a projector_config.pbtxt in the LOG_DIR. TensorBoard will
# read this file during startup.
projector.visualize_embeddings(summary_writer, config)