This project demonstrates a simple yet effective neural network using TensorFlow to classify handwritten digits from the MNIST dataset. It covers data preprocessing, model building, training with callbacks, evaluation, and detailed visualizations of the results. The generated plots (training history, confusion matrix, and sample predictions) are automatically saved to the plots folder.
- Data Preprocessing: Loads the MNIST dataset and normalizes the images.
- Model Architecture: A fully connected neural network with dropout for regularization.
- Callbacks: Implements early stopping and model checkpointing to optimize training.
- Visualization:
- Training and validation accuracy/loss plots.
- A normalized confusion matrix.
- A grid of sample predictions with true vs. predicted labels.
- Modular Code: Organized functions for ease of maintenance and future improvements.
- Python: Version 3.7 to 3.10 (TensorFlow is not yet supported on Python 3.13)
- Libraries:
- TensorFlow
- Matplotlib
- NumPy
- Scikit-learn
-
Clone the Repository:
git clone <repository-url> cd Tensorflow
-
Create a Virtual Environment (Recommended):
python -m venv tf-env
Activate the environment:
- Windows:
tf-env\Scripts\activate
- macOS/Linux:
source tf-env/bin/activate
-
Install Dependencies:
pip install tensorflow matplotlib numpy scikit-learn
Run the main script to train and evaluate the model and generate the plots:
python <your_project_filename>.pyAfter running, check the plots folder for the following saved images:
- training_history.png: Shows training/validation accuracy and loss over epochs.
- confusion_matrix.png: A normalized confusion matrix of the test predictions.
- sample_predictions.png: A grid of randomly selected test images with their true and predicted labels.
Tensorflow/
├── main.py # Main Python script containing the project code
├── plots/ # Directory where generated plots are saved
├── README.md # This file
└── LICENSE # License fileContributions are welcome! Please fork the repository and submit a pull request with your improvements.
- TensorFlow: For providing an excellent deep learning framework.
- MNIST Dataset: For being a benchmark dataset in image classification.
- Open-Source Community: For continuous support and contributions.
This project is licensed under the MIT License – see the LICENSE file for details.