In tensorflow, using function tf.summary.image
, we can display images in tensorboard.
image( name, tensor, max_outputs=3, collections=None )
The data format of variable tensor
is "NHWC", as [batch_size, height, width, channels]
.
but when I use "NCHW" ([batch_size, channels ,height, width]
), how to display images in tensorboard ?
The image summary does not handle multiple memory layout, as some other tensorflow functions do. So currently, your only option is to transpose your images.
As tf.transpose
is a somewhat heavy operation, you can limit the transposition to the number of images that are summarized only, say summary_img_num
:
summary_imgs = tf.transpose(imgs[:summary_img_num], perm=[0,3,1,2])
tf.summary.image('images', summary_imgs, max_outputs=summary_img_num)
If you stick to tf.summary.image
's default max_outputs=3
,
summary_imgs = tf.transpose(imgs[:3], perm=[0,3,1,2])
tf.summary.image('images', summary_imgs)