Search code examples
machine-learningtensorflowcomputer-visiontensorboard

How to see several images in tensorboard?


I want to rewrite my code to visualize all labels in my dataset and also see the result of that to compare.

You can see left the label image and on the right hand-side the learned output:

tensorboard

All my images have different shape and I read them with

for i in range(len(files_mask)):
    t_image_left = tf.read_file(files_left[i], name='read_fileimage_left')
    t_image_right = tf.read_file(files_right[i], name='read_fileimage_right')
    t_image_mask = tf.read_file(files_mask[i], name='read_fileimage_mask')

And reshape them to

    t_left = tf.reshape(t_left, [1, sh[0] / scaling, sh[1] / scaling, 3], name='reshape_t_left')
    t_right = tf.reshape(t_right, [1, sh[0] / scaling, sh[1] / scaling, 3], name='reshape_t_right')
    t_mask = tf.reshape(t_mask, [1, sh[0] / scaling, sh[1] / scaling, 1], name='reshape_t_mask')

Then, I defined some placeholders, and ....

t_im0 = tf.placeholder(tf.float32, [None, None, None, 3], name='left_img')
t_im1 = tf.placeholder(tf.float32, [None, None, None, 3], name='right_img')
t_label = tf.placeholder(tf.float32, [None, None, None, 1], name='label')

... put them into my neuronal network:

tn_prediction0, tn_prediction1 = cnn.construct_stereo_img(t_im0, t_im1)
t_img = tf.subtract(tn_prediction0, tn_prediction1)
tn_logits = cnn.construct_nn2(t_img)

In the scope Train I print them:

with tf.name_scope("Train"):
    optimizer = tf.train.AdamOptimizer(FLAGS.learning_rate).minimize(cost_function)
    tf.summary.image('logits', tn_logits, max_outputs=4)
    tf.summary.image('label', t_label, max_outputs=4)

And let them run in a session:

with tf.Session(config=tf.ConfigProto(gpu_options=tf.GPUOptions(per_process_gpu_memory_fraction=0.333))) as sess:

    coord = tf.train.Coordinator()
    threads = tf.train.start_queue_runners(sess=sess, coord=coord)
    sess.run(init)

    for epoch in range(FLAGS.training_epochs):
        for img in images:
            _, summary_str, costs = sess.run([optimizer, merged_summary_op, cost_function],
                                             feed_dict={t_im0: img.l_img.eval(), t_im1: img.r_img.eval(),
                                                        t_label: img.mask.eval()})

Now, here comes my problem: I want to replace loop with sess.run( ) to NOT iterate over all images.

It is currently feeding one image triple after another. How to several images at the same time, e.g [4, ?, ?, 3]. I tried to use tf.concat(), but if I executing img.l_img.eval() an error occurs, because images have different heights and widths.

I am also totally open to restructuring the whole project.


Solution

  • It is not possible to increase the first dimension of images [1, h, w, rgb], unless the images/batches have the same size.

    Resizing/cropping would lead to bad results.

    short it is not possible.