A PyTorch CNN for classifying handwritten Burmese digits (၀-၉).
Project description
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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bhdr-0.1.0.tar.gz.
File metadata
- Download URL: bhdr-0.1.0.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d1261f3f3777abc965267017a7247fe5645a08617bb8b6ab5db909aade1b77d
|
|
| MD5 |
7cab710bad134fd5da5a68b4ac1aabfc
|
|
| BLAKE2b-256 |
1c6f29ae2707f3daf87ac384c86bba0c7a26adff6891e2cdfa480cd6ca9ff274
|
File details
Details for the file bhdr-0.1.0-py3-none-any.whl.
File metadata
- Download URL: bhdr-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
62a74f0317ca161e7e2d4b04b0d16443a9afad907f185c05a19e9d0ca6df9d20
|
|
| MD5 |
17e5c8e161711b152d7a2fbf55636c08
|
|
| BLAKE2b-256 |
b1f5a365a5892a53ac8ff21b11cbdf9a650d3b4edab7dffe702ceed07bb2a3f0
|