首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于潜在空间图像可视化的TensorFlow嵌入投影仪不起作用?

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

Stack Overflow用户
提问于 2020-02-28 08:26:08
回答 1查看 1.2K关注 0票数 2

有人能帮我解释一下为什么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,尽管它什么也没做。

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

发布于 2020-03-03 07:38:52

我想通了。您必须在编码器的输出上应用np.squeeze。编码器的输出是嵌入投影仪必须是点阵列)。它不能用额外的那个绘图,所以当它被移除时,它就可以工作了。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60443671

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档