✅ Real-World AI Project 2: Handwritten Digit Recognizer 🔢
This project focuses on image classification using deep learning. It introduces computer vision fundamentals with clear results.
Project Overview
- System predicts digits from 0 to 9
- Input is a grayscale image
- Output is a single digit class
Core concepts involved:
Image preprocessing
Convolutional Neural Networks
Feature extraction with filters
Softmax classification
Dataset
MNIST handwritten digits
60,000 training images
10,000 test images
Image size 28 × 28 pixels
Real-World Use Cases
Bank cheque processing
Postal code recognition
Exam sheet evaluation
Form digitization systems
Accuracy Reference
Basic CNN reaches around 98 percent on MNIST
Deeper CNN crosses 99 percent
Tools Used
Python
TensorFlow and Keras
NumPy
Matplotlib
Google Colab
Step 1. Import Libraries
import tensorflow as tf
from tensorflow.keras import layers, models
import matplotlib.pyplot as plt
Step 2. Load and Prepare Data
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()
x_train = x_train / 255.0
x_test = x_test / 255.0
x_train = x_train.reshape(-1, 28, 28, 1)
x_test = x_test.reshape(-1, 28, 28, 1)
Step 3. Build CNN Model
model = models. Sequential([
layers. Conv2D(32, (3,3), activation="relu", input_shape=(28,28,1)),
layers. MaxPooling2D((2,2)),
layers. Conv2D(64, (3,3), activation="relu"),
layers. MaxPooling2D((2,2)),
layers. Flatten(),
layers. Dense(128, activation="relu"),
layers. Dense(10, activation="softmax")
])
Step 4. Compile Model
model.compile(
optimizer="adam",
loss="sparse_categorical_crossentropy",
metrics=["accuracy"]
)
Step 5. Train Model
model.fit(
x_train, y_train,
epochs=5,
validation_split=0.1
)
Step 6. Evaluate Model
test_loss, test_accuracy = model.evaluate(x_test, y_test)
print("Test accuracy:", test_accuracy)
Expected output
Test accuracy around 0.98
Stable validation curve
Fast training on CPU or GPU
Testing with Custom Image
Convert image to grayscale
Resize to 28 × 28
Normalize pixel values
Pass through model.predict
Common Mistakes
Skipping normalization
Wrong image shape
Using RGB instead of grayscale
Portfolio Value
- Shows computer vision basics
- Demonstrates CNN understanding
- Easy to explain in interviews
- Strong beginner-to-intermediate project
Double Tap ♥️ For Part-3