欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

程序员文章站 2022-07-13 11:39:12
...

tf.nn.static_rnn 和 tf.contrib.rnn.static_rnn tf.nn.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