Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tensorflow 使用预加载网络的输出可视化张力板上的嵌入_Tensorflow_Tensorboard - Fatal编程技术网

Tensorflow 使用预加载网络的输出可视化张力板上的嵌入

Tensorflow 使用预加载网络的输出可视化张力板上的嵌入,tensorflow,tensorboard,Tensorflow,Tensorboard,我想知道如何在Tensorboard中可视化来自预加载网络的嵌入。我正在使用创建面嵌入,我已经创建了sprite.png和labels.tsv文件。至于加载网络和设置Tensorboard,这是我到目前为止所做的工作: 1。加载嵌入层 meta_file, ckpt_file = facenet.get_model_filenames(MODEL_DIR) with tf.Graph().as_default(): with tf.Session().as_default() as se

我想知道如何在Tensorboard中可视化来自预加载网络的嵌入。我正在使用创建面嵌入,我已经创建了
sprite.png
labels.tsv
文件。至于加载网络和设置Tensorboard,这是我到目前为止所做的工作:

1。加载嵌入层

meta_file, ckpt_file = facenet.get_model_filenames(MODEL_DIR)
with tf.Graph().as_default():
    with tf.Session().as_default() as sess:
        # load the network 
        model_dir_exp = os.path.expanduser(MODEL_DIR)
        saver = tf.train.import_meta_graph(os.path.join(model_dir_exp, meta_file))
        saver.restore(tf.get_default_session(), os.path.join(model_dir_exp, ckpt_file))

        # setup the lambda function needed to get the embeddings
        images_placeholder = tf.get_default_graph().get_tensor_by_name("input:0")
        embeddings = tf.get_default_graph().get_tensor_by_name("embeddings:0")
        phase_train_placeholder = tf.get_default_graph().get_tensor_by_name("phase_train:0")
        find_embeddings = lambda img : sess.run(embeddings, feed_dict = {images_placeholder : img, phase_train_placeholder : False})
2。查找嵌入项

face_embeddings = np.zeros((n_images,128))
face_embeddings = []
for i in range(n_batches):
    start = i * batch_size
    end = min((i + 1) * batch_size, n_images)

    # Get the embeddings
    face_embeddings[start:end, :] = find_embeddings(face_images[start:end])
3。设置张力板

from tensorflow.contrib.tensorboard.plugins import projector

embedding = tf.Variable(tf.zeros([33, 128]), name = "embedding")
config = projector.ProjectorConfig()
embedding_config = config.embeddings.add()
embedding_config.tensor_name = embedding.name
embedding_config.metadata_path = os.path.join(MODEL_DIR, 'labels.tsv')
embedding_config.sprite.image_path = os.path.join(MODEL_DIR,'sprite.png')
embedding_config.sprite.single_image_dim.extend([160, 160])

writer = tf.summary.FileWriter(MODEL_DIR)
projector.visualize_embeddings(writer, config)

虽然当我在Tensorboard中加载时,它说它找不到数据。我已经查看了,当我运行
find MODEL_DIR | grep tfevents
时,没有显示任何内容,所以我猜这就是问题所在。我已经看过了,看起来他们在训练阶段有检查点,虽然我没有,因为我使用的是预先训练好的模型。关于如何让Tensorboard显示这种情况下的嵌入,您有什么想法吗?

您需要使用
tf.Saver()
创建一个检查点。有关示例代码,请参阅NMT seq2seq教程,或查看文档。您需要使用
tf.Saver()
创建检查点。有关示例代码,请参阅NMT seq2seq教程,或查看文档。