Python 模型问题。使用Keras和Tensorflow进行预测

Python 模型问题。使用Keras和Tensorflow进行预测,python,numpy,tensorflow,keras,neural-network,Python,Numpy,Tensorflow,Keras,Neural Network,这里我给出了28列和+1000行的测试输入 训练有素的模型应该接受它,但我得到了形状兼容性的错误 这是我的密码: my_data = genfromtxt('test_rgb.csv', delimiter=',',skip_header=1) test_data=my_data[0:,1:-1] for test_row in test_data: predictions = model.predict(test_row) print(predictions) 当您使用p

这里我给出了28列和+1000行的测试输入 训练有素的模型应该接受它,但我得到了形状兼容性的错误

这是我的密码:

my_data = genfromtxt('test_rgb.csv', delimiter=',',skip_header=1)
test_data=my_data[0:,1:-1]

for test_row in test_data:
    predictions = model.predict(test_row)
    print(predictions)

当您使用predict时,您必须为您的模型提供张量(向量列表),这意味着如果您只想从一段数据进行预测,您必须像(1,(INPUT_SHAPE))

在您的情况下,尝试使用if

model.predict(np.array(test_row).reshape((1,a,b,c)))

您指定了输入形状=(a,b,c,)

它在错误中表示正确,您的模型需要的输入形状(28,),您提供的数据的形状为(1,)


在使用预测方法进行验证之前,可以尝试打印数据的形状。您可能只需要重塑数据。

谢谢大家,解决方案是重塑行测试

测试行=测试行。重塑(1,28)