我不断收到与输入形状相关的错误。任何帮助将不胜感激。谢谢!
import tensorflow as tf
(xtrain, ytrain), (xtest, ytest) = tf.keras.datasets.mnist.load_data()
model = tf.keras.Sequential([
tf.keras.layers.Conv2D(16, kernel_size=3, activation='relu'),
tf.keras.layers.MaxPooling2D(pool_size=2),
tf.keras.layers.Conv2D(32, kernel_size=3, activation='relu'),
tf.keras.layers.MaxPooling2D(pool_size=2),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(64, activation='relu'),
tf.keras.layers.Dense(10, activation='softmax')
])
model.compile(loss='categorical_crossentropy',
optimizer='adam',
metrics='accuracy')
history = model.fit(xtrain, ytrain,
validation_data=(xtest, ytest),
epochs=10, batch_size=8)
Run Code Online (Sandbox Code Playgroud)
ValueError:层序的输入 0 与层不兼容::预期 min_ndim=4,发现 ndim=3。收到的完整形状:[8, 28, 28]