Aurelie Mei Yin Ng Yin Hing 101246374
This project explores Optical Character Recognition (OCR) using deep learning, focusing on whether multi-task learning (character + font classification) improves robustness to unseen fonts.
A convolutional neural network based on a pretrained ResNet18 backbone is trained to recognize alphanumeric characters across multiple font styles. The system compares a baseline model (character-only training) against a multi-task model that also predicts font identity.
- Build a CNN-based OCR system for 36 classes (A–Z, 0–9)
- Investigate whether font supervision improves character recognition
- Evaluate generalization to unseen fonts
- Analyze representation learning under multi-task learning
project/
├── main.py # Main script: dataset generation, training, evaluation, plots
├── fonts/ # TrueType/OpenType font files
├── dataset/
│ └── images/ # Generated character images
├── labels.csv # Dataset manifest
├── results/ # Output figures and saved models
│ ├── loss_curves.png
│ ├── Baseline_Seen Fonts.png
│ ├── Baseline_Unseen Fonts.png
│ ├── Multitask_Seen Fonts.png
│ ├── Multitask_Unseen Fonts.png
│ ├── per_character_accuracy_seen.png
│ ├── per_character_accuracy_unseen.png
│ ├── baseline.pth
│ └── multitask.pth
└── README.mdpip install torch torchvision pillow numpy pandas scikit-learn matplotlibPython 3.8+ is recommended.
Download TrueType (.ttf) or OpenType (.otf) fonts and place them in the fonts/ directory.
Update the FONTS_DIR path in main.py to point to fonts folder.
The dataset is generated automatically on first run if labels.csv does not exist. To regenerate (e.g. after changing font size or augmentation settings), delete dataset/ and labels.csv before running:
rm -rf dataset/ labels.csvpython main.pyThis will:
- Generate the dataset (if not already generated)
- Split fonts 80/20 into seen/unseen sets
- Train the baseline CNN
- Train the multi-task CNN
- Evaluate both models on seen and unseen font test sets
- Save all plots and model weights to
results/