Small target detection method and system based on improved YOLOv7 algorithm, storage medium and electronic equipment

By adding the small object detection head and adaptive bounding box regression loss weight in the YOLOv7 model, the balance problem between small object detection speed and accuracy in the prior art is solved, and higher detection accuracy and faster detection speed are achieved.

CN119649187APending Publication Date: 2025-03-18NANJING DRUM TOWER HOSPITAL
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411700469.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-26
Publication Date
2025-03-18

AI Technical Summary

Technical Problem

The prior art cannot improve the accuracy of small target detection while maintaining the detection speed, resulting in the easy missed detection of small targets in specific scenarios.

Method used

By adding a small object detection head in the YOLOv7 model, and performing 4-fold downsampling feature extraction on the small object data based on the detection head, and adding adaptive weights to the bounding box regression loss, the model's detection accuracy of the small object is improved.

Benefits of technology

With almost no increase in detection costs, the detection accuracy of the YOLOv7 object detection algorithm for small targets is improved, effectively taking into account the speed and accuracy of small target detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119649187A_ABST
    Figure CN119649187A_ABST
Patent Text Reader

Abstract

The invention provides a small target detection method and system based on an improved YOLOv7 algorithm, a storage medium and electronic equipment, and relates to the technical field of target detection. According to the technology, the expression effect of a YOLOv7 model in an urban traffic road end detection scene is improved from two aspects: an adaptive bounding box loss weight is introduced under the condition that a model network structure is not changed, and the small object detection precision of the model is improved; a detection head for a small object is added under the condition that the reasoning time is slightly increased, and the small object detection precision of the model can also be improved. On the premise that the detection cost is hardly increased, the small target detection precision of the YOLOv7 target detection algorithm is improved, and the speed and precision of small target detection are well considered.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of target detection, and in particular to a small target detection method, system, storage medium and electronic device based on an improved YOLOv7 algorithm. Background Art

[0002] Object detection technology is an important branch of computer vision. It aims to accurately locate and identify all objects of interest in an image or video, and determine their categories and locations. Compared with simple image classification tasks, object detection not only needs to identify what the object is, but also its specific location in the image. A rectangular bounding box is usually used to mark the location range of the object. In object detection technology, small object detection has always been a pain point for object detection algorithms, especially when edge deployment is limited by computing power and a small model has to be used. It is easy to miss small targets when sacrificing accuracy for detection speed.

[0003] The YOLOv7 algorithm is a representative of the existing open source models with high speed and accuracy. It performs well in public datasets and is often used for small target detection.

[0004] However, the YOLOv7 algorithm needs to be further optimized for detecting small objects in specific scenes. This is because in order to reduce missed detections and false detections of small objects in existing technologies, the detection time must be increased accordingly, and in order to save detection time, the detection accuracy must be sacrificed. In other words, the existing small object detection technology cannot achieve a good balance between speed and accuracy. Summary of the invention

[0005] 1. Technical issues to be resolved

[0006] In view of the shortcomings of the prior art, the present invention provides a small target detection method, system, storage medium and electronic device based on an improved YOLOv7 algorithm, which solves the problem that the prior art cannot take into account both the speed and accuracy of small target detection.

[0007] (II) Technical solution

[0008] To achieve the above objectives, the present invention is implemented through the following technical solutions:

[0009] In the first aspect, the present application first proposes a small target detection method based on an improved YOLOv7 algorithm, the method comprising:

[0010] Acquire small target data, and construct a target detection data set based on the small target data;

[0011] A small target detection model is trained based on the data set, and the small target detection model includes: adding a small target detection head to the YOLOv7 model, and performing 4 times downsampling features on the small target data based on the small target detection head; and adding an adaptive weight to the bounding box regression loss of the YOLOv7 model.

[0012] Small target detection is performed based on the small target detection model after training and optimization.

[0013] In one embodiment, the step of acquiring small target data and constructing a target detection data set based on the small target data includes: performing data cleaning and labeling on the acquired small target data.

