Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/harris-giki/digitclassificationnn_ml

This project demonstrates the classification of handwritten digits from the MNIST dataset using a basic neural network model. It involves data preprocessing, model building with Keras, and evaluation.
https://github.com/harris-giki/digitclassificationnn_ml

artificial-intelligence classification machine-learning neural-networks

Last synced: about 1 month ago
JSON representation

This project demonstrates the classification of handwritten digits from the MNIST dataset using a basic neural network model. It involves data preprocessing, model building with Keras, and evaluation.

Awesome Lists containing this project

README

        


MNIST Handwritten Digit Classification using Neural Networks


This project demonstrates a simple neural network model to classify handwritten digits from the MNIST dataset using TensorFlow and Keras. The model is trained using a basic feedforward neural network, and the project also explores image preprocessing, model training, prediction, and evaluation techniques.


Requirements


To run this project, the following dependencies are required:



  • Python 3.x

  • TensorFlow

  • NumPy

  • OpenCV

  • Matplotlib

  • Seaborn


You can install the required dependencies using pip:


pip install tensorflow numpy opencv-python matplotlib seaborn

Dataset


The MNIST dataset consists of 70,000 28x28 grayscale images of handwritten digits (0-9). The dataset is divided into a training set of 60,000 images and a test set of 10,000 images. This project uses these images to train a neural network for the task of handwritten digit classification.


Steps


1. Data Preprocessing


The dataset is loaded using keras.datasets.mnist. The pixel values of the images are normalized to a range between 0 and 1 by dividing each pixel value by 255.


2. Model Building


A basic neural network is used for classification:




  • Flatten Layer: The 28x28 image is flattened into a 1D array of 784 features.


  • Dense Layers: Two hidden layers of 50 neurons each with ReLU activation are used.


  • Output Layer: A final output layer with 10 neurons (one for each digit) and sigmoid activation is used to make the classification.


3. Model Training


The model is trained for 15 epochs using the Adam optimizer and sparse categorical cross-entropy loss function.


4. Model Evaluation


After training, the model is evaluated on the test set to calculate accuracy and loss.


5. Prediction


The trained model is used to make predictions on the test images, and the predicted labels are compared to the true labels. The model's predictions are visualized using a confusion matrix.


6. Custom Image Prediction


A custom image of a handwritten digit is loaded, resized, and converted to grayscale. The image is then scaled and reshaped to match the input format of the model. The model predicts the digit in the image, and the predicted label is displayed.


Code Walkthrough


1. Loading Libraries and Data


Libraries such as TensorFlow, NumPy, and OpenCV are imported. The MNIST dataset is loaded from Keras.


2. Preprocessing


Data is scaled to the range [0, 1] by dividing by 255. The first image in the training set is displayed using Matplotlib.


3. Model Architecture


The model consists of three layers: Flatten, Dense (2 hidden layers), and Output layer. relu activation is used for hidden layers, and sigmoid for the output layer.


4. Training the Model


The model is trained on the training set with a specified number of epochs.


5. Model Evaluation


The model's accuracy is calculated on the test set.


6. Prediction and Confusion Matrix


The model's predictions are visualized with a confusion matrix using Seaborn.


7. Custom Image Prediction


A custom image is loaded, resized, converted to grayscale, and reshaped for prediction by the model.


Results


The model achieves high accuracy on the MNIST test set. The confusion matrix provides insights into where the model may have misclassified the digits. The model is capable of making predictions on custom handwritten digit images.


Future Work


Possible future improvements include:




  • Model Improvement: Experiment with more advanced models, such as Convolutional Neural Networks (CNNs), to improve accuracy.


  • Real-time Prediction: Implement real-time digit recognition using a camera feed.


Acknowledgements



  • MNIST Dataset

  • TensorFlow & Keras for providing a high-level deep learning framework.

  • OpenCV for image preprocessing.