我想重写我的代码,以便可视化数据集中所有的标签,并查看结果以进行比较。
你可以在左侧看到标签图片,在右侧看到学习后的输出:
我所有的图片形状都不同,我用以下方式读取它们:
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')
然后将它们重塑为:
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')
接着,我定义了一些占位符,然后…
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')
…将它们输入我的神经网络:
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)
在训练范围内,我打印它们:
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)
然后在会话中运行它们:
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()})
现在,我的难题是:我想用sess.run( )
替换循环,不再遍历所有图片。
目前它是一次处理一个图片三元组。如何同时处理多张图片,例如[4, ?, ?, 3]
。我尝试使用tf.concat()
,但在执行img.l_img.eval()
时,由于图片的高度和宽度不同,会发生错误。
我也很乐意重构整个项目。
回答:
除非图片/批次具有相同大小,否则无法增加图片的第一维度[1, h, w, rgb]。
调整大小/裁剪会导致不良结果。
简而言之,这是不可能的。