Neural Networks: convolutional neural Networks

Source: Internet
Author: User

First, preface

This convolutional neural network is the further depth of the multilayer neural network described above, which introduces the idea of deep learning into the neural network, and extracts different levels of images from the image by convolution operation, and uses the training process of neural network to automatically adjust the parameters of convolution core. Thus, unsupervised production of the most suitable classification characteristics. This generalization may be a bit abstract, I try to describe it in detail below, but if you want to get a better understanding of how the whole process works, you need to understand deeplearning.

This article will cover the principle of convolution and the general concept of image feature extraction, and describe the implementation of convolutional neural network in detail. However, due to limited energy, there is no further introduction to the principles of human visual stratification and machine learning, which will be described later in the related articles on deep learning.

Second, convolution

Convolution is an important arithmetic in the analysis of mathematics, in fact, is a very simple concept, but a lot of people do image processing of this concept is not clear, for the sake of simplicity, we only introduce the discrete form of convolution, then on the image, the image with a convolution kernel convolution operation, is actually a filtering process. Let's take a look at the basic mathematical representation of convolution:

F(X,Y)°W(X,Y)=∑S=−AA∑t= −bb w ( S,t ) f (x− s, Y−t ) /span> f (x, Y) °w (x, y) =∑S=−AA∑T=−BBW (s,t) F (x−s,y−t)

whichI=F(x,y) I=f (x, y) is an image,F(x,y) f (x, y) is the image I abovexX rowyThe grayscale value of the point on the y column. andW(x,y) W (x, y) has too many names, filters, convolution cores, response functions, and so on, andaA andbb defines the size of the convolution core, w(x,y)w (y).

From the above equation, it is obvious that convolution actually provides a weight template that slides on the image, aligns the center to each pixel in the image, and then weights all the pixels covered by the template, and takes the result as a response to the point on the image as the convolution core. So we can see the following points from the entire convolution operation:

1) convolution is a linear operation

2) The size of the convolution kernel, which defines the size of the neighborhood in which any point in the image participates in the operation.

3) The weight value on the convolution kernel indicates the contribution ability of the corresponding neighbor points to the final result, the greater the weights, the greater the contribution ability.

4) The convolution core moves along all the pixels of the image and calculates the response, resulting in a large image such as the original image.

5) When dealing with points on the edge, the convolution cores will overwrite the points that are not defined in the outer layer of the image, and there are several ways to set these undefined points, either with an inner pixel image or a full set of 0.

Three, convolution feature layer

In fact, image feature extraction in the blog some of the other articles have been mentioned, here I would like to say a feature extraction and convolution of the relationship. In fact, most of the image feature extraction relies on convolution operations, such as the significant edge feature is the result of filtering the image with various gradient convolution operators. The target feature in an image is mainly reflected in the relationship between the pixels and the surrounding pixels, and these neighborhood pixel relationships form lines, corners, contours, etc. The convolution operation is the operation that uses the neighborhood point to redefine the value of the point by a certain weight.

Convolution operators for horizontal gradients:

The convolution operator for vertical gradients:

According to the theory of deep learning about human visual stratification, human visual identification of the target is layered, the lower layer will extract some edge features, and then higher level of the shape or target cognition, higher level will analyze some movement and behavior. That is to say, the high-level feature is a combination of low-level features, from low-rise to higher-layer features more abstract, more and more expressive semantics or intentions. The higher the level of abstraction, the less likely there is to speculate, and the better the classification.

Deep learning is to achieve the target classification by this kind of automatic feature extraction, construct some basic feature layer, then use these basic features to construct higher level abstraction, more accurate classification feature.

The whole convolutional neural network structure is also easy to understand, it in the ordinary multilayer neural network in front of the addition of 2 layer feature layer, the two layers of feature layer is the weight of the adjustable convolution operation.

Iv. convolutional Neural Networks

In the original multilayer neural network structure, all nodes of each layer are calculated forward according to the weight of the continuous line, and become the output of the next layer node. Each weight line is different from each other and is not shared. The value of each next layer node is related to all nodes in the previous layer.

Unlike the common multilayer neural network, there are feature extraction and dimensionality reduction layers in the convolutional neural network, where the junction links are partially connected and a feature map is generated from a convolution core, and all the nodes on the feature map share the parameters of this set of convolution cores.

Here we design a 5-story convolutional neural network, an input layer, an output layer, 2 feature extraction layers, and a fully connected hidden layer. The design ideas of each layer are explained in detail below.

In the general introduction of convolutional neural network in the article you may see in the feature layer there are 2 layers of dimensionality reduction, here we will convolution and reduced dimension synchronization, only used in the convolution operation, traversing the image in the pixel by step interval.

input layer : Ordinary multilayer neural network, the first layer is the eigenvector. The general image is selected by man-made feature, the characteristic vector is computed by the characteristic function, and as input of the neural network. The output layer of convolutional neural network is the whole image, such as example 29*29, then we can expand the image by column, forming 841 nodes. The first layer of the node does not have any connecting lines ahead.

layer 1th: The 1th layer is the feature layer, which is a 6 convolution template with the first layer of the image convolution formed 6 images of 13*13. That is to say, in this layer we calculate a bias weight, there are only (5*5+1) *6=156 weight parameters, but the second layer of the node is 6 images by column expansion, that is, there are 6*13*13=1014 nodes.