[0014] Preferably, data cleaning includes: deleting duplicate data, filtering low-quality images, format conversion and resizing, and category balancing; labeling includes: marking the category and bounding box coordinates of the target to be detected in each image of the acquired small target data.

[0015] In one embodiment, the YOLOv7 model includes: a YOLOv7-tiny model.

[0016] Preferably, the YOLOv7 model also includes: YOLOv7-x, YOLOv7-w6, YOLOv7-e6, YOLOv7-e6e and other models.

[0017] In some embodiments, the YOLOv7 model also includes: YOLOv4, YOLOv5, YOLOv8, YOLOv10 and other models.

[0018] In another embodiment, the bounding box regression loss of the YOLOv7 model includes a CIoU loss function.

[0019] Preferably, the bounding box regression loss function after adding an adaptive weight can be expressed as:

[0020]

[0021] γ i =min(2,(1+w.max()*h.max()-w i *h i ))

[0022] Among them, bbox_loss represents the bounding box loss; N is the size of the batch, w and h are the vectors composed of the width and height of the bounding boxes of all targets in the entire batch predicted by the model; i represents the number of each target in the entire batch, ranging from 1 to N; iou is the vector composed of the CIoU of the model prediction box and the real box; γ iRepresents the adaptive weight coefficient. The larger the target size, the larger the γ i The smaller the target size, the smaller γ i The larger the size, the larger the size; w.max() represents the maximum width of all target bounding boxes in the entire batch; h.max() represents the maximum height of all target bounding boxes in the entire batch; w i represents the width of the i-th bounding box; h i Represents the height of the i-th bounding box.

[0023] In a preferred embodiment, after adding a small target detection head, features from high layers are fused in the newly added detection head, and the ELAN structure is used multiple times to extract fused features.

[0024] In the second aspect, the present application also proposes a small target detection system based on an improved YOLOv7 algorithm, the system comprising:

[0025] A data acquisition module, used to acquire small target data and construct a target detection data set based on the small target data;

[0026] A model training module is used to train a small target detection model based on the data set, wherein the small target detection model includes: adding a small target detection head to the YOLOv7 model, and performing 4 times downsampling of the small target data based on the small target detection head; and adding an adaptive weight to the bounding box regression loss of the YOLOv7 model.

[0027] The small target detection module is used to perform small target detection based on the trained and optimized small target detection model.

[0028] In one embodiment, the data acquisition module further includes: a data preprocessing module, which is used to clean and label the acquired small target data.

[0029] Preferably, data cleaning includes: deleting duplicate data, filtering low-quality images, format conversion and resizing, and category balancing; labeling includes: marking the category and bounding box coordinates of the target to be detected in each image of the acquired small target data.

[0030] In one embodiment, the YOLOv7 model includes: a YOLOv7-tiny model.

[0031] Preferably, the YOLOv7 model also includes: YOLOv7-x, YOLOv7-w6, YOLOv7-e6, YOLOv7-e6e and other models.

[0032] In some embodiments, the YOLOv7 model also includes: YOLOv4, YOLOv5, YOLOv8, YOLOv10 and other models.

[0033] In another embodiment, the bounding box regression loss of the YOLOv7 model includes a CIoU loss function.

[0034] Preferably, the bounding box regression loss function after adding an adaptive weight can be expressed as:

[0035]

[0036] γ i =min(2,(1+w.max()*h.max()-w i *h i ))

[0037] Among them, bbox_loss represents the bounding box loss; N is the batch size, w and h are the vectors composed of the bounding box width and height of all targets in the entire batch predicted by the model; i represents the number of each target in the entire batch, ranging from 1 to N; iou is the vector composed of the CIoU of the model prediction box and the real box; γ i Represents the adaptive weight coefficient. The larger the target size, the larger the γ i The smaller the target size, the smaller γ i The larger the size, the larger the size; w.max() represents the maximum width of all target bounding boxes in the entire batch; h.max() represents the maximum height of all target bounding boxes in the entire batch; w i represents the width of the i-th bounding box; h i Represents the height of the i-th bounding box.

