问题 - TensorBoard只显示一张图片
受此启发 How can I visualize the weights(variables) in cnn in Tensorflow?
这是代码:
# --- image reader ---
# - rsq: random shuffle queue with [fn l] pairs
def img_reader_jpg(rsq):
fn, label = rsq.dequeue()
img_b = tf.read_file(fn)
img_u = tf.image.decode_jpeg(img_b, channels=3)
img_f = tf.cast(img_u, tf.float32)
img_4 = tf.expand_dims(img_f,0)
return img_4, label
# filenames and labels are pre-loaded
fv = tf.constant(fnames)
lv = tf.constant(ohl)
rsq = tf.RandomShuffleQueue(len(fnames), 0, [tf.string, tf.float32])
do_enq = rsq.enqueue_many([fv, lv])
# reading_op
image, label = img_reader_jpg(rsq)
# test: some op
im_t = tf.placeholder(tf.float32, shape=[None,30,30,3], name='img_tensor')
lab_t = tf.placeholder(tf.float32, shape=[None,2], name='lab_tensor')
some_op = tf.add(im_t,im_t)
ims_op = tf.image_summary("img", im_t)
# service ops
init_op = tf.initialize_all_variables()
# run it
with tf.Session() as sess:
summary_writer = tf.train.SummaryWriter(summ_dir, graph_def=sess.graph_def)
print 'log at:', summ_dir
sess.run(init_op)
sess.run(do_enq)
print "rsq.size:", rsq.size().eval()
for i in xrange(5):
print "\ni:",i
img_i, lab_i = sess.run([image, label]) # read image - right?
print "I:", img_i.shape , " L:", lab_i
feed_dict = {
im_t: img_i
}
img2 = sess.run([some_op], feed_dict = feed_dict)
# now summary part
imss = sess.run(ims_op, feed_dict = feed_dict)
#print "imss",imss
summary_writer.add_summary(imss,i)
print "rsq.size:", rsq.size().eval()
summary_writer.close()
print 'ok'
这是输出:
log at: /mnt/code/test_00/log/2016-01-09 17:10:37
rsq.size: 1225
i: 0
I: (1, 30, 30, 3) L: [ 1. 0.]
i: 1
I: (1, 30, 30, 3) L: [ 1. 0.]
i: 2
I: (1, 30, 30, 3) L: [ 0. 1.]
i: 3
I: (1, 30, 30, 3) L: [ 0. 1.]
i: 4
I: (1, 30, 30, 3) L: [ 0. 1.]
rsq.size: 1220
ok
看起来不错
然而结核病只有一个图像。我怀疑我错过了TF如何工作的重要事项-.i.e。什么导致图执行时间。
第二个问题:我需要做些什么才能看到TB中的结果,即 img2 = img + img ?
答案 0 :(得分:6)
你是对的,你只能看到一张图片。您在每个for循环中调用一次图像摘要操作,每次调用它时,都会传递一个图像。
您可以执行的操作是查看要查看的所有图像,将这些图像编译为单个张量。如果我们引用TensorFlow API(链接总是更改,那么找到最新的)
tf.image_summary(tag,tensor,max_images = 3,collections = None, name = None)
从TF 1.0.0开始,就是这样:
tf.summary.image(name,tensor,max_outputs = 3,collections = None)
将“多个图像张量”放入,将max_images设置为您拥有的图像数量,您应该能够在TensorBoard中看到所有图像。
如果仍有问题,请告诉我。
答案 1 :(得分:1)
自r0.12起,tf.image_summary
已替换为tf.summary.image
tf.summary.image(name, tensor, max_outputs=3, collections=None)