Tensorflow 数据输入切换:训练/验证 [英] Tensorflow Data Input Toggle: Train/Validation

查看:26
本文介绍了Tensorflow 数据输入切换:训练/验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我从方便但速度较慢的占位符切换后,我的数据通过队列运行器进入我的图表.

在每个训练时期之后,我希望运行一次验证通过.除了训练阶段,验证阶段使用不同的数据,没有增强和改组.

问题很简单:我如何切换这些东西?

一些观察:

  • 我无法通过 tf.placeholder 布尔值切换 string_input_producer 中的 shuffle 选项.
  • 我发现的唯一在线示例使用 placeholder 将训练与验证数据分开.反过来,这些不使用高级队列运行器.
  • 我确实设法使用 tf.cond() 完成了上述操作,在这里我将测试 is_training tf.placeholder 布尔值我通过了 feed_dict.这个解决方案是最优化的吗?这个 tf.conf() 方法的开销有多大?

解决方案

对我来说效果很好的方法是使用tf.placeholder_with_default:

<块引用>

images_train, labels_train = train_data_pipeline(fnlist_train, ref_grid)images_val,labels_val = val_data_pipeline(fnlist_val,ref_grid)图像 = tf.placeholder_with_default(images_train, shape=[None, FLAGS.nx_image, FLAGS.ny_image, FLAGS.nz_image])标签 = tf.placeholder_with_default(labels_train, shape=[None, label_length])

在训练期间,imageslabels 直接来自训练队列.对于间歇性验证步骤,我在调用 sess.run() 时通过 feed_dict 提供 imageslabels.唯一的小问题是验证数据也是来自队列的张量,而 feed_dict 不接受张量,所以我首先调用 sess.run([images_val, labels_val]) 来获取 numpy 值然后在 feed_dict 中使用它们.似乎运行良好,并且从 tensor==>numpy==>tensor 转换的延迟最小,无论如何都只会在验证期间发生.

对于验证数据有单独处理要求的情况,可以在设置单独的验证队列和处理流程时处理.

I have data that comes into my graph through queue runners, after I switched from the handy but speed-inferior placeholders.

After each training epoch, I wish to run a validation pass. Other than the the training pass, the validation pass uses different data, no augmentation and no shuffling.

The question is simple: how do I toggle these things?

A few observations:

  • I cannot toggle the shuffle option in the string_input_producer through a tf.placeholder boolean.
  • The only examples on-the-line that I have found use the placeholder to seperate the training from the validation data. These in turn, do not use the superior queue runners.
  • I did manage to do the above with a tf.cond() here i would test for a is_training tf.placeholder boolean that i pass through the feed_dict. Is this solution the most optimal? How expensive is this tf.conf() method?

解决方案

The method that works well for me is to use tf.placeholder_with_default:

images_train, labels_train = train_data_pipeline(fnlist_train, ref_grid)
images_val, labels_val = val_data_pipeline(fnlist_val, ref_grid)
images = tf.placeholder_with_default(images_train, shape=[None, FLAGS.nx_image, FLAGS.ny_image, FLAGS.nz_image])
labels = tf.placeholder_with_default(labels_train, shape=[None, label_length])

During training, images and labels come directly from the training queue. For the intermittent validation steps I feed images and labels through a feed_dict in a call tosess.run(). The only slight hack is that is that the validation data are also tensors from a queue and feed_dict doesn't accept tensors, so I call sess.run([images_val, labels_val]) first to get numpy values and then use them in the feed_dict. Seems to work well and there is minimal delay from the tensor==>numpy==>tensor conversion, which only occurs during validation anyway.

And for your case where the validation data have separate processing requirements, this can be handled when you set up the separate validation queue and processing flow to it.

这篇关于Tensorflow 数据输入切换:训练/验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