TensorFlow Face Recognition (TensorFlow + Dlib + OpenCV) to build a convolutional neural network-based face recognition depth learning - theory and explain the code, documentation and source code

© 2015-2019 Wang Liguang. All Rights Reserved. This article is a blogger original article, shall not be reproduced without the bloggers allowed in any form, otherwise it will pursue your legal responsibility. You are reading this article means that you have agreed to the Site statement (see top article)! This article is for reference only, please effectiveness of screening yourself, any problems, bloggers do not assume any responsibility!
This link: https://blog.csdn.net/happywlg123/article/details/86719292

1 Project Overview

Face recognition has a very wide range of applications in modern society. The digital image processing course, I chose to do a face recognition system depth learning. I designed depth study of face recognition systems based on camera images obtained by using dlib classifier locate the face, using a convolution neural network recognition. I designed the system has three output categories. In addition to identifying me and other students, but I'm still LFW people on the network face gallery download some pictures to the label for the image tag as a third category. Detailed design and implementation of processes on the system will be described in detail in the following sections.

Solemn statement:
This document authored by Luke (wlg).
This document was originally curriculum report, it is to do a small amount of adaptation only learn to share.
Without permission is strictly prohibited to copy, reprint or quote any part of the document! Hereby declare!
This document comes from github: https: //github.com/lukegood/DIY_Face_recognition_system
go to the above link for github source code and text.

Partitioning module 2 function and structure

I realize the system is divided into four parts and processing images captured by the camera module, the local picture processing module, convolution neural network structures and training modules and test modules, each of which is stored in a .py file.
Camera picture collection and processing module is mainly responsible for collecting facial images, photographs intercepted by calling camera, locate the face, designated normalized, and ultimately save face picture.
Local photo processing module is mainly used to process I downloaded on the network down as the third classification categories used in the picture, and its main function is to read into the picture, use dlib locate the face, and then save the images to the face I set up specifications for use.
Convolution neural network structures and training modules to complete before the major spread, divide the training set and test set, back-propagation and other functions, is a key part of the whole system.
The main part of the test to call the camera to capture human face images, and then read the saved training before maturity into the network for recognition.
The system structure as shown below:
Here Insert Picture Description
a system configuration diagram

3 project realization

Sample collection and processing of 3.1

Sample collection and processing focused on the camera image acquisition and processing module, two local image processing modules.
First, the camera picture collection and processing modules to collect and process I and other students of the picture. OpenCV calls using the camera, and then intercept and grayscale images, then use dlib find a face and save the image to the appropriate size. Specific process as shown below:
Here Insert Picture Description
Figure 2 capture processes
in downloading pictures LFW gallery does not meet the specifications I want to use, so the design of a local photo processing module. In the local photo processing, the basic flow above the same, difference is that the input from the camera no longer read, but the local picture. Specific processes as shown below:
Here Insert Picture Description
Figure 3 local image processing flow
explained below with the key code associated with sample collection and processing.
First, using ** camera = cv2.VideoCapture (0) ** to open the camera, after gradation processing using a positioning face dlib classifier, to obtain the corresponding coordinates.
Here Insert Picture Description
4 positioning coordinates of the face
, after obtaining the The corners face in the picture taken by the camera in the face interception, saved as a standard we want. By the code face = img [x1: y1, x2: y2], face = cv2.resize (face, (size, size)) to complete.
Upon completion of the acquisition and processing of images, then carry out construction work on neural network.

Solemn statement:
This document authored by Luke (wlg).
This document was originally curriculum report, it is to do a small amount of adaptation only learn to share.
Without permission is strictly prohibited to copy, reprint or quote any part of the document! Hereby declare!
This document comes from github: https: //github.com/lukegood/DIY_Face_recognition_system
go to the above link for github source code and text.

Build and train the neural network convolution 3.2

3.2.1 convolution, pooling, activation and discarded

