1.Do not pass an `input_shape`/`input_dim` argument to a layer. When using Sequential models, prefer using an `Input(shape)` object as the first layer in the model instead.
这个错误是因为从 Keras 2.x 版本开始,推荐使用 Input
层来明确指定模型的输入形状,而不是在添加第一个非 Input
层时通过 input_shape
或 input_dim
参数来指定。
#原代码
model=tf.keras.Sequential([
#unit1 第一层卷积层
tf.keras.layers.Conv2D(16,kernel_size=(3,3),padding="same",activation=tf.nn.relu,input(shape=(28, 28, 1))),
#***********************
#修改后的代码
model=tf.keras.Sequential([
tf.keras.layers.Input(shape=(28, 28, 1)), # 假设输入是一个 28x28 的灰度图像
#unit1 第一层卷积层
tf.keras.layers.Conv2D(16,kernel_size=(3,3),padding="same",activation=tf.nn.relu),
#***********************
2.AttributeError: EagerTensor object has no attribute 'reshape'. If you are looking for numpy-related methods, please run the following: tf.experimental.numpy.experimental_enable_numpy_behavior()
#原代码
X_train=X_train.reshape(60000,28,28,1)
X_test=X_test.reshape(10000,28,28,1)
#修改代码
X_train=np.array(X_train).reshape(60000,28,28,1)
X_test=np.array(X_test).reshape(10000,28,28,1)