我正在寻找一个有虹膜数据的张拉板嵌入示例,比如嵌入投影仪http://projector.tensorflow.org/
但不幸的是我找不到。关于如何在viz/中做这件事的一些信息。
有人知道这个功能的基本教程吗?
基本要素:
1)设置一个2D张量变量,以容纳嵌入。
embedding_var = tf.Variable(....)2)定期将嵌入保存在LOG_DIR中。
3)将元数据与嵌入相关联。
发布于 2016-12-21 12:00:07
听起来,您想要在TensorBoard上运行the的可视化部分。正如您所描述的,Tensorflow的API只在如何记录中提供了基本的命令。
我已经用MNIST数据集将我的工作解决方案上传到我的GitHub回购.
是的,它分为三个一般步骤:
只有泛型细节被嵌入到TensorFlow r0.12发行版中。在官方源代码中没有我所知道的完整代码示例。
我发现有两项涉及的任务在“如何”中没有被记录下来。
tf.Variable中虽然TensorFlow是为使用GPU而设计的,但在这种情况下,我选择用CPU生成the可视化,因为这个过程占用的内存比我的MacBookPro GPU所能访问的内存要多。TensorFlow包含了对MNIST数据集的API访问,所以我使用了它。MNIST数据是一个结构化的numpy数组。使用tf.stack函数可以将此数据集堆叠成张量列表,这些张量可以嵌入到可视化中。下面的代码包含了如何提取数据并设置TensorFlow嵌入变量。
with tf.device("/cpu:0"):
embedding = tf.Variable(tf.stack(mnist.test.images[:FLAGS.max_steps], axis=0), trainable=False, name='embedding')创建元数据文件是通过对numpy数组的切片来完成的。
def save_metadata(file):
with open(file, 'w') as f:
for i in range(FLAGS.max_steps):
c = np.nonzero(mnist.test.labels[::1])[1:][0][i]
f.write('{}\n'.format(c))具有要与之关联的图像文件,如“如何- to”中所述。我已经将前10,000个MNIST图像的png文件上载到我的GitHub。
到目前为止,TensorFlow对我来说工作得很好,它的计算速度快,文档完整,而且这个API在功能上似乎已经完成了我现在要做的任何事情。我期待着在未来的一年中用自定义数据集生成更多的可视化。这篇文章是从我的博客编辑的。祝你好运,请告诉我事情进展如何。:)
发布于 2017-03-08 15:59:01
我用过FastText的预训练字向量和TensorBoard。
import os
import tensorflow as tf
import numpy as np
import fasttext
from tensorflow.contrib.tensorboard.plugins import projector
# load model
word2vec = fasttext.load_model('wiki.en.bin')
# create a list of vectors
embedding = np.empty((len(word2vec.words), word2vec.dim), dtype=np.float32)
for i, word in enumerate(word2vec.words):
embedding[i] = word2vec[word]
# setup a TensorFlow session
tf.reset_default_graph()
sess = tf.InteractiveSession()
X = tf.Variable([0.0], name='embedding')
place = tf.placeholder(tf.float32, shape=embedding.shape)
set_x = tf.assign(X, place, validate_shape=False)
sess.run(tf.global_variables_initializer())
sess.run(set_x, feed_dict={place: embedding})
# write labels
with open('log/metadata.tsv', 'w') as f:
for word in word2vec.words:
f.write(word + '\n')
# create a TensorFlow summary writer
summary_writer = tf.summary.FileWriter('log', sess.graph)
config = projector.ProjectorConfig()
embedding_conf = config.embeddings.add()
embedding_conf.tensor_name = 'embedding:0'
embedding_conf.metadata_path = os.path.join('log', 'metadata.tsv')
projector.visualize_embeddings(summary_writer, config)
# save the model
saver = tf.train.Saver()
saver.save(sess, os.path.join('log', "model.ckpt"))然后在终端中运行以下命令:
tensorboard --logdir=log发布于 2017-03-03 12:55:54
看看这个“动手TensorBoard (2017年TensorFlow Dev首脑会议)”https://www.youtube.com/watch?v=eBbEDRsCmv4,它演示了在MNIST数据集中嵌入TensorBoard。
在这里可以找到对话的示例代码和幻灯片,https://github.com/mamcgrath/TensorBoard-TF-Dev-Summit-Tutorial
https://stackoverflow.com/questions/41258391
复制相似问题