Convolution layer plays an important role in the whole network, and for extracting a feature of the sample processing, choose a good convolution has an important impact on the level of accuracy throughout the convolutional neural network recognition. In selecting convolution kernel, the general use of "small nuclear convolution, convolution multi-layers" principle. So, I finally adopted the structure in image recognition is very commonly used in three convolution. 3 by using the convolution kernel size of 3, the row and column on the moving step are set to 1. In order to ensure that the sample size unchanged after convolution layer, to facilitate further processing, I used the "all-zero fill", that is, outside the sample add a layer of "0."
After each layer convolutional layer, I layer is connected to a pool, maximum use of the pooled sample is performed. My resolution pooled layer was fixed at 2 by 2, that is, after convolution sample is divided into a number of small 2-by-2 area, captures the maximum in each small area, and then merged layer as pool output. The reason for pooling, although after the convolution sample size has not changed, but the pooled sample length and width will be reduced by half.
After the completion of the pool, letting me sample had an activation function. The role of activation function is to add some nonlinear factors to the neural network, the neural network so that you can better solve classification problems. In selecting activation function of time, I used relu function. I passed literature review found that many of the current literature recommended relu function because of its small computational cost and can alleviate problems gradient disappears. In order to reduce training time, I chose to use relu function.
Here Insert Picture Description
5relu schematic diagram function
before the completion of the activation layer down the network input, I was introduced to give up. The reason for introducing abandon that, we need to construct a network of training parameters generally large and are prone to over-fitting problem. In order to enhance the generalization of the model, we can give up, let some random parameters do not participate in training. However, abandoning only for purposes of training phase, in real time model used, all parameters are to be involved in the calculation of.
Finally, this part of the network structure as shown below:
Here Insert Picture Description
FIG. 6 a schematic configuration
in the network structure of my design, the prepared sample is first input (64 643), after convolution, the same sample size, but the number of channels becomes 32 3. Then passes through the cell layers, the length and width of the sample by half, so that after the first layer and the convolution pooled sample size becomes 32 32 32 Calculation other layers identical to the first layer. After the second convolution kernel layer pooled sample size becomes 16 16 32 After the third layer of the convolution kernel after pooling, the sample size becomes 8 . 8 64 and as input into the fully connected neural network.
The codes, convolutional layer is disposed, and a cell layer function using the activation and the introduction of discard, by TensorFlow can call functions implemented, for convenience, can define their own function, which then calls the function in the TensorFlow, so that only the parameters of their function in the desired configuration TensorFlow good, after only need to call your own functions and transfer the sample to be optimized parameters on it. As shown below:
Here Insert Picture Description
Here Insert Picture Description

Here Insert Picture Description
7 convolution to create their own packed, pooled, abandoning function

3.2.2 fully connected neural network

In the fully connected neural network, I mainly set up one hidden layer and one output layer. Now my literature, increasing the number of layers of hidden layer Network errors can be reduced, but at the same time increases the complexity of the network, the network produced a tendency to easily fit, it is often obtained by increasing the number of lower nodes of the hidden layer error layers better than to add some.
In order to determine how much better set up a hidden layer nodes, I made some attempts were tried on the accuracy of network test set at 256,512,1024 three kinds of hidden layer node situation.
In order to control variables, the input sample is determined to be 6000, which I, my partner and third classified srf pictures of each 2000. The ratio of training set and test set to 95: 5, batch_size set to 100 samples, after performing 400 batch_size stopped.
256,512,1024 test set accuracy and a loss in the hidden layer nodes as follows:
...
(go github links for source code and text: https: //github.com/lukegood/DIY_Face_recognition_system)

The project reference: http: //tumumu.cn/2017/05/02/deep-learning-face, to express my gratitude!

Contact blogger

If you have questions, you can communicate with me. Please leave a message in the article directly, or send me an e-mail. If you want to send a message (Visit this link for contact details: https: //www.wangliguang.cn/ page_id = 81? ). If you have time I usually reply, but I do not guarantee a reply, please understand.
If you absolutely want to reply, you can see below, a reward bloggers.

A reward bloggers

Write articles and answer questions is not easy, I hope you can give me some support! Once you have a reward us, we are willing to provide you with a number of Q & A. (Visit this link for a reward and illustrations: https: //www.wangliguang.cn/ page_id = 337?)

Guess you like

Origin blog.csdn.net/happywlg123/article/details/86719292