[0038] Furthermore, in the model training module, after adding a small target detection head, features from high layers are fused in the newly added detection head, and the ELAN structure is used multiple times to extract fused features.

[0039] In a third aspect, the present application also proposes a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the small target detection method based on the improved YOLOv7 algorithm as described above.

[0040] In a fourth aspect, the present application further proposes an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of the small target detection method based on the improved YOLOv7 algorithm as described above are implemented.

[0041] (III) Beneficial effects

[0042] The present invention provides a small target detection method, system, storage medium and electronic device based on an improved YOLOv7 algorithm. Compared with the prior art, the present invention has the following beneficial effects:

[0043] The small target detection method, system, storage medium and electronic device based on the improved YOLOv7 algorithm proposed in the present invention improve the detection accuracy of the YOLOv7 target detection algorithm for small targets without almost increasing the detection cost (detection time and detection hardware), and well balance the speed and accuracy of small target detection. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0045] Figure 1 This is a flowchart of a small target detection method based on an improved YOLOv7 algorithm in an embodiment of the present invention;

[0046] Figure 2 The YOLOv7-tiny model structure diagram with a small target detection head added to the embodiment of the present invention;

[0047] Figure 3 This is a graph showing the measured indicators of the small target detection method of the present invention on the urban traffic dataset. DETAILED DESCRIPTION

[0048] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention are clearly and completely described. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0049] Object detection technology is an important branch of computer vision. It aims to accurately locate and identify all objects of interest in an image or video, and determine their categories and locations. Compared with simple image classification tasks, object detection not only needs to identify what the object is, but also its specific location in the image. A rectangular bounding box is usually used to mark the location range of the object. In object detection technology, small object detection has always been a pain point for object detection algorithms, especially when edge deployment is limited by computing power and a small model has to be used. It is easy to miss small targets when sacrificing accuracy for detection speed.

[0050] For example, in the roadside detection scenario of urban traffic, in order to reduce communication latency, it is usually necessary to deploy edge computing devices to perform model inference on the end side. The small computing power of edge devices and the real-time requirements of traffic scenarios limit the use of large models. In addition, cameras are usually placed on crossbars high up on the road, and small objects such as pedestrians and motor vehicle license plates under high vision account for a high proportion. This requires us to use small models with a small number of parameters and fast inference speed on the one hand, and reduce missed detection and false detection of small objects on the other hand. The balance between detection speed and accuracy is particularly important.

[0051] Although YOLOv7 is a representative of the existing open source models with high speed and accuracy, and it also performs well in public data sets, it still needs further optimization for use in specific scenarios. For example, how to balance the detection speed and accuracy of small targets such as pedestrians and license plates in urban traffic scenes.

[0052] The embodiments of the present application provide a small target detection method, system, storage medium and electronic device based on an improved YOLOv7 algorithm, thereby solving the problem that the prior art cannot take into account both the speed and accuracy of small target detection, and achieving the purpose of improving the small target detection accuracy under the premise of slightly increasing the model inference time.

[0053] The technical solution in the embodiment of the present application is to solve the above technical problems, and the overall idea is as follows:

[0054] In order to balance the speed and accuracy of small target detection, this application is based on YOLOv7, one of the most advanced single-stage real-time target detection algorithms, to optimize small target detection and make it more suitable for the detection of small object targets. Specifically, this application improves the performance of the YOLOv7-tiny model, the fastest model in the YOLOv7 series, in various detection scenarios from two perspectives. Introducing adaptive bounding box loss weights without changing the model network structure increases the model's accuracy in detecting small objects; adding a detection head for small objects while slightly increasing the inference time can also increase the model's accuracy in detecting small objects.

