How Transfer Learning Helped Me Train a Currency Note Classifier for Raspberry Pi
When I started working on CashMaster6688, a microcontroller-based currency sorting system for our 1st year hardware project, one of the biggest challenges was teaching a machine to recognize different Sri Lankan banknotes in real time.
We used Pi Camera Module 3 to detect notes and needed the system to run on a Raspberry Pi 4B 4GB, which meant the model had to be accurate and lightweight. Training a deep learning model from scratch was not practical within the time period. That’s where transfer learning became a gamechanger.
In this article, I’ll walk you through how I approached the training process, why I chose transfer learning, and what I learned along the way.
The Problem
I needed to classify the following classes:
- 20 Rupee note
- 50 Rupee note
- 100 Rupee note
- 500 Rupee note
- 1000 Rupee note
additionally, I used No note (empty compartment) to help for physical sorting system.
The images were captured using a Raspberry Pi Camera Module 3 under real hardware conditions. The dataset was relatively small (around 200–250 images per class), which made training a model from scratch risky due to overfitting.
Why Transfer Learning?
Training a convolutional neural network from scratch usually requires:
- Tens of thousands of images
- Significant computational resources
- A lot of time for hyperparameter tuning
I didn’t have those luxuries.
Transfer learning allowed me to start with a model that already understood basic visual features (edges, textures, shapes) from the large ImageNet dataset. I only needed to adapt the final layers to recognize banknotes.
This approach saved a huge amount of time and gave me much better results with limited data.
Model Selection
I experimented with two architectures:
- MobileNetV2 — Extremely lightweight and designed for mobile/edge devices
- EfficientNetB0 — Slightly more accurate while still remaining efficient
Both models are excellent choices for Raspberry Pi deployment because they balance accuracy and speed. I eventually converted the trained models to TensorFlow Lite for real-time inference.
Get Dileepa Prabhath’s stories in your inbox
Join Medium for free to get updates from this writer.
As our Final Model MobileNetV2 was chosen which worked best with our hardware setup.
Dataset Preparation
The dataset was organized in a simple folder structure:
dataset/
├── 20/
├── 50/
├── 100/
├── 1000/
└── no_note/Before training, I applied several preprocessing steps:
- Resized all images to 224×224
- Normalized pixel values
- Applied data augmentation (rotation, zoom, shifts, brightness changes, horizontal flips)
Data augmentation was crucial. Since the notes would be placed in slightly different positions and lighting conditions in the real system, augmentation helped the model generalize better.
Training Process
I used Google Colab for training. The process was divided into two stages:
Stage 1: Feature Extraction
- Froze the base model (MobileNetV2 / EfficientNetB0)
- Added a custom classification head:
- Global Average Pooling
- Dense layer (128 units)
- Softmax output layer (5 classes)
- Trained only the new layers with a higher learning rate
Stage 2: Fine-Tuning
- Unfroze the later layers of the base model
- Used a very small learning rate (1e-5)
- Continued training with Early Stopping to prevent overfitting
This two-stage approach is one of the most effective ways to apply transfer learning on small datasets.
Challenges I Faced
Even with transfer learning, I ran into several practical issues:
- Overfitting
Applied strong data augmentation + early stopping. - Class imbalance / small dataset
Used transfer learning instead of training from scratch. - Color differences (training vs. Pi camera)
Matched preprocessing carefully
Use real image captured from same camera use to detect notes. - Large model size for Raspberry Pi
Converted final model to TensorFlow Lite which is light version of TensorFlow Model.
Results
With transfer learning, I was able to reach over 90% validation accuracy in a relatively short time. Training from scratch with the same dataset would have been much less effective.
The final model was converted to .tflite format and successfully ran on the Raspberry Pi with acceptable inference speed.
Key Takeaways
- Transfer learning is extremely powerful when you have limited data and time.
- Choosing the right architecture (MobileNet / EfficientNet) is important for edge deployment.
- Data augmentation and careful preprocessing matter just as much as the model itself.
- Always match the preprocessing between training and inference.
Final Thoughts
Building the note recognition system for CashMaster6688 taught me that you don’t always need massive datasets or powerful GPUs to create useful AI applications. With transfer learning and careful engineering, even a small dataset can power a real hardware product.
If you’re working on a similar edge AI project, I highly recommend starting with transfer learning, it can save you weeks of work.








