0
我試圖在培訓期間最大化GPU佔用率。我有可變長度的序列,我想密集包裝成固定長度的批次。從本質上講,我希望短序列跟隨另一個序列,並且我想要分割長序列以使它們在下一批中繼續。例如:連續,固定長度的可變長度序列批次
// Say batch size is 2 and desired sequence length is 4
s1 = [a, b, c, d, e, f]
s2 = [x, y, z]
s3 = [l, m, n, o]
// Resulting batches:
b1 = [[a, b, c, d]
[x, y, z, l]]
b2 = [[e, f, _, _]
[m, n, o, _]]
在Tensorflow中有一個簡單的方法嗎?我的序列來自tf.TextLineReader
:
file_queue = tf.train.string_input_producer('./example_text')
reader = tf.TextLineReader()
key, sentence = reader.read(file_queue)
// convert string to int32 vector
sequence_tensor = to_sequence(sentence)
// what I wish I had:
batch = tf.fixed_length_batch_from_variable_length_sequences(
sequence_tensor, batch_size, fixed_length)
非常感謝您的任何建議。