【问题标题】:ValueError: Input 0 of layer sequential is incompatible with the layer:ValueError: 层序的输入 0 与层不兼容:
【发布时间】:2021-05-31 22:03:46
【问题描述】:
model = keras.models.Sequential([
keras.layers.Dense(30, activation = "relu", input_shape=[8]),
keras.layers.Dense(100, activation = "relu"),
keras.layers.Dense(1)])

model.compile(loss="mse", optimizer=keras.optimizers.SGD(lr=1e-3))

checkpoint_cb = keras.callbacks.ModelCheckpoint("Model-{epoch:02d}.h5")

history = model.fit(X_train, y_train, epochs=10,
             validation_data=(X_valid,y_valid),
               callbacks=[checkpoint_cb])

我正在尝试使用回调来拟合模型,但出现以下错误:

ValueError: Input 0 of layer sequential is incompatible with the layer: expected axis -1 of input shape to have value 8 but received input with shape [None, 28, 28]

可能的错误是什么?

【问题讨论】:

    标签: tensorflow keras neural-network callback artificial-intelligence


    【解决方案1】:

    您的 X_train 的形状是 (None,28,28),但您将形状 (None,8) 的输入提供给密集层。

    重塑你的 X_train

    X_train = X_train.reshape(-1, 28*28)
    

    型号应该是

    model = keras.models.Sequential([
    keras.layers.Dense(30, activation = "relu", input_shape=(784,)),
    keras.layers.Dense(100, activation = "relu"),
    keras.layers.Dense(1)])
    

    【讨论】:

      猜你喜欢
      • 2021-07-04
      • 2020-11-28
      • 2021-09-13
      • 1970-01-01
      • 2021-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多