2017-07-24 156 views
4

我想弄清楚如何在分佈式訓練中設置我的輸入管道tensorflow。目前尚不清楚讀者是否會從一個進程讀取數據並將數據發送給所有工作人員,或者每臺服務器將啓動它自己的輸入管道?我們如何確保每個工人都有不同的意見?Tensorflow輸入管道分佈式訓練

+0

,每個工人有他們自己的閱讀器 –

+0

請閱讀您正在使用的標籤的描述。 「ML」是指編程語言。 – molbdnilo

回答

0

我會給我如何做到這一點的例子:

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_indextask_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如果你遵循任何的從谷歌標準的例子