【发布时间】: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 ConvLSTM2DCell或from tensorflow import keras ; from keras.layers import ConvLSTM2DCell
标签: python tensorflow tensorflow2.0 tf.keras