我试图在tensorboard中显示我的嵌入。当我打开张量板的嵌入选项卡时,我得到:“正在计算PCA ...”,并且张量板无限地挂起。
我在TF版本0.12和1.1上尝试过,结果相同。
import os
import numpy as np
import tensorflow as tf
from tensorflow.contrib.tensorboard.plugins import projector
LOG_DIR = os.getcwd()+"\LOG"
embeddings = np.array([[ 0.00403953, -0.00622064, -0.01170987, 0.02049868, -0.01784528,
-0.00844114, 0.00360506, -0.09942514, 0.032083 , -0.0056223 ],
[-0.04307625, -0.01297725, 0.03254195, 0.00583903, -0.00986445,
-0.02183709, 0.01153475, -0.10950625, -0.03583045, -0.03795925],
[-0.03899275, -0.0046966 , 0.01469164, 0.01740974, 0.01288737,
-0.0306037 , 0.0353404 , -0.09731412, 0.04237695, 0.02322971],
[-0.00181839, 0.00105444, -0.01013809, 0.04349392, -0.02176337,
-0.04931752, -0.02105442, -0.07082064, 0.00941054, -0.02279854],
[ 0.0296278 , 0.0406456 , -0.01181266, 0.03085812, -0.0182738 ,
-0.01673431, 0.0178362 , -0.1398714 , 0.0270176 , -0.00516446],
[-0.0595875 , -0.047008 , 0.002867 , 0.00726775, -0.002714 ,
-0.029009 , 0.002205 , -0.10231575, -0.0291282 , 0.01943275],
[-0.00291987, -0.069231 , -0.02141933, -0.01235343, 0.000823 ,
-0.05252166, -0.000757 , -0.11705633, 0.0241631 , 0.02844123],
[ 0.0141408 , -0.02469571, -0.01984159, -0.00944844, 0.00886971,
-0.0474157 , -0.01649545, -0.13802414, -0.02138517, 0.01678829],
[ 0.008873 , 0.05906433, -0.020482 , -0.01096687, -0.022655 ,
-0.04205434, 0.02315167, -0.12080999, -0.029119 , -0.03175637],
[ 0.028179 , -0.04476625, -0.017764 , 0.02365533, 0.00857486,
-0.0018825 , 0.0024118 , -0.11940325, 0.0164014 , -0.00140572]],
dtype=np.float32)
emb_var = tf.Variable(embeddings, name='embeddingsreal')
with tf.Session() as sess:
saver = tf.train.Saver([emb_var])
sess.run(emb_var.initializer)
saver.save(sess, os.path.join(LOG_DIR, 'emb2.ckpt'))
config = projector.ProjectorConfig()
# One can add multiple embeddings.
embedding = config.embeddings.add()
embedding.tensor_name = emb_var.name
# Saves a config file that TensorBoard will read during startup.
projector.visualize_embeddings(tf.summary.FileWriter(LOG_DIR), config)