A deep learning project that performs object detection on handwritten digits — simultaneously classifying what the digit is and localizing where it appears in an image using bounding box regression.
Built with TensorFlow and Keras as a custom multi-output CNN from scratch.
Given an image with a digit placed at a random location, the model:
- Classifies the digit (0–9)
- Localizes it by predicting a bounding box
[xmin, ymin, xmax, ymax]
This is the core idea behind object detection — not just what is in the image, but where.
Input (75x75x1)
│
▼
Conv2D(16) → AveragePooling
Conv2D(32) → AveragePooling
Conv2D(64) → AveragePooling
│
▼
Flatten → Dense(128)
│
├──► Dense(10, softmax) → Classification Output (digit 0–9)
└──► Dense(4) → Bounding Box Output [xmin, ymin, xmax, ymax]
The model uses two output heads trained simultaneously:
| Head | Loss Function | Metric |
|---|---|---|
| Classification | Categorical Crossentropy | Accuracy |
| Bounding Box | Mean Squared Error (MSE) | MSE |
- Source: MNIST via
tensorflow_datasets - Each 28×28 digit is randomly placed inside a 75×75 canvas
- Bounding box coordinates are normalized between 0 and 1
- Train set: 60,000 images | Validation set: 10,000 images
| Tool | Purpose |
|---|---|
| TensorFlow / Keras | Model building & training |
| TensorFlow Datasets | MNIST data loading |
| NumPy | Array operations |
| Matplotlib | Visualization |
| Pillow (PIL) | Bounding box drawing |
Model is evaluated using:
- Classification Accuracy — how often the digit label is correct
- Bounding Box MSE — how close predicted box coordinates are to ground truth
- IoU (Intersection over Union) — overlap between predicted and true bounding boxes (threshold: 0.6)
git clone https://github.com/your-username/object-detection-tensorflow.git
cd object-detection-tensorflowpip install tensorflow tensorflow-datasets numpy matplotlib pillowOpen objectdetection.ipynb in Jupyter or Google Colab and run all cells.
- Optimizer: Adam
- Epochs: 20
- Batch Size: 64
- Strategy:
tf.distribute(supports multi-GPU)
object-detection-tensorflow/
│
├── objectdetection.ipynb # Main notebook
├── my_mnist_model.keras # Saved trained model (after training)
└── README.md
- Multi-output neural networks
- Bounding box regression
- IoU-based evaluation
- Custom data preprocessing pipelines with
tf.data - Transfer of object detection concepts to digit localization
HB Mrudhal Ankith
B.Tech AI & ML | Amity University, Bangalore
GitHub • LinkedIn