简体   繁体   English

Tensorflow RNN教程

[英]Tensorflow RNN tutorial

I am following RNN tutorial of Tensorflow . 我正在关注Tensorflow的RNN教程 I am having trouble understanding the function ptb_producer in reader.py in following script : 我无法理解以下脚本中reader.py中的function ptb_producer

    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

Can anyone explain what tf.train.range_input_producer is doing ? 谁能解释一下tf.train.range_input_producer在做什么?

I have been trying to understand the same tutorial for weeks now. 我已经尝试了几周了解同一个教程。 In my opinion, what makes it so difficult is the fact that all the functions one calls from TensorFlow are not executed immediately, but rather add their corresponding operation nodes to the graph. 在我看来,令人困难的是,TensorFlow调用的所有函数都不会立即执行,而是将相应的操作节点添加到图形中。

According to the official documentation , a Range Input Producer 'generates integers from 0 to limit - 1 in a queue'. 根据官方文档 ,Range Input Producer'生成从0limit - 1整数limit - 1队列中的limit - 1 '。 So, the way I see it, the code in question i = tf.train.range_input_producer(epoch_size, shuffle=False).dequeue() creates a node, which acts as a counter, producing the next number in the sequence 0:(epoch_size) once executed. 所以,我看到它的方式,有问题的代码i = tf.train.range_input_producer(epoch_size, shuffle=False).dequeue()创建一个节点,作为一个计数器,产生序列中的下一个数字0:(epoch_size)一旦执行。

This is used to get the next batch from the input data. 这用于从输入数据中获取下一批。 The raw data is split into batch_size rows, so that in every run batch_size batches are given to the training function. 原始数据被拆分为batch_size行,以便在每次运行时将batch_size批次提供给training函数。 In every batch (row), a sliding window of size num_steps moves forward. 在每个批次(行)中,大小为num_steps的滑动窗口向前移动。 The counter i allows the window to move forward by num_steps in every call. 计数器i允许窗口在每次调用中向前移动num_steps

Both x and y are of shape [batch_size, num_steps] , since they contain batch_size batches of num_steps steps each. xy的形状都是[batch_size, num_steps] ,因为它们每个都包含batch_size批次的num_steps步骤。 Variable x is the input and y is the expected output for the given input (it is produced by moving the window one item to the left, so that iff x = data[i:(i + num_steps] then y = data[(i + 1):(i + num_steps + 1)] . 变量x是输入, y是给定输入的预期输出(它是通过将窗口向左移动一个项目产生的,因此iff x = data[i:(i + num_steps] then y = data[(i + 1):(i + num_steps + 1)]

It has been a nightmare for me, but I hope this post helps people in the future. 这对我来说是一场噩梦,但我希望这篇文章能帮助未来的人们。

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

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