1. 程式人生 > >tf.nn.static_rnn 和 tf.contrib.rnn.static_rnn

tf.nn.static_rnn 和 tf.contrib.rnn.static_rnn

tf.nn.static_rnn 和 tf.contrib.rnn.static_rnn 是一樣的,都表示同一個

這裡講解一下 tf.nn.static_rnn

tf.nn.static_rnn

tf.nn.static_rnn(
    cell,
    inputs,
    initial_state=None,
    dtype=None,
    sequence_length=None,
    scope=None
)
'''
Args:
		cell: An instance of RNNCell.
		inputs: A length T list of inputs, each a Tensor of shape [batch_size, input_size], or a nested tuple of such elements.
		initial_state: (optional) An initial state for the RNN. If cell.state_size is an integer, this must be a Tensor of appropriate type and shape [batch_size, cell.state_size]. If cell.state_size is a tuple, this should be a tuple of tensors having shapes [batch_size, s] for s in cell.state_size.
		dtype: (optional) The data type for the initial state and expected output. Required if initial_state is not provided or RNN state has a heterogeneous dtype.
		sequence_length: Specifies the length of each sequence in inputs. An int32 or int64 vector (tensor) size [batch_size], values in [0, T).
		scope: VariableScope for the created subgraph; defaults to "rnn".
Returns:
		A pair (outputs, state) where:
		outputs is a length T list of outputs (one for each input), or a nested tuple of such elements.
		state is the final state
'''

引數說明

建立一個RNN 通過指定的RNNCell :就是引數cell
cell:一個RNNCell例項
inputs: 長度為T的輸入list,每個都是形狀的張量[batch_size,input_size]
== initial_state:== (可選)RNN的初始狀態。如果cell.state_size是一個整數,那麼它必須是一個具有適當型別和形狀的張量[batch_size,cell.state_size](這裡也就是state_tuple=False)。 如果cell.state_size是一個元組,那麼它應該是一個張量元組,元組的每個元素的形狀為[batch_size,s] (s in cell.state_size)(這裡也就是

state_tuple=True
sequence_length: 指定輸入中每個序列的長度(一旦提供,將動態編碼dynamic_rnn)。int32或int64型別的向量(張量)大小[batch_size],值在[0,T]之間。
返回:
(outputs, state)這樣的一個元祖
outputs: 是輸出長度T的列表(每個時間步輸出一個)
state:最後時間步的RNN的state