Burmese Handwritten Digit Recognition (CNN) 
An end-to-end Computer Vision project focused on classifying handwritten Myanmar (Burmese) digits (၀-၉) using a custom PyTorch Convolutional Neural Network.
This project explores the domain gap between academic datasets and real-world, unconstrained handwriting, utilizing data augmentation and custom preprocessing pipelines to improve model robustness.
📖 Overview
While standard models achieve high accuracy (+99%) on clean validation sets like the BHDD (Burmese Handwritten Digit Dataset), they frequently fail in real-world applications due to variance in stroke thickness, aspect ratio distortion, and background noise.
Inspired by the recent myMNIST benchmark research, this project implements a 2-layer CNN architecture and a robust image preprocessing pipeline to bridge that domain gap, allowing the model to accurately read thin, edge-to-edge, unpadded handwriting.
Model Architecture (V2)
The network is a custom PyTorch CNN designed to extract both simple edge features and complex geometric loops (crucial for Burmese digits like ၅, ၆, and ၉).
- Layer 1:
Conv2d(1 -> 16 channels) + ReLU + Max Pooling - Layer 2:
Conv2d(16 -> 32 channels) + ReLU + Max Pooling - Classifier: Fully Connected Linear Layers (1568 -> 128 -> 10)
- Optimizer: Adam (
lr=0.001) - Loss: Cross-Entropy
🛠️ Engineering Challenges & Solutions
During real-world inference testing, the initial model failed due to three primary data pipeline issues. Here is how they were resolved:
1. The Aspect Ratio Distortion
- Problem: Raw images drawn on rectangular canvases were being forcibly squished into
28x28squares via standardtransforms.Resize, mathematically destroying the shape of tall digits like ၇ and ၂. - Solution: Implemented a custom
fit_and_padfunction using PIL. It scales the longest edge to 20 pixels while maintaining the exact aspect ratio, and then pastes it onto a pure black28x28canvas, perfectly mimicking the BHDD dataset padding.
2. The Box Artifact (Thresholding)
- Problem: Dark gray backgrounds from drawing apps were being pasted onto pure black tensors, creating a sharp square artifact. The CNN locked onto the square edge rather than the digit, resulting in total prediction failure.
- Solution: Injected a thresholding binarization step
img.point(lambda p: 255 if p > 128 else 0)before padding to crush gray backgrounds to pure0and boost strokes to255.
3. Stroke Thickness & The Domain Gap
- Problem: The model failed on incredibly thin handwriting because the
F.max_pool2dlayers compressed the thin strokes into disconnected dots. - Solution: Rebuilt the
DataLoaderto include a Data Augmentation pipeline (RandomRotation,RandomAffinefor scaling and translation) applied only to the training set. This forced the CNN to learn true geometric topology rather than memorizing thick-stroke pixel layouts.
How to Run
This project was developed entirely in Google Colab.
- Click the
Open in Colabbadge at the top of the.ipynbfile. - Run the notebook sequentially to instantiate the network and the
fit_and_padpipeline. - Use the final Inference cell to upload your own custom
.pngor.jpgdrawings of Burmese digits to test the model.
Author
Shin Thant Tun Computer Engineering Undergraduate
King Mongkut's Institute of Technology Ladkrabang (KMITL)
Release files for bhdr 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| bhdr-0.1.0.tar.gz | 6.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| bhdr-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.9 kB
Release files / bhdr-0.1.0.tar.gz
| Download URL | bhdr-0.1.0.tar.gz |
|---|---|
| Size | 6.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1d1261f3f3777abc965267017a7247fe5645a08617bb8b6ab5db909aade1b77d
|
|
BLAKE2b-256 checksum How to use checksums |
1c6f29ae2707f3daf87ac384c86bba0c7a26adff6891e2cdfa480cd6ca9ff274
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.13
|
Release files / bhdr-0.1.0-py3-none-any.whl
| Download URL | bhdr-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
62a74f0317ca161e7e2d4b04b0d16443a9afad907f185c05a19e9d0ca6df9d20
|
|
BLAKE2b-256 checksum How to use checksums |
b1f5a365a5892a53ac8ff21b11cbdf9a650d3b4edab7dffe702ceed07bb2a3f0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.13
|