问题 - TensorBoard只显示一个图像
灵感来自于 如何在Tensorflow中可视化cnn中的权重(变量)?
这是代码:
# --- 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
看起来不错
交付了5张[图片标签]对
如果我取消注释print"imss",我可以看到5个不同的缓冲区,每个缓冲区都有自己的png图像
op图在TB中看起来不错
但是TB中只有一个图像.我怀疑我错过了一些关于TF如何工作的重要信息 - 在图形执行时间导致了什么.
第二个问题:我需要做些什么才能看到结果,即img2 = img + img TB?
你是对的,你只会看到一个图像.您在每个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中看到所有图像.
如果还有问题,请告诉我.