问题描述
我正在尝试创建一个简单的 CNN 来对 MNIST 数据集中的图像进行分类.该模型达到了可接受的精度,但我注意到该模型在每个 epoch 中仅在 1875 张图像上进行了训练.可能是什么原因造成的?怎么修?
I am trying to create a simple CNN to classify images in MNIST dataset. The model achieved an acceptable accuracy but I noticed that the model is trained only on 1875 images in each epoch. What could be the cause of it? How can it be fixed?
model=models.Sequential()
model.add(layers.Conv2D(filters=32,kernel_size=(3,3),activation='relu',input_shape=(28,28,1)))
model.add(layers.MaxPooling2D((2,2)))
model.add(layers.Conv2D(filters=64,kernel_size=(3,3),activation='relu'))
model.add(layers.MaxPooling2D((2,2)))
model.add(layers.Conv2D(filters=64,kernel_size=(3,3),activation='relu'))
model.add(layers.Flatten())
model.add(layers.Dense(64,activation='relu'))
model.add(layers.Dense(10,activation='softmax'))
Model: "sequential"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv2d (Conv2D) (None, 26, 26, 32) 320
_________________________________________________________________
max_pooling2d (MaxPooling2D) (None, 13, 13, 32) 0
_________________________________________________________________
conv2d_1 (Conv2D) (None, 11, 11, 64) 18496
_________________________________________________________________
max_pooling2d_1 (MaxPooling2 (None, 5, 5, 64) 0
_________________________________________________________________
conv2d_2 (Conv2D) (None, 3, 3, 64) 36928
_________________________________________________________________
flatten (Flatten) (None, 576) 0
_________________________________________________________________
dense (Dense) (None, 64) 36928
_________________________________________________________________
dense_1 (Dense) (None, 10) 650
=================================================================
Total params: 93,322
Trainable params: 93,322
Non-trainable params: 0
model.compile(optimizer='adam',loss='sparse_categorical_crossentropy',metrics=['accuracy'])
model.compile(optimizer='adam',loss='sparse_categorical_crossentropy',metrics=['accuracy'])
model.fit(train_images,train_labels,epochs=5)
model.fit(train_images,train_labels,epochs=5)
Epoch 1/5
1875/1875 [==============================] - 55s 29ms/step - loss: 0.0760 - accuracy: 0.9776
Epoch 2/5
1875/1875 [==============================] - 54s 29ms/step - loss: 0.0576 - accuracy: 0.9825
Epoch 3/5
1875/1875 [==============================] - 55s 29ms/step - loss: 0.0454 - accuracy: 0.9862
Epoch 4/5
1875/1875 [==============================] - 55s 29ms/step - loss: 0.0396 - accuracy: 0.9879
Epoch 5/5
1875/1875 [==============================] - 55s 29ms/step - loss: 0.0336 - accuracy: 0.9900
<tensorflow.python.keras.callbacks.History at 0x7f3e0ff43b70>
推荐答案
培训没有问题.模型正在接受 1875 个批次的训练,每批次 32 张图像,而不是 1875 张图像.
There's no problem with the training. Model is being trained on 1875 batches of 32 images each, not 1875 images.
1875*32 = 60000 张图片
1875*32 = 60000 images
这篇关于如果 MNIST 数据集中有 60000 张图像,为什么模型只在 1875 张训练集图像上进行训练?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!