This a project I made to build a Neural Network model that can classify Indian coins based on their denomination and can also classify weather the coin is valid or fake/invalid. The Neural Network was built on a ConvNet archetecture and has learnt on around 2000 images of coins, both valid and invalid.
Vending machines and money changers use several methods to detect and identify coins that are inserted into them. Though these methods are effective, they still cause some probelms, which can be potentially solved by replaceing the existing methods with a Neural Network model that can classify the coins based on their denominations and validity.
The main goal of this project is to build one such NN model to solve the existing problems. The probelms and solution are discussed in detail in the sections below.
Vending machines and money changers deal with taking in cash form a user, identifying the denomination of the cash, and detect cash's validity ( i.e is it a real or a counterfeit (fake)). Coins seem to be a major type of cash that are exchanged in these machines. The current methods of identifying the denomination of coins by the these machines commonly involves measuring the weight, size, and thickness of the coin using techniques such as light sensing, and detecting weather the coin is real or fake involves obtaining the composition of the coin to detect if it is metallic or not using techniques such as electromagnetic field transmission. These methods do work, except there are two problems:
- In many countries (like India), the versions of coins keep changing overtime and consequently the dimensions and compositions of the coins change too making it difficult to identify and detect coins using the afore mentioned methods.
- Fake coins can be made of metallic plates that resemble the size and composition of real coins, when such plates are inserted into the machine, they might get falsely detect as valid coins.
One potential way to solve these problems would be to use Machine Learning to identify the coin denomination and detect it's validity. But how? An ML model can be trained on a dataset of images of both real and fake coins of various denominations. If the images were captured with a flash, the amount of light reflected off of the surface of metallic coins would be higher compared to that of non-metallic fake coins. Also the higher reflection from metallic surface would produce regions of bright spots only in images of metallic coins.
The figure below shows some images captured with flash, taken from the dataset, showing some differences present between the images of real and fake coins.
(a) & (b) are images of a real coin, showing reflected light as bright spots on the coin.
(c) is the image of a fake non-metallic coin, not showing any apparent bright spots of light.
(d) is fake too but is a metallic plate and thus showing spots of brightness, but lacks the presence of imprints of denomination, the rupee symbol and artistry.
(e) is fake, made by printing the image of a real coin on a piece of paper and pasted on a plastic plate, and thus the image contains both the spots of brightness and the information and artistry similar to that of a real coin but lacks the lustrous appearance of a real coin. Also the paper surface appears rougher compared to a real coin.
Keeping in mind these differences, a dataset of images was created containing 1750 images of various real and fake coins captured with flash.
The images are then classified into the following types.
-
The front face of real/valid Indian coins consisting the imprint of common denominations- Rs 1, Rs 2, and Rs 5.
-
The back or reverse face of real/valid coins that do not show their denomination values.
-
Fake/Invalid coins.
The images were originally captured with a 12MP camera with a resolution of around 2000x4000 pixels and were processed in OpenCV to detect the region of the coin within the image, crop it along the region and resize it to a resolution of 256x256 pixels.
This preprocessing was done to make it easier for ML models to learn important features. The code for processing is present in the file detect_coins.py
or the notebook version detect_coins.ipynb
and the steps involved in the processing are described in detail in the Image Processing guide.
All the original images together take up over 3GB of space. Hence I'ev added only few of those images to this repo. You can find those images in the path images/original
. Let me know if you want to have all the images.
The processed images though take up only 70MB of space, hence all 1750 processed images were added, you can find them in images/processed
. Ive trained the NN model on these processed images.
The NN model trained on this dataset can classify images as either:
- 1 Rupee Coin
- 2 Rupee Coin
- 5 Rupee Coin
- Reverse face of coin
- Inavlid image / fake coin
Test Loss: 0.06
Test Accuracy: 0.98
I've created a notebook containing the setup, building, and evaluation of the model. You can find it here.
Find the same dataset on Kaggle here.
And the same notebook here.