【问题标题】:ConvLSTMCell in tensorflow 2张量流2中的ConvLSTMCell
【发布时间】:2020-01-14 07:33:49
【问题描述】:

从 1 升级到 tensorflow 版本 2 后,tf.contrib 中的所有模块都被贬值了。

为了申请attention method,我需要每个单元格的状态。

最初,我在 tf 版本 1 中所做的是:


#ConvLSTMCell
convlstm_layer = tf.contrib.rnn.ConvLSTMCell(
                conv_ndims = 2,    
                input_shape = [10, 10, 32],
                output_channels = 32,
                kernel_shape = [2, 2],
                use_bias = True,
                skip_connection = False,
                forget_bias = 1.0,
                initializers = None,
                )


# Run RNN with ConvLSTMCell
outputs, state = tf.compat.v1.nn.dynamic_rnn(convlstm_layer, conv1_out, time_major = False, dtype = input.dtype)

现在,我正在尝试将其转换为 tf 版本 2 中的代码。

但是,正如我上面提到的,两个模块(tf.contrib 和 tf.compat)都被贬值了。

我找到了 tf.compat.v1.nn.dynamic_rnn 的替代品 tf.keras.layers.rnn

但是没有这样的函数可以创建 ConvLSTMCell。有什么建议吗?

【问题讨论】:

  • 实际上你仍然可以在 TF2 中获取这个单元格,方法是 from tensorflow.python.keras.layers.convolutional_recurrent import ConvLSTM2DCellfrom tensorflow import keras ; from keras.layers import ConvLSTM2DCell

标签: python tensorflow tensorflow2.0 tf.keras


【解决方案1】:

我想你要找的东西在这里:https://www.tensorflow.org/api_docs/python/tf/keras/layers/ConvLSTM2D?version=stable

您可以将其导入您的代码中,例如:

import tensorflow as tf
conv_lstm_layer = tf.keras.layers.ConvLSTM2D(my_parameters)

【讨论】:

  • 我看到了这个错误。 ValueError: The RNN cell should have an attribute state_size`(整数元组,每个 RNN 状态一个整数)。`
  • 好吧,你需要检查参数,不要指望从TF1.X版本复制粘贴所有参数并从头开始工作。
  • 我的意思是,tf.keras.layers.ConvLSTM2D 应该有 'state_size' 属性才能传递给 tf.keras.layers.RNN。这一层缺少一堆单元格属性,需要在 tf.kears.layers.RNN 中实现
猜你喜欢
  • 1970-01-01
  • 2021-04-03
  • 2018-12-13
  • 1970-01-01
  • 1970-01-01
  • 2017-11-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多