问题描述
我的输入形状应该是 100x100.它代表一个句子.每个词是一个 100 维的向量,一个句子最多有 100 个词.
My input shape is supposed to be 100x100. It represents a sentence. Each word is a vector of 100 dimensions and there are 100 words at maximum in a sentence.
我向 CNN 输入了 8 个句子.我不确定这是否意味着我的输入形状应该改为 100x100x8.
I feed eight sentences to the CNN.I am not sure whether this means my input shape should be 100x100x8 instead.
然后是以下几行
Convolution2D(10, 3, 3, border_mode='same',
input_shape=(100, 100))
抱怨:
输入 0 与层卷积 2d_1 不兼容:预期 ndim=4,发现 ndim=3
Input 0 is incompatible with layer convolution2d_1: expected ndim=4, found ndim=3
这对我来说没有意义,因为我的输入维度是 2.我可以通过将 input_shape 更改为 (100,100,8) 来解决它.但是预期的 ndim=4"位对我来说没有意义.
This does not make sense to me as my input dimension is 2. I can get through it by changing input_shape to (100,100,8). But the "expected ndim=4" bit just does not make sense to me.
我也不明白为什么带有 10 个过滤器的 3x3 卷积层不接受 100x100 的输入.
I also cannot see why a convolution layer of 3x3 with 10 filters do not accept input of 100x100.
甚至我都解决了对预期的 ndim=4"的抱怨.我的激活层遇到了问题.它在那里抱怨:
Even I get thru the complains about the "expected ndim=4". I run into problem in my activation layer. There it complains:
不能将 softmax 应用于非 2D 或 3D 的张量.这里,ndim=4
Cannot apply softmax to a tensor that is not 2D or 3D. Here, ndim=4
谁能解释一下这里发生了什么以及如何解决?非常感谢.
Can anyone explain what is going on here and how to fix it? Many thanks.
推荐答案
我遇到了同样的问题,我解决了它,将 channel
的一维添加到 input_shape
参数.
I had the same problem and I solved it adding one dimension for channel
to input_shape
argument.
我建议以下解决方案:
Convolution2D(10, 3, 3, border_mode='same', input_shape=(100, 100, 1))
这篇关于在构建 CNN 时,我收到来自 Keras 的抱怨,这些抱怨对我来说毫无意义.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!