← Back

DNN Handwritten Digit Classifier

DNN Handwritten Digit Classifier

A Deep Neural Network that recognizes handwritten digits (0-9) with 97%+ accuracy. Built using TensorFlow on the MNIST dataset to understand multi-layer networks and hierarchical feature learning.

Technologies

Python TensorFlow NumPy Machine Learning Deep Learning

Project Overview

This is my second neural network project β€” a Deep Neural Network (DNN) that recognizes handwritten digits from the famous MNIST dataset. Building on my ANN knowledge, this project explores what happens when we add depth to neural networks.

The goal was to understand:

  • How multiple layers learn hierarchical features
  • Why non-linearity (ReLU) is essential
  • How softmax enables multi-class classification
  • The difference between ANN and DNN

🎯 The Problem

Given a 28Γ—28 pixel grayscale image of a handwritten digit, classify it as one of 10 classes (0-9).

Dataset: MNIST

  • 60,000 training images
  • 10,000 test images
  • 28Γ—28 pixels, grayscale

πŸ’‘ The Solution

A 4-layer DNN architecture:

model = tf.keras.Sequential([
    tf.keras.layers.Flatten(input_shape=(28, 28)),
    tf.keras.layers.Dense(128, activation='relu'),
    tf.keras.layers.Dense(64, activation='relu'),
    tf.keras.layers.Dense(10, activation='softmax')
])

Layer-by-Layer Breakdown

LayerPurposeOutput Shape
FlattenConvert 2D image β†’ 1D vector784
Dense(128, relu)Learn simple patterns (edges)128
Dense(64, relu)Learn complex patterns (shapes)64
Dense(10, softmax)Output probabilities for 0-910

πŸ”§ Technologies Used

  • Python 3.8+ β€” Programming language
  • TensorFlow/Keras β€” Deep learning framework
  • NumPy β€” Numerical computations
  • MNIST Dataset β€” Built-in TensorFlow dataset

πŸ“Š Key Concepts Demonstrated

1. Data Normalization

x_train = x_train / 255.0  # Scale pixels to 0-1

2. ReLU Activation (Non-linearity)

activation='relu'  # max(0, x)

3. Softmax for Multi-class Output

Dense(10, activation='softmax')  # Probabilities sum to 1

4. Adam Optimizer

optimizer='adam'  # Adaptive learning rate

5. Categorical Cross-Entropy Loss

loss='sparse_categorical_crossentropy'  # For integer labels

πŸ“ˆ Results

MetricValue
Training Accuracy~98%
Validation Accuracy~97%
Test Accuracy~97-98%
Epochs5
Training Time~30 seconds

🧠 What Each Layer Learns

Flatten     β†’ Raw pixel values
Dense(128)  β†’ Edges, simple curves
Dense(64)   β†’ Digit parts (loops, lines)
Dense(10)   β†’ Final classification probabilities

This is hierarchical feature learning β€” building complex understanding from simple patterns!

πŸš€ What This Project Taught Me

  1. Depth enables complexity β€” more layers = more abstract features
  2. Non-linearity is essential β€” ReLU allows learning complex patterns
  3. Softmax outputs probabilities β€” perfect for classification
  4. Normalization matters β€” raw pixels hurt training stability
  5. Adam > SGD for most deep learning tasks
  6. Overfitting happens β€” regularization is important

This project is part of my AI/ML learning journey. Next up: Convolutional Neural Networks for image classification!

"Exploring technology through creative projects"

β€” K.M.N.Sangeeth Kariyapperuma

Navigation
HomeProjectsBlog
Connect

Β© 2026 NipunSGeeTH. All rights reserved.

Crafted with Love ❀️