python - ValueError : Error when checking target: expected dense_2 to have 3 dimensions, 但得到形状为 (10000, 1) 的数组

标签 python neural-network keras

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

这是我的模型摘要。

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: Error when checking target: expected dense_2 to have 3 dimensions, but got array with shape (22, 1)

最佳答案

因为你有一个 binary_classification 任务,你的最后一层应该看起来像这样

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

现在您的模型正在输出与形状不匹配的 3D 阵列 你的目标(2D)

关于python - ValueError : Error when checking target: expected dense_2 to have 3 dimensions, 但得到形状为 (10000, 1) 的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49623436/

相关文章:

python - CNN 凯拉斯 : How many weights will be trained?

python - Keras 使用 set seed 得到不同的结果

python - 无法安装 Tensorflow,tensorflow-base-1.12 错误

python - 索引 Keras 张量

machine-learning - 生成对抗网络需要类别标签吗?

neural-network - 有没有人尝试过将代码编译成神经网络并对其进行进化?

python - python中的邻近矩阵

python - sympy - 扩展时如何加法组合指数?

python - 如果函数调用在 python2.x/3.x 中太长,如何缩进

Java SSL 套接字无法从客户端连接