
Project Developed by : Prajwal Nimje, Mahesh Sasikumar, Alan Sunny
Artificial Intelligence has been witnessing a monumental growth in bridging the gap between the capabilities of humans and machines. Researchers and enthusiasts alike, work on numerous aspects of the field to make amazing things happen. One of many such areas is the domain of Computer Vision. Here, we are building a model for the identification of currencies of different countries using Convolutional Neural Network.
Convolutional Neural Network(CNN) is a type of feed-forward artificial neural network in which the connectivity pattern between its neurons is inspired by the organization of the animal visual cortex. This algorithm takes in an input image, assign importance (learnable weights and biases) to various aspects/objects in the image and be able to differentiate one from the other. Consider the following example,
In the figure, we have an RGB image which has been separated by its three color planes — Red, Green, and Blue. There are a number of such color spaces in which images exist — Grayscale, RGB, HSV, CMYK, etc.
You can imagine how computationally intensive things would get once the images reach dimensions, say 8K (7680×4320). The role of CNN is to reduce the images into a form which is easier to process, without losing features which are critical for getting a good prediction.
Convolution : Convolution is a specialized kind of linear operation. In Mathematics, Convolution between two functions produces a third function expressing how the shape of one function is modified by other. A kernel is a small 2D matrix whose contents are based upon the operations to be performed. A kernel maps on the input image by simple matrix multiplication and addition, the output obtained is of lower dimensions and therefore easier to work with. The convolution operation reduces the number of free parameters, allowing the network to be deeper with fewer parameters.
Pooling : Pooling layers reduce the dimensions of the data by combining the outputs of neuron clusters at one layer into a single neuron in the next layer. Local pooling combines small clusters, typically 2 x 2. Global pooling acts on all the neurons of the convolutional layer. In addition, pooling may compute a max or an average. Max pooling uses the maximum value from each of a cluster of neurons at the prior layer. Average pooling uses the average value from each of a cluster of neurons at the prior layer.
Importing Libraries And Packages: TensorFlow bundles together a slew of machine learning and deep learning models and algorithms and makes them useful by way of a common metaphor. Keras is one of the leading high-level neural networks APIs. Neural layers, cost functions, optimizers, initialization schemes, activation functions, and regularization schemes are all standalone modules that you can combine to create new models. Matplotlib is a plotting library for the Python programming language and its numerical mathematics extension NumPy. It provides an object-oriented API for embedding plots into applications using general-purpose GUI.
Importing Dataset Directory from Google Drive.
Rescaling Image image from range [0,255] to [0,1]
Initializing train_dataset and validation_dataset from Google Drive. Here, we are using two datasets, one is training dataset and other is validation dataset. Each of the datasets consists of two classes, images of Indian and US currencies. Since we have only two classes, we use class_mode = ‘binary’.
We have applied Convolution layers and Maxpooling function for training the model. Flattening converts the data into a 1-dimensional array for inputting it to the next layer. We flatten the output of the convolutional layers to create a single long feature vector. And it is connected to the final classification model, which is called a fully-connected layer.
We have compiled our model. Since there are two classes, we have used loss = ‘binary_crossentropy’.
We have taken the epoch as 30, i.e, the learning algorithm will work through the entire training dataset 30 number of times. One epoch means that each sample in the training dataset has had an opportunity to update the internal model parameters. Since the dataset is small, we have taken the steps per epoch as 3.
Now, the algorithm has finished training the model. Now, it’s time to test the data. We have created another test dataset which consists samples of both Indian and US currencies.
Here, we are using a test dataset in our model to test and differentiate between Indian currencies and US currencies. The index of Indian currency is 0 and that of US currency is 1. If the model predicts the image as 0, the algorithm will display result as “Indian Currency”. Else, if the model predicts 1, algorithm will display “US currency”.