[0055] The small target detection method, system, storage medium and electronic device based on the improved YOLOv7 algorithm proposed in this application are suitable for the detection of various small targets, including but not limited to the detection of small targets such as pedestrians and license plates in the roadside detection scene of urban traffic, the detection of small-sized lesions such as tumors, nodules, and calcifications in medical images, the detection of a large number of small targets in images taken at high altitudes in remote sensing image analysis, the detection of pests and diseases in agricultural monitoring, the detection of small-sized defects in industrial automation, etc. In order to facilitate the explanation of the technical solution of this application, the detection of small targets such as pedestrians and license plates in the roadside detection scene of urban traffic is used as an example to illustrate the implementation of the technical solution of this application, but the limitation of this application scenario does not serve as a limitation on the technical solution of this application.

[0056] Glossary:

[0057] Bounding Box is a concept widely used in computer vision and image processing. It is a rectangular box that defines or contains the position and range of the target object in an image (or video frame). Bounding box can be two-dimensional, used to process objects in a flat image; it can also be extended to three-dimensional, used to describe the range of objects in three-dimensional space, such as in some three-dimensional reconstruction or object tracking scenarios.

[0058] Bounding box regression loss is a metric used in object detection algorithms to measure the difference between the predicted bounding box and the true bounding box. Its purpose is to optimize the model by minimizing this loss so that the predicted bounding box is as close to the true bounding box as possible.

[0059] Downsampling refers to the process of resampling a signal (which can be an audio signal, video signal, digital image, etc.) to reduce its sampling rate. In this process, the amount of data is reduced or the frequency characteristics of the signal are changed by reducing the number of samples in the signal. The sampling rate (also called sampling frequency) refers to the number of times an analog signal is sampled per unit time, usually expressed in Hertz (Hz). For example, an audio system with a sampling rate of 44100Hz means that the audio signal is sampled 44100 times per second.

[0060] In order to better understand the above technical solution, the above technical solution will be described in detail below in conjunction with the accompanying drawings and specific implementation methods.

[0061] Embodiment 1:

[0062] In the first aspect, the present invention first proposes a small target detection method based on an improved YOLOv7 algorithm, see Figure 1 , the method comprising:

[0063] S1. Acquire small target data, and construct a target detection data set based on the small target data;

[0064] S2. Training a small target detection model based on the data set, the small target detection model comprising: adding a small target detection head to the YOLOv7 model, and performing a 4-fold downsampling feature on the small target data based on the small target detection head; and adding an adaptive weight to the bounding box regression loss of the YOLOv7 model.

[0065] S3. Perform small target detection based on the small target detection model after training and optimization.

[0066] The small target detection method based on the improved YOLOv7 algorithm proposed in this embodiment improves the detection accuracy of the YOLOv7 target detection algorithm for small targets without almost increasing the detection cost (detection time and detection hardware), and well balances the speed and accuracy of small target detection.

[0067] The following is attached to the instruction manual Figure 1 -, 2, and an explanation of the specific steps S1-S3 to illustrate in detail the implementation process of an embodiment of the present invention.

[0068] S1. Acquire small target data, and construct a target detection dataset based on the small target data.

[0069] S11. Collect small target data.

[0070] Collect target images from the perspective of road-side cameras in urban traffic scenes, which mainly include motor vehicles, non-motor vehicles, pedestrians, etc. at intersections and lanes.

[0071] S12. Constructing a target detection data set based on the small target data

[0072] The target detection dataset is constructed using the small target image data collected in the previous step, which mainly includes data cleaning and labeling. Specifically, data cleaning includes: deleting duplicate data; filtering low-quality images; format conversion and resizing; category balancing, etc. Labeling includes: selecting appropriate annotation tools, such as LabelImg, LabelMe, CVAT, etc.; defining annotation specifications, such as how to draw the bounding box, the definition of category labels, etc.; performing annotation; quality control, checking and reviewing the annotation results to ensure the accuracy and completeness of the annotation. Make corrections and supplements when necessary. Among them, the label includes the category and bounding box coordinates of the target to be detected in each image. After labeling, the small target image data is divided into training set, validation set and test set.

