【发布时间】:2022-01-12 23:41:11
【问题描述】:
为这个新手问题道歉,我正在尝试使用 Keras 训练回归模型,但在 model.fit() 中出现错误。
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
import numpy as np
inputs = keras.Input(shape=(6,5), name="digits")
x = layers.Dense(64, activation="relu", name="dense_1")(inputs)
x = layers.Dense(64, activation="relu", name="dense_2")(x)
outputs = layers.Dense(1, activation="softmax", name="predictions")(x)
model = keras.Model(inputs=inputs, outputs=outputs)
x_train = np.array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14],
[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14]])
y_train = np.array([1, 2, 3, 1, 2, 3])
model.compile(loss=keras.losses.SparseCategoricalCrossentropy())
history = model.fit(x_train,y_train)
这是错误,这是什么意思以及如何解决?我正在使用 TensorFlow 2.7.0。
图层“模型”的输入 0 与图层不兼容:预期 shape=(None, 6, 5), 找到 shape=(None, 5)
【问题讨论】:
标签: python tensorflow keras tensorflow2.0