Convolutional Neural Networks – Explained!
Convolution Neural Network (CNN) is a fast emerging, feed-forward artificial neural networks, most commonly applied in analyzing visual imagery in a deep-neural network.
It is applied to regular based artificial intelligence applications in our daily life. What does it mean in our daily life? Let’s first analyze these concepts.
Do you try a facial recognition lock in your mobile?
How your email provider is detecting spam emails?
How Facebook is detecting faces from your photos and suggesting a tag option?
How do your eCommerce providers recommend products to you?
How your mobile works during voice to text search translator?
So all these above tasks are running using the concept of Artificial Intelligence Neural Networks. Convolution Neural Network is a class of deep-feed forward architecture neural networks most commonly applied in analyzing visual imagery. Typically the output result has fully connected networks with feature maps. CNN works with a collection of algorithms when you apply in daily life problems. So you can make your own Artificial intelligence application with deep neural networks like personal assistant voice bots, face detection attendance programs, auto answered systems etc. But how will we implement these networks in our daily life problem? Bingo! We have different techniques to implement these networks like computer vision, natural language processing, text analysis etc. We need some training data like your friend’s images, conversation chat records, previous documents, historical data etc. basically Conv net implement in classification techniques, so it will auto predict what you want exactly. These networks support different types of applications like object detection, face recognition, speech to text, and text analysis etc. So we want some data to train these networks, we pre-process and convert our data to large size multidimensional arrays. For example, suppose we have a digital image then how can we convert this image into dynamic arrays (matrix)? Let’s computer vision and do this task in this way,
import cv2 image = cv2.imread(“example.jpg”, 1) print(type(image)) Output: < type numpy="" ndarray="">
So computer vision operation converts our image to numpy array data. We can use this data in convolution networks.
Typical architecture of convolutional neural networks:
A Convolutional Neural Network (CNN) is comprised of one or more convolutional layersand then followed by one or more fully connected layers as in a standard multilayer neural network.
Fully connected networks
In a fully connected layer, each neuron is connected to every neuron in the previous layer, and each connection has its own weight. This is a totally general purpose connection pattern and makes no assumptions about the features in the input data, thus it doesn’t bring any advantage that the knowledge of the data being used can bring. These types of layers are very expensive in terms of memory and computation.
In contrast, in a convolution layer each neuron is only connected to a few nearby local neurons in the previous layer, and the same set of weights is used to connect to them.
For example, in the following image, the neurons in the h1 layer are connected only to some input units (pixels)
A feature map is as same as a filter or “kernel” in this particular context. The weights of the filter determine what specific features are detected.
So for example, Franck has provided a great visual. Notice that his filter/feature-detector has x1 along the diagonal elements and x0 along all the other elements. This kernel weighting would thus detect pixels in the image that have a value of 1 along the image’s diagonals.
In the above example, we used a 3×3 filter (5×5 could also be used, but would be too complex). The values from the filter were multiplied element-wise with the original matrix (input image), then summed up. To get the full convolved matrix, the algorithm keep’s repeating this small procedure for each element by sliding the filter over the whole original matrix.
Understanding and coding with Python
import numpy as np x = [6,2] h = [1,2,5,4] y = np.convolve(x,h,"full") print(y) Output: array([ 6, 14, 34, 34, 8]) sliding x window over h: • 6 = 6 * 1 + 2 * 0 • 14 = 6 * 2 + 2 * 1 • 34 = 6*5 + 2*2 • 34 = 6 * 4 + 2 * 5 • 8 = 6 * 0 + 2 * 4
Now we will verify what Python did in Visually (Full Padding)
Let’s think of the kernel as a sliding window. We have to come with the solution of padding zeros on the input array. This is a very famous implementation and it will be easier to show how it works with a simple example, consider this case:
First Step [2 6] | | [0 1 2 5 4] = 2 * 0 + 6 * 1 = 6 Second step [2 6] | | [0 1 2 5 4] = 2 * 1 + 6 * 2 = 14 Third Step: [2 6] | | [0 1 2 5 4] = 2 * 2 + 6 * 5 = 34 Fourth step: [2 6] | | [0 1 2 5 4 ] = 2 * 5 + 6 * 4 = 34 Fifth step: [2 6] | | [0 1 2 5 4 ] 0 = 2 * 4 + 6 * 0 = 8 The result of the convolution for this case, listing all the steps, would then be: Y = [6 14 34 34 8]
Convolution: 2D operation with Python (Numpy/Scipy)
Now let’s see 2D operation Below we will apply the equation to an image represented by a 3x3 matrix according to the function g = (-1 1). Please note that when we apply the kernel we always use its inversion.
In Python Code
from scipy import signal as sg I= [[255, 7, 3], [212, 240, 4], [218, 216, 230],] g= [[-1,1]] print ('With zero padding \n') print (sg.convolve( I, g)) Output: With zero padding [[-255 248 4 3] [-212 -28 236 4] [-218 2 -14 230]] For a more difficult case where: h= [ [-1 1] , [2 3] ]
So in the above example, we understand how convolutional network will work, typically inputting data have multi-dimensional arrays to filter the feature set of arrays with the kernel. CNN has hidden layers with feed forward neurons. The output result has fully connected neurons with set-off feature maps.
Applications of Convolutional Neural Networks
• Image recognition • Video analysis • Natural language processing • Drug discovery • Health Risk Assessment and Biomarkers of Aging discovery
Our Recent Posts
Best Local SEO Strategies for Small And Medium Scale Local Business Local search is a primary aspect for a business. If an individual living in Hyderabad, India needs to ... Read More