繁体   English   中英

Tensorflow输入管道用于分布式培训

[英]Tensorflow input pipeline for distributed training

我试图弄清楚如何在分布式训练中为张量流设置输入管道。 尚不清楚读取器是否将从单个进程中读取并将数据发送给所有工作进程,还是每个服务器将启动其自己的输入管道? 我们如何确保每个工人都得到不同的投入?

我将举例说明如何做到这一点:

import tensorflow as tf
batch_size = 50
task_index = 2
num_workers = 10
input_pattern = "gs://backet/dir/part-00*"

获取存储桶中与input_pattern对应的文件的所有名称

files_names = tf.train.match_filenames_once(
                input_pattern, name = "myFiles")

选择工作程序task_index名称。 tf.strided_slice类似于列表的切片:a [::,task_index](为工作器task_index选择每个task_index文件)

to_process = tf.strided_slice(files_names, [task_index],
                 [999999999], strides=[num_workers])
filename_queue = tf.train.string_input_producer(to_process,
                     shuffle=True, #shufle files
                     num_epochs=num_epochs)

reader = tf.TextLineReader()
_ , value = reader.read(filename_queue)
col1,col2 = tf.decode_csv(value,
        record_defaults=[[1],[1]], field_delim="\t")

train_inputs, train_labels = tf.train.shuffle_batch([col1,[col2]],
        batch_size=batch_size,
        capacity=50*batch_size,
        num_threads=10,
        min_after_dequeue = 10*batch_size,
        allow_smaller_final_batch = True)

loss = f(...,train_inputs, train_labels)
optimizer = ...

with tf.train.MonitoredTrainingSession(...) as mon_sess:
    coord = tf.train.Coordinator()
    with coord.stop_on_exception():
        _ = tf.train.start_queue_runners(sess = mon_sess, coord=coord)
        while not coord.should_stop() and not mon_sess.should_stop():
            optimizer.run()

我不确定在分布式TensorFlow实现的情况下我的方法是实现输入管道的最佳方法,因为每个工作程序都读取存储桶中所有文件的名称


关于TensorFlow中输入管道的好讲座: http ://web.stanford.edu/class/cs20si/lectures/notes_09.pdf

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM