Skip to content

Prediction of digits using CNN (Convolutional Neural Network)

Notifications You must be signed in to change notification settings

sabinaaskerova/digit_prediction

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Convolutional Neural Network (CNN) for Digit Recognition

This project uses CNN (TensorFlow, Keras) to recognize digits from the MNIST dataset.

The neural network is built using the Sequential API of Keras.

Convolutional and Pooling Layers:

  • The first convolutional layer with 32 filters of size (3, 3), ReLU activation, and input shape (28, 28, 1).

  • Max pooling layer with a pool size of (2, 2).

  • The second convolutional layer with 64 filters of size (3, 3) and ReLU activation.

  • Another max pooling layer with a pool size of (2, 2).

Flatten and Dense Layers:

  • A flatten layer to convert the 2D feature maps into a 1D vector.

  • A dense layer with 64 neurons and ReLU activation.

  • The final dense layer with 10 neurons (number of classes) and softmax activation for multi-class classification.

Model Compilation

The model is compiled using the Adam optimizer, categorical crossentropy as the loss function, and accuracy as the metric to monitor during training.

model.compile(optimizer='adam',
              loss='categorical_crossentropy',
              metrics=['accuracy'])

Model Training

The training process involves fitting the model to the training data for 5 epochs with a batch size of 64. The validation split is set to 20% to monitor performance on a validation subset.

model.fit(train_images.reshape(-1, 28, 28, 1), train_labels, epochs=5, batch_size=64, validation_split=0.2)

Results

Test accuracy: 0.9891999959945679
Test loss:0.034049030393362045

I also tested the model to see if it can predict the digits written by myself.

While exploring the data, I observed that most sevens in the dataset were written without a horizontal bar. There was a vsible lack of horizontal-bar-sevens in the dataset (the way I personally write it). Screenshot from 2024-03-08 22-22-36

And it turned out to be more difficult for a model to recognize such sevens (on the left).

I also presented an extreme case of writing a '3' digit to the model and it had hard time recognizing it to (also possibly due to poor picture quality)

About

Prediction of digits using CNN (Convolutional Neural Network)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published