Tensorflow输入管道与队列工作流程 - 提供数据

时间:2017-05-17 12:52:23

标签: python tensorflow deep-learning

我通过队列使用Tensorflow输入管道。

因此,我这样做:

images, volumes = utils.inputs(FLAGS.train_file_path, FLAGS.batch_size, FLAGS.num_epochs)
v_images, v_volumes = utils.inputs(FLAGS.val_file_path, FLAGS.batch_size)

阅读数据。

init = tf.group(tf.global_variables_initializer(), tf.local_variables_initializer())


with tf.Session() as sess:

    # Start input enqueue threads.
    coord = tf.train.Coordinator()
    threads = tf.train.start_queue_runners(sess=sess, coord=coord)
    try:

        step = 0
        while not coord.should_stop():
            _, train_loss = sess.run([train_optimizer, loss])

            if step % FLAGS.val_interval == 0:
                for val_step in range(0, FLAGS.val_iter):
                        val_loss = sess.run(v_loss)

如何确保我使用images, volumes和卷进行培训,v_images, v_volumes进行验证?

修改

logits = utils.inference(images, FLAGS.stacks, True)
v_logits = utils.inference(v_images, FLAGS.stacks, False)

loss = utils.get_loss(logits, volumes, FLAGS.stacks, 'train')
v_loss = utils.get_loss(v_logits, v_volumes, FLAGS.stacks, 'val')

编辑2

summary_train_op = tf.summary.merge_all('train')
summary_val_op = tf.summary.merge_all('val')

with tf.Session() as sess:

    summary_writer = tf.summary.FileWriter(FLAGS.train_dir + FLAGS.run, sess.graph)
    summary_writer_val = tf.summary.FileWriter(FLAGS.train_dir + FLAGS.run + FLAGS.run_val)

1 个答案:

答案 0 :(得分:0)

一种技术是单独构建图形节点以进行培训和验证。

考虑“net”是您的模型图。

 _,loss_train_value, logits_train_value = sess.run([train_optimizer, loss_train,logits_train]) 

现在,如果你这样做,

loss_train_s = tf.summary.scalar("loss_train", loss_train)
acc_train_s = tf.summary.scalar("acc_train", acc_train)
loss_val_s = tf.summary.scalar("loss_val", loss_val)
train_summary_op = tf.summary.merge([loss_train_s,acc_train_s])
val_summary_op = tf.summary.merge([loss_val_s])

我希望这会有所帮助。

更新

 $(function () {
       $("#searchName").autocomplete({
           source: function (request, response) {                    
                   $.ajax({
                        url: "/YourController/SearchUserByName",
                        type: "POST",
                        data: { name: $("#searchName").val() },
                        dataType: "JSON",
                        success: function (data) {
                            response($.map(data.lastName, function (item) {
                                return {
                                    label: item
                                }
                            }));
                        },
                    });
                },
                minLength: 4
          })
 });

更新2

我正在明确地做所有事情,如下所示。可能有更好的方法来做到这一点。

public ActionResult SearchUserByName(string name)
{
     .
     .
     .

     return Json(lastName);
}