即使日志目录中有检查点文件,嵌入式投影仪也不会显示任何内容。
我的代码是文件的修改版本:mnist_t-sine.py来自:https://github.com/normanheckscher/mnist-tensorboard-embeddings。它已被修改为绘制嵌入的直方图(没有多大意义,但只是为了检查张量板是否有效)。
这是我的代码:https://drive.google.com/open?id=0B8ZdOStUW_DCb3Uwbm9VTnQ5SzA
# Copyright 2016 Norman Heckscher. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""MNIST dimensionality reduction with TensorFlow and TensorBoard.
This demonstrates the functionality of the TensorBoard Embedding Visualization dashboard using MNIST.
https://www.tensorflow.org/versions/r0.12/how_tos/embedding_viz/index.html#tensorboard-embedding-visualization
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import argparse
import sys
import os
import numpy as np
from tensorflow.contrib.tensorboard.plugins import projector
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
FLAGS = None
def generate_embeddings():
# Import data
mnist = input_data.read_data_sets(FLAGS.data_dir,
one_hot=True,
fake_data=FLAGS.fake_data)
sess = tf.InteractiveSession()
# Input set for Embedded TensorBoard visualization
# Performed with cpu to conserve memory and processing power
with tf.device("/cpu:0"):
embedding = tf.Variable(tf.stack(mnist.test.images[:FLAGS.max_steps], axis=0), trainable=False, name='embedding')
tf.summary.histogram("Embedding",embedding)
tf.summary.tensor_summary("Embeddings", embedding)
saver = tf.train.Saver()
writer = tf.summary.FileWriter(FLAGS.log_dir + '/projector', sess.graph)
merged_summ = tf.summary.merge_all()
tf.global_variables_initializer().run()
# Add embedding tensorboard visualization. Need tensorflow version
# >= 0.12.0RC0
config = projector.ProjectorConfig()
embed= config.embeddings.add()
embed.tensor_name = 'embedding'
embed.metadata_path = os.path.join(FLAGS.log_dir + '/projector/metadata.tsv')
embed.sprite.image_path = os.path.join(FLAGS.data_dir + '/mnist_10k_sprite.png')
summ = sess.run(merged_summ)
for i in range(20):
writer.add_summary(summ,i)
# Specify the width and height of a single thumbnail.
embed.sprite.single_image_dim.extend([28, 28])
projector.visualize_embeddings(writer, config)
print(sess.run(embedding))
saver.save(sess, os.path.join(
FLAGS.log_dir, 'projector/a_model.ckpt'), global_step=FLAGS.max_steps)
def generate_metadata_file():
# Import data
mnist = input_data.read_data_sets(FLAGS.data_dir,
one_hot=True,
fake_data=FLAGS.fake_data)
def save_metadata(file):
with open(file, 'w') as f:
for i in range(FLAGS.max_steps):
c = np.nonzero(mnist.test.labels[::1])[1:][0][i]
f.write('{}\n'.format(c))
save_metadata(FLAGS.log_dir + '/projector/metadata.tsv')
def main(_):
if tf.gfile.Exists(FLAGS.log_dir + '/projector'):
tf.gfile.DeleteRecursively(FLAGS.log_dir + '/projector')
tf.gfile.MkDir(FLAGS.log_dir + '/projector')
tf.gfile.MakeDirs(FLAGS.log_dir + '/projector') # fix the directory to be created
generate_metadata_file()
generate_embeddings()
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--fake_data', nargs='?', const=True, type=bool,
default=False,
help='If true, uses fake data for unit testing.')
parser.add_argument('--max_steps', type=int, default=50,
help='Number of steps to run trainer.')
parser.add_argument('--data_dir', type=str, default='/Users/norman/Documents/workspace/mnist-tensorboard-embeddings/mnist_data',
help='Directory for storing input data')
parser.add_argument('--log_dir', type=str, default='/Users/norman/Documents/workspace/mnist-tensorboard-embeddings/logs',
help='Summaries log directory')
FLAGS, unparsed = parser.parse_known_args()
tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
这些是Tensorboard Graph,Histogram和Distribution选项卡的屏幕截图正常工作,但Embeddings选项卡除外:
空白嵌入标签:
我已经从支持GPU的源代码中卸载并重新安装了tensorflow。以下是输出:tensorboard --inspect --logdir=logs
:
======================================================================
Processing event files... (this can take a few minutes)
======================================================================
Found event files in:
logs/projector
These tags are in logs/projector:
audio -
histograms
Embedding
images -
scalars -
tensor
======================================================================
Event statistics for logs/projector:
audio -
graph
first_step 0
last_step 0
max_step 0
min_step 0
num_steps 1
outoforder_steps []
histograms
first_step 0
last_step 19
max_step 19
min_step 0
num_steps 20
outoforder_steps []
images -
scalars -
sessionlog:checkpoint -
sessionlog:start -
sessionlog:stop -
tensor
first_step 0
last_step 19
max_step 19
min_step 0
num_steps 20
outoforder_steps []
======================================================================
答案 0 :(得分:0)
我已经解决了这个问题,重新安装pip为:pip install tensorflow-tensorboard
的tensorboard,正如GitHub问题所示:https://github.com/tensorflow/tensorflow/issues/10756,由eiennohito打开。