2017-03-05 141 views
1

我正在關注RNN tutorial of Tensorflow。 我無法理解在reader.pyfunction ptb_producer在下面的腳本:Tensorflow RNN教程

with tf.control_dependencies([assertion]): 
     epoch_size = tf.identity(epoch_size, name="epoch_size") 

    i = tf.train.range_input_producer(epoch_size, shuffle=False).dequeue() 
    x = tf.strided_slice(data, [0, i * num_steps],[batch_size, (i + 1) * num_steps]) 
    x.set_shape([batch_size, num_steps]) 
    y = tf.strided_slice(data, [0, i * num_steps + 1],[batch_size, (i + 1) * num_steps + 1]) 
    y.set_shape([batch_size, num_steps]) 
    return x, y 

誰能解釋一下tf.train.range_input_producer是幹什麼的?

回答

0

我一直在嘗試瞭解幾周的相同教程。在我看來,真正困難的是TensorFlow調用的所有函數都不是立即執行,而是將相應的操作節點添加到圖中。

根據official documentation,範圍輸入生產者'在隊列中生成從0limit - 1的整數'。所以,我看到它的方式,問題i = tf.train.range_input_producer(epoch_size, shuffle=False).dequeue()中的代碼創建了一個節點,該節點充當計數器,一旦執行,將生成序列0:(epoch_size)中的下一個數字。

這用於從輸入數據中獲取下一批。原始數據分爲batch_size行,因此每次運行batch_size批次都會被賦予訓練功能。在每批(行)中,尺寸爲num_steps的滑動窗口向前移動。計數器i允許窗口在每次調用中按num_steps前進。

兩個xy是形狀[batch_size, num_steps]的,因爲它們含有的每個num_stepsbatch_size步驟批次。可變x是輸入y是給定輸入的預期輸出(它是由一個項目移動窗口的左側產生,使iff x = data[i:(i + num_steps] then y = data[(i + 1):(i + num_steps + 1)]

這一直是我的噩夢,但我希望這篇文章幫助未來的人