Skip to content

Swapnil4646/MNIST-by-using-ANN-model

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

🔢 MNIST Digit Classification using ANN

Recognizing handwritten digits with a fully connected neural network built in TensorFlow and Keras

Python TensorFlow Keras Pandas NumPy Jupyter Google Colab


📌 Overview

This project builds an Artificial Neural Network (ANN) that classifies handwritten digits, 0 through 9, using the classic MNIST dataset. The full workflow lives inside a single Colab notebook and covers everything from raw pixel data to a trained model with 97.43% test accuracy.

It is a clean example of how a relatively simple feed forward network, with the right preprocessing and a touch of dropout regularization, can perform extremely well on a well structured image classification problem.


✨ Highlights

🎯 What 📋 Detail
Final Test Accuracy 97.43%
Dataset Size 42,000 labeled digit images
Input Features 784 pixels per image (28 x 28 flattened)
Architecture 4 layer fully connected ANN with dropout
Training Epochs 10
Framework TensorFlow / Keras Sequential API

🧠 How It Works

flowchart LR
    A[📂 Load mnist.csv] --> B[🔍 Explore data]
    B --> C[⚙️ Normalize pixels 0 to 1]
    C --> D[🏷️ One hot encode labels]
    D --> E[✂️ Train test split]
    E --> F[🏗️ Build ANN model]
    F --> G[🚀 Train for 10 epochs]
    G --> H[📊 Evaluate accuracy]
    H --> I[🖼️ Visualize predictions]
Loading

🗂️ Dataset

The dataset is the classic MNIST handwritten digits dataset, provided here as a flat CSV file (mnist.csv) rather than the usual image format.

  • 🧾 42,000 rows, each representing one digit image
  • 🎨 785 columns total, one label column plus 784 pixel0 to pixel783 columns
  • 🔢 Each pixel value ranges from 0 to 255, representing grayscale intensity
  • 🧩 Every row, once reshaped, forms a 28 x 28 grayscale image

Before training, the pixel values are scaled down to a 0 to 1 range, and the digit labels are converted into one hot encoded vectors for the 10 output classes.


🏗️ Model Architecture

A simple yet effective Sequential ANN built with Keras:

model = Sequential([
    Dense(256, activation='relu', input_shape=(784,)),
    Dropout(0.3),
    Dense(128, activation='relu'),
    Dropout(0.3),
    Dense(64, activation='relu'),
    Dense(10, activation='softmax')
])
Layer Type Units Activation Notes
1 Dense 256 ReLU Input layer, takes 784 flattened pixels
2 Dropout 30% dropout for regularization
3 Dense 128 ReLU Hidden layer
4 Dropout 30% dropout for regularization
5 Dense 64 ReLU Hidden layer
6 Dense 10 Softmax Output layer, one node per digit

⚙️ Compilation settings

  • 🧮 Optimizer: Adam
  • 📉 Loss function: categorical_crossentropy
  • 📈 Metric tracked: accuracy

🚀 Training

The model was trained for 10 epochs with a batch size of 64, using an 80/20 train test split.

Epoch Train Accuracy Val Accuracy Train Loss Val Loss
1 75.48% 94.60% 0.7642 0.1741
5 96.70% 97.18% 0.1029 0.0931
10 98.18% 97.43% 0.0591 0.0942

📊 Both accuracy and loss curves for training and validation are plotted at the end of training, making it easy to visually confirm the model is learning well without overfitting heavily.


✅ Results

🏆 Final Test Accuracy: 97.43%

After training, the model is evaluated on the untouched 20% test split. The notebook also picks the first 5 test images and displays each one alongside its true label and the model's predicted label, giving a quick visual sanity check on real predictions rather than just a single accuracy number.


🛠️ Tech Stack

Category Tools Used
🐍 Language Python 3
🧠 Deep Learning TensorFlow, Keras
📊 Data Handling Pandas, NumPy
📈 Visualization Matplotlib
🤖 Preprocessing Scikit learn (train_test_split)
☁️ Environment Google Colab

📁 Project Structure

MNIST-by-using-ANN-model/
│
├── mnist (1).ipynb     # Main notebook: data loading, training, evaluation
└── README.md           # You are here

▶️ Getting Started

  1. Clone the repository

    git clone https://github.com/sarthakNaikare/MNIST-by-using-ANN-model.git
  2. Open the notebook Upload mnist (1).ipynb to Google Colab or run it locally in Jupyter.

  3. Get the dataset The notebook expects a file named mnist.csv at /content/mnist.csv. Place your copy of the MNIST CSV dataset there before running.

  4. Run all cells Execute the notebook top to bottom. Training takes well under a minute per epoch on Colab's standard runtime.


🔮 Future Improvements

  • 🧬 Swap the ANN for a CNN to push accuracy even higher
  • 🎛️ Add hyperparameter tuning (learning rate, layer sizes, dropout rate)
  • 🛑 Introduce early stopping and learning rate scheduling
  • 🧪 Build a small confusion matrix view to spot which digits get confused most often
  • 🌐 Wrap the trained model in a simple web demo for live digit recognition

👤 Author

Swapnil Yadav

⭐ If you found this project useful or interesting, consider giving it a star!

About

Artificial neural network for handwritten digit classification on MNIST. 4 layer dense architecture with dropout, trained on 42,000 images, hits 97.43% test accuracy.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors