Training method and device, fingerprint recognition method and device, electronic equipment
By introducing the training method of the sum of comparison losses in the convolutional neural network model, the differences between each domain are learned, the overfitting problem is solved, and the generalization of the model and the ability to identify samples from different domains are improved.
Patent Information
- Application Number
- CN202011351546.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-11-25
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2040-11-25
AI Technical Summary
During the training process, the convolutional neural network model is prone to overfitting to samples in a certain domain, resulting in poor ability to distinguish positive and negative samples from other domains, affecting its generalization.
A training method is used to extract and preprocess the sample features through the backbone network and the comparison learning loss network, calculate the sum of the comparison loss and the sum of the classification loss of the sample pair, and perform backpropagation on the weighted sum. , to learn the differences between each domain and avoid overfitting.
The generalization of the neural network model is improved, enabling it to more accurately distinguish between positive and negative samples from different domains, and enhance the ability to identify samples with features that are too close.
Smart Images

Figure CN112613341B
Abstract
Description
Technical Field
[0001] The present application belongs to the field of machine learning, and specifically relates to a training method and device, a fingerprint recognition method and device, an electronic device and a storage medium. Background Art
[0002] After the convolutional neural network model is trained through training samples, the final effect to be achieved by the convolutional neural network model is to accurately classify positive and negative samples. Among them, the samples generated by the same project or the same device in the training samples are called samples of the same domain, or samples of the same sample type.
[0003] Currently, the training of convolutional neural network models usually relies on the training data accumulated from past projects that are the same or similar to the project to which the convolutional neural network model is connected as training samples. In other words, the training samples may include samples from different domains, and the samples in each domain contain positive samples and negative samples. The training process is to learn the sum of the classification losses of the training samples, so as to learn a decision surface for distinguishing positive and negative samples.
[0004] However, this method of simply reusing past data for training does not take into account the differences between samples in each domain in the training samples, which may cause the decision surface to overfit the samples in a certain domain, making the feature distance between positive and negative samples in other domains too close. This further causes the trained neural network model to be able to accurately distinguish between positive and negative samples in the overfitted domain, but it is difficult to accurately distinguish between positive and negative samples in other domains whose feature distances are too close, affecting the generalization of the convolutional neural network model. Summary of the invention
[0005] In view of this, the purpose of the present application is to provide a training method and device, a fingerprint recognition method and device, an electronic device and a storage medium, so that the trained neural network model has better generalization.
[0006] The embodiment of the present application is implemented as follows:
[0007] In a first aspect, an embodiment of the present application provides a training method for training a neural network model, wherein the neural network model includes a backbone network and a comparison learning loss network, and the method includes: extracting features from an acquired sample image set through the backbone network to obtain sample features; preprocessing the sample features through the comparison learning loss network to obtain preprocessing features; calculating the sum of comparison losses of all sample pairs included in the sample image set based on the preprocessing features; calculating the sum of classification losses of all samples included in the sample image set based on the sample features; and training the neural network model based on the sum of the comparison losses and the sum of the classification losses.
[0008] The neural network training method provided in this solution has an additional sum of comparison losses when training the neural network model, compared with the traditional method of training the neural network model. When the neural network model trains and learns the sum of comparison losses, it can solve the parameters used to characterize the comparison differences between each sample through gradient calculation. By learning this parameter, the neural network model can learn the comparison differences between similar samples in each domain and different types of samples in each domain as much as possible, so that when forming the feature space, the neural network model can not only consider the differences between positive and negative samples, but also the differences brought by the domain, thereby avoiding overfitting of samples in certain specific domains in the training set, which is conducive to enhancing the generalization of the neural network model.
[0009] In combination with the embodiment of the first aspect, in a possible implementation manner, the neural network model is trained according to the sum of the comparison losses and the sum of the classification losses, including: weighted summing the sum of the comparison losses and the sum of the classification losses, and back-propagating the parameters obtained after the weighted sum within the neural network model.
[0010] In combination with the embodiment of the first aspect, in a possible implementation manner, each sample included in the sample image set has a sample label, and the preprocessing of the sample features to obtain preprocessed features includes: performing global average pooling on the sample features corresponding to each sample included in the sample image set to obtain global features corresponding to each sample; calculating the feature distance corresponding to each sample pair included in the sample image set based on the global features corresponding to each sample; calculating the positive and negative sample pair mask matrix of the sample image set based on the sample label of each sample; the preprocessing features are the feature distance corresponding to each sample pair and the positive and negative sample pair mask matrix.
[0011] In combination with the embodiment of the first aspect, in a possible implementation manner, calculating a positive and negative sample pair mask matrix of the sample image set according to the sample label of each sample includes:
[0012] Based on the formula M = {m i,j |m i,j =(y i = =y j )}, calculate the positive and negative sample pair mask matrix of the sample image set; where, if the sample label y of the i-th sample i and the sample label y of the jth sample j If the sample labels y of the i-th sample are the same, then the sample pair consisting of the i-th sample and the j-th sample is a positive sample pair, and the corresponding parameter of the positive sample pair in the positive and negative sample pair mask matrix is 1; if the sample label y of the i-th sample is i and the sample label y of the jth sample j If they are not the same, the sample pair consisting of the i-th sample and the j-th sample is a negative sample pair, and the corresponding parameter of the negative sample pair in the positive and negative sample pair mask matrix is 0.
[0013] In combination with the first aspect of the embodiment, in a possible implementation manner, the calculating the feature distance corresponding to each sample pair included in the sample image set includes: for the i-th sample x i With the jth sample x j The sample pairs composed of x i Each feature in the global feature is related to x j The square of the difference between each feature in the global feature is summed, and the value obtained after the square root of the final sum is determined as the i-th sample x i With the jth sample x j The feature distance corresponding to the sample pair.
[0014] In combination with the embodiment of the first aspect, in a possible implementation manner, the preprocessing feature is the feature distance corresponding to each sample pair included in the sample image set and the mask matrix of positive and negative sample pairs of the sample image set, and the sum of the comparison losses of all sample pairs included in the sample image set is calculated based on the preprocessing feature, including: summing the comparison losses of all positive sample pairs included in the sample image set to obtain the sum of the comparison losses of the positive samples; summing the comparison losses of all negative sample pairs included in the sample image set to obtain the sum of the comparison losses of the negative samples; and summing the sum of the positive sample comparison losses and the negative sample comparison losses. The sum of the sample comparison losses is summed to obtain the sum of the comparison losses; wherein, for each positive sample pair included in the sample image set, the comparison loss of the positive sample pair is: the product of the parameters corresponding to the positive sample pair in the positive and negative sample pair mask matrix and the feature distance corresponding to the positive sample pair; for each negative sample pair included in the sample image set, the comparison loss of the negative sample pair is: the product of the parameters corresponding to the negative sample pair in the positive and negative sample pair mask matrix and the feature distance optimization value of the negative sample pair; the feature distance optimization value of the negative sample pair is: the larger value of the difference between the preset parameters and the feature distance corresponding to the negative sample pair and 0.
[0015] In combination with the embodiment of the first aspect, in a possible implementation, calculating the sum of the classification losses of all samples included in the sample image set based on the sample characteristics includes: calculating the cross entropy of each sample included in the sample image set based on the sample characteristics, and summing each obtained cross entropy to obtain the sum of the classification losses.
[0016] In combination with the embodiment of the first aspect, in a possible implementation manner, the neural network model is used to identify live fingerprints and foreign objects under the screen.
[0017] In a second aspect, an embodiment of the present application provides a training device for training a neural network model, wherein the neural network model includes a backbone network and a comparison learning loss network. The training device includes: a feature extraction module, a preprocessing module, a calculation module and a training module. The feature extraction module is used to extract features from the acquired sample image set through the backbone network to obtain sample features; the preprocessing module is used to preprocess the sample features through the comparison learning loss network to obtain preprocessed features; the calculation module is used to calculate the sum of the comparison losses of all sample pairs included in the sample image set based on the preprocessing features; the calculation module is also used to calculate the sum of the classification losses of all samples included in the sample image set based on the sample features; the training module is used to train the neural network model based on the sum of the comparison losses and the sum of the classification losses.
[0018] In combination with the second aspect embodiment, in a possible implementation, the training module is used to perform a weighted sum of the sum of the comparison loss and the sum of the classification loss, and back-propagate the parameters obtained after the weighted sum in the neural network model.
[0019] In combination with the second aspect embodiment, in a possible implementation, each sample included in the sample image set has a sample label, and the preprocessing module is used to perform global average pooling on the sample features corresponding to each sample included in the sample image set through the comparison learning loss network to obtain the global features corresponding to each sample; based on the global features corresponding to each sample, the feature distance corresponding to each sample pair included in the sample image set is calculated; based on the sample label of each sample, the positive and negative sample pair mask matrix of the sample image set is calculated; the preprocessing features are the feature distance corresponding to each sample pair and the positive and negative sample pair mask matrix.
[0020] In combination with the second aspect of the embodiment, in a possible implementation manner, the preprocessing module is used to calculate the i,j |m i,j =(y i = =y j )}, calculate the positive and negative sample pair mask matrix of the sample image set; where, if the sample label y of the i-th sample i and the sample label y of the jth sample j The same, then the sample pair consisting of the i-th sample and the j-th sample is a positive sample pair, and the corresponding parameter of the positive sample pair in the positive and negative sample pair mask matrix is 1; if the sample label y of the i-th sample i and the sample label y of the jth sample j If they are not the same, the sample pair consisting of the i-th sample and the j-th sample is a negative sample pair, and the corresponding parameter of the negative sample pair in the positive and negative sample pair mask matrix is 0.
[0021] In combination with the second aspect embodiment, in a possible implementation manner, for the i-th sample x i With the jth sample x j The sample pairs composed of the preprocessing module are also used to convert x i Each feature in the global feature is related to x j The square of the difference between each feature in the global feature is summed, and the value obtained after the square root of the final sum is determined as the i-th sample x i With the jth sample x j The feature distance corresponding to the sample pair.
[0022] In combination with the second aspect embodiment, in a possible implementation manner, the preprocessing feature is the feature distance corresponding to each sample pair included in the sample image set and the mask matrix of the positive and negative sample pairs of the sample image set, and the calculation module is used to sum the comparison losses of all positive sample pairs included in the sample image set to obtain the sum of the positive sample comparison pair losses; sum the comparison losses of all negative sample pairs included in the sample image set to obtain the sum of the negative sample comparison pair losses; sum the sum of the positive sample comparison pair losses and the sum of the negative sample comparison pair losses to obtain the The sum of the comparison losses; wherein, for each positive sample pair included in the sample image set, the comparison loss of the positive sample pair is: the product of the parameters corresponding to the positive sample pair in the positive and negative sample pair mask matrix and the feature distance corresponding to the positive sample pair; for each negative sample pair included in the sample image set, the comparison loss of the negative sample pair is: the product of the parameters corresponding to the negative sample pair in the positive and negative sample pair mask matrix and the optimized value of the feature distance of the negative sample pair; the optimized value of the feature distance of the negative sample pair is: the larger value of the difference between the preset parameters and the feature distance corresponding to the negative sample pair and 0.
[0023] In combination with the second aspect embodiment, in a possible implementation, the calculation module is used to calculate the cross entropy of each sample included in the sample image set according to the sample characteristics, and sum each obtained cross entropy to obtain the sum of the classification losses.
[0024] In combination with the embodiment of the second aspect, in a possible implementation manner, the neural network model is used to identify live fingerprints and foreign objects under the screen.
[0025] In a third aspect, an embodiment of the present application further provides a fingerprint recognition method, the method comprising: collecting a fingerprint to be recognized; inputting the fingerprint to be recognized into a neural network model obtained after training by the training method of any implementation method of the first aspect for recognition, and obtaining an output result.
[0026] In a fourth aspect, the present application also provides a fingerprint recognition device, including a collection module and a recognition module. The collection module is used to collect the fingerprint to be recognized; the recognition module is used to input the fingerprint to be recognized into a neural network model obtained after training by the training method of any implementation method of the first aspect for recognition, and obtain an output result.
[0027] In the fifth aspect, an embodiment of the present application also provides an electronic device comprising: a memory and a processor, wherein the memory and the processor are connected; the memory is used to store programs; the processor calls the program stored in the memory to execute the method provided in the above-mentioned first aspect embodiment and / or any possible implementation method combined with the first aspect embodiment.
[0028] In the sixth aspect, an embodiment of the present application also provides a non-volatile computer-readable storage medium (hereinafter referred to as storage medium), on which a computer program is stored. When the computer program is run by a computer, it executes the method provided by the above-mentioned first aspect embodiment and / or any possible implementation method combined with the first aspect embodiment.
[0029] Other features and advantages of the present application will be described in the following description, and partly become apparent from the description, or understood by implementing the embodiments of the present application. The purpose and other advantages of the present application can be realized and obtained by the structures specifically pointed out in the written description and the drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can also be obtained based on these drawings without creative work. As shown in the drawings, the above and other purposes, features and advantages of the present application will be clearer. The same reference numerals indicate the same parts in all the drawings. The drawings are not deliberately scaled to the actual size, and the focus is on showing the main purpose of the present application.
[0031] Figure 1 A schematic structural diagram of an electronic device provided in an embodiment of the present application is shown.
[0032] Figure 2 A flow chart of a training method provided in an embodiment of the present application is shown.
[0033] Figure 3 A schematic diagram of the structure of a training device provided in an embodiment of the present application is shown.
[0034] Figure 4 A flow chart of a fingerprint recognition method provided in an embodiment of the present application is shown.
[0035] Figure 5 A schematic structural diagram of a fingerprint recognition device provided in an embodiment of the present application is shown.
[0036] Label: 100 - electronic device; 110 - processor; 120 - memory; 500 - training device; 510 - feature extraction module; 520 - preprocessing module; 530 - calculation module; 540 - training module; 600 - fingerprint recognition device; 610 - acquisition module; 620 - recognition module. DETAILED DESCRIPTION
[0037] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application.
[0038] It should be noted that similar numbers and letters represent similar items in the following figures, so once an item is defined in one figure, it does not need to be further defined and explained in the subsequent figures. At the same time, in the description of this application, relational terms such as "first", "second", etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply that there is any such actual relationship or order between these entities or operations. Moreover, the term "comprise" or any other variant thereof is intended to cover non-exclusive inclusion, so that the process, method, article or equipment including a series of elements includes not only those elements, but also includes other elements that are not clearly listed, or also includes elements inherent to such process, method, article or equipment. In the absence of more restrictions, the elements defined by the statement "comprise one..." do not exclude the existence of other identical elements in the process, method, article or equipment including the elements.
[0039] Furthermore, the term "and / or" in this application is merely a term used to describe the association relationship between associated objects, indicating that three relationships may exist. For example, A and / or B may represent three situations: A exists alone, A and B exist at the same time, and B exists alone.
[0040] In addition, the defects existing in the neural network model training method in the prior art (the training results overfit to the domain corresponding to a certain project, affecting the generalization of the convolutional neural network model) are the results obtained by the applicant after practice and careful research. Therefore, the process of discovering the above-mentioned defects and the solutions proposed in the embodiments of this application for the above-mentioned defects below should be recognized as the applicant's contribution to this application.
[0041] In order to solve the above problems, the embodiments of the present application provide a training method, an apparatus, an electronic device and a storage medium, so that the trained neural network model has better generalization for recognizing images from different domains.
[0042] The technology can be implemented by using corresponding software, hardware or a combination of software and hardware. The following is a detailed introduction to the embodiments of the present application.
[0043] First, refer to Figure 1 The electronic device 100 used to implement the training method and apparatus of the embodiment of the present application is described. A neural network model is deployed on the electronic device 100.
[0044] Optionally, the electronic device 100 is not limited to a personal computer (PC), a tablet computer, a mobile Internet device (MID), a personal digital assistant or a server.
[0045] The electronic device 100 may include: a processor 110 and a memory 120 .
[0046] It should be noted that Figure 1 The components and structures of the electronic device 100 shown are merely exemplary and non-limiting. The electronic device 100 may also have other components and structures as required.
[0047] The processor 110, the memory 120, and other components that may appear in the electronic device 100 are directly or indirectly electrically connected to each other to achieve data transmission or interaction. For example, the processor 110, the memory 120, and other components that may appear may be electrically connected to each other via one or more communication buses or signal lines.
[0048] The memory 120 is used to store programs, for example, a program corresponding to the training method described below or a training device described below. Optionally, when a neural network model is stored in the memory 120, the neural network model includes at least one software function module that can be stored in the memory 120 in the form of software or firmware.
[0049] Optionally, the software function modules included in the neural network model may also be solidified in the operating system (OS) of the electronic device 100 .
[0050] The processor 110 is used to execute executable modules stored in the memory 120, such as software function modules or computer programs included in the neural network model. After receiving the execution instruction, the processor 110 can execute the computer program, for example, to perform: extracting features from the acquired sample image set through the backbone network to obtain sample features; preprocessing the sample features through the comparison learning loss network to obtain preprocessing features; calculating the sum of the comparison losses of all sample pairs included in the sample image set according to the preprocessing features; calculating the sum of the classification losses of all samples included in the sample image set according to the sample features; and training the neural network model according to the sum of the comparison losses and the sum of the classification losses.
[0051] Of course, the method disclosed in any embodiment of the present application can be applied to the processor 110 or implemented by the processor 110.
[0052] The following will be combined Figure 2 The flowchart shown introduces the training method provided in this application.
[0053] Step S110: extracting features from the acquired sample image set through the backbone network to obtain sample features.
[0054] Taking the training of a neural network model for identifying live fingerprints and foreign objects under the screen as an example, the neural network model is set on a hardware device (such as a mobile phone, tablet, etc.), so that the hardware device has the function of live fingerprint recognition.
[0055] Since there are many types and models of hardware devices, for each hardware device, the under-screen fingerprint live image and the under-screen foreign object image (non-live image, such as attack image) obtained by the hardware device can be collected to form a sample.
[0056] Among them, for each sample, the staff can mark the sample in advance according to the effect presented by the sample to form a sample label corresponding to the sample.
[0057] The sample label is used to characterize the sample. For example, in the above example, for the live fingerprint image under the screen, the sample label "positive sample" can be added; for the foreign body image under the screen, the sample label "negative sample" can be added. For another example, in some other embodiments, for the tumor cell image, the sample label "positive sample" can be added; for the non-tumor cell image, the sample label "negative sample" can be added.
[0058] For samples from the same hardware device (including positive samples and negative samples), these samples belong to the same domain, and for samples from different hardware devices, these samples belong to different domains. The domains corresponding to the samples are different, that is, the sample categories are different.
[0059] In the embodiments of the present application, positive samples are referred to as samples of the same type, negative samples are referred to as samples of the same type, and positive samples are referred to as samples of different types. In order to distinguish samples of the same type from samples of the same sample category, and to distinguish samples of different types from samples of different sample categories, "domain" is used to represent "sample category" below. Accordingly, samples of the same sample category are referred to as samples from the same domain, and samples of different sample categories are referred to as samples from different domains.
[0060] After obtaining a large number of samples, random sampling can be performed from the large number of samples according to a random sampling method to obtain multiple sample image sets, wherein the number of samples included in each sample image set is the same.
[0061] Of course, a sample image set includes positive samples and negative samples. In addition, a sample image set should include samples from all domains as much as possible.
[0062] After obtaining the sample image set, the backbone of a traditional neural network with feature extraction function (such as the backbone of a Mobile Net, ResNet, Xception Net, etc.) can be used to extract features from each sample in the sample image set, thereby obtaining the sample feature X of the current batch of sample image sets.
[0063] Step S120: preprocessing the sample features by comparing the learning loss network to obtain preprocessed features.
[0064] The preprocessing features include: a feature distance corresponding to each sample pair and a mask matrix of positive and negative sample pairs corresponding to the sample image set.
[0065] It is worth pointing out that each sample included in the sample image set can form a sample pair with another sample included in the sample image set.
[0066] The feature distance corresponding to each sample pair is used to characterize the feature distance between two samples included in the sample pair.
[0067] The process of calculating feature distance is introduced below.
[0068] When preprocessing the sample features, for the sample features corresponding to each sample included in the sample image set, the average response value of its spatial dimension can be calculated, that is, global average pooling can be performed to obtain the global feature X′=GlobalAvgPooling(X) corresponding to each sample.
[0069] Subsequently, for the global feature X′ corresponding to each sample, the feature distance corresponding to each pair of samples included in the sample image set is calculated.
[0070] In some implementations, the L2 distance may be used as the characteristic distance. In this case, the formula Calculate the feature distance corresponding to each sample pair included in the sample image set.
[0071] Among them, d i,j is the i-th sample x i With the jth sample x j The feature distance corresponding to the sample pair, k represents the sample x i The features of are counted from 1, l represents the sample x j The features of start counting from 1, n-channel is x i or xj The dimensions of the included features.
[0072] It is worth pointing out that since all samples in the sample image set are extracted through the same backbone network, the dimensions of the features included in all samples in the sample image set are the same, which is n-channel.
[0073] formula The meaning is: for the i-th sample x i With the jth sample x j The sample pairs composed of x i Each feature in the global feature is related to x j The square of the difference between each feature in the global feature is summed, and the value obtained after the square root of the final sum is determined as the i-th sample x i With the jth sample x j The feature distance corresponding to the sample pair composed of i The global characteristics of x j The Euclidean distance of the global features.
[0074] Of course, in some other implementations, other distances may be used as the characteristic distance, such as L1 distance, etc., and accordingly, the formula for calculating the characteristic distance changes accordingly.
[0075] The positive and negative sample pair mask matrix corresponding to the sample image set is used to characterize the relationship between the sample labels of each sample pair included in the sample image set.
[0076] As mentioned above, a corresponding sample label is set for each sample in advance. In the embodiment of the present application, the positive and negative sample pair mask matrix of the sample image set can be calculated according to the sample label of each sample. The specific calculation process is as follows.
[0077] Based on the formula M = {m i,j m i,j =(y i = =y j )}, calculate the positive and negative sample pair mask matrix of the sample image set; where, if the sample label y of the i-th sample i and the sample label y of the jth sample j If the sample labels y of the i-th sample are the same, then the sample pair consisting of the i-th sample and the j-th sample is a positive sample pair. Correspondingly, the corresponding parameter of the positive sample pair in the positive and negative sample pair mask matrix is 1. i and the sample label y of the jth sample j If they are not the same, the sample pair consisting of the i-th sample and the j-th sample is a negative sample pair, and the corresponding parameter of the negative sample pair in the positive and negative sample pair mask matrix is 0.
[0078] Step S130: Calculate the sum of the comparison losses of all sample pairs included in the sample image set according to the preprocessing features.
[0079] Specifically, we can first calculate the sum of the feature comparison losses of all positive sample pairs included in the sample image set, that is, the sum of the positive sample comparison losses L pos , and calculate the sum of the feature comparison losses of all negative sample pairs included in the sample image set, that is, the sum of the negative sample comparison losses L neg ; Then compare the sum of the positive sample and the pair loss L pos The sum of the losses compared with the negative samples is L neg Sum up and get the sum of the comparison losses of all sample pairs included in the sample image set L contrastive =L pos +L neg .
[0080] Among them, for any positive sample pair (assuming that the samples included in the positive sample pair are x i With x j ), and the corresponding feature comparison loss is: the parameter m corresponding to the positive sample pair in the positive and negative sample pair mask matrix i,j The feature distance d corresponding to the positive sample pair i,j Then the sum of the positive sample comparison loss of all positive sample pairs included in the sample image set is (Since the negative sample pair m i,j is 0, so the formula can exclude negative samples).
[0081] Among them, for any negative sample pair (assuming that the negative sample pair includes samples x i With x j ), and the corresponding feature comparison loss is: the parameter m corresponding to the negative sample pair in the positive and negative sample pair mask matrix i,j The feature distance d from the negative sample pair i,j The feature distance d of the negative sample pair i,j The optimized value is: the preset parameter margin and the feature distance d corresponding to the negative sample pair i,j The larger value between the difference between 0 and Max(0,margin-d i,j ). Then the sum of the negative sample comparison losses of all negative sample pairs included in the sample image set is (Since the m of the positive sample pair i,j is 1, so the formula can exclude positive samples).
[0082] Of course, the value of margin can be adjusted according to actual conditions.
[0083] Step S140: Calculate the sum of classification losses of all samples included in the sample image set according to the sample features.
[0084] In the conventional neural network model training process, the sum of the classification loss of the sample image set is generally calculated. Generally speaking, the sum of the classification loss can be obtained by calculating the cross entropy of each sample included in the sample image set and summing each cross entropy obtained.
[0085] Step S150: training the neural network model according to the sum of the comparison losses and the sum of the classification losses.
[0086] Specifically, the sum of the comparison loss and the sum of the classification loss can be weighted and summed, and the parameters obtained after the weighted summation can be back-propagated in the neural network model to achieve the purpose of training.
[0087] For example, in some implementations, the sum of the comparison losses and the sum of the classification losses may be weightedly summed using the formula 0.3A+0.7B, where A is the sum of the comparison losses and B is the sum of the classification losses.
[0088] In the embodiment of the present application, when the neural network model is trained based on the loss value, compared with the traditional method of training the neural network model, an additional comparison loss sum L contrastive , the sum of the comparison losses is L contrastive It plays an auxiliary role in training.
[0089] The sum of the comparison losses is L contrastive In the process of back propagation, it is learned by the neural network model. In the learning process, the neural network model can solve the parameters used to characterize the comparison difference between the two samples included in each sample pair (positive sample pair and negative sample) in the sample image set through gradient calculation, that is, the comparison difference between the two samples.
[0090] By learning this parameter, the neural network model can learn the comparison differences between similar samples in each domain and different types of samples in each domain as much as possible, so that when forming the feature space, the neural network model can not only consider the differences between positive and negative samples, but also consider the differences brought by different domains, thereby avoiding overfitting of the neural network model to samples in certain specific domains in the training set, which is conducive to enhancing the generalization of the neural network model.
[0091] Specifically, by learning the parameter, the neural network model can fully learn the contrast differences between similar samples in each domain and the contrast differences between samples of different classes in each domain, so that in the formed feature space, the inter-class distances between samples of the same class are shortened, that is, the inter-class distances between positive samples are shortened, and the inter-class distances between negative samples are shortened; the inter-class distances between samples of different classes are increased, that is, the inter-class distances between positive samples and negative samples are increased. In the feature space formed by each sample in this way, similar samples in the same domain and different domains are clustered as much as possible, and samples of different classes in the same domain and different domains are separated as much as possible, forming two sample clusters (positive sample clusters and negative sample clusters) with more compact feature distributions, so that the boundary between the positive sample cluster and the negative sample cluster can be made as clear as possible, so that the neural network model being trained can fully learn the boundary between positive and negative samples.
[0092] When the neural network model is trained, the boundaries between positive and negative samples are fully learned, so positive and negative samples from various domains can be accurately identified. Compared with the traditional neural network model that only learns fuzzy boundaries, the generalization of the neural network model can be improved, which helps the neural network model to accurately identify images to be identified from different domains (different devices or different projects). When the neural network model is used to identify live fingerprint images under the screen and foreign body images under the screen (non-live images, such as attack images), it is beneficial to the generalization ability of the neural network model for live fingerprint images and foreign body images under the screen from different projects.
[0093] Based on the neural network model for identifying live fingerprint images and foreign body images under the screen obtained through the above training method, please refer to Figure 3 The present application also provides a fingerprint recognition method, the method comprising:
[0094] Step S210: Collect fingerprints to be identified.
[0095] Step S220: input the fingerprint to be identified into the neural network model for identification, and obtain an output result.
[0096] like Figure 4 As shown, the embodiment of the present application also provides a training device 500 for training a neural network model. The neural network model includes a backbone network and a comparison learning loss network, and the training device 500 includes: a feature extraction module 510, a preprocessing module 520, a calculation module 530 and a training module 540.
[0097] A feature extraction module 510 is used to extract features from the acquired sample image set through the backbone network to obtain sample features;
[0098] A preprocessing module 520, configured to preprocess the sample features through the comparison learning loss network to obtain preprocessed features;
[0099] A calculation module 530, configured to calculate the sum of comparison losses of all sample pairs included in the sample image set according to the preprocessing features;
[0100] The calculation module 530 is further used to calculate the sum of classification losses of all samples included in the sample image set according to the sample features;
[0101] The training module 540 is used to train the neural network model according to the sum of the comparison loss and the sum of the classification loss.
[0102] In a possible implementation, the training module 540 is used to perform a weighted summation of the sum of the comparison loss and the sum of the classification loss, and perform back-propagation of the parameters obtained after the weighted summation in the neural network model.
[0103] In a possible implementation, each sample included in the sample image set has a sample label, and the preprocessing module 520 is used to perform global average pooling on the sample features corresponding to each sample included in the sample image set through the comparison learning loss network to obtain the global features corresponding to each sample; calculate the feature distance corresponding to each sample pair included in the sample image set according to the global features corresponding to each sample; calculate the positive and negative sample pair mask matrix of the sample image set according to the sample label of each sample; the preprocessing features are the feature distance corresponding to each sample pair and the positive and negative sample pair mask matrix.
[0104] In a possible implementation manner, the preprocessing module 520 is used to calculate the number of i,j |m i,j =(y i = =y j )}, calculate the positive and negative sample pair mask matrix of the sample image set; where, if the sample label y of the i-th sample i and the sample label y of the jth sample j If the sample labels y of the i-th sample are the same, then the sample pair consisting of the i-th sample and the j-th sample is a positive sample pair, and the corresponding parameter of the positive sample pair in the positive and negative sample pair mask matrix is 1; if the sample label y of the i-th sample is i and the sample label y of the jth sample j If they are not the same, the sample pair consisting of the i-th sample and the j-th sample is a negative sample pair, and the corresponding parameter of the negative sample pair in the positive and negative sample pair mask matrix is 0.
[0105] In a possible implementation, for the i-th sample x i With the jth sample x j The preprocessing module 520 is also used to convert x i Each feature in the global feature is related to x j The square of the difference between each feature in the global feature is summed, and the value obtained after the square root of the final sum is determined as the i-th sample x i With the jth sample x j The feature distance corresponding to the sample pair.
[0106] In a possible implementation, the preprocessing feature is the feature distance corresponding to each sample pair included in the sample image set and the mask matrix of the positive and negative sample pairs of the sample image set. The calculation module 530 is used to sum the comparison losses of all positive sample pairs included in the sample image set to obtain the sum of the positive sample comparison losses; sum the comparison losses of all negative sample pairs included in the sample image set to obtain the sum of the negative sample comparison losses; sum the sum of the positive sample comparison losses and the sum of the negative sample comparison losses to obtain the comparison loss. The sum of the losses; wherein, for each positive sample pair included in the sample image set, the comparison loss of the positive sample pair is: the product of the parameters corresponding to the positive sample pair in the positive and negative sample pair mask matrix and the feature distance corresponding to the positive sample pair; for each negative sample pair included in the sample image set, the comparison loss of the negative sample pair is: the product of the parameters corresponding to the negative sample pair in the positive and negative sample pair mask matrix and the optimized value of the feature distance of the negative sample pair; the optimized value of the feature distance of the negative sample pair is: the larger value of the difference between the preset parameters and the feature distance corresponding to the negative sample pair and 0.
[0107] In a possible implementation, the calculation module 530 is used to calculate the cross entropy of each sample included in the sample image set according to the sample features, and sum each obtained cross entropy to obtain the sum of the classification losses.
[0108] In a possible implementation, the neural network model obtained through training is used to identify live fingerprints and foreign objects under the screen.
[0109] The training device 500 provided in the embodiment of the present application has the same implementation principle and technical effects as those of the aforementioned method embodiment. For the sake of brief description, for matters not mentioned in the embodiment of the training device 500, reference may be made to the corresponding contents in the aforementioned method embodiment.
[0110] like Figure 5 As shown, the embodiment of the present application further provides a fingerprint recognition device 600 , including a collection module 610 and a recognition module 620 .
[0111] The collection module 610 is used to collect fingerprints to be identified;
[0112] The identification module 620 is used to input the fingerprint to be identified into the trained neural network model for identification and obtain an output result.
[0113] In addition, an embodiment of the present application further provides a storage medium, on which a computer program is stored. When the computer program is run by a computer, the training method as described above is executed, or the fingerprint recognition method as described above is executed.
[0114] In addition, an embodiment of the present invention further provides an electronic device, including a processor and a memory connected to the processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the electronic device executes the above-mentioned training method or the above-mentioned fingerprint recognition method. Figure 1 .
[0115] In summary, the training method and device, fingerprint recognition method and device, electronic device and storage medium proposed in the embodiment of the present invention extract features and process features of samples in the sample image set to obtain preprocessing features. Then, the sum of the comparison losses of all sample pairs included in the sample image set is calculated based on the preprocessing features, and the neural network model is trained together with the sum of the classification losses calculated according to the sample features. When training the neural network model, compared with the traditional way of training the neural network model, there is an additional sum of comparison losses. When the neural network model trains and learns the sum of the comparison losses, the parameters used to characterize the comparison differences between each sample can be solved by gradient calculation. By learning the parameters, the neural network model can learn the comparison differences between similar samples in each domain and different samples in each domain as much as possible, so that when the neural network model forms the feature space, it can not only consider the differences between positive and negative samples, but also consider the differences brought by the domain, thereby avoiding overfitting of samples in certain specific domains in the training set, which is conducive to enhancing the generalization of the neural network model.
[0116] It should be noted that the various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0117] In the several embodiments provided in the present application, it should be understood that the disclosed neural network model and method can also be implemented in other ways. The neural network model embodiments described above are merely schematic. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the neural network models, methods and computer program products according to multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a portion of a code, and the module, program segment or a portion of the code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.
[0118] In addition, the functional modules in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
[0119] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a storage medium. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a laptop, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0120] The above description is only a specific implementation manner of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application.
Claims
1. A training method, characterized in that: For training a neural network model, the neural network model includes a backbone network and a comparison learning loss network, and the method includes: Extracting features from the acquired sample image set through the backbone network to obtain sample features; Preprocessing the sample features through the comparison learning loss network to obtain preprocessed features; Calculating the sum of comparison losses of all sample pairs included in the sample image set according to the preprocessing features; According to the sample features, the sum of the classification losses of all samples included in the sample image set is calculated; Training the neural network model according to the sum of the comparison losses and the sum of the classification losses; The preprocessing feature is a feature distance corresponding to each sample pair included in the sample image set and a mask matrix of positive and negative sample pairs of the sample image set. The sum of the comparison losses of all sample pairs included in the sample image set is calculated based on the preprocessing feature, including: Summing the comparison losses of all positive sample pairs included in the sample image set to obtain the sum of the positive sample comparison losses; Summing the comparison losses of all negative sample pairs included in the sample image set to obtain the sum of the negative sample comparison losses; Summing the sum of the comparison losses of the positive samples and the sum of the comparison losses of the negative samples to obtain the sum of the comparison losses; Among them, for each positive sample pair included in the sample image set, the comparison loss of the positive sample pair is: the product of the parameters corresponding to the positive sample pair in the positive and negative sample pair mask matrix and the feature distance corresponding to the positive sample pair; for each negative sample pair included in the sample image set, the comparison loss of the negative sample pair is: the product of the parameters corresponding to the negative sample pair in the positive and negative sample pair mask matrix and the optimized value of the feature distance of the negative sample pair; the optimized value of the feature distance of the negative sample pair is: the larger value of the difference between the preset parameters and the feature distance corresponding to the negative sample pair and 0.
2. The method according to claim 1, characterized in that The training of the neural network model according to the sum of the comparison loss and the sum of the classification loss includes: The sum of the comparison loss and the sum of the classification loss are weightedly summed, and the parameters obtained after the weighted summation are back-propagated in the neural network model.
3. The method according to claim 1, characterized in that: Each sample included in the sample image set has a sample label, and the preprocessing of the sample features to obtain preprocessed features includes: Performing global average pooling on sample features corresponding to each sample included in the sample image set to obtain a global feature corresponding to each sample; Calculating the feature distance corresponding to each pair of samples included in the sample image set according to the global feature corresponding to each sample; According to the sample label of each sample, a positive and negative sample pair mask matrix of the sample image set is calculated; The preprocessing features are the feature distance corresponding to each sample pair and the positive and negative sample pair mask matrix.
4. The method according to claim 3, characterized in that According to the sample label of each sample, a positive and negative sample pair mask matrix of the sample image set is calculated, including: Jordi i Sample labels for samples With j Sample labels for samples The same, then i The samples and j The sample pair consisting of samples is a positive sample pair, and the corresponding parameter of the positive sample pair in the positive and negative sample pair mask matrix is 1; Jordi i Sample labels for samples With j Sample labels for samples If they are not the same, i The samples and j The sample pair consisting of samples is a negative sample pair, and the corresponding parameter of the negative sample pair in the positive and negative sample pair mask matrix is 0.
5. The method according to claim 1, characterized in that The step of calculating the sum of classification losses of all samples included in the sample image set according to the sample features includes: According to the sample features, the cross entropy of each sample included in the sample image set is calculated, and each obtained cross entropy is summed to obtain the sum of the classification losses.
6. The method according to any one of claims 1 to 5, characterized in that: The neural network model is used to identify live fingerprints and foreign objects under the screen.
7. A fingerprint recognition method, characterized in that: The method comprises: Collect fingerprints to be identified; The fingerprint to be identified is input into a neural network model obtained after being trained according to any training method as claimed in claims 1-6, and an output result is obtained.
8. A training device, characterized in that: Used to train a neural network model, the neural network model includes a backbone network and a comparison learning loss network, the device includes: A feature extraction module, used to extract features from the acquired sample image set through the backbone network to obtain sample features; A preprocessing module, used for preprocessing the sample features through the comparison learning loss network to obtain preprocessed features; A calculation module, used for calculating the sum of comparison losses of all sample pairs included in the sample image set according to the preprocessing features; The calculation module is further used to calculate the sum of classification losses of all samples included in the sample image set according to the sample features; A training module, used for training the neural network model according to the sum of the comparison loss and the sum of the classification loss; The preprocessing feature is a feature distance corresponding to each sample pair included in the sample image set and a mask matrix of positive and negative sample pairs of the sample image set, and the calculation module is specifically used to sum the comparison losses of all positive sample pairs included in the sample image set to obtain the sum of the positive sample comparison losses; Summing the comparison losses of all negative sample pairs included in the sample image set to obtain the sum of the negative sample comparison losses; Summing the sum of the comparison losses of the positive samples and the sum of the comparison losses of the negative samples to obtain the sum of the comparison losses; Among them, for each positive sample pair included in the sample image set, the comparison loss of the positive sample pair is: the product of the parameters corresponding to the positive sample pair in the positive and negative sample pair mask matrix and the feature distance corresponding to the positive sample pair; for each negative sample pair included in the sample image set, the comparison loss of the negative sample pair is: the product of the parameters corresponding to the negative sample pair in the positive and negative sample pair mask matrix and the optimized value of the feature distance of the negative sample pair; the optimized value of the feature distance of the negative sample pair is: the larger value of the difference between the preset parameters and the feature distance corresponding to the negative sample pair and 0.
9. A fingerprint recognition device, characterized in that: The device comprises: A collection module, used for collecting fingerprints to be identified; The recognition module is used to input the fingerprint to be recognized into a neural network model obtained after training according to any training method in claims 1-6, and obtain an output result.
10. An electronic device, characterized in that: include: A memory and a processor, wherein the memory and the processor are connected; The memory is used to store programs; The processor calls the program stored in the memory to execute the method according to any one of claims 1 to 7.
11. A storage medium, characterized in that: A computer program is stored thereon, and when the computer program is executed by a computer, the method according to any one of claims 1 to 7 is executed.
