YOLOv8 target detection system based on improved CA attention mechanism
By introducing an improved CA attention mechanism and non-maximum suppression algorithm in the YOLOv8 target detection system, the problem of large amount of model parameters and inaccurate feature expression is solved, which improves detection accuracy and reduces target missed detection.
Patent Information
- Application Number
- CN202311753209.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-18
- Publication Date
- 2025-03-28
- Estimated Expiration
- 2043-12-18
AI Technical Summary
In the prior art, in the target detection, there are problems such as large number of model parameters, inaccurate feature expression, and easy to miss detection due to overlapping targets.
Introduce an improved CA attention mechanism, combine the basic YOLOv8 model, increase the attention of the model to each pixel point, build a lightweight YOLOv8 model, and introduce a non-maximum suppression algorithm to improve the accuracy of the detection box.
It improves the accuracy of feature expression, reduces the number of parameters of the model, improves the model efficiency, and improves the accuracy of the detection box, and reduces target missed detection.
Smart Images

Figure CN119169404B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of target detection technology, and in particular to a YOLOv8 target detection system and method based on an improved CA attention mechanism. Background Art
[0002] Object detection is an important task in the field of computer vision. It mainly processes and detects the category and position distribution of specific visual classes in images. Object detection provides the most basic information required by computer vision by establishing an effective computer application model, that is, determining where the target to be identified is. It is usually divided into target recognition and target positioning. The progress of target detection algorithms is of great significance to the development of computer vision.
[0003] YOLOv8 is an advanced object detection model that introduces new features and improvements to further improve performance and flexibility. A key feature of Yolov8 is its scalability, and it is designed as a framework that supports all previous YOLO versions. In addition to scalability, Yolov8 includes many other innovations (such as: a new backbone network, a new anchor-free detection head, and a new loss function) that make it an attractive choice for a wide range of object detection and image segmentation tasks.
[0004] In deep learning tasks, if the model wants to achieve higher accuracy, the training data set needs to be supported by a large number of pictures. Manually labeling each picture will consume a lot of manpower. Therefore, the use of transfer learning technology here to apply weighted samples to the current target model can greatly reduce labor costs. When using the original yolov8 model, a large number of parameters will be generated in the training task, which leads to relatively high requirements for detection equipment. How to solve the large number of model parameters and lightweight model is an important issue. In order to increase the model's attention to training features, an attention mechanism will be added to the model to improve the accuracy of training while keeping the number of parameters unchanged. Finally, in the detection task, targets may overlap with each other. During the detection process, some targets may be missed due to overlapping problems, resulting in losses.
[0005] The invention patent with application number CN202310752443.5 discloses a small target detection method, system and storage medium based on knowledge distillation, wherein the method includes: constructing a distillation loss function of the Yolov7L student model by using a distillation method including multi-scale feature map distillation and result distillation based on an attention mechanism; training the Yolov7L student model based on multiple training samples and according to the trained Yolov7L teacher model, the multi-scale attention module and the distillation loss function to obtain a trained Yolov7L student model; wherein the multi-scale attention module is used to optimize the small target detection results of the trained Yolov7L teacher model; inputting the image to be tested into the trained Yolov7L student model for small target detection to obtain the small target detection results of the image to be tested. The above invention improves the small target recognition accuracy of the Yolov7 model by combining multi-scale feature maps and introducing a knowledge distillation method with an attention module.
[0006] However, although the above-mentioned existing technology introduces the attention mechanism, when there are more image pixels, there are fewer perception channels, the attention to the pixels is more evenly distributed, and the feature expression is not accurate enough. In addition, the backbone network of the conventional Yolov7 model requires more input parameters and has low efficiency. When outputting overlapping target detection frames, it is also easy to cause target omission.
[0007] In view of this, there is an urgent need for a YOLOv8 target detection system and method based on an improved CA attention mechanism to at least address the above-mentioned deficiencies. Summary of the invention
[0008] One of the purposes of the present invention is to provide a YOLOv8 target detection system based on an improved CA attention mechanism, and train a basic YOLOv8 model according to an acquired data set. The improved CA attention mechanism is introduced and combined with the basic YOLOv8 model, which deepens the model's attention to each pixel point and improves the accuracy of feature expression; a lightweight YOLOv8 model is constructed, which reduces the number of model parameters and improves model efficiency; and a non-maximum suppression algorithm is introduced to achieve higher accuracy of the detection frame.
[0009] The YOLOv8 target detection system based on the improved CA attention mechanism provided by the embodiment of the present invention includes:
[0010] The data set acquisition subsystem is used to acquire the data set;
[0011] The basic model training subsystem is used to train the basic YOLOv8 model according to the data set;
[0012] Attention mechanism improvement subsystem, used to improve the CA attention mechanism;
[0013] The model reorganization subsystem is used to build a lightweight YOLOv8 model based on the improved results of the CA attention mechanism and the basic YOLOv8 model;
[0014] The target detection subsystem is used to obtain detection images and perform target detection based on the detection images and the lightweight YOLOv8 model.
[0015] Preferably, the data set acquisition subsystem includes:
[0016] The module for obtaining images to be processed is used to obtain the annotated images to be processed;
[0017] The data enhancement module is used to perform data enhancement on the annotated images to be processed and construct a data set. The data set includes: training set, validation set and test set;
[0018] Among them, the module for obtaining images to be processed includes:
[0019] An evaluation information acquisition submodule is used to obtain evaluation information of the labeled nodes;
[0020] A target annotation node determination submodule is used to determine the target annotation node according to the evaluation information;
[0021] The annotated picture set sending submodule is used to send the to-be-annotated picture set to each target annotation node;
[0022] The reply information acquisition submodule is used to obtain the reply information of the target annotation node;
[0023] The error node determination submodule is used to compare the reply information and determine the error node;
[0024] A selection node determination submodule is used to remove the error nodes in the target annotation nodes and use the remaining target annotation nodes as selection nodes;
[0025] A uniqueness retention submodule is used to retain the uniqueness of the labeled images to be labeled according to the reply information of the selection node, so as to obtain a first image set;
[0026] A data set platform access submodule, used for acquiring a second image set based on the data set platform;
[0027] The to-be-processed annotated image acquisition submodule is used to acquire the to-be-processed annotated images from the first image set and the second image set.
[0028] Preferably, the basic model training subsystem includes:
[0029] The basic YOLOv8 model training module is used to input the data set into the preset YOLOv8 model for training to obtain the trained basic YOLOv8 model. The basic YOLOv8 model includes: a backbone network, a neck network and a head network. The backbone network includes: a multi-scale convolution module, a C2f module and a global attention module.
[0030] Preferably, the attention mechanism improvement subsystem includes:
[0031] A feature conversion module is used to convert input features to obtain conversion features;
[0032] The mechanism improvement module is used to determine the C2f-CA module based on the CA attention mechanism according to the conversion features, MLP multi-layer perceptron and C2f module.
[0033] Preferably, the model reorganization subsystem includes:
[0034] A backbone network replacement module, used to replace the backbone network of the basic YOLOv8 model with MobileViT to obtain a first adjusted model;
[0035] Improved result parsing module, used to parse the improved results of CA attention mechanism and determine the C2f-CA module;
[0036] A C2f module determination module, used to determine the C2f module in the first adjustment model;
[0037] A second adjustment model determination module, used to replace all C2f modules in the first adjustment model with C2f-CA modules to obtain a second adjustment model;
[0038] The lightweight model determination module is used to construct a lightweight YOLOv8 model based on the Soft-nms algorithm and the second adjustment model.
[0039] Preferably, the target detection subsystem includes:
[0040] The extraction feature determination module is used to input the detection image into the lightweight YOLOv8 model to determine the extraction features of the C2f-CA modules at the 16th, 19th and 22nd layers;
[0041] The target detection module is used to perform target detection based on the extracted features.
[0042] Preferably, the target detection module includes:
[0043] A sub-confidence determination sub-module, used to determine the category confidence and bounding box confidence of each first object detection box according to the extracted features;
[0044] The object detection box confidence calculation submodule is used to multiply the category confidence and the bounding box confidence to obtain the object detection box confidence of the first object detection box;
[0045] A current detection frame determination submodule is used to traverse each first target detection frame in turn to determine the current detection frame currently traversed;
[0046] The confidence condition determination submodule is used to determine whether the current detection box meets the confidence condition;
[0047] A highlight submodule is used to highlight the corresponding current detection frame if the current detection frame meets the confidence condition;
[0048] The target detection completion judgment submodule is used to complete the target detection when all current detection boxes that need to be highlighted are highlighted.
[0049] Preferably, the confidence condition determination submodule includes:
[0050] An overlap determination unit, used for determining whether there is at least one first target detection frame other than the current detection frame overlapping with the current detection frame;
[0051] A first confidence condition determination unit, configured to determine that if the confidence of the target detection frame of the current detection frame does not exist, then the corresponding current detection frame satisfies the confidence condition if the confidence of the target detection frame of the current detection frame is greater than or equal to a preset first threshold;
[0052] an overlap calculation unit, configured to calculate, if any, an overlap between the current detection frame and a first target detection frame other than the current detection frame;
[0053] A first detection frame set acquisition unit is configured to use the corresponding current detection frame and the corresponding first target detection frame as a first detection frame set if the overlap degree is greater than or equal to a preset second threshold, wherein the first detection frame set includes: a plurality of second target detection frames;
[0054] The second confidence condition determination unit is used to determine whether a second target detection frame whose target detection frame confidence is the largest and whose target detection frame confidence is greater than or equal to a first threshold satisfies the confidence condition.
[0055] The YOLOv8 target detection system based on the improved CA attention mechanism provided by the embodiment of the present invention also includes:
[0056] A second detection frame set determining unit is configured to use the corresponding current detection frame and the corresponding first target detection frame as a second detection frame set if the overlap is less than a preset second threshold and greater than a preset third threshold, wherein the second detection frame set includes: a plurality of third target detection frames;
[0057] A detection category acquisition unit, used to acquire the detection category of the third object detection frame;
[0058] A detection frame set splitting unit, used for splitting the second detection frame set according to the detection category to obtain a detection frame subset;
[0059] A third target detection frame determination unit is used to respectively determine a third target detection frame in each detection frame subset whose target detection frame confidence is the largest and whose target detection frame confidence is greater than or equal to a first threshold;
[0060] A display mark determining unit, used to determine a display mark of a third object detection frame according to the detection category;
[0061] The highlighting unit is used to highlight the third target detection frame according to the display mark.
[0062] The YOLOv8 target detection method based on the improved CA attention mechanism provided by the embodiment of the present invention includes:
[0063] Step 1: Get the dataset;
[0064] Step 2: Train the basic YOLOv8 model based on the dataset;
[0065] Step 3: Improve the CA attention mechanism;
[0066] Step 4: Build a lightweight YOLOv8 model based on the improved results of the CA attention mechanism and the basic YOLOv8 model;
[0067] Step 5: Get the detection image and perform target detection based on the detection image and the lightweight YOLOv8 model.
[0068] The beneficial effects of the present invention are:
[0069] The present invention trains the basic YOLOv8 model based on the acquired data set. The improved CA attention mechanism is introduced and combined with the basic YOLOv8 model to deepen the model's attention to each pixel point and improve the accuracy of feature expression; a lightweight YOLOv8 model is constructed to reduce the number of model parameters and improve model efficiency; the non-maximum suppression algorithm is introduced to achieve higher accuracy of the detection frame.
[0070] Other features and advantages of the present invention will be described in the following description, and partly become apparent from the description, or understood by practicing the present invention. The purpose and other advantages of the present invention can be realized and obtained by the structures specifically pointed out in the present application documents.
[0071] The technical solution of the present invention is further described in detail below through the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0072] The accompanying drawings are used to provide a further understanding of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings:
[0073] Figure 1 Schematic diagram of a YOLOv8 target detection system based on an improved CA attention mechanism in an embodiment of the present invention;
[0074] Figure 2 Schematic diagram of a YOLOv8 target detection method based on an improved CA attention mechanism in an embodiment of the present invention. DETAILED DESCRIPTION
[0075] The preferred embodiments of the present invention are described below in conjunction with the accompanying drawings. It should be understood that the preferred embodiments described herein are only used to illustrate and explain the present invention, and are not used to limit the present invention.
[0076] The embodiment of the present invention provides a YOLOv8 target detection system based on an improved CA attention mechanism, such as Figure 1 As shown, including:
[0077] The data set acquisition subsystem 1 is used to acquire a data set; wherein the data set is: a collection of labeled sample images, and the labeled sample images are: labeled images that are labeled according to target detection requirements;
[0078] The basic model training subsystem 2 is used to train a basic YOLOv8 model according to the data set; wherein the YOLOv8 model is one of the latest versions of the YOLO (You Only Look Once) series of models, and the target detection model obtained by training the YOLOv8 model until convergence using the data set as training data is based on the YOLOv8 model;
[0079] Attention mechanism improvement subsystem 3 is used to improve the CA attention mechanism; the improved CA (Channel Attention) attention mechanism is: on the original CA attention mechanism, the MLP multi-layer perceptron technology is used to deepen the model's attention to each pixel;
[0080] Model reorganization subsystem 4 is used to construct a lightweight YOLOv8 model based on the improved results of the CA attention mechanism and the basic YOLOv8 model; the improved results are: on the original CA attention mechanism, the MLP multi-layer perceptron technology is used to deepen the model's attention to each pixel; the lightweight YOLOv8 model is: MobileViT is used to replace the original backbone network of the basic YOLOv8 model, the number of model parameters is reduced, and the model is lightweight; in addition, Soft-nms non-maximum suppression is used to solve the influence of target overlap in target detection;
[0081] The target detection subsystem 5 is used to obtain a detection picture and perform target detection based on the detection picture and the lightweight YOLOv8 model. The detection picture is an image for target detection, and the detection picture is input into the lightweight YOLOv8 model, and the detection box corresponding to each detection task is marked on the detection picture.
[0082] The working principle and beneficial effects of the above technical solution are:
[0083] This application trains the basic YOLOv8 model based on the acquired data set. The improved CA attention mechanism is introduced and combined with the basic YOLOv8 model to deepen the model's attention to each pixel and improve the accuracy of feature expression; a lightweight YOLOv8 model is constructed to reduce the number of model parameters and improve model efficiency; the non-maximum suppression algorithm is introduced to achieve higher accuracy of the detection frame.
[0084] In one embodiment, the data set acquisition subsystem includes:
[0085] The module for acquiring the image to be processed is used to acquire the annotated image to be processed; wherein the annotated image to be processed is: a sample image annotated with the target detection result;
[0086] The data enhancement module is used to perform data enhancement on the annotated images to be processed and construct a data set. The data set includes: a training set, a validation set, and a test set. The data enhancement is to perform a series of changes and expansion operations on the annotated images to be processed to increase the diversity of data samples.
[0087] Among them, the module for obtaining images to be processed includes:
[0088] The evaluation information acquisition submodule is used to obtain the evaluation information of the annotated node; wherein the annotated node is: a communication node of an individual or entity participating in the annotation task; the evaluation information is: an indicator for evaluating the accuracy and reliability of the annotated node;
[0089] The target annotation node determination submodule is used to determine the target annotation node according to the evaluation information; wherein the target annotation node is: an annotation node whose evaluation information meets the preset evaluation standard;
[0090] The annotated picture set sending submodule is used to send a picture set to be annotated to each target annotation node; the picture set to be annotated includes: a plurality of images to be annotated;
[0091] The reply information acquisition submodule is used to obtain the reply information of the target annotation node; wherein the reply information is: the result of the completion of the annotation of the to-be-annotated picture set replied by each target annotation node;
[0092] The error node determination submodule is used to compare the reply information and determine the error node; wherein the error node is: comparing the annotation results of the same to-be-annotated image between multiple target annotation nodes, if there is any annotation box coordinate that deviates from the average annotation box coordinate corresponding to the annotation box by a preset distance, the corresponding target annotation node is determined to be an error node;
[0093] A selection node determination submodule is used to remove the error nodes in the target annotation nodes and use the remaining target annotation nodes as selection nodes;
[0094] The uniqueness preservation submodule is used to preserve the uniqueness of the labeled images to be labeled according to the reply information of the selection node, so as to obtain a first image set; wherein, when performing the uniqueness preservation, the average labeling result of the labeling results of each image to be labeled in the reply of the selection node is determined;
[0095] A data set platform access submodule, used to obtain a second image set based on a data set platform; wherein the data set platform is: a public annotated data platform, including public annotated images for target detection;
[0096] The to-be-processed annotated image acquisition submodule is used to acquire the to-be-processed annotated images from the first image set and the second image set.
[0097] The working principle and beneficial effects of the above technical solution are:
[0098] The present application performs data enhancement on the acquired labeled images to be processed and constructs a data set, so as to provide a data set that meets the requirements for subsequent target detection, classification or segmentation tasks, improve the robustness and generalization ability of the model, and reduce the model's dependence on a large amount of labeled data; in addition, when acquiring the labeled images to be processed, an annotation node is introduced, and the target annotation node is screened according to the evaluation information of the annotation node, and the accurate first image set is determined according to the comparison result of the reply information of the target annotation node to the set of labeled images, and in addition, the second image set is supplemented from the big data platform, which improves the comprehensiveness of the acquisition of the images to be processed and improves the accuracy of subsequent model training.
[0099] In one embodiment, the basic model training subsystem includes:
[0100] The basic YOLOv8 model training module is used to input the data set into the preset YOLOv8 model for training to obtain the trained basic YOLOv8 model, wherein the basic YOLOv8 model includes: backbone network, neck network and head network, and the backbone network includes: multi-scale convolution module, C2f (Convolution to Fully Connected) module and global attention module. Among them, the preset YOLOv8 model is: a variant of the YOLO (You Only Look Once) series model, consisting of a backbone network, a neck network and a head network. The backbone network helps the model to extract features of different scales and semantics, the neck network extracts and integrates features, and the head network outputs the detection target.
[0101] The working principle and beneficial effects of the above technical solution are:
[0102] This application introduces the YOLOv8 model and trains it through the data set to improve the scalability performance of subsequent detection models.
[0103] In one embodiment, the attention mechanism improvement subsystem includes:
[0104] The feature conversion module is used to convert the input features to obtain conversion features; wherein the input features are: image features of the detected target image, and converting the input features means putting the channel dimension at the end, that is, performing a transposition operation on the input features to amplify the cross-dimensional channel space dependency;
[0105] The mechanism improvement module is used to determine the C2f-CA module based on the CA attention mechanism, according to the conversion features, MLP multi-layer perceptron and C2f module. Among them, MLP (Multi-Layer Perceptron) is a neural network structure composed of two fully connected layers, and the output of the C2f-CA module is:
[0106]
[0107] Among them, y c (i, j) is the image feature at the height i and width j output by the C2f-CA module, x c (i,j) is the image feature at the height i and width j of the input C2f-CA module, is the attention weight in the horizontal direction, is the attention weight in the vertical direction.
[0108] The working principle and beneficial effects of the above technical solution are:
[0109] In order to avoid compressing all spatial information into the channel, this application transforms the input features to obtain conversion features, introduces MLP multi-layer perceptron, amplifies the cross-dimensional channel spatial dependency, adds the conversion features and MLP multi-layer perceptron to the C2f module to obtain the C2f-CA module, and adds the attention weights in the horizontal and vertical directions to the input features, which greatly improves the image representation capability.
[0110] In one embodiment, the model reshaping subsystem includes:
[0111] A backbone network replacement module is used to replace the backbone network of the basic YOLOv8 model with MobileViT to obtain a first adjusted model; wherein MobileViT is a lightweight visual Transformer model that reduces the number of model parameters and computational complexity while maintaining high performance;
[0112] Improved result parsing module, used to parse the improved results of CA attention mechanism and determine the C2f-CA module;
[0113] A C2f module determination module, used to determine the C2f module in the first adjustment model;
[0114] A second adjustment model determination module, used to replace all C2f modules in the first adjustment model with C2f-CA modules to obtain a second adjustment model;
[0115] The lightweight model determination module is used to construct a lightweight YOLOv8 model based on the Soft-nms algorithm and the second adjustment model. The Soft-nms algorithm is a non-maximum suppression algorithm in target detection.
[0116] The working principle and beneficial effects of the above technical solution are:
[0117] This application replaces the backbone network of the basic YOLOv8 model with MobileViT, specifically: replace the 1st, 2nd, 3rd, 4th, 5th, 7th, and 9th layers of the basic YOLOV8 with the MV2Block module, and replace the 6th layer of the basic YOLOV8 with the MobileViTBlock module; during detection, the detection image enters the MV2Block module, the first layer first performs a 1×1 convolution to increase the dimension, the second layer is a 3×3 Depthwise convolution, the number of input channels is equal to the number of output channels, and the third layer is a 1×1 convolution to reduce the dimension. When the detection image enters the MobileViTBlock module, local feature modeling is performed through a convolution layer with a convolution kernel size of 3×3, and then the number of channels is adjusted through a convolution layer with a convolution kernel size of 1×1. Then, global feature modeling is performed through the Unfold, Transformer, and Fold structures in turn, and then the number of channels is adjusted back to the original size through a convolution layer with a convolution kernel size of 1×1. Then, the shortcut branch is used to concat the original input feature map, and finally a convolution layer with a convolution kernel size of 3×3 is used to perform feature fusion to obtain the output. The backbone network is replaced by a lightweight visual Transformer model to improve resource efficiency.
[0118] The head network of the basic YOLOv8 model has 12 layers. The 11th and 14th layers of the head network are upsampling modules, the 12th, 15th, 18th and 21st layers are Concat modules, the 13th, 16th, 19th and 22nd layers are C2f-CA modules, and the 17th and 20th layers are CBS modules. The head network first performs upsampling of the image output by the backbone network in the 11th layer, doubling the length and width of the feature map. The 12th layer concatenates the results of the 11th layer with the results of the 6th layer to increase the number of channels of the image. The 13th layer uses the C2f-CA module to perform convolution operations on the image to extract features. The 14th layer upsampling module doubles the length and width of the image output by the 13th layer. The 15th layer Concat module concatenates the image output by the 14th layer with the output of the 5th layer, integrating feature information of different scales. The 16th layer uses the C2f-CA module to perform convolution operations on the image to extract features. The CBS module of the 17th layer performs convolution operations on the image, reducing the length and width of the image to half of the original. The Concat module of the 18th layer concatenates the image output by the 17th layer with the output of the 13th layer, integrating feature information of different scales. The 19th layer uses the C2f-CA module to perform convolution operations on the feature map to extract features. The CBS module of the 20th layer performs convolution operations on the feature map, reducing the length and width of the image to half of the original. The Concat module of the 21st layer concatenates the image output by the 20th layer with the output of the 10th layer, integrating feature information of different scales. The 22nd layer uses the C2f-CA module to convolve the image to extract features that integrate information of different scales, which can improve the training accuracy while keeping the number of parameters unchanged.
[0119] The Soft-nms algorithm is introduced to sort all first target detection boxes based on their confidence, among which the first target detection box M with the highest score is selected, and then the remaining first target detection boxes with the highest scores whose overlap with M exceeds a threshold (the threshold is pre-set) will be suppressed, thus avoiding missed detection caused by target overlap in the target detection process.
[0120] In one embodiment, based on the Soft-nms algorithm and according to the second adjustment model, a lightweight YOLOv8 model is constructed, including:
[0121] Resetting the confidence of the first target detection box according to a linear weighted confidence reset function or a Gaussian weighted confidence reset function;
[0122] Among them, the linear weighted confidence reset function is:
[0123]
[0124] Among them, the Gaussian weighted confidence reset function is:
[0125]
[0126] Among them, b i is the first target detection frame other than the first target detection frame M, s i for b i Reset confidence, N t is the manually set intersection-over-union ratio threshold, iou(M,b i ) is M and b i The intersection-and-combination ratio between them, σ is the preset Gaussian weighting coefficient, e is the natural logarithm base, and D is the storage b i A collection of .
[0127] The working principle and beneficial effects of the above technical solution are:
[0128] The present application introduces a linear weighted confidence reset function and a Gaussian weighted confidence reset function to reset the confidence of the first target detection frame, thereby improving the accuracy of determining the detection frame.
[0129] In one embodiment, the target detection subsystem includes:
[0130] The extraction feature determination module is used to input the detection image into the lightweight YOLOv8 model to determine the extraction features of the C2f-CA modules at the 16th, 19th and 22nd layers; wherein the detection image is: an image that needs to be detected; the extraction features are: features of different extracted layers;
[0131] The target detection module is used to perform target detection based on the extracted features.
[0132] The working principle and beneficial effects of the above technical solution are:
[0133] In the lightweight YOLOv8 model, this application extracts the features of the C2f-CA modules at layers 16, 19, and 22. These layers are located deep in the model and have been processed by a series of convolution and attention mechanisms, providing richer semantic information and more accurate target positioning information. Using these features, the accuracy and stability of target detection are improved while maintaining the advantages of the lightweight model.
[0134] In one embodiment, the target detection module includes:
[0135] The sub-confidence determination submodule is used to determine the category confidence and bounding box confidence of each first target detection frame according to the extracted features; wherein the category confidence is: the prediction score or probability of the target category in each target detection frame by the target detection model, indicating the possibility that the target belongs to each category; the bounding box confidence is: the prediction score or probability of whether the target exists in each target detection frame by the target detection model, indicating the degree of the target existence in the detection frame;
[0136] The object detection box confidence calculation submodule is used to multiply the category confidence and the bounding box confidence to obtain the object detection box confidence of the first object detection box;
[0137] A current detection frame determination submodule is used to traverse each first target detection frame in turn to determine the current detection frame currently traversed;
[0138] The confidence condition determination submodule is used to determine whether the current detection frame meets the confidence condition; wherein the confidence condition is: a threshold condition for screening the target detection frame to be displayed;
[0139] A highlighting submodule is used to highlight the corresponding current detection frame if the current detection frame meets the confidence condition; wherein the highlighting rule is preset manually;
[0140] The target detection completion judgment submodule is used to complete the target detection when all current detection boxes that need to be highlighted are highlighted.
[0141] The working principle and beneficial effects of the above technical solution are:
[0142] Based on the extracted features, the present application determines the possibility that the first target detection box represents the target belonging to each category and the degree to which the target exists in the detection box, and calculates the target detection box confidence based on the category confidence and the bounding box confidence, which is more accurate; based on the current detection box's judgment on the confidence condition, the current detection box that meets the confidence condition is determined to be highlighted, thereby improving the accuracy of target detection.
[0143] In one embodiment, the confidence condition determination submodule includes:
[0144] An overlap determination unit, used for determining whether there is at least one first target detection frame other than the current detection frame overlapping with the current detection frame;
[0145] A first confidence condition determination unit, used for, if the confidence of the target detection frame of the current detection frame does not exist, if it is greater than or equal to a preset first threshold, then the corresponding current detection frame satisfies the confidence condition; wherein the preset first threshold is manually preset;
[0146] An overlap calculation unit, used to calculate the overlap between the current detection frame and a first target detection frame other than the current detection frame, if any; wherein the overlap is: the intersection ratio between the two target detection frames;
[0147] A first detection frame set acquisition unit is used to use the corresponding current detection frame and the corresponding first target detection frame as a first detection frame set if the overlap degree is greater than or equal to a preset second threshold, wherein the first detection frame set includes: a plurality of second target detection frames; wherein the preset second threshold is: 90%;
[0148] The second confidence condition determination unit is used to determine whether a second target detection frame whose target detection frame confidence is the largest and whose target detection frame confidence is greater than or equal to a first threshold satisfies the confidence condition.
[0149] The working principle and beneficial effects of the above technical solution are:
[0150] During target detection, there may be a situation of double detection frames. For example, a target that is partially obscured cannot be clearly identified, and multiple target detection frames appear. In this case, the first target detection frames that appear have a large degree of overlap. The second target detection frame with the largest confidence and a target detection frame confidence greater than or equal to the first threshold can be selected, thereby reducing the misjudgment rate of double detection frames.
[0151] The embodiment of the present invention provides a YOLOv8 target detection system based on an improved CA attention mechanism, further comprising:
[0152] a second detection frame set determining unit, configured to use the corresponding current detection frame and the corresponding first target detection frame as a second detection frame set if the overlap is less than a preset second threshold and greater than a preset third threshold, wherein the second detection frame set includes: a plurality of third target detection frames; wherein the preset third threshold is: 50%;
[0153] A detection category acquisition unit, used to acquire the detection category of the third target detection frame; wherein the detection category is the type of target detected by the third target detection frame;
[0154] A detection frame set splitting unit, used for splitting the second detection frame set according to the detection category to obtain a detection frame subset;
[0155] A third target detection frame determination unit is used to respectively determine a third target detection frame in each detection frame subset whose target detection frame confidence is the largest and whose target detection frame confidence is greater than or equal to a first threshold;
[0156] A display mark determination unit, used to determine a display mark of the third target detection frame according to the detection category; wherein the rule for determining the display mark according to the detection category is manually preset;
[0157] The highlighting unit is used to highlight the third target detection frame according to the display mark.
[0158] The working principle and beneficial effects of the above technical solution are:
[0159] During target detection, there may be a situation where the detection targets are densely distributed and the detection frames overlap. At this time, it is inappropriate to blindly select the target detection frame with the target detection frame confidence, which is easy to cause missed detection of the detection target. Therefore, detection categories are introduced to determine the third target detection frame with the largest target detection frame confidence in the detection frame subset corresponding to each detection category and the target detection frame confidence greater than or equal to the first threshold, and display them separately, avoiding missed detection when different targets overlap, and making target detection more comprehensive.
[0160] The embodiment of the present invention provides a YOLOv8 target detection method based on an improved CA attention mechanism, such as Figure 2 As shown, including:
[0161] Step 1: Get the dataset;
[0162] Step 2: Train the basic YOLOv8 model based on the dataset;
[0163] Step 3: Improve the CA attention mechanism;
[0164] Step 4: Build a lightweight YOLOv8 model based on the improved results of the CA attention mechanism and the basic YOLOv8 model;
[0165] Step 5: Get the detection image and perform target detection based on the detection image and the lightweight YOLOv8 model.
[0166] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.
Claims
1. YOLOv8 target detection system based on improved CA attention mechanism, characterized by: include: The data set acquisition subsystem is used to acquire the data set; The basic model training subsystem is used to train the basic YOLOv8 model according to the data set; Attention mechanism improvement subsystem, used to improve the CA attention mechanism; The attention mechanism improvement subsystem includes: A feature conversion module is used to convert input features to obtain conversion features; The mechanism improvement module is used to determine the C2f-CA module based on the CA attention mechanism according to the conversion features, MLP multi-layer perceptron and C2f module; The model reorganization subsystem is used to build a lightweight YOLOv8 model based on the improved results of the CA attention mechanism and the basic YOLOv8 model; The target detection subsystem is used to obtain detection images and perform target detection based on the detection images and the lightweight YOLOv8 model.
2. The YOLOv8 target detection system based on the improved CA attention mechanism as claimed in claim 1, characterized in that The data set acquisition subsystem includes: The module for obtaining images to be processed is used to obtain the annotated images to be processed; The data enhancement module is used to perform data enhancement on the annotated images to be processed and construct a data set. The data set includes: training set, validation set and test set.
3. The YOLOv8 target detection system based on the improved CA attention mechanism as claimed in claim 1, characterized in that Basic model training subsystem, including: The basic YOLOv8 model training module is used to input the data set into the preset YOLOv8 model for training to obtain the trained basic YOLOv8 model. The basic YOLOv8 model includes: a backbone network, a neck network and a head network. The backbone network includes: a multi-scale convolution module, a C2f module and a global attention module.
4. The YOLOv8 target detection system based on the improved CA attention mechanism as claimed in claim 1, characterized in that Model reorganization subsystem, including: A backbone network replacement module, used to replace the backbone network of the basic YOLOv8 model with MobileViT to obtain a first adjusted model; Improved result parsing module, used to parse the improved results of CA attention mechanism and determine the C2f-CA module; A C2f module determination module, used to determine the C2f module in the first adjustment model; A second adjustment model determination module, used to replace all C2f modules in the first adjustment model with C2f-CA modules to obtain a second adjustment model; The lightweight model determination module is used to construct a lightweight YOLOv8 model based on the Soft-nms algorithm and the second adjustment model.
5. The YOLOv8 target detection system based on the improved CA attention mechanism as claimed in claim 1, characterized in that The target detection subsystem includes: The extraction feature determination module is used to input the detection image into the lightweight YOLOv8 model to determine the extraction features of the C2f-CA modules at the 16th, 19th and 22nd layers; The target detection module is used to perform target detection based on the extracted features.
6. The YOLOv8 target detection system based on the improved CA attention mechanism as claimed in claim 5, characterized in that Object detection module, including: A sub-confidence determination sub-module, used to determine the category confidence and bounding box confidence of each first object detection box according to the extracted features; The object detection box confidence calculation submodule is used to multiply the category confidence and the bounding box confidence to obtain the object detection box confidence of the first object detection box; A current detection frame determination submodule is used to traverse each first target detection frame in turn to determine the current detection frame currently traversed; The confidence condition determination submodule is used to determine whether the current detection box meets the confidence condition; A highlight submodule is used to highlight the corresponding current detection frame if the current detection frame meets the confidence condition; The target detection completion judgment submodule is used to complete the target detection when all current detection boxes that need to be highlighted are highlighted.
7. The YOLOv8 target detection system based on the improved CA attention mechanism as claimed in claim 6, characterized in that The confidence condition determination submodule includes: An overlap determination unit, used for determining whether there is at least one first target detection frame other than the current detection frame overlapping with the current detection frame; A first confidence condition determination unit, configured to determine that if the confidence of the target detection frame of the current detection frame does not exist, then the corresponding current detection frame satisfies the confidence condition if the confidence of the target detection frame of the current detection frame is greater than or equal to a preset first threshold; an overlap calculation unit, configured to calculate, if any, an overlap between the current detection frame and a first target detection frame other than the current detection frame; A first detection frame set acquisition unit is configured to use the corresponding current detection frame and the corresponding first target detection frame as a first detection frame set if the overlap degree is greater than or equal to a preset second threshold, wherein the first detection frame set includes: a plurality of second target detection frames; The second confidence condition determination unit is used to determine whether a second target detection frame whose target detection frame confidence is the largest and whose target detection frame confidence is greater than or equal to a first threshold satisfies the confidence condition.
8. The YOLOv8 target detection system based on the improved CA attention mechanism as claimed in claim 7, characterized in that Also includes: A second detection frame set determining unit is configured to use the corresponding current detection frame and the corresponding first target detection frame as a second detection frame set if the overlap is less than a preset second threshold and greater than a preset third threshold, wherein the second detection frame set includes: a plurality of third target detection frames; A detection category acquisition unit, used to acquire the detection category of the third object detection frame; A detection frame set splitting unit, used for splitting the second detection frame set according to the detection category to obtain a detection frame subset; A third target detection frame determination unit is used to respectively determine a third target detection frame in each detection frame subset whose target detection frame confidence is the largest and whose target detection frame confidence is greater than or equal to a first threshold; A display mark determining unit, used to determine a display mark of a third object detection frame according to the detection category; The highlighting unit is used to highlight the third target detection frame according to the display mark.
9. YOLOv8 target detection method based on improved CA attention mechanism, characterized in that: include: Step 1: Get the dataset; Step 2: Train the basic YOLOv8 model based on the dataset; Step 3: Improve the CA attention mechanism; The step 3: improving the CA attention mechanism includes: Transform the input features to obtain transformed features; Based on the CA attention mechanism, the C2f-CA module is determined according to the conversion features, MLP multi-layer perceptron and C2f module; Step 4: Build a lightweight YOLOv8 model based on the improved results of the CA attention mechanism and the basic YOLOv8 model; Step 5: Get the detection image and perform target detection based on the detection image and the lightweight YOLOv8 model.
Citation Information
Patent Citations
Knowledge distillation-based small target detection method and system, and storage medium
CN116778300A
Lightweight target detection method and system based on YOLOv8 improvement
CN116740538A