[0073] S2. Training a pre-built small target detection model based on the data set, the small target detection model comprising: adding a small target detection head to the YOLOv7 model, and performing a 4-fold downsampling feature on the small target data based on the small target detection head; and adding an adaptive weight to the bounding box regression loss of the YOLOv7 model.

[0074] The original YOLOv7 model has three detection heads for detecting targets of different sizes, large, medium and small, corresponding to the features after the original image is downsampled by 8 times, 16 times and 32 times in the feature extraction process. The higher the downsampling multiple, the larger the model's field of view and the better the detection effect for large targets. But at the same time, the loss of details is more serious, which is not friendly to small target detection. For example, for the roadside detection scene of urban traffic, since the camera is arranged at a high place, the proportion of small targets to be detected in the camera's field of view, such as pedestrians and license plates, is very high. When extracting image features, the YOLOv7 model will downsample multiple times to condense and refine information, and small targets can easily disappear completely during the downsampling process. In order to improve the detection accuracy of small-sized targets such as pedestrians and license plates in urban traffic scenes, it is necessary to improve the original YOLOv7 model.

[0075] In this embodiment, for specific scenarios in urban traffic scenes where the road-side camera is located at a high position and there are many small-sized targets to be detected, such as pedestrians and license plates, a small target detection head is added to the YOLOv7 model, and the features of the original image are downsampled by 4 times, thereby improving the small target detection accuracy at the cost of slightly increasing the computational overhead.

[0076] In this embodiment, the YOLOv7 model is not specifically limited, including but not limited to the YOLOv7-tiny model, and other size models of YOLOv7, such as YOLOv7-x, YOLOv7-w6, YOLOv7-e6, YOLOv7-e6e, etc. In addition to the YOLOv7 series, it can also be used for YOLOv4, YOLOv5, YOLOv8, YOLOv10, etc. In a preferred embodiment, the YOLOv7 model uses the YOLOv7-tiny model. The small target detection model structure modified based on the YOLOv7-tiny model is as follows Figure 2 As shown in the figure, the blue shaded part is a new structure based on the original YOLOv7-tiny model, and the main body is a small-scale detection head. In addition, in order to further improve the detection accuracy, the new detection head integrates features from high layers (the other three layers), that is, features after 8x, 16x, and 32x downsampling, and uses the ELAN structure to extract fused features multiple times.

[0077] Although adding a small-scale detection head to detect small targets will slightly increase the number of model parameters and floating-point operations, it can achieve a greater improvement in accuracy at the cost of a slight increase in parameters and calculations.

[0078] In addition, in the prior art, the accuracy of small target detection using the YOLOv7 model is poor. There is another reason: the loss function of the YOLOv7 algorithm includes classification loss, confidence loss, and bounding box regression loss, but the weight of the small target bounding box loss in the total loss is small and cannot be adaptively adjusted according to actual needs, thus ignoring the importance of the small target bounding box, resulting in poor small target detection accuracy. Based on this:

[0079] In a preferred embodiment, in order to further improve the accuracy of small target detection, an adaptive weight is added to the bounding box regression loss of the above YOLOv7 model to increase the weight of the small target bounding box loss in the total loss.

[0080] For the bounding box regression loss of the YOLOv7 model, the official default is CIoU loss. In order to increase the emphasis on small object bounding boxes, this embodiment adds an adaptive weight to CIoU loss. The smaller the bounding box, the greater the weight, in order to increase the weight of small object bounding box loss in the total loss. Adding an adaptive weight to CIoU loss can be expressed as a formula:

[0081]

[0082] γ i =min(2,(1+w.max()*h.max()-w i *h i ))

[0083] Where bbox_loss represents the bounding box loss; N is the batch size; w and h are vectors consisting of the width and height of the bounding boxes of all targets in the entire batch predicted by the model; i represents the number of each target in the entire batch, ranging from 1 to N; iou is the vector consisting of the CIoU of the model predicted box and the true box; γ i Represents the adaptive weight coefficient. The larger the target size, the larger the γ i The smaller the target size, the smaller γ i The larger the size, the larger the size; w.max() represents the maximum width of all target bounding boxes in the entire batch; h.max() represents the maximum height of all target bounding boxes in the entire batch; w i represents the width of the i-th bounding box; h i Represents the height of the i-th bounding box.

