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