使用 Tensorflow 可视化多重嵌入

Visualizing multiple embedding With Tensorflow

我想基于多个张量变量(即基于不同的嵌入变量)可视化我的数据。换句话说,我需要做的是:

我需要将 100 维向量(图像 feature/embeddings)存储到 5 个不同的变量中。然后我需要根据 5 个不同的变量可视化我的数据。也就是说,我需要根据前 20 个特征可视化我的数据,然后根据后 20 个特征等等...

当我查看 https://www.tensorflow.org/get_started/embedding_viz 上的嵌入可视化教程时,他们说我们可以添加多个嵌入。这就是我要找的。

如何在tensorflow中做到这一点?

非常感谢任何帮助!!

所以它不起作用的原因是因为我试图将 100 维嵌入分成 100 个不同的变量。那没有用。所以当我把我的embeddings分成5个不同的部分,也就是说,把它们分成5个不同的变量时,它就成功了。下面是我的代码:

import numpy as np
import tensorflow as tf
from tensorflow.contrib.tensorboard.plugins import projector

LOG_DIR = \
    'C:/Users/user/PycharmProjects/VariationalAutoEncoder/' \
    'Tensorflow-DeconvNet-Segmentation/Embeddings/features_images.ckpt'

feature_vectors = np.loadtxt('features.txt')
feature_vectors = feature_vectors[:5329]

print("feature_vectors_shape:",feature_vectors.shape)

sub_features = []
for i in range(20):
    features = tf.Variable(feature_vectors[:, 5 * i: 5 * (i + 1)], name=('features' + str(i)))
    sub_features.append(features)

with tf.Session() as sess:

    saver = tf.train.Saver()
    sess.run(tf.global_variables_initializer())
    saver.save(sess, LOG_DIR)

    config = projector.ProjectorConfig()
    for i in range(20):
        embedding = config.embeddings.add()
        embedding.tensor_name = sub_features[i].name

        embedding.sprite.image_path = \
            'C:/Users/user/PycharmProjects/VariationalAutoEncoder/Tensorflow-DeconvNet-Segmentation/master.jpg'
        embedding.sprite.single_image_dim.extend([112, 112])

    # Saves a config file that TensorBoard will read during startup.
    projector.visualize_embeddings(tf.summary.FileWriter(LOG_DIR), config)