[0084] This formula can increase the proportion of small targets in the loss function, allowing the model to pay more attention to small targets during training and improve its detection accuracy.

[0085] In addition, adding the bounding box loss adaptive weight only modifies the loss function and has no effect on the YOLOv7 model structure itself. It can improve the small target detection accuracy without increasing the model parameters and inference time.

[0086] For the small target detection model formed by the improvement of the YOLOv7 model, the training set in step S1 is used for model training and optimization. Then the model performance is tested on the validation set, and the model convergence is judged based on the loss function curve and accuracy indicators such as mAP.

[0087] S3. Perform small target detection based on the small target detection model after training and optimization.

[0088] When the model training optimization reaches the expected level, the small target detection model after training and optimization can be used to perform small target detection. At this time, it is only necessary to obtain the small target data to be detected, and then use the small target detection model after training and optimization to obtain the detection result.

[0089] At this point, the entire process of the small target detection method based on the improved YOLOv7 algorithm in this embodiment is completed.

[0090] In order to verify the superiority of the above method of this embodiment, the following experiments are performed to verify:

[0091] The measured indicators of a small target detection method based on an improved YOLOv7 algorithm corresponding to the above embodiment on an urban traffic dataset (https: / / github.com / vvgoder / SEU_PML_Dataset) are as follows: Figure 3 As shown. Figure 3 From the data results, we can see that adding the bounding box loss adaptive weight only modifies the loss function and has no effect on the model structure. It can improve the accuracy of small target detection without increasing the model parameters and inference time. Adding a detection head will increase the model's parameters and floating-point operations. Compared with the 6.02e6 parameters and 13.2GFLOPs floating-point calculations of the original YOLOv7-tiny model, the increase in the detection head increases to 6.11e6 and 15.6GFLOPs respectively. The measured single-frame detection speed on the v100 graphics card (input image resolution 640×640) increased from 5.4ms to 6.6ms. The increase in parameters and calculations is in exchange for a greater improvement in accuracy.

[0092] In addition, using the two methods together can further improve the detection accuracy under the condition of slightly increasing the number of model parameters and inference time. For example, in the mAP@0.5 indicator, the two methods are used together, and the detection accuracy of pedestrians and license plates is increased from 0.513 and 0.677 to 0.542 and 0.695 respectively, and the average accuracy of different categories is increased from 0.618 to 0.648.

[0093] Embodiment 2:

[0094] In a second aspect, the present invention further provides a small target detection system based on an improved YOLOv7 algorithm, the system comprising:

[0095] A data acquisition module, used to acquire small target data and construct a target detection data set based on the small target data;

[0096] A model training module is used to train a small target detection model based on the data set, wherein the small target detection model includes: adding a small target detection head to the YOLOv7 model, and performing 4 times downsampling of the small target data based on the small target detection head; and adding an adaptive weight to the bounding box regression loss of the YOLOv7 model.

[0097] The small target detection module is used to perform small target detection based on the trained and optimized small target detection model.

[0098] In one embodiment, the data acquisition module further includes: a data preprocessing module, which is used to clean and label the acquired small target data.

[0099] Preferably, data cleaning includes: deleting duplicate data, filtering low-quality images, format conversion and resizing, and category balancing; labeling includes: marking the category and bounding box coordinates of the target to be detected in each image of the acquired small target data.

[0100] In one embodiment, the YOLOv7 model includes: a YOLOv7-tiny model.

[0101] Preferably, the YOLOv7 model also includes: YOLOv7-x, YOLOv7-w6, YOLOv7-e6, YOLOv7-e6e and other models.

[0102] In some embodiments, the YOLOv7 model also includes: YOLOv4, YOLOv5, YOLOv8, YOLOv10 and other models.

