Face target detection method based on improved YOLOv8
By introducing the DAttention and AIFI modules, as well as the TSACLoss function, into the YOLOv8 network, the accuracy and precision of face target detection are improved, and the problem of detecting dense small face targets is solved.
Patent Information
- Application Number
- CN202510294889.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-13
- Publication Date
- 2025-11-11
- Estimated Expiration
- 2045-03-13
AI Technical Summary
Existing technologies suffer from problems such as poor localization, false positives and false negatives, and insufficient detection accuracy when detecting dense small faces in complex scenarios.
In the YOLOv8 network model, a deformable attention mechanism, DAttention, is introduced to improve the feature fusion module C2f in the backbone network. The spatial pyramid pooling module SPPF is replaced by an attention-based intra-scale feature interaction network, AIFI. A translation-sensitive angle-constrained loss function, TSACLoss, is proposed to optimize the localization of detected targets.
It improves the accuracy and precision of face detection, especially in the detection of dense small face targets, significantly reducing the false negative rate and false positive rate.
Smart Images

Figure CN120088835B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of deep learning and object detection, and in particular to a face object detection method based on an improved YOLOv8. Background Technology
[0002] In the field of computer vision, face detection is an important research direction, dedicated to accurately identifying and locating faces from complex image or video data. With the deep integration of security monitoring, mobile device applications, and face recognition technology, the demand for accurate face recognition and detection is growing rapidly. Currently, mainstream object detection algorithms in deep learning can be divided into two main categories: two-stage detection algorithms and one-stage detection algorithms.
[0003] Two-stage algorithms typically achieve high detection accuracy but suffer from slower detection speeds. Representative two-stage algorithms include R-CNN, Faster R-CNN, and Mask R-CNN. Representative one-stage algorithms include YOLO, SSD, and RetinaNet. One-stage algorithms directly predict objects and bounding boxes within the network, sacrificing some accuracy for faster detection. YOLO is an end-to-end detection algorithm known for its fast detection speed and compact model size. Although its accuracy is lower than two-stage algorithms like Faster R-CNN, it has significant advantages in scenarios with high real-time requirements and limited computational resources.
[0004] Traditional face detection algorithms mostly utilize bounding box detection mechanisms. However, if the IoU value is too low, small faces may be mistaken for background and missed. Algorithms such as designing multi-scale feature fusion networks, constructing attention modules to reduce background interference, and establishing contextual association models can further improve face detection accuracy. While these algorithms demonstrate high performance in most face detection tasks, they still suffer from numerous false positives and false negatives when dealing with densely packed small faces in complex scenes. Therefore, face detection models require further optimization and improvement. Summary of the Invention
[0005] Purpose of the invention: The technical problem to be solved by the present invention is to provide a face target detection method based on an improved YOLOv8 to address the shortcomings of the existing technology, thereby solving the problems of poor localization, false detection and missed detection, and insufficient detection accuracy of the existing technology when dealing with dense small face targets in complex scenes.
[0006] This invention, based on the original YOLOv8 network model, introduces a deformable attention mechanism, DAttention, to improve the feature fusion module C2f in the backbone network, making the network more focused on key facial information; it replaces the spatial pyramid pooling module SPPF with an attention-based intra-scale feature interaction network, AIFI, to improve feature extraction efficiency; and it proposes a translation-sensitive angle-constrained loss function to optimize the model for target localization. The method includes the following steps:
[0007] Step 1: Using a face dataset, if the face dataset has provided a training set and a validation set, select the training set and validation set for use; otherwise, divide the training set and validation set into a 4:1 ratio, convert all labels of the training set and validation set into YOLO format, and assign them all to the face category, i.e., the face category.
[0008] Step 2: Construct and train the improved YOLOv8 network model, which includes a backbone network, a neck network, and a head network.
[0009] The training set images are preprocessed and then input into the backbone network to obtain feature maps of three different sizes.
[0010] Step 3: Input the feature maps of the three different sizes into the neck network, and perform feature fusion in two ways, bottom-up and top-down, based on the feature pyramid network FPN and the path aggregation network PAN, to obtain the fused feature map.
[0011] Step 4: Use the detection head in the head network to predict the fused feature map, generate the target category and bounding box location, and use Non-Maximum Suppression (NMS) to remove overlapping predicted boxes to obtain the final detection result; During the training process, the validation set is used for validation simultaneously, and the model evaluation index is calculated after each round of training, and the model weights are selected based on the model evaluation index.
[0012] Step 1 includes: For the face dataset, create a folder structure in the YOLO format, put the image data and text labels from the training and validation sets into the corresponding folders, write a script to convert the face dataset into YOLO format, and unify the category number of the target object as face:0.
[0013] Step 2 includes:
[0014] Step 2.1: Adjust the size of the images in the training set to 640×640 (it can also be 480×480 or 800×800, but 640×640 can achieve a good balance between computational resource consumption and feature extraction accuracy), check that the channel order of the images is red, green, blue, RGB, process the images using the Mosaic data augmentation method, and then input them into the backbone network.
[0015] Step 2.2: The backbone network is reconstructed through the attention-weighted feature fusion module C2f_DA and the attention-based intrascale feature interaction module AIFI. The reconstructed backbone network includes a convolution module, a feature fusion module, an attention-weighted feature fusion module and an intrascale feature interaction module.
[0016] There are 6 convolutional modules, namely the first convolutional module, the second convolutional module, the third convolutional module, the fourth convolutional module, the fifth convolutional module and the sixth convolutional module; and there are 3 feature fusion modules, namely the first feature fusion module, the second feature fusion module and the third feature fusion module.
[0017] In this system, the first convolutional module, the second convolutional module, and the first feature fusion module are connected in series to form a basic feature extraction link. Subsequently, the third convolutional module and the second feature fusion module are connected in series, and the system is repeatedly stacked through the fourth convolutional module and the third feature fusion module to achieve progressive downsampling. The fifth convolutional module is connected in series with the attention-weighted feature fusion module, and the output is compressed by the sixth convolutional module and input to the intra-scale feature interaction module. The intra-scale feature interaction module enhances global semantics through multi-head self-attention and finally performs a residual connection with the output of the attention-weighted feature fusion module. The second and third feature fusion modules directly transfer shallow high-resolution features to the deep neck network through cross-layer skip connections.
[0018] The six convolutional modules are used for basic feature extraction and channel dimension adjustment;
[0019] The three feature fusion modules are used for multi-scale feature fusion;
[0020] The attention-weighted feature fusion module uses the deformable attention mechanism DAttention with 8 attention heads by default, each capturing features from different subspaces. The output formula is as follows:
[0021] ,
[0022] in, This represents the output of the m-th attention head. This represents the softmax function. This indicates a query for the embedding of the m-th attention head. This represents the transformed key value. This represents the dimension of each attention head. Represents the sampling function. These are the sampling grid coordinates. It is a dynamic offset. Indicates the value after transformation;
[0023] Furthermore, a fixed-position encoding table is used to explicitly learn the spatial relationship between queries and key values, compensating for long-distance dependencies that might be ignored by dynamic offsets. The fixed-position encoding table follows an expectation of 0 and a variance of 0.01. 2 It follows a normal distribution and satisfies:
[0024] ,
[0025] in, This represents a fixed-position coding table. It is a three-dimensional tensor. It is the query sequence length. It is the length of the key-value sequence;
[0026] The attention-weighted feature fusion module first processes the input data through convolution, then segments the data and feeds it into two or more residual blocks that incorporate the deformable attention mechanism DAttention to achieve different levels of attention weighting and feature fusion. Finally, the outputs of the residual blocks are spliced together, which helps to solve the problem of dense small face feature confusion and high false negative rate caused by the fixed sampling grid in the feature fusion module.
[0027] Specifically, a 1×1 sixth convolutional module is added after the attention-weighted feature fusion module to adapt to the intra-scale feature interaction module. The feature map output by the attention-weighted feature fusion module is 20×20×1024 in size. After being compressed to 256 channels by the 1×1 sixth convolutional module, the 20×20×256 feature map is flattened by the intra-scale feature interaction module to become 400×256. Spatial information is enhanced by two-dimensional sine and cosine position coding. Interaction features are learned using a multi-head self-attention mechanism and a feedforward network. Finally, the output feature map size is restored to 20×20×1024. The attention-weighted feature fusion module and the intra-scale feature interaction module are cascaded to achieve a two-stage feature extraction from local deformation perception to global semantic enhancement.
[0028] Step 2.3: Extract feature information from the fifth, seventh, and eleventh layers of the backbone network to obtain feature maps of three different sizes, namely 80×80, 40×40, and 20×20.
[0029] Step 3 includes:
[0030] Step 3.1, the neck network includes a feature fusion module and a convolution module;
[0031] The neck network has four feature fusion modules: the fourth feature fusion module, the fifth feature fusion module, the sixth feature fusion module, and the seventh feature fusion module; the neck network has two convolutional modules: the seventh convolutional module and the eighth convolutional module.
[0032] The fourth and fifth feature fusion modules are used in the Feature Pyramid Network (FPN). Starting from a 20×20 feature map, after upsampling, the feature map is connected across layers with the third feature fusion module. The result is then output to the fourth feature fusion module. After upsampling, the fourth feature fusion module is connected across layers with the second feature fusion module. The result is then output to the fifth feature fusion module, thus completing bottom-up feature fusion and enhancing semantic information.
[0033] The sixth and seventh feature fusion modules are used in the path aggregation network PAN. Starting from an 80×80 feature map, downsampling is achieved through the seventh convolution module, which is connected across layers with the fourth feature fusion module. The result is output to the sixth feature fusion module. The sixth feature fusion module is downsampled through the eighth convolution module, which is connected across layers with the intra-scale feature interaction module. The result is output to the seventh feature fusion module, completing top-down feature fusion and refining the localization.
[0034] The two convolutional modules are used for feature dimension alignment;
[0035] Step 3.2: During the fusion process of the four feature fusion modules, feature maps of different resolutions undergo convolution, upsampling, downsampling and element-wise addition more than twice, and finally form optimized feature maps of three sizes: 80×80, 40×40 and 20×20, and output the optimized feature maps.
[0036] Step 4 includes:
[0037] Step 4.1, the head network includes convolutional modules and convolutional layers;
[0038] The head network has 6 convolutional modules and 6 convolutional layers. The 6 convolutional modules and 6 convolutional layers correspond one-to-one and are connected in series.
[0039] The convolutional module and convolutional layer are used to generate bounding box predictions and classification predictions;
[0040] Step 4.2: Based on a predetermined threshold (usually 0.25), filter out predicted bounding boxes with a confidence level less than the threshold in the predicted feature map; then use Non-Maximum Suppression (NMS) to remove redundant predicted bounding boxes, retaining the predicted bounding boxes most likely to contain the target object. The formula for NMS is:
[0041] ,
[0042] in, This represents the score of the i-th predicted box. Represents the prediction box With the i-th prediction box The crossover ratio between them It is the prediction box with the highest score. This represents the i-th prediction box. This represents the threshold value, typically 0.7; i ranges from 1 to K. This indicates the number of prediction boxes in the current batch;
[0043] Step 4.3: After obtaining the predicted bounding boxes filtered by Non-Maximum Suppression (NMS), calculate the loss value between the predicted and ground truth bounding boxes. This loss value includes the object classification loss and the bounding box regression loss. An angle-constrained intersection-union ratio (TAIoU) loss across spatial translation is designed to optimize the bounding box regression loss. The formula for TAIoU is:
[0044] ,
[0045] The TAIoU includes the translation-sensitive angular constraint loss function TSACLoss (TSACLoss) and the intersection-over-union (IoU) index; wherein, the formula for the translation-sensitive angular constraint loss function TSACLoss is:
[0046] ,
[0047] ,
[0048] ,
[0049] in, Indicates angle loss, This represents the difference in width between the predicted bounding box and the ground truth bounding box. and These represent the top-left and bottom-left vertices of the actual bounding box, respectively. and These represent the top-left and bottom-left vertices of the prediction box, respectively. yes Point and Vertical distance difference between points yes Point and Vertical distance difference between points The translation distance d is represented by... Click Vector of a point The translation distance d is represented by... Click Vector of a point The translation distance d is represented by... Click Vector of a point TSACLoss is the width of the true bounding box, and TSACLoss is the angle constraint loss value.
[0050] The The vertical offset between the predicted bounding box and the ground truth bounding box is penalized to ensure target alignment. To further constrain width consistency, the key to TSACLoss lies in breaking through the single-image spatial constraint, introducing a translation matching space, and determining the specific translation distance through experiments to achieve more accurate loss value calculation.
[0051] The present invention also provides an electronic device, including a processor and a memory, the memory storing program code that, when executed by the processor, causes the processor to perform the steps of the method.
[0052] The present invention also provides a storage medium storing a computer program or instructions that, when the computer program or instructions are run on a computer, execute the steps of the method described.
[0053] Compared with existing technologies, the beneficial effects of this invention are as follows: 1. This invention optimizes the YOLOv8 network structure. Addressing the shortcomings of YOLOv8 in detecting dense small faces, it introduces DAttention to improve the feature fusion module C2f in the backbone network. By adjusting the attention weights, it better captures the subtle features of small targets, enabling the network to achieve precise focusing. AIFI is used instead of SPPF to improve the efficiency and targeting of feature extraction. 2. This invention proposes a translation-sensitive angle-constrained loss function, TSACLoss, and combines it with IoU to obtain the TAIoU bounding box loss function, replacing the original model's CIoU. TSACLoss breaks away from the traditional method of measuring bounding box overlap from the same image space, using translation distance as a constraint and considering the geometric angle relationship of the bounding box vertices, thus addressing the shortcomings of IoU. Compared to CIoU, TAIoU can optimize the localization of predicted boxes, improve the quality of the boxes, and thereby improve the detection accuracy of the network model. Attached Figure Description
[0054] Figure 1 This is a structural diagram of the improved YOLOv8 network model of this invention.
[0055] Figure 2This is a structural diagram of the attention-weighted feature fusion module in the backbone network of this invention.
[0056] Figure 3 This is a structural diagram of the intra-size feature interaction module in the backbone network of this invention.
[0057] Figure 4 This is a schematic diagram illustrating the principle of the translation-sensitive angle constraint loss function proposed in this invention.
[0058] Figure 5 This is a curve comparison of the original model and various improved modules on the evaluation metrics during the training process of this invention. Detailed Implementation
[0059] The present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments, and the advantages of the present invention as described above or otherwise will become clearer.
[0060] This embodiment provides a face target detection method based on an improved YOLOv8. Building upon the original YOLOv8 network model, it introduces DAttention to improve the feature fusion module C2f in the backbone network, making the network more focused on key facial information; it uses AIFI instead of SPPF to improve feature extraction efficiency; and it proposes a TSACLoss optimization model for target localization. The overall network model of the improved YOLOv8 is as follows: Figure 1 As shown, the input image passes through the backbone network, neck network, and head network sequentially, and the output detection results are displayed. The structure of the attention-weighted feature fusion module (C2f_DA) is as follows: Figure 2 As shown, the input data is first pre-processed through a convolutional module, then segmented and fed into multiple attention-weighted residual blocks, and finally the outputs are concatenated; the Intra-Scale Feature Interaction (AIFI) module is as follows: Figure 3 As shown, it mainly employs two-dimensional sine and cosine position encoding and a multi-head attention mechanism; the principle of the translation-sensitive angle-constrained loss function (TSACLoss) is as follows. Figure 4 As shown, the optimization effect of controlling the angle loss with translation amount on target localization is not limited to the original image space; the evaluation index curves of various training processes are shown in the figure. Figure 5 As shown.
[0061] The improved YOLOv8 network model was built and trained using the PyTorch framework. The dataset used was the challenging WIDER FACE dataset. The optimizer was SGD, with an initial learning rate of 0.01 and a momentum optimization parameter of 0.005. The training batch size was 8, and the total training time was 250 epochs. The method includes the following steps:
[0062] Step 1: Use the publicly available large-scale face dataset WIDER FACE. WIDER FACE provides a training set containing 12,880 images and a test set containing 3,226 images. Convert all labels from the training and validation sets to YOLO format and assign them all to the "face" category, i.e., the face category. The specific steps are as follows:
[0063] Step 1.1: For WIDER FACE, create a folder structure in the YOLO format, put the image data and text labels from the training and validation sets into the corresponding folders, and write a script to convert the face dataset into YOLO format, unifying the category number of the target object as face:0.
[0064] Step 2: Construct and train the improved YOLOv8 network model, which includes a backbone network, a neck network, and a head network. The training set images are preprocessed and then input into the backbone network to obtain feature maps of three different sizes. The specific steps are as follows:
[0065] Step 2.1: Adjust the image size in the training set to 640×640, check that the channel order of the image is red, green, blue, RGB, process the image using the Mosaic data augmentation method, and then input it into the backbone network;
[0066] Step 2.2: The backbone network is reconstructed through the attention-weighted feature fusion module C2f_DA and the attention-based intra-scale feature interaction module AIFI. The reconstructed backbone network includes a convolution module, a feature fusion module, an attention-weighted feature fusion module, and an intra-scale feature interaction module.
[0067] There are 6 convolutional modules, namely the first convolutional module, the second convolutional module, the third convolutional module, the fourth convolutional module, the fifth convolutional module and the sixth convolutional module; and there are 3 feature fusion modules, namely the first feature fusion module, the second feature fusion module and the third feature fusion module.
[0068] In this system, the first convolutional module, the second convolutional module, and the first feature fusion module are connected in series to form a basic feature extraction link. Subsequently, the third convolutional module and the second feature fusion module are connected in series, and the system is repeatedly stacked through the fourth convolutional module and the third feature fusion module to achieve progressive downsampling. The fifth convolutional module is connected in series with the attention-weighted feature fusion module, and its output is compressed by the sixth convolutional module and input to the intra-scale feature interaction module. The intra-scale feature interaction module enhances global semantics through multi-head self-attention and finally performs a residual connection with the output of the attention-weighted feature fusion module. The second and third feature fusion modules directly transfer shallow high-resolution features to the deep neck network through cross-layer skip connections.
[0069] The six convolutional modules are used for basic feature extraction and channel dimension adjustment;
[0070] The three feature fusion modules are used for multi-scale feature fusion;
[0071] The attention-weighted feature fusion module uses the deformable attention mechanism DAttention with 8 attention heads by default, each capturing features from different subspaces. The output formula is as follows:
[0072] ,
[0073] in, This represents the output of the m-th attention head. This represents the softmax function. This indicates a query for the embedding of the m-th attention head. This represents the transformed key value. This represents the dimension of each attention head. Represents the sampling function. These are the sampling grid coordinates. It is a dynamic offset. Indicates the value after transformation;
[0074] Furthermore, a fixed-position encoding table is used to explicitly learn the spatial relationship between queries and key values, compensating for long-distance dependencies that might be ignored by dynamic offsets. The fixed-position encoding table follows an expectation of 0 and a variance of 0.01. 2 It follows a normal distribution and satisfies:
[0075] ,
[0076] in, This represents a fixed-position coding table. It is a three-dimensional tensor, and 8 corresponds to the number of attention heads. It is the query sequence length. It is the length of the key-value sequence;
[0077] The attention-weighted feature fusion module first processes the input data through convolution, then segments the data and feeds it into two or more residual blocks that incorporate the deformable attention mechanism DAttention to achieve different levels of attention weighting and feature fusion. Finally, the outputs of the residual blocks are spliced together, which helps to solve the problem of dense small face feature confusion and high false negative rate caused by the fixed sampling grid in the feature fusion module.
[0078] Specifically, a 1×1 sixth convolutional module is added after the attention-weighted feature fusion module to adapt to the intra-scale feature interaction module. The feature map output by the attention-weighted feature fusion module is 20×20×1024 in size. After being compressed to 256 channels by the 1×1 sixth convolutional module, the 20×20×256 feature map is flattened by the intra-scale feature interaction module to become 400×256. Spatial information is enhanced by two-dimensional sine and cosine position coding. Interaction features are learned using a multi-head self-attention mechanism and a feedforward network. Finally, the output feature map size is restored to 20×20×1024. The attention-weighted feature fusion module and the intra-scale feature interaction module are cascaded to achieve a two-stage feature extraction from local deformation perception to global semantic enhancement.
[0079] Step 2.3: Extract feature information from the fifth, seventh, and eleventh layers of the backbone network to obtain feature maps of three different sizes, namely 80×80, 40×40, and 20×20.
[0080] Step 3: Input the feature maps of the three different sizes into the neck network, and perform feature fusion based on the Feature Pyramid Network (FPN) and the Path Aggregation Network (PAN) in both bottom-up and top-down approaches to obtain the fused feature map. The specific steps are as follows:
[0081] Step 3.1, the neck network includes a feature fusion module and a convolution module;
[0082] There are four feature fusion modules: the fourth feature fusion module, the fifth feature fusion module, the sixth feature fusion module, and the seventh feature fusion module; there are two convolution modules: the seventh convolution module and the eighth convolution module.
[0083] The fourth and fifth feature fusion modules are used in the Feature Pyramid Network (FPN). Starting from a 20×20 feature map, they are upsampled and connected across layers with the third feature fusion module. The result is then output to the fourth feature fusion module. After upsampling, the fourth feature fusion module is connected across layers with the second feature fusion module. The result is then output to the fifth feature fusion module, completing bottom-up feature fusion and enhancing semantic information. The sixth and seventh feature fusion modules are used in the Path Aggregation Network (PAN). Starting from an 80×80 feature map, they are downsampled through the seventh convolution module and connected across layers with the fourth feature fusion module. The result is then output to the sixth feature fusion module. The sixth feature fusion module is downsampled through the eighth convolution module and connected across layers with the intra-scale feature interaction module. The result is then output to the seventh feature fusion module, completing top-down feature fusion and refining localization.
[0084] The two convolutional modules are used for feature dimension alignment;
[0085] Step 3.2: During the fusion process of the four feature fusion modules, feature maps of different resolutions undergo convolution, upsampling, downsampling and element-wise addition more than twice, and finally form optimized feature maps of three sizes: 80×80, 40×40 and 20×20, and output the optimized feature maps.
[0086] Step 4: Use the detection head in the head network to predict the fused feature map, generating the target category and bounding box location. Non-maximum suppression (NMS) is then used to remove overlapping predicted boxes, yielding the final detection result. During training, a validation set is used for simultaneous validation. After each training round, a model evaluation metric is calculated, and model weights are selected based on this metric. The specific steps are as follows:
[0087] Step 4.1, the head network includes convolutional modules and convolutional layers;
[0088] There are 6 convolutional modules and 6 convolutional layers. The 6 convolutional modules and 6 convolutional layers correspond one-to-one and are connected in series.
[0089] The convolutional module and convolutional layer are used to generate bounding box predictions and classification predictions;
[0090] Step 4.2: Based on a predetermined threshold (usually 0.25), filter out predicted bounding boxes with a confidence level less than the threshold in the predicted feature map; then use Non-Maximum Suppression (NMS) to remove redundant predicted bounding boxes, retaining the predicted bounding boxes most likely to contain the target object. The formula for NMS is:
[0091] ,
[0092] in, This represents the score of the i-th predicted box. Represents the prediction box With the i-th prediction box The crossover ratio between them It is the prediction box with the highest score. This represents the i-th prediction box. This represents the threshold value, typically 0.7; i ranges from 1 to K. This indicates the number of prediction boxes in the current batch;
[0093] Step 4.3: After obtaining the predicted bounding boxes filtered by Non-Maximum Suppression (NMS), calculate the loss value between the predicted and ground truth bounding boxes. This loss value includes the object classification loss and the bounding box regression loss. An angle-constrained intersection-union ratio (TAIoU) loss across spatial translation is designed to optimize the bounding box regression loss. The formula for TAIoU is:
[0094] ,
[0095] The TAIoU includes a translation-sensitive angle constraint loss function and an intersection-union ratio (IoU) index; wherein, the formula for the translation-sensitive angle constraint loss function TSACLoss is:
[0096] ,
[0097] ,
[0098] ,
[0099] in, Indicates angle loss, This represents the difference in width between the predicted bounding box and the ground truth bounding box. and These represent the top-left and bottom-left vertices of the actual bounding box, respectively. and These represent the top-left and bottom-left vertices of the prediction box, respectively. yes Point and Vertical distance difference between points yes Point and Vertical distance difference between points The translation distance d is represented by... Click Vector of a point The translation distance d is represented by... Click Vector of a point The translation distance d is represented by... Click Vector of a point TSACLoss is the width of the true bounding box, and TSACLoss is the angle constraint loss value.
[0100] The The vertical offset between the predicted bounding box and the ground truth bounding box is penalized to ensure target alignment. To further constrain width consistency, the key to TSACLoss lies in breaking through the single-image spatial constraint, introducing a translation matching space, and determining the specific translation distance through experiments to achieve more accurate loss value calculation.
[0101] The trained model was evaluated on three subsets of the WIDER FACE dataset: Easy, Medium, and Hard. The evaluation metrics used in this invention are: accuracy (P), recall (R), mean precision (50%), and mean precision (50-95%); where the accuracy performance on the subsets specifically refers to mean precision (50%).
[0102] Accuracy refers to the proportion of samples that are actually positive among those predicted as positive by the model, and the formula is as follows:
[0103] ,
[0104] Recall rate refers to the proportion of samples that are actually positive that are correctly predicted as positive by the model. The formula is as follows:
[0105] ,
[0106] The mean average precision of 50 refers to the mean average precision when the IoU threshold is 0.5, while the mean average precision of 50-95 refers to the mean average precision when the IoU ranges from 0.5 to 0.95, with a step size of 0.05.
[0107] Figure 5 The training metrics of the baseline network model and various improved models are compared. Except for C2f_DA, the other improved modules can significantly outperform the original model in accuracy and also have slight improvements in other metrics. The comprehensive improved model achieves the best results in accuracy, recall, mean precision (50%), and mean precision (50-95%).
[0108] Table 1
[0109]
[0110] To better demonstrate the performance of the improved YOLOv8 network model, the specific performance of the original model and the improved model on different difficulty subsets is listed in Table 1.
[0111] Table 1 lists the accuracy, number of parameters, and computational cost (floats per second) of different models. Compared to the baseline network model, the improved C2f_DA module, AIFI module, and TSACLoss loss function all achieve superior performance on the easy and medium difficulty subsets; except for the C2f_DA module, the other improvements improve accuracy on the difficult difficulty subset; among them, the TSACLoss loss function performs best. Overall, the improved YOLOv8 model of this invention achieves accuracy of 93.4%, 91.4%, and 81.0% on three different difficulty subsets, respectively, representing improvements of 0.8%, 0.6%, and 0.7% compared to the original network model. Although the improved model has an increased number of parameters, the actual computational cost has decreased, reducing the computational resources consumed.
[0112] The experiments in the embodiments demonstrate that the technical solution of the present invention performs well on the challenging face detection dataset WIDER FACE, effectively improving the accuracy of face target detection and providing a feasible solution to the problem of detecting dense small faces in complex environments.
[0113] This invention provides a face target detection method based on an improved YOLOv8. Many methods and approaches exist for implementing this technical solution; the above description is merely a preferred embodiment of the invention. It should be noted that those skilled in the art can make various improvements and modifications without departing from the principles of this invention, and these improvements and modifications should also be considered within the scope of protection of this invention. All components not explicitly stated in this embodiment can be implemented using existing technologies.
Claims
1. A face target detection method based on improved YOLOv8, characterized in that, Includes the following steps: Step 1: Use the face dataset. If the face dataset has provided training and validation sets, select the training and validation sets directly for use. Otherwise, divide the training and validation sets proportionally, convert all labels of the training and validation sets to YOLO format, and assign them all to the face category, i.e., the face category. Step 2: Construct and train the improved YOLOv8 network model, which includes a backbone network, a neck network, and a head network. The training set images are preprocessed and then input into the backbone network to obtain feature maps of three different sizes. The backbone network is reconstructed by using the attention-weighted feature fusion module C2f_DA and the attention-based intra-scale feature interaction module AIFI. The reconstructed backbone network includes a convolution module, a feature fusion module, an attention-weighted feature fusion module, and an intra-scale feature interaction module. The attention-weighted feature fusion module first processes the input data through convolution, then segments the data and feeds it into two or more residual blocks that incorporate the deformable attention mechanism DAttention to achieve attention weighting and feature fusion at different levels. Finally, the outputs of the residual blocks are concatenated. Step 3: Input the feature maps of the three different sizes into the neck network, and perform feature fusion in two ways, bottom-up and top-down, based on the feature pyramid network FPN and the path aggregation network PAN, to obtain the fused feature map. Step 4: Use the detection head in the head network to predict the fused feature map, generate the target category and bounding box location, and use non-maximum suppression (NMS) to remove overlapping predicted boxes to obtain the final detection result; During the training process, the validation set is used for validation simultaneously, and the model evaluation index is calculated after each round of training, and the model weights are selected based on the model evaluation index. In step 4, after obtaining the predicted bounding boxes filtered by Non-Maximum Suppression (NMS), the loss value between the predicted bounding boxes and the ground truth bounding boxes is calculated. This loss value includes the object classification loss and the bounding box regression loss. An angle-constrained intersection-union ratio (TAIoU) loss across spatial translation is designed to optimize the bounding box regression loss. The formula for TAIoU is: , The TAIoU includes the translation-sensitive angle constraint loss function TSACLoss and the intersection-union ratio (IoU) index; wherein, the formula for the translation-sensitive angle constraint loss function TSACLoss is: , , , in, Indicates angle loss, This represents the difference in width between the predicted bounding box and the ground truth bounding box. and These represent the top-left and bottom-left vertices of the actual bounding box, respectively. and These represent the top-left and bottom-left vertices of the prediction box, respectively. yes Point and Vertical distance difference between points yes Point and Vertical distance difference between points The translation distance d is represented by... Click Vector of a point The translation distance d is represented by... Click Vector of a point The translation distance d is represented by... Click Vector of a point is the width of the ground truth bounding box, TSACLoss is the angle constraint loss value, and K represents the number of predicted bounding boxes in the current batch.
2. The method according to claim 1, characterized in that, Step 1 includes: For the face dataset, create a folder structure in the YOLO format, put the image data and text labels from the training and validation sets into the corresponding folders, write a script to convert the face dataset into YOLO format, and unify the category number of the target object as face:
0.
3. The method according to claim 2, characterized in that, Step 2 includes: Step 2.1: Adjust the size of the images in the training set, check that the channel order of the images is red, green, blue, RGB, process the images using the Mosaic data augmentation method, and then input them into the backbone network; Step 2.2: The backbone network has 6 convolutional modules, namely the first convolutional module, the second convolutional module, the third convolutional module, the fourth convolutional module, the fifth convolutional module and the sixth convolutional module, and 3 feature fusion modules, namely the first feature fusion module, the second feature fusion module and the third feature fusion module. In this system, the first convolutional module, the second convolutional module, and the first feature fusion module are connected in series to form a basic feature extraction link. Subsequently, the third convolutional module and the second feature fusion module are connected in series, and the system is repeatedly stacked through the fourth convolutional module and the third feature fusion module to achieve progressive downsampling. The fifth convolutional module is connected in series with the attention-weighted feature fusion module, and the output is compressed by the sixth convolutional module and input to the intra-scale feature interaction module. The intra-scale feature interaction module enhances global semantics through multi-head self-attention and finally performs a residual connection with the output of the attention-weighted feature fusion module. The second and third feature fusion modules directly transfer shallow high-resolution features to the deep neck network through cross-layer skip connections. The six convolutional modules are used for basic feature extraction and channel dimension adjustment; The three feature fusion modules are used for multi-scale feature fusion; The attention-weighted feature fusion module uses the attention head of the deformable attention mechanism DAttention, and the output formula is: , in, This represents the output of the m-th attention head. This represents the softmax function. This indicates a query for the embedding of the m-th attention head. This represents the transformed key value. This represents the dimension of each attention head. Represents the sampling function. These are the sampling grid coordinates. It is a dynamic offset. Indicates the value after transformation; The spatial relationship between queries and key values is explicitly learned using a fixed-position encoding table, which follows an expectation of 0 and a variance of 0.
01. 2 It follows a normal distribution and satisfies: , in, This represents a fixed-position coding table. It is a three-dimensional tensor. It is the query sequence length. It is the length of the key-value sequence; A 1×1 sixth convolutional module is added after the attention-weighted feature fusion module to adapt to the intra-scale feature interaction module. The feature map output by the attention-weighted feature fusion module is 20×20×1024 in size. After being compressed to 256 channels by the 1×1 sixth convolutional module, the feature map of size 20×20×256 is flattened by the intra-scale feature interaction module to become 400×256. Spatial information is enhanced by two-dimensional sine and cosine position coding. Interaction features are learned by multi-head self-attention mechanism and feedforward network. Finally, the output feature map size is restored to 20×20×1024. The attention-weighted feature fusion module and the intra-scale feature interaction module are cascaded to realize a two-stage feature extraction from local deformation perception to global semantic enhancement. Step 2.3: Extract feature information from the fifth, seventh, and eleventh layers of the backbone network to obtain feature maps of three different sizes, namely 80×80, 40×40, and 20×20.
4. The method according to claim 3, characterized in that, Step 3 includes: Step 3.1, the neck network includes a feature fusion module and a convolution module; The neck network has four feature fusion modules: the fourth feature fusion module, the fifth feature fusion module, the sixth feature fusion module, and the seventh feature fusion module; the neck network has two convolutional modules: the seventh convolutional module and the eighth convolutional module. The fourth and fifth feature fusion modules are used in the Feature Pyramid Network (FPN). Starting from a 20×20 feature map, after upsampling, the feature map is connected across layers with the third feature fusion module. The result is then output to the fourth feature fusion module. After upsampling, the fourth feature fusion module is connected across layers with the second feature fusion module. The result is then output to the fifth feature fusion module, thus completing bottom-up feature fusion and enhancing semantic information. The sixth and seventh feature fusion modules are used in the path aggregation network PAN. Starting from an 80×80 feature map, downsampling is achieved through the seventh convolution module, which is connected across layers with the fourth feature fusion module. The result is output to the sixth feature fusion module. The sixth feature fusion module is downsampled through the eighth convolution module, which is connected across layers with the intra-scale feature interaction module. The result is output to the seventh feature fusion module, completing top-down feature fusion and refining the localization. Two convolutional modules are used for feature dimension alignment; Step 3.2: During the fusion process of the four feature fusion modules, feature maps of different resolutions undergo convolution, upsampling, downsampling and element-wise addition more than twice, and finally form optimized feature maps of three sizes: 80×80, 40×40 and 20×20, and output the optimized feature maps.
5. The method according to claim 4, characterized in that, Step 4 includes: Step 4.1, the head network includes convolutional modules and convolutional layers; The head network has 6 convolutional modules and 6 convolutional layers. The 6 convolutional modules and 6 convolutional layers correspond one-to-one and are connected in series. The convolutional module and convolutional layer are used to generate bounding box predictions and classification predictions; Step 4.2: Filter out predicted bounding boxes with a confidence level less than a threshold in the predicted feature map; then use Non-Maximum Suppression (NMS) to remove redundant predicted bounding boxes, retaining the predicted bounding boxes most likely to contain the target object. The formula for NMS is: , in, This represents the score of the i-th predicted box. Represents the prediction box With the i-th prediction box The crossover ratio between them It is the prediction box with the highest score. This represents the i-th prediction box. This represents the threshold; i takes values from 1 to K.
6. An electronic device, characterized in that, It includes a processor and a memory, the memory storing program code that, when executed by the processor, causes the processor to perform the steps of the method as described in any one of claims 1 to 5.
7. A storage medium, characterized in that, It stores a computer program or instructions that, when run on a computer, perform the steps of the method as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Pedestrian small target detection method based on improved YOLOv8
CN118865444A
Limestone granularity detection method and equipment based on YOLO-ADM and storage medium
CN119359735A