ValueError:检查目标时出错:预期density_2具有3维,但数组的形状为(10000,1)

ValueError:检查目标时出错:预期density_2具有3维,但数组的形状为(10000,1)

问题描述:

我正在使用keras MLP网络对3-D字向量input_shape=(None,24,73)进行二进制分类.我使用了两个密集层dense_1dense_2.在dense_2处出现一个我无法解决的错误.

I am using keras MLP network for binary classification of 3-D word vector input_shape=(None,24,73). I have used two dense layers dense_1 and dense_2. At dense_2 I'm getting an error which I've not been able to solve.

这是我的模型摘要.

Layer (type)                 Output Shape              Param #   
=================================================================
dense_1 (Dense)              (None, 8, 90)             6660      
_________________________________________________________________
dense_2 (Dense)              (None, 8, 1)              91        
=================================================================
Total params: 6,751
Trainable params: 6,751
Non-trainable params: 0

ValueError:检查目标时出错:预期density_2具有3 尺寸,但数组的形状为(22,1)

ValueError: Error when checking target: expected dense_2 to have 3 dimensions, but got array with shape (22, 1)

由于您执行了binary_classification任务,因此最后一层应如下所示

Since you have a binary_classification task your last layer should look something like this

model.add(Dense(1, activation='sigmoid'))

现在,您的模型已放出与形状不匹配的3D阵列 您的目标(2D)

Right now you model is out puting 3D array which don't match the shape of your target (2D)