This project demonstrates a neural network model built using TensorFlow and Keras to classify handwritten digits from the MNIST dataset. The MNIST dataset is a popular dataset for testing and benchmarking machine learning algorithms and contains 70,000 grayscale images of handwritten digits (0 to 9) with a size of 28x28 pixels.
This project provides a practical example of using a Multilayer Perceptron (MLP) neural network for image classification. The neural network is trained to recognize and classify digits from the MNIST dataset. It covers the full workflow from data preprocessing to model training, evaluation, and visualization of results.
- Neural Network Model: A fully connected neural network with hidden layers and dropout regularization.
- Data Preprocessing: Normalization of input data and conversion of labels to one-hot encoding.
- Model Training: Training the model using the Adam optimizer and categorical cross-entropy loss function.
- Model Evaluation: Evaluation of the model's performance on the test set.
- Visualization: Plotting training/validation accuracy and loss, and visualizing predictions.
Make sure you have the following installed:
- Python 3.x
- TensorFlow
- Matplotlib
If you haven't installed TensorFlow and Matplotlib yet, you can do so using pip:
pip install tensorflow matplotlib
-
Clone the Repository:
Clone the repository to your local machine:
git clone https://github.com/your-username/mnist-digit-classification.git
-
Navigate to the Directory:
Go to the project directory:
cd mnist-digit-classification
-
Run the Script:
Run the script using Python:
python mnist_digit_classification.py
When you run the script, it will:
- Load the MNIST dataset.
- Preprocess the data (normalize and one-hot encode).
- Define a neural network model with hidden layers and dropout.
- Train the model on the training set and validate it on a validation set.
- Evaluate the model on the test set.
- Plot the training and validation accuracy and loss over epochs.
- Display a few test samples with predicted and true labels.
The script will produce outputs similar to:
-
Test Accuracy: The accuracy of the model on the test dataset, for example:
Test Accuracy: 0.98
-
Training and Validation Curves: Plots of accuracy and loss over the training epochs.
-
Predicted Samples: Displays images of a few test samples with the model's predicted label and the true label.
To predict a new digit image, you can modify the X_test
variable to load your custom image and pass it to the model for prediction.
Contributions are welcome! If you have ideas for new features, improvements, or bug fixes, please feel free to open an issue or create a pull request.
- Fork the Repository: Click the 'Fork' button at the top right of this page.
- Clone Your Fork: Clone your forked repository to your local machine.
git clone https://github.com/your-username/mnist-digit-classification.git
- Create a Branch: Create a new branch for your feature or bug fix.
git checkout -b feature/your-feature-name
- Make Changes: Make your changes and commit them with a descriptive message.
git commit -m "Add: feature description"
- Push Changes: Push your changes to your forked repository.
git push origin feature/your-feature-name
- Create a Pull Request: Go to the original repository on GitHub and create a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.
Thank you for using the Handwritten Digit Classification with Neural Network! If you have any questions or feedback, feel free to reach out. Happy coding! 😊