The real difficulty of building the 2nd layer is that the connection line is set, the node of the current layer is not connected with all the nodes in the previous layer, but only with 25 neighboring points, so the second layer must have (25+1) *13*13*6=26364 line, but these links share 156 weights. According to the previous multi-layer network C + + design, each wired object has 2 members, one is the index of the weight, one is the index of the previous node, so it is necessary to properly set the index value of each line, which is also the difference between convolutional neural network and the general full-link layer.

The 2nd layer: The 2nd layer is also a feature layer, it is composed of 50 feature images, each feature image is the size of the 5*5, this feature image each point is from the previous layer 6 features image of each image to take 25 neighborhood points in the last weighted together, so each point is a node has (5* 5+1) *6=156 A link line, then the current layer has a total of 5*5*50=1250 nodes, so there are 195,000 weights of the link line, but only (5*5+1) *6*50=7800 a weight parameter, The value of each weight link can be found in an array of 7,800 weight parameters.

So the key to the 3rd layer is how to establish the index of the weight index of each link and the node linked to the previous layer.

The 3rd layer: and ordinary multi-neural network is not different, is a hidden layer, there are 100 nodes, each node and the previous layer in the 1250 nodes, a total of 125,100 weights and 125,100 link lines.

The 4th layer: The output layer, it is the number of nodes related to the classification, assuming that we are set to 10 classes, the output layer is 10 nodes, the corresponding expectations of the setting in the multilayer neural network has been introduced, each output node and the above hidden layer 100 nodes connected, total (100+1) *10=1010 link line, 1010 weights.

As can be seen from the above, the core of convolutional neural networks is the creation of convolutional layers, so when designing the Cnnlayer class, you need two member functions to create the network layer, one for creating the normal full-join layer, and one for creating the convolution layer.

1 class Cnnlayer 2 {3 private:4     cnnlayer* prelayer; 5     vector<cnnneural> m_neurals; 6     vector<double > m_weights; 7 Public:8     Cnnlayer () {prelayer = nullptr;} 9     //create convolutional layer     void Createconvlayer (unsigned curnumberofneurals, Unsigned prenumberofneurals, unsigned prenumberoffeatmaps, unsigned curnumberoffeatmaps);/     /Create a normal layer of     void Createlayer (unsigned curnumberofneurals,unsigned prenumberofneurals),     void Backpropagate (vector<double >& Derrwrtdxn, vector<double>& derrwrtdxnm, double eta); 14};

Create a normal layer, in the above described in the multilayer neural network has been given code, it receives two parameters, one is the front layer node, and the current layer node number.

The creation of convolutional layers is much more complex, and the determination of index values of all the linked lines requires a clearer understanding of the entire network. The Createconvlayer function is designed here, it receives 4 parameters, corresponding to the current layer node number, the previous layer node, the first layer of the feature graph and the current level of the number of feature images.

Here is the C + + code, to understand this part can be a little bit difficult, because the feature map is actually in the column expansion, so the concept of neighborhood is more abstract, we consider to restore the feature image, from the perspective of the image to consider.

 1 void Cnnlayer::createconvlayer 2 (unsigned curnumberofneurals, unsigned prenumberofneurals, unsigned Prenumberoffeatmaps, unsigned curnumberoffeatmaps) 3 node 5 unsigned preimgsize = Prenumberofneur of {4//previous layer and current layer feature graph Als/prenumberoffeatmaps; 6 unsigned curimgsize = curnumberofneurals/curnumberoffeatmaps; 7 8//Initialization weight 9 unsigned numberofweights = prenumberoffeatmaps*curnumberoffeatmaps* (5 * 5 + 1); Ten for (Unsigne D i = 0; I! = numberofweights;  i++) Each {M_weights.push_back (0.05*rand ()/Rand_max), 13}14//establishes all Nexus lines for (unsigned i = 0; I! = curnumberoffeatmaps;  i++) (Unsigned imgrow = sqrt (preimgsize); The size of the previous Layer feature image, IMGROW=IMGCOL19//Gap 2 sampling, around the neighborhood of 25 points for (int c = 2; c < imgRow-2; c= c+ 2) 21 {                 (int r = 2; r < ImgRow-2; R =r + 2) @ cnnneural neural;25             for (unsigned k = 0; K! = prenumberofneurals; k++) 26    {for (int kk = 0; KK < (5*5+1); KK + +) Connection connection;30//index of weights connection.weightidx = i* (curnumberoff Eatmaps* (5 * 5 + 1) + k* (5 * 5 + 1) + kk;32//Node index Connection.neurali                     DX = k*preimgsize + c*imgrow + r;34 neural.m_connections.push_back (connection); 35 }36 m_neurals.push_back (neural); 37}38}39}40}41}

V. Training and identification

After the whole network structure is set up, training can only be trained according to the multi-layer neural network, and the weights updating strategy is consistent. Therefore, in general, convolutional neural networks and ordinary multilayer neural networks are structurally different. convolutional neural Networks feature extraction layer and dimensionality reduction layer, the link between them is a partial link, multiple links sharing weights. The nodes of the multilayer neural network between two layers are all connected. Besides this, the weights update, the training, the recognition are all consistent.

Training to get a set of weights, that is, under this set of weights, the network can better extract image features for classification recognition.

About the source of the problem: the individual is very not recommended to use other people's source code, so my blog all the articles will not give the entire project source code, but will give some core functions of codes, if you read the article carefully, you will be able to understand the core idea of the algorithm. Trying to do it yourself will be more helpful to your understanding. If you have any questions, just leave a comment below.

Neural Networks: convolutional neural Networks (RPM)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.