本文介绍了如果MNIST数据集中有60000个图像,为什么该模型仅对1875个训练集图像进行训练?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个简单的CNN,以对MNIST数据集中的图像进行分类.该模型达到了可接受的精度,但我注意到该模型仅在每个时期中均在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>

colab中的模型截图

受过训练的模型的屏幕截图

推荐答案

培训没有问题.正在对模型进行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个训练集图像进行训练?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 01:25