【问题标题】:ValueError: Error when checking input: expected dense_13_input to have shape (3,) but got array with shape (1,)ValueError:检查输入时出错:预期的dense_13_input具有形状(3,)但得到的数组具有形状(1,)
【发布时间】:2020-09-01 01:43:05
【问题描述】:

我试图用我的 keras 模型预测手动编码的数据,但它不起作用:

print(np.array([5.1, 3.5, 1.4]).shape)
prediction = model.predict(np.array([5.1, 3.5, 1.4]))

给我:

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

我该如何解决这个问题?谢谢

【问题讨论】:

    标签: python machine-learning keras neural-network artificial-intelligence


    【解决方案1】:

    你必须添加批次维度 (n_batch, feat_dim) ==> (1,3)

    inp = Input((3))
    x = Dense(10)(inp)
    model = Model(inp, x)
    X = np.array([5.1, 3.5, 1.4])
    
    model.predict(X[None,:])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-05
      • 1970-01-01
      • 1970-01-01
      • 2021-02-26
      • 2022-11-03
      • 2019-08-21
      • 2020-12-05
      • 2018-01-01
      相关资源
      最近更新 更多