0

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.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>

screenshot of model in colab

screenshot of trained model

desertnaut
  • 57,590
  • 26
  • 140
  • 166
  • 1
    This exact question has been asked many times before, please use the search functionality before asking a question, you might find it has been answered already. – Dr. Snoopy Jun 04 '20 at 07:55

1 Answers1

11

There's no problem with the training. Model is being trained on 1875 batches of 32 images each, not 1875 images.

1875*32 = 60000 images

Reuben
  • 467
  • 3
  • 9