当前位置:网站首页>Face recognition software based on deepface model

Face recognition software based on deepface model

2022-06-10 22:50:00 biyezuopinvip

Resource download address :https://download.csdn.net/download/sheziqiong/85601096

Face recognition software ( No external API)

V2.0 be based on DeepFace Model design of face recognition software
V1.0 be based on PCA Model design of face recognition software

V2.0

  • After watching teacher wuenda's “ Deep learning course ”, Understand the application of deep convolution neural network in face recognition . It says DeepFace The model has an implementation process in the job , So take this opportunity , The model is applied to our own face recognition software .
  • introduce DeepFaceNet Model , The recognition accuracy is improved . At the same time One-Shot problem .

The new file

  • dir ‘deepface’: Contains model files 、 Identification function 、 Coding function, etc
    1. ‘deepface.h5’ :DeepFace Model file , use Keras(Tensorflow backend) Load model .
    2. ‘fr_utils.py’ : Deep face recognition interface , contain : Model coding face function 、 Face recognition function .
    3. ‘inception_blocks.py’:DeepFace Model interface file , contain : Load model functions 、 Model loss function .

Update the details

  1. 'face_recognition.py’ New in ’DeepFaceRecognition’ class , For face recognition .
  2. Add processing of identification details , Unregistered users will display “Unknown”.
  3. Histogram equalization is added to image preprocessing , Increased recognition accuracy in darker places .

V1.0

  • At first , In the database course design part , I use C# A sign in recording system based on face recognition is designed . The face recognition part of this system uses Shangtang technology Face++ API. Because the recognition speed is relatively slow , You also need to be connected to the Internet , I always want to change it to offline recognition . therefore , There is this blog .
  • Based on a blog I wrote before 《 Face recognition in image processing 》 Based on PCA The face model is obtained by the training model method .
  • Based on face model 、Python Designed this small software . This frees you from using third parties API The shortcomings of , Faster recognition . however , After testing , This method is greatly affected by light .

development tool

Environmental Science

  1. windows 10
  2. Anaconda(Spyder)

Language

  1. software design :Python
  2. Model training uses :Matlab

frame

  1. python-opencv
    • Realize the function of face detection , Get the face area
  2. numpy
    • Matrix operations
  3. scipy
    • Scientific Computing , Load model file
  4. tkinter
    • GUI Development

Function introduction

Face recognition

  • In this software design , The model file we use is Matlab Derived .mat file . Two matrices are saved in the file mean_face And V, The former is Average face vector , The latter is the face space matrix .

  • The size of the user's face image saved by the software is 112 x 92. Every time you start the software , Load all user images into memory , And stretch the two-dimensional image into one-dimensional vector .
    v u s e r ( i ) v_{user}^{(i)} vuser(i) On behalf of the user i i i Face image vector

  • then , We combine all user image vectors into a user image matrix , Each column of the matrix is the user image vector :

U = [ ( v u s e r ( 0 ) ) T   ( v u s e r ( 1 ) ) T   ⋯   ( v u s e r ( n ) ) T ] U = \begin{bmatrix} (v_{user}^{(0)})^T \ (v_{user}^{(1)})^T \ \cdots \ (v_{user}^{(n)})^T \end{bmatrix} U=[(vuser(0))T (vuser(1))T  (vuser(n))T]

  • The user image matrix U U U Subtract the average face vector from each column in v m e a n _ f a c e v_{mean \_ face} vmean_face, Then the matrix after the operation is projected to the model space update matrix U U U:

U = V T ⋅ ( U . −   v m e a n _ f a c e ) U = V^T \cdot (U .- \ v_{mean \_ face}) U=VT(U. vmean_face)

  • In this way , We get the user face matrix after dimensionality reduction .

Identification process

  1. Collect face images , Extract the face part , And convert the image into vector form : v i n p u t v_{input} vinput

  2. The face vector obtained in the previous step is projected into the model space according to the following formula :
    v p c a = V T ⋅ ( v i n p u t − v m e a n _ f a c e ) v_{pca}=V^T \cdot (v_{input} - v_{mean \_ face}) vpca=VT(vinputvmean_face)

  3. Take what you got in the last step v p c a v_{pca} vpca Vector and U U U Each column in the matrix is calculated Euclidean distance , Find the nearest column to identify the target .

Identify function code

def __recognize(self, image, face):
        """ the system approves the user's identity according to his face """
        name = ''
        try:
            (x, y, w, h) = face
            image = Image.fromarray(image).crop((x, y, x+w, y+h)).resize(self.img_size)
            img_vec = self.V.T.dot(np.array(image).reshape([-1, 1]) - self.mean_face)
            distances = [la.norm(img_vec - self.user_matrix[:, j].reshape([-1, 1])) \
                         for j in range(self.user_matrix.shape[1])]
            
            min_dis = np.min(distances)
            index = np.where(distances == min_dis)[0][0]
            # print(min_dis, index)
            name = self.user_names[index]
        except:
            pass
        
        return name

Portrait import

  • It is mainly for the convenience of importing user portraits , Therefore, this function is added .

  • Select the import folder path in the interface , Cycle through all images in the folder . Extract the portrait part and convert it into gray image , Save to the relative path where the software stores the portrait .

Photo entry

  • In order to input user portrait information , The user can turn on the camera 、 After entering the name , Click the Photo button on the interface , You can save the portrait information to the software folder .

Software defect

  1. Light problems
    • such as : After entering the portrait in the place with bright light , Users can easily be mistaken in dark places .
    • The way to try to solve the problem is : Histogram equalization is used in image preprocessing , But it only played a part .
    • So when used , The input environment should be consistent with the detection environment as far as possible .

Resource download address :https://download.csdn.net/download/sheziqiong/85601096

原网站

版权声明
本文为[biyezuopinvip]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206101631045372.html