Machine learning and neural network is a sub field in computer science, which has gained a huge popularity today as a result of its vast range of applications.This could be applied in a simple and effective manner,when conventional programming methods fail.
Artificial neural networks (ANNs) mimic the structure of the human brain. ANNs consist of a large number of interconnected artificial neurons.It is believed that trained neural networks are able to perform various activities successfully.
There are two main types of learning methods,
- Supervised learning.
- Unsupervised learning.
Let us focus on a practical implementation of a supervised learning method.We need to have a training dataset which contains input data and their corresponding classes in order to train a network using supervised learning.This can be done by following the steps below.
Step 1 – Pre processing input data
First,we consider a simple “Sinhala handwriting detection” system. In order to implement such a system we need data belongs to every class (In this example “ර”,”ග”,”ට”,”ප”). The following figure shows a unprocessed handwriting sample(left) and processed sample(right).
In order to use these as input data they should be extracted and categorized manually,they should be saved into separate images.This can be done in Matlab using the “image processing toolbox“.Some simple image processing codes are given below.
These separated segments are stored as 20×20 images along with their corresponding class inside a structured array which could be saved separately for future use as a ‘traindata.mat’ file.
There are some cases in which multiple images are used to create the input dataset,alternative ways of processing should be used.(Example here)
Step 2 – Creating the neural network
We need to first create a neural network according to the complexity of the problem.We can decide the number of inputs/outputs and the type of transfer functions by analyzing the problem. As we created 20×20 images we must have 400 input nodes and since we have 4 output classes we need at most 4 output nodes.
Many types of neural networks can be created in Matlab.(I found out that for this example a patternnet with 2 hidden layers containing 20 nodes each would do the trick)
View(net) command can be used to visualize the created network to verify the architecture and the type of transfer functions used in each layer.
The network can be modified according to the user requirement if necessary using the following commands.
Step 3 – Training a neural network using test data
In order to train the created network,we need to convert our input images in to a column vector (dimension 400×1) and target classes should be assigned binary values according to our preference. The following code was used to do the above mentioned conversion.
Line 25 [net,tr] = train(net,X’,T’);can be used to train the current network over and over again until it reaches a satisfying state. During training the following GUI will pop and inform the current state of the training process.(Additional information can be accessed by using provided functions eg. plotconfution matrix)
Step 4 -Testing the ANN
We need a separate set of classified input data for testing the performance of the neural network. plotconfusion(T’,net(X’)) can be used to quantitatively represent the performance of the network after each training session.
Finally the trained network can be used to identify written text with trained classes. This could be implemented by using more advanced image processing techniques to increase accuracy of correct classification.
It should be noted that although we performed training by using a fixed size dataset; a well-trained ANN will be able to classify various sizes and types of similar letters.
As you can see by this simple example above, a neural network is a very powerful tool which can be used to classify data based on patterns. Supervised learning can be used to identify faces, types of cars and even to predict weather.
We should keep in mind that neural network outputs are unpredictable; hence testing and training are two essential steps in building a reliable ANN. The “network structure” also plays an important role in the performance of the network.
Feel free to contact the writer for any further clarification on this article.