Keras:模型预测,检查输入形状时出错

时间:2018-09-13 22:56:39

标签: python keras

我有一个Keras模型和一个要调用predict的numpy数组。具体来说,我有:

名为numpy.ndarray的{​​{1}}如下:

test

当我做array([ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12920, 11891, 4605, 2425, 6780, 5096, 13821, 4405, 10345, 4468, 5910, 11891, 10906, 14994, 12073, 8581, 3544, 13846, 3110, 2425, 3407, 9631, 13846, 4479, 9964, 2556, 4479, 2686, 8895, 10959, 1531, 11891, 1494, 10376, 13846, 12856, 13846, 3110, 2425, 3407, 3267, 181, 4479, 14842, 4639, 7723, 11891, 11449, 2425, 5662, 2282, 5129, 2518, 13846, 4479, 4780, 2598, 4926, 543, 7304, 12020, 8143, 10998, 13846, 12853, 13846, 12856, 11891, 3785, 9131, 7448, 13846, 10376, 13846, 8245, 3788, 12211, 2425, 13614, 10049, 2556, 8245, 1406, 6423, 3110, 2425, 3407, 5726, 2619, 1494, 13694, 7434, 12086, 7304, 3267, 9184]) 时,我看到:

test.shape

当我做(180,) 时,我会回来:

model.predict(test)

知道我做错了什么吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

Keras希望有一组样本能够对shape (180,)数组的 group 组做出预测。似乎您正在传递一个样本,它被解释为180个形状为(1,)的样本。您可以尝试将此一个样本包装在数组中,或使用test.reshape(1, -1)创建一个样本组。换句话说,将其传递给(1, 180)数组,它将返回一个预测的数组。