【问题标题】:use tf.nn.dynamic_rnn but final state don't have c and h使用 tf.nn.dynamic_rnn 但最终状态没有 c 和 h
【发布时间】:2019-02-21 13:22:09
【问题描述】:

我正在使用 tensorflow,我想用 RNN 运行一个程序,但出现以下错误:

a=self._encoder_final_state[0].c
AttributeError: 'Tensor' object has no attribute 'c'

程序是这样的:

self._encoder_cells = build_rnn_layers(
    cell_type=self._hparams.cell_type,
    num_units_per_layer=self._num_units_per_layer,
    use_dropout=self._hparams.use_dropout,
    dropout_probability=self._hparams.dropout_probability,
    mode=self._mode,
    residual_connections=self._hparams.residual_encoder,
    highway_connections=self._hparams.highway_encoder,
    dtype=self._hparams.dtype,
)

self._encoder_outputs, self._encoder_final_state = tf.nn.dynamic_rnn(
    cell=self._encoder_cells,
    inputs=encoder_inputs,
    sequence_length=self._inputs_len,
    parallel_iterations=self._hparams.batch_size[0 if self._mode == 'train' else 1],
    swap_memory=False,
    dtype=self._hparams.dtype,
    scope=scope,
)
a=self._encoder_final_state[0].c

【问题讨论】:

    标签: tensorflow recurrent-neural-network tensor


    【解决方案1】:

    来自dynamic_rnndocs

    如果单元格是 LSTMCells state 将是一个包含 LSTMStateTuple 对应每个单元格。

    here 您可以看到确实LSTMStateTuple 是具有所需ch 属性的那些。

    不幸的是,您的代码没有给我任何线索您使用的是哪种单元格,但显然它们不是LSTMCells。所以我不能给你任何比切换到LSTMCells更好的建议。

    【讨论】:

      猜你喜欢
      • 2014-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多