[0103] In another embodiment, the bounding box regression loss of the YOLOv7 model includes a CIoU loss function.

[0104] Preferably, the bounding box regression loss function after adding an adaptive weight can be expressed as:

[0105]

[0106] γ i =min(2,(1+w.max()*h.max()-w i *h i ))

[0107] Among them, bbox_loss represents the bounding box loss; N is the batch size, w and h are the vectors composed of the bounding box width and height of all targets in the entire batch predicted by the model; i represents the number of each target in the entire batch, ranging from 1 to N; iou is the vector composed of the CIoU of the model prediction box and the real box; γ i Represents the adaptive weight coefficient. The larger the target size, the larger the γ i The smaller the target size, the smaller γ i The larger the size, the larger the size; w.max() represents the maximum width of all target bounding boxes in the entire batch; h.max() represents the maximum height of all target bounding boxes in the entire batch; w i represents the width of the i-th bounding box; h i Represents the height of the i-th bounding box.

[0108] Furthermore, in the model training module, after adding a small target detection head, features from high layers are fused in the newly added detection head, and the ELAN structure is used multiple times to extract fused features.

[0109] It can be understood that the small target detection system based on the improved YOLOv7 algorithm provided in an embodiment of the present invention corresponds to the small target detection method based on the improved YOLOv7 algorithm mentioned above, and the explanations, examples, beneficial effects and other parts of the relevant contents can refer to the corresponding contents in the small target detection method based on the improved YOLOv7 algorithm, which will not be repeated here.

[0110] Embodiment 3:

[0111] In a third aspect, the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the small target detection method based on the improved YOLOv7 algorithm as described in any of the above embodiments, the method comprising:

[0112] Small target data is obtained, and a target detection data set is constructed based on the small target data; a small target detection model is trained based on the data set, wherein the small target detection model includes: adding a small target detection head to a YOLOv7 model, and performing 4 times downsampling features on the small target data based on the small target detection head; and adding an adaptive weight to the bounding box regression loss of the YOLOv7 model.

[0113] Small target detection is performed based on the small target detection model after training and optimization.

[0114] It can be understood that the small target detection storage medium based on the improved YOLOv7 algorithm provided in an embodiment of the present invention corresponds to the small target detection method based on the improved YOLOv7 algorithm mentioned above, and the explanations, examples, beneficial effects and other parts of the relevant contents can refer to the corresponding contents in the small target detection method based on the improved YOLOv7 algorithm, which will not be repeated here.

[0115] Embodiment 4:

[0116] In a fourth aspect, the present invention further provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of the small target detection method based on the improved YOLOv7 algorithm as described in any one of the above embodiments are implemented, and the method comprises:

[0117] Acquire small target data, and construct a target detection data set based on the small target data;

[0118] A small target detection model is trained based on the data set, and the small target detection model includes: adding a small target detection head to the YOLOv7 model, and performing 4 times downsampling features on the small target data based on the small target detection head; and adding an adaptive weight to the bounding box regression loss of the YOLOv7 model.

[0119] Small target detection is performed based on the trained and optimized small target detection model.

[0120] It can be understood that the small target detection electronic device based on the improved YOLOv7 algorithm provided in an embodiment of the present invention corresponds to the small target detection method based on the improved YOLOv7 algorithm mentioned above, and the explanations, examples, beneficial effects and other parts of the relevant contents can refer to the corresponding contents in the small target detection method based on the improved YOLOv7 algorithm, which will not be repeated here.

[0121] In summary, compared with the prior art, the present invention has the following beneficial effects:

[0122] 1. The small target detection method, system, storage medium and electronic device based on the improved YOLOv7 algorithm proposed in the present invention improve the detection accuracy of the YOLOv7 target detection algorithm for small targets without almost increasing the detection cost (detection time and detection hardware), and well balance the speed and accuracy of small target detection.

[0123] 2. The present invention improves the bounding box regression loss weight in the loss function of the YOLOv7 model, and adaptively adjusts its proportion in the total loss according to the target size. The smaller the target, the greater the proportion of its bounding box loss in the total loss, so that it is more valued during back propagation, thereby achieving the purpose of improving the small target detection accuracy of the model without changing the model network structure.

