我正在尝试创建一个简单的CNN,以对MNIST数据集中的图像进行分类。该模型达到了可接受的精度,但我注意到该模型仅在每个时期中均以1875张图像进行训练。可能是什么原因造成的?怎么解决?
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.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>
答案 0 :(得分:0)
培训没有问题。正在对模型进行1875批处理,每批处理32张图像,而不是1875张图像。
1875 * 32 = 60000张图片