当构建CNN时,我收到了Keras的投诉,这些投诉对我来说没有意义. [英] When bulding a CNN, I am getting complaints from Keras that do not make sense to me.

查看:63
本文介绍了当构建CNN时,我收到了Keras的投诉,这些投诉对我来说没有意义.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的输入形状应该是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.

推荐答案

我遇到了同样的问题,并且解决了这个问题,在input_shape参数中添加了channel的一维.

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的投诉,这些投诉对我来说没有意义.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