预测keras中的特征值列表

时间:2019-05-14 11:23:28

标签: numpy keras

在尝试在keras模型中使用predict_classes时,即使输入形状似乎是必需的,该函数也会引发异常

model = get_model()
flist = [10, 1.0, 0.0, 0.0, 1]
X = np.array(flist)
print(X.shape) # prints (5,)
model.predict_classes(X)

不断抛出错误

ValueError: Error when checking input: expected dense_1_input to have shape (5,) but got array with shape (1,)

1 个答案:

答案 0 :(得分:1)

X的形状必须为(Number_of_samples, input_dim)。使用np.expand_dims

X = np.expand_dims(X,axis=0)
相关问题