【发布时间】:2020-10-16 23:44:35
【问题描述】:
我目前尝试使用带有 TensorFlow 后端的 Keras 中的论文(类似于 https://arxiv.org/pdf/1605.00894.pdf,第 5 页)重新创建模型,但在构建具有 TimeDistributed 层的有状态 RNN 时似乎卡住了开始。
这是有问题的部分的精简代码:
model = Sequential()
model.add(TimeDistributed(
Conv2D(
filters=40,
kernel_size=(3,3),
padding="same",
data_format="channels_last"
),
name="C1",
batch_input_shape=(1, None, 80, 128, 3)
))
# (leaving out the pooling)
model.add(ConvLSTM2D(
filters=10,
kernel_size=(3,3),
padding="same",
return_sequences=True,
stateful=True
))
ConvLSTM2D层中stateful参数设置为true时,出现如下错误信息:
ValueError: If a RNN is stateful, it needs to know its batch size. Specify the batch size of your input tensors:
- If using a Sequential model, specify the batch size by passing a `batch_input_shape` argument to your first layer.
- If using the functional API, specify the time dimension by passing a `batch_shape` argument to your Input layer.
The same thing goes for the number of rows and columns.
我也尝试添加以下输入层,但这似乎没有帮助:
model.add(Input(
name="input",
batch_input_shape=(1, None, 80, 128, 3)
))
另外,我使用功能 API 构建了相同的模型(使用 batch_shape 而不是 batch_input_shape),但我收到了相同的错误消息。
我已阅读有关此主题的一些主题,但似乎没有一个解决方案对我有用。也许我只是忽略了一些明显的错误......
【问题讨论】:
标签: python tensorflow keras recurrent-neural-network stateful