我一直在尝试将卷积神经网络与 GRU 堆叠起来,以解决图像到文本的问题。这是我的模型:
model=Sequential()
model.add(TimeDistributed(Conv2D(16,kernel_size
(3,3),data_format="channels_last",input_shape=
(129,80,564,3),padding='SAME',strides=(1,1))))
model.add(TimeDistributed(Activation("relu")))
model.add(TimeDistributed(Conv2D(16,kernel_size =(3,3),strides=(1,1))))
model.add(TimeDistributed(Activation("relu")))
model.add(TimeDistributed(MaxPooling2D(pool_size=2,strides=(1,1) )))
model.add(TimeDistributed(Reshape((280*38*16,))))
model.add(TimeDistributed(Dense(32)))
model.add(GRU(512))
model.add(Dense(50))
model.add(Activation("softmax"))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=
['accuracy'])
当我尝试拟合我的模型时,出现以下错误:
-------------------------------------------------------------------------
ValueError Traceback (most recent call
last)
<ipython-input-125-c6a3c418689c> in <module>()
1 nb_epoch = 100
----> 2 model.fit(X2,L2, epochs=100)
10 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/nn_ops.py
in _get_sequence(value, n, channel_index, name)
71 else:
72 raise ValueError("{} should be of length 1, {} or {} but was
{}".format(
---> 73 name, n, n + 2, current_n))
74
75 if channel_index == 1:
ValueError: strides should be of length 1, 1 or 3 but was 2
我什至无法理解为什么会出现此消息。我已经为所有层指定了“步幅”参数。任何帮助将不胜感激。
PS - 当我尝试拟合没有 TimeDistributed 层的模型时,我没有遇到任何问题。也许这与引发此错误有关。