[0124] 3. In small target detection scenarios such as road-side detection scenarios in urban traffic, the present invention adds a detection head for small targets on the basis of the original YOLOv7 model, thereby improving the small target detection accuracy at the cost of slightly increasing the computational overhead.

[0125] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.

[0126] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A small target detection method based on an improved YOLOv7 algorithm, characterized in that: The method comprises: Acquire small target data, and construct a target detection data set based on the small target data; A small target detection model is trained based on the data set, and the small target detection model includes: adding a small target detection head to the YOLOv7 model, and performing 4 times downsampling features on the small target data based on the small target detection head; and adding an adaptive weight to the bounding box regression loss of the YOLOv7 model. Small target detection is performed based on the small target detection model after training and optimization.

2. The method according to any one of claims 1, characterized in that The YOLOv7 model includes: a YOLOv7-tiny model.

3. The method according to any one of claims 1 to 2, characterized in that: The bounding box regression loss of the YOLOv7 model includes the CIoUloss function.

4. The method according to claim 3, characterized in that The bounding box regression loss function after adding an adaptive weight can be expressed as: γ i =min(2,(1+w.max()*h.max()-w i *h i )) Among them, bbox_loss represents the bounding box loss; N is the size of the batch, w and h are the vectors composed of the width and height of the bounding boxes of all targets in the entire batch predicted by the model; i represents the number of each target in the entire batch, ranging from 1 to N; iou is the vector composed of the CIoU of the model prediction box and the real box; γ i Represents the adaptive weight coefficient. The larger the target size, the larger the γ i The smaller the target size, the smaller γ i The larger the size, the larger the size; w.max() represents the maximum width of all target bounding boxes in the entire batch; h.max() represents the maximum height of all target bounding boxes in the entire batch; w i Indicates the width of the i-th bounding box; h i Represents the height of the i-th bounding box.

5. A small target detection system based on an improved YOLOv7 algorithm, characterized in that: The system comprises: A data acquisition module, used to acquire small target data and construct a target detection data set based on the small target data; A model training module is used to train a small target detection model based on the data set, wherein the small target detection model includes: adding a small target detection head to the YOLOv7 model, and performing 4 times downsampling of the small target data based on the small target detection head; and adding an adaptive weight to the bounding box regression loss of the YOLOv7 model. The small target detection module is used to perform small target detection based on the trained and optimized small target detection model.

6. The system according to any one of claims 5, characterized in that: The YOLOv7 model in the model training module includes: a YOLOv7-tiny model.

7. The system according to any one of claims 5 to 6, characterized in that: The bounding box regression loss of the YOLOv7 model includes the CIoUloss function.

8. The system according to claim 7, characterized in that The bounding box regression loss function after adding an adaptive weight can be expressed as: γ i =min(2,(1+w.max()*h.max()-w i *h i )) Among them, bbox_loss represents the bounding box loss; N is the batch size, w and h are the vectors composed of the bounding box width and height of all targets in the entire batch predicted by the model; i represents the number of each target in the entire batch, ranging from 1 to N; iou is the vector composed of the CIoU of the model prediction box and the real box; γ i represents the adaptive weight coefficient. The larger the target size, the smaller γi is, and the smaller the target size, the larger γi is. w.max() represents the maximum width of all target bounding boxes in the entire batch. h.max() represents the maximum height of all target bounding boxes in the entire batch. w i Indicates the width of the i-th bounding box; h i Represents the height of the i-th bounding box.

9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the small target detection method based on the improved YOLOv7 algorithm as described in any one of claims 1 to 4 are implemented.

10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the steps of the small target detection method based on the improved YOLOv7 algorithm are implemented as described in any one of claims 1 to 4.

Citation Information

Cited By

  • High-precision and high-adaptability intelligent detection and diagnosis method and system for electronic product defects

    CN120673172A