私は100次元の埋め込みを100の異なる変数に分割しようとしていたので、それがうまくいかなかったのです。そして、それはうまくいかなかった。だから私は埋め込みを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)