【发布时间】:2021-06-15 12:34:58
【问题描述】:
我正在构建一个由 1 个 LSTM 层组成的非常简单的 NN。代码如下:
import tensorflow as tf
lstm = tf.keras.layers.LSTM(15, return_sequences = True, return_state = True)
sample_hidden = tf.zeros((1000, 15))
x = tf.zeros((1000, 100, 10))
y, h, c = lstm(x, initial_state=sample_hidden)
当我运行此代码时,我收到以下错误:
ValueError: An `initial_state` was passed that is not compatible with `cell.state_size`. Received `state_spec`=ListWrapper([InputSpec(shape=(1000, 15), ndim=2)]); however `cell.state_size` is [15, 15]
我不明白为什么 cell.state_size 是 [15,15]。但是,即使我尝试输入具有这种大小的零数组,我仍然会遇到同样的错误。
有什么帮助吗?
【问题讨论】:
标签: tensorflow keras lstm