此问题已在此处找到答案:
tensorflow仅在提供的培训数据的1/32上运行[重复](1个答案)
keras未对整个数据集进行培训(2个答案)
昨天关门了。
# 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
1条答案
按热度按时间k97glaaz1#
如果x_trainr最初有42000个样本,而您使用的验证分割为.2,那么您将在33600个样本上进行培训。在model.fit中,您没有指定批次大小,因此默认为32。培训期间显示的数字不是样本数。它是指培训样本数/批次大小。应该是33600/32=1050。但是它显示的是1500,所以我怀疑你的x\u trainr x.8尺寸实际上是48000。所以x trainr=48000/.8=60000。检查x\u trainr的尺寸。