【问题标题】:problem with model.predict , using Keras and Tensorflowmodel.predict 的问题,使用 Keras 和 Tensorflow
【发布时间】:2020-05-11 02:06:02
【问题描述】:

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

这是我的代码:

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)

【问题讨论】:

    标签: python numpy tensorflow keras neural-network


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

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

      在你的情况下尝试使用 if

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

      您指定了 input_shape=(a,b,c,)

      【讨论】:

        【解决方案3】:

        谢谢大家,解决办法是重塑row_test

        test_row=test_row.reshape(1,28)

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-04-13
          • 2020-09-26
          • 2023-02-22
          • 1970-01-01
          • 2018-09-04
          • 1970-01-01
          • 2019-03-08
          • 2018-02-05
          相关资源
          最近更新 更多