#Resizing the image to make it suitable for apply convolution
import numpy as np
img_size = 28
X_trainr = np.array(X_train).reshape(-1, img_size, img_size, 1)
X_testr = np.array(X_test).reshape(-1, img_size, img_size, 1)
# Model Compilation
model.compile(loss = "sparse_categorical_crossentropy", optimizer = "adam", metrics = ["accuracy"])
model.fit(X_trainr, y_train, epochs = 5, validation_split = 0.2) #training the model
我为数字识别代码加载了MNIST数据集。然后,我将数据集分为训练集和测试集。然后将新的维度添加到3D训练集数组中,并将新的数组命名为X_trainr。然后,我完成并拟合了模型。在对模型进行拟合后,模型并没有采集整个训练集(42000个样本(,而是只采集了1500个样本。我尝试过:设置validation_split=0.3然后对1313个样本进行训练为什么我的模型没有采集整个训练集(42000个样本(
输出
Epoch 1/5
1500/1500 [==============================] - 102s 63ms/step - loss: 0.2930 - accuracy: 0.9063 - val_loss: 0.1152 - val_accuracy: 0.9649
Epoch 2/5
1500/1500 [==============================] - 84s 56ms/step - loss: 0.0922 - accuracy: 0.9723 - val_loss: 0.0696 - val_accuracy: 0.9780
Epoch 3/5
1500/1500 [==============================] - 80s 53ms/step - loss: 0.0666 - accuracy: 0.9795 - val_loss: 0.0619 - val_accuracy: 0.9818
Epoch 4/5
1500/1500 [==============================] - 79s 52ms/step - loss: 0.0519 - accuracy: 0.9837 - val_loss: 0.0623 - val_accuracy: 0.9831
Epoch 5/5
1500/1500 [==============================] - 84s 56ms/step - loss: 0.0412 - accuracy: 0.9870 - val_loss: 0.0602 - val_accuracy: 0.9818
如果X_trainr最初有42000个样本,并且您使用了.2的验证分割,那么您正在对33600个样本进行训练。在model.fit中,您没有指定批次大小,因此它默认为32。培训期间显示的数字不是样本数量。它是训练样本数/batch_size。应为33600/32=1050。然而,它显示1500,所以我怀疑你的X_trainr X.8尺寸实际上是48000。因此,Xtrainr=48000/.8=60000。检查X_trainr的尺寸。