An adaptive anchor point matching method for face detection
Through the adaptive anchor point matching method, aiming at the limitations of anchor point matching in the existing technology, the encoding and training state estimators are used to adjust the matching threshold, which solves the problem of low training efficiency and accuracy of the face detection network and improves the detection performance. and robustness.
Patent Information
- Application Number
- CN202210277570.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-21
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2042-03-21
AI Technical Summary
The existing anchor-based single-stage face detection network ignores the intrinsic relationship between the anchor point and the target face when matching the anchor point, uses a fixed matching threshold and sets the anchor point size empirically, resulting in low training efficiency and detection accuracy. The rate is low, especially for small face detection.
An adaptive anchor point matching method is proposed. By encoding the target face and anchor points, scientifically setting the anchor point size, and constructing a training state estimator to adjust the matching threshold in real time, a flexible anchor point matching method is formed, which is suitable for human faces. and object detection networks.
It significantly improves the training efficiency and detection performance of the face detection network, enhances the robustness to faces of different sizes, and is applicable to all anchor-based detectors.
Smart Images

Figure CN114677729B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of face recognition, and in particular to an adaptive anchor point matching method for face detection. Background Art
[0002] Face detection is a basic image processing task in the field of computer vision. Many face-based biometric recognition algorithms require the use of face detection technology, such as face recognition, face alignment, face tracking, face attribute recognition, and age estimation. As a general detection algorithm, the performance of the face detector directly affects the performance of the subsequent face analysis algorithm.
[0003] In actual social production and life, face detection technology has a wide range of application scenarios, such as video surveillance systems, security systems, financial payment systems, public transportation systems, community access control systems, etc. Thanks to the development of deep convolutional neural networks (CNN), the performance of CNN-based face detection networks has been greatly improved. In recent years, the anchor-based single-stage face detection network has shown excellent performance advantages in speed and accuracy, and has gradually become the mainstream design of face detection networks. However, the existing anchor-based single-stage face detection network still has the following limitations when performing anchor matching: 1) The intrinsic connection between the anchor and the target face is ignored; 2) A fixed matching threshold is used, which cannot meet the changing needs of the face detection network for the target face during training;
[0004] 3) The existing anchor point size setting is based on experience, which leads to a large number of (more than 20%) tiny faces being ignored in the training data. Based on the above analysis, due to the limitations of the existing anchor point matching method, the training efficiency of the face detection network is low, which leads to the problem of low detection accuracy, especially for the detection of tiny faces. Therefore, how to overcome the defects of the existing anchor point matching method is still a problem to be solved.
[0005] Based on the above discussion, an adaptive anchor point matching method for face detection is invented, which has high practical application value. Summary of the invention
[0006] The purpose of the present invention is to overcome the shortcomings and deficiencies of the prior art, and proposes an adaptive anchor point matching method for face detection, which selectively matches appropriate anchor points for target faces of different sizes by encoding the target face and the anchor point; sets the anchor point size scientifically and accurately by statistically analyzing the training data and combining the differences in different feature scales in the face detection network; and adaptively adjusts the matching threshold of the anchor point in real time by constructing a training state estimator, thereby forming a set of flexible and adaptive anchor point matching methods. The adaptive anchor point matching method involved in the present invention can greatly improve the training efficiency of the face detection network and the final face detection performance. In addition, the present invention optimizes and improves the existing anchor point matching method, and is therefore suitable for the training of all anchor point-based detectors, including face detectors and object detectors.
[0007] To achieve the above object, the technical solution provided by the present invention is: an adaptive anchor point matching method for face detection, comprising the following steps:
[0008] 1) Prepare training data and build a face detection network;
[0009] The training data includes an input image X and annotation information Y containing a face, wherein the annotation information Y contains a target category Face frame coordinates and facial key point coordinates The subscript i represents the index of the i-th face in the input image;
[0010] The face detection network can process the input image X at three different feature scales and output prediction results at each feature scale, including category prediction Face box coordinate prediction And facial key point coordinate prediction Index representing feature scale; category predictions in three feature scales Merge to D cls , recorded as the total category prediction, face frame coordinate prediction in three feature scales Merge to D box , recorded as the total face frame coordinate prediction, the facial key point coordinate prediction in the three feature scales Denoted as the total facial key point coordinate prediction D lmk ; Among them, the prediction results of different feature scales have different spatial sizes, and the three types of predictions on the same feature scale have the same spatial size;
[0011] 2) Set anchor points, which have two attributes: center coordinates and size. For each feature scale, within a rectangular range determined by its spatial size, take each spatial position as the center, and use the preset length and width as the size, and lay A on each spatial position in sequence. l anchor points of different sizes; finally, according to each anchor point a j The center coordinates and size of the output bounding box j is the index of the anchor point, The anchor points a j The upper left corner horizontal coordinate, upper left corner vertical coordinate, lower right corner horizontal coordinate and lower right corner vertical coordinate of the bounding box; denoted by P l is the set of all anchor points on the lth feature scale;
[0012] 3) Start iteration: Selective target matching. First, according to the pre-set area thresholds T0 and T1, the coordinates of each face frame in step 1) are Encode and get the encoding Then according to each anchor point a in step 2) j The characteristic scale is encoded to obtain the encoding Next, calculate the coordinates of each face frame in turn With each anchor point a j The intersection over union (IoU) ij and their corresponding coded inner products Then, according to the anchor point a j Current IoU threshold h j , select IoU ij Matches greater than this threshold At the same time, add the face frame coordinates Related target categories Facial key point coordinates and the coded inner product Merge Output As a positive sample, record its number as N pos , remember the anchor point a in all positive samples j The index set is POS; finally, for the matching pairs that do not meet the IoU threshold, according to the IoU ij Sort it in descending order and select the first N neg Matching pairs As the negative sample output, record the anchor point a in all negative samples j The index set of is NEG;
[0013] 4) Send the input image X in step 1) to the face detection network for forward reasoning to obtain the total category prediction D cls , total face frame coordinate prediction D box And the total facial key point coordinate prediction Dlmk ; Due to the anchor point a j There is a one-to-one correspondence with each spatial position in the above prediction. According to the positive sample index set POS and the negative sample index set NEG in step 3), from D cls Filter out the positive and negative sample category prediction p j ,j∈{POS,NEG}, from D box Filter out the positive sample face frame coordinate prediction t j ,j∈POS and from D lmk Filter out the positive sample facial key point coordinates prediction m j , j∈POS; Finally, the key point regression loss L is calculated according to the pre-defined loss function lmk , face box regression loss L box and classification loss L cls , and output the total loss L;
[0014] 5) Adaptive IoU threshold adjustment, using the positive and negative sample categories in step 4) to predict p j ,j∈{POS,NEG} and its corresponding category label Calculate the number of samples N that the network predicts correctly in this iteration TP ; According to the positive sample index set POS, calculate the total number of positive samples in this iteration N P ; Finally, use the pre-defined IoU threshold adjustment function to calculate and update the IoU matching threshold of each anchor point in step 3) for target matching in the next iteration;
[0015] 6) According to the loss L in step 4), the parameters of the face detection network are optimized and updated using the gradient descent method; when the loss value is less than a preset threshold, the training is terminated; otherwise, steps 3) to 6) are repeated to enter the next round of iteration.
[0016] Furthermore, in step 1), to obtain the input image X, the images in the training data need to be preprocessed, including random cropping, random horizontal flipping, random color perturbation and normalization, and pixel and size normalization.
[0017] Furthermore, in step 1), the structure of the face detection network is as follows:
[0018] Input: Input image X;
[0019] Part 1: Residual convolution module Conv1;
[0020] Part 2: Residual convolution module Conv2;
[0021] Part 3: Residual convolution module Conv3, the output is recorded as C3;
[0022] Part 4: Residual convolution module Conv4, the output is recorded as C4;
[0023] Part 5: Residual convolution module Conv5, the output is recorded as C5;
[0024] Part 6: Feature pyramid module FPN, input is C3, C4 and C5, output is P3, P4 and P5;
[0025] Part 7: The end detection module contains three prediction branches with different feature scales and the same structure. The structure of the prediction branch l∈{1,2,3} is:
[0026] Input: P[l+2], indicating that the inputs of predicted branches 1, 2, and 3 are P3, P4, and P5 respectively;
[0027] First layer: feature enhancement module SSH;
[0028] The second layer: contains three sub-branches, namely: category prediction module, the output is The face frame coordinate prediction module outputs Facial key point coordinate prediction module, the output is
[0029] Furthermore, in step 2), the size of the anchor point is set according to the area size, aspect ratio and number of face samples in each area interval in the training data, and the size of the anchor points laid at different positions of each feature scale is the same.
[0030] Further, in step 3), the face frame coordinates The encoding calculation formula is:
[0031]
[0032] in, They are the upper left corner horizontal coordinate, upper left corner vertical coordinate, lower right corner horizontal coordinate and lower right corner vertical coordinate of the face frame respectively; is the area of the face frame; T0 and T1 are two pre-set area thresholds;
[0033] For anchor point a j The encoding calculation formula is:
[0034]
[0035] Among them, P1 is the set of all anchor points on the first characteristic scale, P2 is the set of all anchor points on the second characteristic scale, and P3 is the set of all anchor points on the third characteristic scale;
[0036] Anchor Point With face frame coordinates The calculation formula of intersection-over-union ratio is:
[0037]
[0038] in, Anchor point a j The area of ; ∩ and ∪ represent the intersection and union of the two respectively;
[0039] The screening rules for positive sample matching pairs are:
[0040]
[0041] Among them, h j Anchor point a j The matching threshold.
[0042] Further, in step 4), the calculation formula of the key point regression loss function is:
[0043]
[0044] Among them, m j is the network pair anchor point a j The key point coordinates prediction of the location, and is the anchor point a j The matched key point labels and face frame encodings come from the positive sample matching pairs in step 3). is the L1 loss function; α is a hyperparameter that controls the sample weight;
[0045] The calculation formula for face frame regression loss is:
[0046]
[0047] The calculation formula for classification loss is:
[0048]
[0049] Among them, f CE is the cross entropy loss function.
[0050] The calculation formula of total loss L is:
[0051] L=μ1L cls +μ2L lmk +μ3L box
[0052] Among them, μ1, μ2, and μ3 are hyperparameters used to control the weights of the above three losses.
[0053] Further, in step 5), the sample category prediction pj =(p′,p″) has two dimensions, p′ represents the predicted value belonging to a face, and p″ represents the predicted value not belonging to a face; first, from p j Filter out the tags that meet the corresponding category The prediction that p′>p″ is 1, the set of its indexes is TP (True Positive), and the number of elements in TP is counted, denoted as N TP ; Next, count the elements in the positive sample index set POS to get N P ; Finally, calculate and update the IoU threshold of each feature scale. The formula is as follows:
[0054]
[0055] in, represents the IoU threshold on the three feature scales after update, R 1×3 represents a real vector space of shape 1×3, and is the initial value and lower limit of the IoU threshold, and have the same dimensions; t (k) is the training state estimator, which is used to estimate the degree of fit of the network to the data; γ and η are the hyperparameters that control the upper and lower limits of the working range of the training state estimator; t (k) The calculation formula is:
[0056]
[0057] Among them, β is a hyperparameter that controls the update speed of the training state estimator, and k is the current number of iterations;
[0058] Anchor point a j The threshold h j The update rules are:
[0059] a j ∈P l
[0060] in, Indicates taking The lth element in, that is, first determine the anchor point a j The serial number l of the characteristic scale, and then according to the serial number from Determine the updated threshold h j .
[0061] Furthermore, in step 6), the total loss L obtained in step 4) is back-propagated, and the gradient values of various parameters of the face detection network are calculated using the gradient descent method, and finally the network parameters are optimized and updated; when the loss value is less than a preset threshold, the training is terminated; otherwise, steps 3) to 6) are repeated to enter the next round of iteration.
[0062] Compared with the prior art, the present invention has the following advantages and beneficial effects:
[0063] 1. The adaptive anchor point matching method of the present invention optimizes and improves the existing fixed anchor point matching method, which can greatly improve the training efficiency and detection performance of the face detector. In addition, the present invention is applicable to the training of other anchor point-based detectors, including face detectors and object detectors.
[0064] 2. The present invention adopts a selective target matching method and scientifically and accurately sets the anchor point size according to the statistical characteristics of the training data, which is conducive to the face detection network to make full use of target faces of different sizes, thereby improving its robustness under a wide range of face scale changes.
[0065] 3. The present invention uses an adaptive anchor point matching threshold adjustment method, which can automatically adjust the anchor point matching thresholds at different feature scales according to the current training status, such as the degree of fit of the face detection network to the data. This can meet the needs of the face detection network for different target faces at different training stages, and is conducive to further improving the network training efficiency and face detection performance. BRIEF DESCRIPTION OF THE DRAWINGS
[0066] Figure 1 It is a framework flow chart of the method of the present invention.
[0067] Figure 2 Structural diagram of the face detection network. DETAILED DESCRIPTION
[0068] The present invention is further described in detail below in conjunction with embodiments and drawings, but the embodiments of the present invention are not limited thereto.
[0069] See also Figure 1 and Figure 2 As shown, this embodiment provides an adaptive anchor point matching method for face detection, comprising the following steps:
[0070] 1) Prepare training data and build a face detection network;
[0071] The face detection dataset selected for training is WIDER FACE, which collects 32,203 images, including 393,703 faces with annotation information Y. The annotation information of the i-th face includes the target category Face frame coordinates Contains the horizontal and vertical coordinates of the upper left and lower right corners of the face frame; facial key point coordinates Contains the horizontal and vertical coordinates of the positions of the five key points of the eyes, nose tip and mouth corners, R represents the real vector space; to obtain the input image X, it is necessary to preprocess the images in the training data, including random cropping, random horizontal flipping, random color perturbation and normalization, and pixel and size normalization. Among them, the specific details of random cropping are: first, a square block is cropped from the original image at a certain scaling rate (randomly selected from [0.3, 0.45, 0.6, 0.8, 1.0]), and then the block is scaled to 840×840. The three RGB color channels are normalized to [104, 117, 123];
[0072] Construct a face detection network that can process the input image X at three different feature scales and output prediction results at each feature scale, including category prediction Face box coordinate prediction And facial key point coordinate prediction Index representing feature scale; category predictions in three feature scales Merge to D cls , recorded as the total category prediction, face frame coordinate prediction in three feature scales Merge to D box , recorded as the total face frame coordinate prediction, the facial key point coordinate prediction in the three feature scales Denoted as the total facial key point coordinate prediction D lmk ; Among them, the prediction results of different feature scales have different spatial sizes, and the three types of predictions on the same feature scale have the same spatial size; such as Figure 2 As shown, the specific structure of the face detection network is as follows:
[0073] Input: Input image X, shape is 840×840×3;
[0074] Part 1: Residual convolution module Conv1, the output shape is 420×420×64;
[0075] Part 2: Residual convolution module Conv2, with an output shape of 210×210×256;
[0076] Part 3: Residual convolution module Conv3, the output is denoted as C3, and the shape is 105×105×512;
[0077] Part 4: Residual convolution module Conv4, the output is denoted as C4, and the shape is 53×53×1024;
[0078] Part 5: Residual convolution module Conv5, the output is recorded as C5, and the shape is 27×27×2048;
[0079] Part 6: Feature pyramid module FPN, input is C3, C4 and C5, output is P3, P4 and P5, the shapes are 105×105×512, 53×53×1024, 27×27×2048 respectively;
[0080] Part 7: The end detection module contains three prediction branches with different feature scales and the same structure. The structure of the prediction branch l∈{1,2,3} is:
[0081] Input: P[l+2], indicating that the inputs of predicted branches 1, 2, and 3 are P3, P4, and P5 respectively; its shape is recorded as W l ×W l ×C l , where W l and C l denote the spatial size and number of channels of P[l+2] respectively;
[0082] First layer: feature enhancement module SSH, output shape is W l ×W l ×256;
[0083] The second layer: contains three sub-branches, namely: category prediction module, the output is Shape is W l ×W l ×A l ×2; face frame coordinate prediction module, the output is Shape is W l ×W l ×A l ×4; facial key point coordinate prediction module, the output is Shape is W l ×W l ×A l ×10.A l The number of anchor points laid out at each position of the feature scale.
[0084] 2) Set the anchor point, which has two attributes: center coordinates and size; for each feature scale, in a rectangular range W determined by its spatial size l ×W l With each space position as the center and the preset length and width as the size, A is laid in each space position in sequence. l anchor points of different sizes; finally, according to each anchor point a j The center coordinates and size of the output bounding box j is the index of the anchor point, The anchor points a j The upper left corner horizontal coordinate, upper left corner vertical coordinate, lower right corner horizontal coordinate and lower right corner vertical coordinate of the bounding box; denoted by P l is the set of all anchor points on the lth feature scale; the size of the anchor points is set according to the face area, aspect ratio and number of face samples in each area interval in the training data, and the sizes of the anchor points laid at different positions on each feature scale are the same;
[0085] After statistical analysis of the training data WIDER FACE, the anchor point size of feature scale 1 is set to [8, 16, 32], that is, A1=3 anchor points are laid at each spatial position of the feature scale, and the shape is square; the anchor point size of feature scale 2 is set to [64, 128], A2=2, and the shape is square; the anchor point size of feature scale 3 is set to [256, 512], A3=2, and the shape is square.
[0086] 3) Start iteration; Selective target matching. First, according to the pre-set area thresholds T0 and T1, the coordinates of each face frame in step 1) are Encode and get the encoding Then according to each anchor point a in step 2) j The characteristic scale is encoded to obtain the encoding Next, calculate the coordinates of each face frame in turn With each anchor point a j The intersection over union (IoU) ij and their corresponding coded inner products Then, according to the anchor point a j Current IoU threshold h j , select IoU ij Matches greater than this threshold At the same time, add the face frame coordinates Related target categories Facial key point coordinates and the coded inner product Merge Output As a positive sample, record its number as N pos , remember the anchor point a in all positive samples j The index set is POS; finally, for the matching pairs that do not meet the IoU threshold, according to the IoU ij Sort it in descending order and select the first N neg =8N pos Matching pairs As the negative sample output, record the anchor point a in all negative samples j The index set is NEG.
[0087] Specifically, for the face frame coordinates The encoding calculation formula is:
[0088]
[0089] in, They are the upper left corner horizontal coordinate, upper left corner vertical coordinate, lower right corner horizontal coordinate and lower right corner vertical coordinate of the face frame respectively; is the area of the face frame; by statistically analyzing the training data, the area thresholds T0=2048 and T1=32768 are set;
[0090] For anchor point a j The encoding calculation formula is:
[0091]
[0092] Among them, P1 is the set of all anchor points on the first characteristic scale, P2 is the set of all anchor points on the second characteristic scale, and P3 is the set of all anchor points on the third characteristic scale;
[0093] Anchor Point With face frame coordinates The calculation formula of intersection-over-union ratio is:
[0094]
[0095] in, Anchor point a j The area of ; ∩ and ∪ represent the intersection and union of the two respectively;
[0096] The screening rules for positive sample matching pairs are:
[0097]
[0098] Among them, h j Anchor point a j Here h is the matching threshold. j It changes adaptively according to the degree of fit of the network to the data.
[0099] 4) Send the input image X in step 1) to the face detection network for forward reasoning to obtain the total category prediction D cls , total face frame coordinate prediction D box And the total facial key point coordinate prediction D lmk ; Due to the anchor point a j There is a one-to-one correspondence with each spatial position in the above prediction. According to the positive sample index set POS and the negative sample index set NEG in step 3), from D cls Filter out the positive and negative sample category prediction p j,j∈{POS,NEG}, from D box Filter out the positive sample face frame coordinate prediction t j ,j∈POS and from D lmk Filter out the positive sample facial key point coordinates prediction m j , j∈POS; Finally, the key point regression loss L is calculated according to the pre-defined loss function lmk , face box regression loss L box and classification loss L cls , and output the total loss L;
[0100] Specifically, the calculation formula of the key point regression loss function is:
[0101]
[0102] Among them, m j is the network pair anchor point a j The key point coordinates prediction of the location, and is the anchor point a j The matched key point labels and face frame encodings come from the positive sample matching pairs in step 3). is the L1 loss function; α=1.2 is a hyperparameter that controls the sample weight;
[0103] The calculation formula for face frame regression loss is:
[0104]
[0105] The calculation formula for classification loss is:
[0106]
[0107] Among them, f CE is the cross entropy loss function.
[0108] The calculation formula of total loss L is:
[0109] L=μ1L cls +μ2L lmk +μ3L box
[0110] Among them, μ1=1.0, μ2=1.0, μ3=2.0 are hyperparameters used to control the weights of the above three losses.
[0111] 5) Adaptive IoU threshold adjustment, using the positive and negative sample categories in step 4) to predict p j ,j∈{POS,NEG} and its corresponding category label Calculate the number of samples N that the network predicts correctly in this iterationTP ; According to the positive sample index set POS, calculate the total number of positive samples in this iteration N P ; Finally, use the pre-defined IoU threshold adjustment function to calculate and update the IoU matching threshold of each anchor point in step 3) for target matching in the next iteration;
[0112] Specifically, the sample category prediction p j =(p′,p″) has two dimensions, p′ represents the predicted value belonging to a face, and p″ represents the predicted value not belonging to a face; first, from p j Filter out the tags that meet the corresponding category The prediction that p′>p″ is 1, the set of its indexes is TP (True Positive), and the number of elements in TP is counted, denoted as N TP ; Next, count the elements in the positive sample index set POS to get N P ; Finally, calculate and update the IoU threshold of each feature scale. The formula is as follows:
[0113]
[0114] in, represents the IoU threshold on the three feature scales after update, R 1×3 Represents a real vector space with a shape of 1×3; sets the initial value of the IoU threshold and lower limit and have the same dimensions; t (k) The training state estimator is used to estimate the degree of fit of the network to the data; the hyperparameters γ=0.2 and η=0.7 are set to control the upper and lower limits of the working range of the training state estimator; t (k) The calculation formula is:
[0115]
[0116] Among them, β = 0.99 is a hyperparameter that controls the update speed of the training state estimator, and k is the current number of iterations;
[0117] Anchor point a j The threshold h j The update rules are:
[0118] a j ∈P l
[0119] in, Indicates taking The lth element in, that is, first determine the anchor point a jThe serial number l of the characteristic scale, and then according to the serial number from Determine the updated threshold h j .
[0120] 6) According to the loss L in step 4), select the learning rate as 5e-4, and use the stochastic gradient descent (SGD) method to optimize and update the parameters of the face detection network. When the total loss L is less than 5.0, the training is terminated; otherwise, repeat steps 3) to 6) to enter the next round of iteration.
[0121] The above embodiments are preferred implementation modes of the present invention, but the implementation modes of the present invention are not limited to the above embodiments. Any other changes, modifications, substitutions, combinations, and simplifications that do not deviate from the spirit and principles of the present invention should be equivalent replacement methods and are included in the protection scope of the present invention.
Claims
1. An adaptive anchor point matching method for face detection, characterized in that: The following steps are involved: 1) Prepare training data and build a face detection network; The training data includes an input image X and annotation information Y containing a face, wherein the annotation information Y contains a target category Face frame coordinates and facial key point coordinates The subscript i represents the index of the i-th face in the input image; The face detection network can process the input image X at three different feature scales and output prediction results at each feature scale, including category prediction Face box coordinate prediction And facial key point coordinate prediction An index representing the feature scale; Class prediction in three feature scales Merge to D cls , recorded as the total category prediction, face frame coordinate prediction in three feature scales Merge to D box , recorded as the total face frame coordinate prediction, the facial key point coordinate prediction in the three feature scales Denote as the total facial key point coordinate prediction D lmk ; Among them, the prediction results of different feature scales have different spatial sizes, and the three types of predictions on the same feature scale have the same spatial size; The structure of the face detection network is as follows: Input: Input image X; Part 1: Residual convolution module Conv1; Part 2: Residual convolution module Conv2; Part 3: Residual convolution module Conv3, the output is recorded as C3; Part 4: Residual convolution module Conv4, the output is recorded as C4; Part 5: Residual convolution module Conv5, the output is recorded as C5; Part 6: Feature pyramid module FPN, input is C3, C4 and C5, output is P3, P4 and P5; Part 7: The end detection module contains three prediction branches with different feature scales and the same structure. The structure of the prediction branch l∈{1,2,3} is: Input: P[l+2], indicating that the inputs of predicted branches 1, 2, and 3 are P3, P4, and P5 respectively; First layer: feature enhancement module SSH; The second layer: contains three sub-branches, namely: category prediction module, the output is The face frame coordinate prediction module outputs Facial key point coordinate prediction module, the output is 2) Set anchor points, which have two attributes: center coordinates and size. For each feature scale, within a rectangular range determined by its spatial size, take each spatial position as the center, and use the preset length and width as the size, and lay A on each spatial position in sequence. l anchor points of different sizes; finally, according to each anchor point a j The center coordinates and size of the output bounding box j is the index of the anchor point, The anchor points a j The upper left corner horizontal coordinate, upper left corner vertical coordinate, lower right corner horizontal coordinate and lower right corner vertical coordinate of the bounding box; denoted by P l is the set of all anchor points on the lth feature scale; 3) Start iteration: Selective target matching. First, according to the pre-set area thresholds T0 and T1, the coordinates of each face frame in step 1) are Encode and get the encoding Then according to each anchor point a in step 2) j The characteristic scale is encoded to obtain the encoding Next, calculate the coordinates of each face frame in turn With each anchor point a j The intersection over union (IoU) ij and their corresponding coded inner products Then, according to the anchor point a j Current IoU threshold h j , select IoU ij Matches greater than this threshold At the same time, add the face frame coordinates Related target categories Facial key point coordinates and the coded inner product Merge Output As a positive sample, record its number as N pos , remember the anchor point a in all positive samples j The index set is POS; finally, for the matching pairs that do not meet the IoU threshold, according to the IoU ij Sort it in descending order and select the first N neg Matching pairs As the negative sample output, record the anchor point a in all negative samples j The index set of is NEG; Face frame coordinates The encoding calculation formula is: in, They are the upper left corner horizontal coordinate, upper left corner vertical coordinate, lower right corner horizontal coordinate and lower right corner vertical coordinate of the face frame respectively; is the area of the face frame; T0 and T1 are two pre-set area thresholds; For anchor point a j The encoding calculation formula is: Among them, P1′ is the set of all anchor points on the first characteristic scale, P2′ is the set of all anchor points on the second characteristic scale, and P′3 is the set of all anchor points on the third characteristic scale; Anchor Point With face frame coordinates The calculation formula of intersection-over-union ratio is: in, Anchor point a j The area of ; ∩ and ∪ represent the intersection and union of the two respectively; The screening rules for positive sample matching pairs are: Among them, h j Anchor point a j The matching threshold of 4) Send the input image X in step 1) to the face detection network for forward reasoning to obtain the total category prediction D cls , total face frame coordinate prediction D box And the total facial key point coordinate prediction D lmk ; Due to the anchor point a j There is a one-to-one correspondence with each spatial position in the prediction. According to the positive sample index set POS and the negative sample index set NEG in step 3), from D cls Filter out the positive and negative sample category prediction p j ,j∈{POS,NEG}, from D box Filter out the positive sample face frame coordinate prediction t j ,j∈POS and from D lmk Filter out the positive sample facial key point coordinates prediction m j , j∈POS; Finally, the key point regression loss L is calculated according to the pre-defined loss function lmk , face box regression loss L box and classification loss L cls , and output the total loss L; The calculation formula of the key point regression loss function is: Among them, m j is the network anchor point a j The key point coordinates of the location are predicted, and Positive sample matching pairs from step 3) f L1 is the L1 loss function; α is a hyperparameter that controls the sample weight; The calculation formula for face frame regression loss is: The calculation formula for classification loss is: Among them, f CE is the cross entropy loss function; The calculation formula of total loss L is: L=μ1L cls +μ2L lmk +μ3L box Among them, μ1, μ2, and μ3 are hyperparameters used to control the three loss weights; 5) Adaptive IoU threshold adjustment, using the positive and negative sample categories in step 4) to predict p j ,j∈{POS,NEG} and its corresponding category label Calculate the number of samples N that the network predicts correctly in this iteration TP ; According to the positive sample index set POS, calculate the total number of positive samples in this iteration N P ; Finally, use the pre-defined IoU threshold adjustment function to calculate and update the IoU matching threshold of each anchor point in step 3) for target matching in the next iteration; Sample category prediction p j =(p′,p″) has two dimensions, p′ represents the predicted value belonging to a face, and p″ represents the predicted value not belonging to a face; first, from p j Filter out the tags that meet the corresponding category The prediction of p′>p″ is 1, and the set of its indexes is TP, and the number of elements in TP is counted, denoted by N TP ; Next, count the elements in the positive sample index set POS to get N P ; Finally, calculate and update the IoU threshold of each feature scale. The formula is as follows: in, represents the IoU threshold on the three feature scales after update, R 1×3 represents a real vector space of shape 1×3, and is the initial value and lower limit of the IoU threshold, and have the same dimensions; t (k) is the training state estimator, which is used to estimate the degree of fit of the network to the data; γ and η are the hyperparameters that control the upper and lower limits of the working range of the training state estimator; t (k) The calculation formula is: Among them, β is a hyperparameter that controls the update speed of the training state estimator, and k is the current number of iterations; Anchor point a j The threshold h j The update rules are: in, Indicates taking The lth element in, that is, first determine the anchor point a j The serial number l of the characteristic scale, and then according to the serial number from Determine the updated threshold h j ; 6) According to the loss L in step 4), the parameters of the face detection network are optimized and updated using the gradient descent method; when the loss value is less than a preset threshold, the training is terminated; otherwise, steps 3) to 6) are repeated to enter the next round of iteration.
2. According to claim 1, an adaptive anchor point matching method for face detection is characterized in that, in step 1), to obtain the input image X, the images in the training data need to be preprocessed, including random cropping, random horizontal flipping, random color perturbation and normalization, and pixel and size normalization.
3. According to the adaptive anchor point matching method for face detection described in claim 1, it is characterized in that, in step 2), the size of the anchor point is set according to the area size, aspect ratio and number of face samples in each area interval in the training data, and the size of the anchor points laid at different positions of each feature scale is the same.
4. According to claim 1, an adaptive anchor point matching method for face detection is characterized in that, in step 6), the total loss L obtained in step 4) is back-propagated, and the gradient value of each parameter of the face detection network is calculated using the gradient descent method, and finally the network parameters are optimized and updated; when the loss value is less than a preset threshold, the training is terminated; otherwise, steps 3) to 6) are repeated to enter the next round of iteration.
