用于潜在空间图像可视化的TensorFlow嵌入投影仪?

问题描述 投票:1回答:1

有人可以帮我解决为什么Tensorflow嵌入式投影仪无法正常工作吗?我正在训练自动编码器,现在正在尝试可视化潜在空间。我遵循了这个非常有用的教程:https://github.com/anujshah1003/Tensorboard-own-image-data-image-features-embedding-visualization

我一直在重新检查我的工作,但找不到任何错误。如所附图像所示,投影机在此屏幕上启动和结束。它只是说点和尺寸正在加载,但实际上没有点被加载。我正在使用的图像和下面的代码。任何指针,不胜感激。非常感谢你!我正在将Tensorflow 1.9.0与Keras 2.1.6和Python 2.7一起使用。我当时使用的是Tensorboard 1.9.0,但尽管它什么也没做,但降级到1.5.1。

image_list = load_crops(num_positive,num_negative,h5_file,only_positives)
LOG_DIR = os.getcwd() + '/embedding-logs'


#now get the feature vectors by creating the encoder and running images through
embedding = encoder.predict(image_list)
features = tf.Variable(embedding, name='features')


#obtain the labels and name them
n_classes = 2
num_of_samples = embedding.shape[0]
num_of_samples_each_class = num_of_samples/n_classes

y = np.ones((num_of_samples,), dtype = 'int64')
y[:num_of_samples_each_class] = 0 
y[num_of_samples_each_class:num_of_samples_each_class*2] = 1  
names = ['CD3+','FOXP3+']

#generate metadata file that says which features belong to which label
#metadata allows to assign labels to each point in embedded space.  label will be the name and the number we assign
metadata_file = open(os.path.join(LOG_DIR, 'metadata_2_classes.tsv'), 'a+')
metadata_file.write('Class\tName\n')

k=num_of_samples_each_class 
j=0
for i in range(num_of_samples):
    c = names[y[i]]
    if i%k==0:
        j=j+1
    metadata_file.write('{}\t{}\n'.format(j,c))
metadata_file.close()


#we have to generate sprite image if we want to see the images in the visualization
sprite = images_to_sprite(image_list)
cv2.imwrite(os.path.join(LOG_DIR, 'sprite_2_classes.png'), sprite)

#run session
with tf.Session() as sess:
    img_data = image_list

    saver = tf.train.Saver([features])
    sess.run(features.initializer)
    saver.save(sess, os.path.join(LOG_DIR, 'images_2_classes.ckpt'))

    config = projector.ProjectorConfig()
    embedding = config.embeddings.add()
    embedding.tensor_name = features.name
    # Link this tensor to its metadata file (e.g. labels).
    embedding.metadata_path = os.path.join(LOG_DIR, 'metadata_2_classes.tsv')
    # Comment out if you don't want sprites
    embedding.sprite.image_path = os.path.join(LOG_DIR, 'sprite_2_classes.png')
    embedding.sprite.single_image_dim.extend([img_data.shape[1], img_data.shape[1]])
    # Saves a config file that TensorBoard will read during startup.
    projector.visualize_embeddings(tf.summary.FileWriter(LOG_DIR), config)

What shows up on Tensorboard

tensorflow keras visualization embedding dimensionality-reduction
1个回答
0
投票

我知道了。我忘记在编码器的输出上应用np.squeeze。我的编码器的输出为(600,1,100)。它无法绘制多余的图形,因此当我制作(600,100)时,它可以工作。

© www.soinside.com 2019 - 2024. All rights reserved.