Small target detection method and system based on improved yolov7 algorithm, and storage medium and electronic device

By adding a small object detection head and adaptive bounding box regression loss weights to the YOLOv7 model, the YOLOv7 algorithm is optimized, resolving the contradiction between speed and accuracy in small object detection and achieving efficient detection when deployed at the edge.

WO2026114435A1PCT designated stage Publication Date: 2026-06-04NANJING DRUM TOWER HOSPITAL

Patent Information

Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
NANJING DRUM TOWER HOSPITAL
Filing Date
2025-12-31
Publication Date
2026-06-04

AI Technical Summary

Technical Problem

Existing technologies cannot balance speed and accuracy in small target detection without increasing detection time and hardware costs, especially when deployed at the edge.

Method used

A small object detection head is added to the YOLOv7 model, and 4x downsampling feature extraction is performed. Adaptive weights are added to the bounding box regression loss to optimize the YOLOv7 model and improve the accuracy of small object detection.

Benefits of technology

It significantly improves the accuracy of small target detection with almost no increase in detection cost, balancing speed and accuracy, and is suitable for various scenarios such as urban traffic, medical imaging, and remote sensing images.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure PCTCN2025148046-FTAPPB-I100001
    Figure PCTCN2025148046-FTAPPB-I100001
  • Figure PCTCN2025148046-FTAPPB-I100002
    Figure PCTCN2025148046-FTAPPB-I100002
  • Figure PCTCN2025148046-FTAPPB-I100003
    Figure PCTCN2025148046-FTAPPB-I100003
Patent Text Reader

Abstract

The present invention relates to the technical field of target detection. Provided are a small target detection method and system based on an improved YOLOv7 algorithm, and a storage medium and an electronic device. In the technique, the performance and effect of a YOLOv7 model in an urban traffic road-end detection scenario is improved from two perspectives: introducing an adaptive bounding box loss weight without changing the network structure of the model, thereby increasing the detection accuracy of the model with regard to a small target; and adding a detection head for a small target with only a slight increase in the inference time, which also increases the detection accuracy of the model with regard to the small target. In the present invention, the detection accuracy of a YOLOv7 target detection algorithm with regard to a small target is improved with almost no increase in the detection cost, thereby ensuring both the speed and accuracy of small target detection.
Need to check novelty before this filing date? Find Prior Art

Description

Small target detection method, system, storage medium, and electronic device based on improved YOLOv7 algorithm Technical Field

[0001] This invention relates to the field of target detection technology, and specifically to a method, system, storage medium, and electronic device for small target detection based on an improved YOLOv7 algorithm. Background Technology

[0002] Object detection is an important branch of computer vision, aiming to accurately locate and identify all objects of interest in images or videos, determining their category and location. Compared to simple image classification tasks, object detection not only needs to identify what the object is, but also to pinpoint its exact location within the image, typically using rectangular bounding boxes to delineate the target's position. However, small object detection has always been a pain point for object detection algorithms, especially when deployed at edge environments and limited by computational constraints, necessitating the use of smaller models. Sacrificing accuracy for speed can easily lead to missed small objects.

[0003] The YOLOv7 algorithm is a representative of fast and accurate existing open-source models. It performs well on public datasets and is often used for small object detection.

[0004] However, the YOLOv7 algorithm still needs further optimization when detecting small targets in specific scenarios. This is because existing technologies must increase detection time to reduce false positives and false negatives for small objects, while sacrificing detection accuracy is necessary to save detection time. In other words, existing small target detection technologies cannot achieve a good balance between speed and accuracy. Summary of the Invention

[0005] (a) Technical problems to be solved

[0006] To address the shortcomings of existing technologies, this invention provides a small target detection method, system, storage medium, and electronic device based on an improved YOLOv7 algorithm, solving the problem that existing technologies cannot simultaneously achieve both speed and accuracy in small target detection.

[0007] (II) Technical Solution

[0008] To achieve the above objectives, the present invention provides the following technical solution:

[0009] Firstly, this application 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 dataset based on the small target data;

[0011] A small object detection model is trained based on the dataset. The small object detection model includes: adding a small object detection head to the YOLOv7 model, and performing a 4-fold downsampling feature on the small object data based on the small object detection head; and adding an adaptive weight to the bounding box regression loss of the YOLOv7 model.

[0012] Small object detection is performed based on the trained and optimized small object detection model.

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

[0014] Preferably, data cleaning includes: deduplication, low-quality image filtering, format conversion and resizing, and category balancing; labeling includes: labeling 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: the YOLOv7-tiny model.

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

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

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

[0019] Preferably, the bounding box regression loss function with an added adaptive weight can be expressed as follows:

[0020]

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

[0022] Where bbox_loss represents the bounding box loss; N is the batch size; w and h are vectors composed of the width and height of the bounding boxes of all objects in a whole batch predicted by the model; i represents the index of each object in the whole batch, with values ​​from 1 to N; iou is a vector composed of the CIoU between the model's predicted box and the ground truth box; γ iγ represents the adaptive weighting coefficient; the larger the target size, the greater the γ. i The smaller the value, the smaller the target size, and thus the smaller the γ value. i The larger the value, the greater the value; w.max() represents the maximum width of all bounding boxes in the entire batch; h.max() represents the maximum height of all bounding boxes in the entire batch; w i h represents the width of the i-th bounding box. i This represents the height of the i-th bounding box.

[0023] In a preferred embodiment, after adding a small target detection head, features from higher layers are fused into the new detection head, and the fused features are extracted multiple times using the ELAN structure.

[0024] Secondly, this application also proposes a small target detection system based on the improved YOLOv7 algorithm, the system comprising:

[0025] The data acquisition module is used to acquire small target data and construct a target detection dataset based on the small target data;

[0026] The model training module is used to train a small object detection model based on the dataset. The small object detection model includes: adding a small object detection head to the YOLOv7 model and performing a 4-fold downsampling feature on the small object data based on the small object detection head; and adding an adaptive weight to the bounding box regression loss of the YOLOv7 model.

[0027] The small object detection module is used to detect small objects based on the trained and optimized small object 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: deduplication, low-quality image filtering, format conversion and resizing, and category balancing; labeling includes: labeling 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: the YOLOv7-tiny model.

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

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

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

[0034] Preferably, the bounding box regression loss function with an added adaptive weight can be expressed as follows:

[0035]

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

[0037] Where bbox_loss represents the bounding box loss; N is the batch size; w and h are vectors composed of the width and height of the bounding boxes of all objects in a whole batch predicted by the model; i represents the index of each object in a whole batch, with values ​​from 1 to N; iou is a vector composed of the CIoU between the model's predicted box and the ground truth box; γ i γ represents the adaptive weighting coefficient; the larger the target size, the greater the γ. i The smaller the value, the smaller the target size, and thus the smaller the γ value. i The larger the value, the greater the value; w.max() represents the maximum width of all bounding boxes in the entire batch; h.max() represents the maximum height of all bounding boxes in the entire batch; w i h represents the width of the i-th bounding box. i This 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 higher levels are fused into the newly added detection head, and the ELAN structure is used multiple times to extract the fused features.

[0039] Thirdly, this application also proposes a non-transitory computer-readable storage medium storing a computer program 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] Fourthly, this application further proposes an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the steps of the small target detection method based on the improved YOLOv7 algorithm as described above.

[0041] (III) Beneficial Effects

[0042] This invention provides a small target detection method, system, storage medium, and electronic device based on an improved YOLOv7 algorithm. Compared with existing technologies, it has the following advantages:

[0043] The present invention proposes a small target detection method, system, storage medium, and electronic device based on the improved YOLOv7 algorithm. It improves the detection accuracy of the YOLOv7 target detection algorithm for small targets with almost no increase in detection cost (detection time and detection hardware), and well balances the speed and accuracy of small target detection. Attached Figure Description

[0044] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

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

[0046] Figure 2 is a structural diagram of the YOLOv7-tiny model with an added small target detection head in an embodiment of the present invention;

[0047] Figure 3 shows the measured performance of the small target detection method of the present invention on an urban traffic dataset. Detailed Implementation

[0048] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention are described clearly and completely. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0049] Object detection is an important branch of computer vision, aiming to accurately locate and identify all objects of interest in images or videos, determining their category and location. Compared to simple image classification tasks, object detection not only needs to identify what the object is, but also to pinpoint its exact location within the image, typically using rectangular bounding boxes to delineate the target's position. However, small object detection has always been a pain point for object detection algorithms, especially when deployed at edge environments and limited by computational constraints, necessitating the use of smaller models. Sacrificing accuracy for speed can easily lead to missed small objects.

[0050] For example, in urban traffic detection scenarios, edge computing devices are typically deployed on the edge to perform model inference in order to reduce communication latency. However, the limited computing power of edge devices and the real-time requirements of traffic scenarios restrict the use of large models. In addition, cameras are usually mounted on crossbars at high points on the road, and the proportion of small objects such as pedestrians and vehicle license plates is relatively high in the high field of view. This requires us to use small models with fewer parameters and faster inference speeds, while also minimizing missed or false detections of small objects. The balance between detection speed and accuracy is particularly important.

[0051] While YOLOv7 is a representative of fast and accurate existing open-source models and has shown impressive performance on public datasets, it still needs further optimization for specific scenarios, such as how to balance the detection speed and accuracy of small targets like pedestrians and license plates in urban traffic scenarios.

[0052] This application provides a small target detection method, system, storage medium, and electronic device based on an improved YOLOv7 algorithm, which solves the problem that the existing technology cannot balance the speed and accuracy of small target detection, and achieves the goal of improving the accuracy of small target detection with a slight increase in model inference time.

[0053] The technical solution in this application is to solve the above-mentioned technical problems, and the general idea is as follows:

[0054] To balance speed and accuracy in small object detection, this application optimizes YOLOv7, one of the most advanced single-stage real-time object detection algorithms, to better suit the detection of small objects. Specifically, this application improves the YOLOv7-tiny model, the fastest in the YOLOv7 series, from two perspectives, enhancing its performance in various detection scenarios. First, it introduces adaptive bounding box loss weights without changing the model's network structure, increasing the model's accuracy in small object detection. Second, it adds a detection head specifically for small objects, slightly increasing inference time, which also improves the model's accuracy in small object detection.

[0055] The small target detection method, system, storage medium, and electronic device proposed in this application, based on the improved YOLOv7 algorithm, are applicable to the detection of various small targets, including but not limited to the detection of pedestrians, license plates, and other small targets in urban traffic roadside detection scenarios; the detection of small lesions such as tumors, nodules, and calcifications in medical imaging; the detection of numerous small targets in aerial images captured in remote sensing image analysis; the detection of pests and diseases in agricultural monitoring; and the detection of small defects in industrial automation, etc. To facilitate the explanation of the technical solution of this application, the detection of small targets such as pedestrians and license plates in urban traffic roadside detection scenarios will be used as an example to illustrate the implementation of the technical solution of this application. However, the limitation of this application scenario is not intended to limit the technical solution of this application.

[0056] Definitions:

[0057] A bounding box is a widely used concept in computer vision and image processing. It is a rectangular box used to define or contain the position and extent of a target object in an image (or video frame). Bounding boxes can be two-dimensional, used to process objects in planar images; they can also be extended to three dimensions to describe the extent of an object in three-dimensional space, such as in some 3D 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 approximates the true bounding box as accurately 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. This process reduces the number of samples in the signal to decrease the amount of data or alter the signal's frequency characteristics. The sampling rate (also called the sampling frequency) refers to the number of times an analog signal is sampled per unit of time, usually expressed in Hertz (Hz). For example, an audio system with a sampling rate of 44,100 Hz means that the audio signal is sampled 44,100 times per second.

[0060] To better understand the above technical solutions, the following will provide a detailed explanation of the technical solutions in conjunction with the accompanying drawings and specific implementation methods.

[0061] Example 1:

[0062] Firstly, this invention proposes a small target detection method based on an improved YOLOv7 algorithm, as shown in Figure 1. This method includes:

[0063] S1. Obtain small target data and construct a target detection dataset based on the small target data;

[0064] S2. Train a small object detection model based on the dataset. The small object detection model includes: adding a small object detection head to the YOLOv7 model and performing a 4-fold downsampling feature on the small object data based on the small object 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 trained and optimized small target detection model.

[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 increasing the detection cost (detection time and detection hardware), thus achieving a good balance between speed and accuracy in small target detection.

[0067] The implementation process of an embodiment of the present invention will be described in detail below with reference to Figures 1-2 in the specification and the explanation of the specific steps S1-S3.

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

[0069] S11. Collect data from small targets.

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

[0071] S12. Construct a target detection dataset based on the small target data.

[0072] The target detection dataset is constructed using the small target image data collected in the previous step, mainly including data cleaning and labeling. Specifically, data cleaning includes: deduplication; low-quality image filtering; format conversion and resizing; class balancing, etc. Labeling includes: selecting appropriate annotation tools, such as LabelImg, LabelMe, CVAT, etc.; defining annotation specifications, such as the method of drawing bounding boxes and the definition of class labels; performing annotation; quality control, checking and reviewing the annotation results to ensure the accuracy and completeness of the annotations. Corrections and supplements are made as necessary. The labels include the class of the target to be detected in each image and the bounding box coordinates. After labeling, the small target image data is divided into training, validation, and test sets.

[0073] S2. Train a pre-built small object detection model based on the dataset. The small object detection model includes: adding a small object detection head to the YOLOv7 model and performing a 4-fold downsampling feature on the small object data based on the small object detection head; and adding an adaptive weight to the bounding box regression loss of the YOLOv7 model.

[0074] The original YOLOv7 model has three detector heads to detect targets of different sizes, corresponding to features extracted from the original image after downsampling by 8x, 16x, and 32x respectively. Higher downsampling factors result in a larger field of view and better detection of large targets. However, this also leads to greater loss of detail and makes it less effective for detecting small targets. For example, in urban traffic scene detection, because cameras are positioned high up, small targets such as pedestrians and license plates occupy a large portion of the camera's field of view. The YOLOv7 model performs multiple downsampling operations to condense and refine information during feature extraction, making it easy for small targets to disappear completely during this process. To improve the detection accuracy of small targets such as pedestrians and license plates in urban traffic scenes, the original YOLOv7 model needs to be improved.

[0075] In this embodiment, for specific scenarios in urban traffic scenes where roadside cameras are positioned high and there are many small targets such as pedestrians and license plates among the targets to be detected, a small target detection head is added to the YOLOv7 model. The feature is downsampled by 4 times according to the original image, which improves 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, and includes, but is not limited to, the YOLOv7-tiny model, as well as other sizes of YOLOv7 models, such as YOLOv7-x, YOLOv7-w6, YOLOv7-e6, YOLOv7-e6e, etc. Besides the YOLOv7 series, it can also be used for YOLOv4, YOLOv5, YOLOv8, YOLOv10, etc. In a preferred embodiment, the YOLOv7-tiny model is selected. The structure of the small target detection model modified based on the YOLOv7-tiny model is shown in Figure 2. The blue shaded area in the figure represents the newly added structure based on the original YOLOv7-tiny model, the main body of which is a small-scale detection head. Furthermore, to further improve detection accuracy, features from higher layers (the other three layers) are fused into the newly added detection head, namely features downsampled by 8x, 16x, and 32x, and the ELAN structure is used multiple times to extract the fused features.

[0077] Adding a small-scale detector to detect small targets will slightly increase the number of model parameters and floating-point operations, but the accuracy can be improved by sacrificing the slight increase in parameters and computation.

[0078] Furthermore, another reason for the poor accuracy of small object detection using the YOLOv7 model in existing technologies is that the YOLOv7 algorithm's loss function includes classification loss, confidence loss, and bounding box regression loss. However, the weight of the small object bounding box loss in the total loss is relatively small and cannot be adaptively adjusted according to actual needs, thus neglecting the importance of small object bounding boxes and resulting in poor small object detection accuracy. Based on this:

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

[0080] For the bounding box regression loss of the YOLOv7 model, the official default is to use CIoU loss. This embodiment adds an adaptive weight to the CIoU loss to increase the importance given to small bounding boxes; the smaller the bounding box, the larger the weight, aiming to increase the weight of the small bounding box loss in the total loss. Adding an adaptive weight to the CIoU loss can be expressed as the 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 composed of the width and height of the bounding boxes of all objects in a whole batch predicted by the model; i represents the index of each object in a whole batch, with values ​​from 1 to N; iou is a vector composed of the CIoU between the model's predicted box and the ground truth box; γ i γ represents the adaptive weighting coefficient; the larger the target size, the greater the γ. i The smaller the value, the smaller the target size, and thus the smaller the γ value. i The larger the value, the greater the value; w.max() represents the maximum width of all bounding boxes in the entire batch; h.max() represents the maximum height of all bounding boxes in the entire batch; w i h represents the width of the i-th bounding box. i This represents the height of the i-th bounding box.

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

[0085] Furthermore, adding adaptive weights to the bounding box loss only modifies the loss function and has no impact on the YOLOv7 model structure itself. It can improve the accuracy of small object detection without increasing the number of model parameters or inference time.

[0086] For the small object detection model improved from the YOLOv7 model, the training set from step S1 is used for model training and optimization. Then, the model performance is tested on the validation set, and convergence is determined based on the loss function curve and accuracy metrics such as mAP.

[0087] S3. Perform small target detection based on the trained and optimized small target detection model.

[0088] Once the model training and optimization reach the expected level, the trained and optimized small target detection model can be used to detect small targets. At this point, it is only necessary to obtain the data of the small targets to be detected, and then use the trained and optimized small target detection model to obtain the detection results.

[0089] This completes the entire process of the small target detection method based on the improved YOLOv7 algorithm in this embodiment.

[0090] To verify the superiority of the method described in this embodiment, the following experiments are conducted:

[0091] Figure 3 shows the measured performance of a small object detection method based on the improved YOLOv7 algorithm, corresponding to the above embodiment, on the urban traffic dataset (https: / / github.com / vvgoder / SEU_PML_Dataset). As can be seen from the data results in Figure 3, adding adaptive weights to the bounding box loss only modifies the loss function and has no impact on the model structure. It can improve the accuracy of small object detection without increasing the number of model parameters or inference time. Adding a detection head increases the number of model parameters and floating-point computation. Compared to the original YOLOv7-tiny model's 6.02e6 parameters and 13.2 GFLOPs of floating-point computation, adding a detection head results in 6.11e6 parameters and 15.6 GFLOPs, respectively. The measured single-frame detection speed (input image resolution 640×640) on a v100 graphics card increased from 5.4ms to 6.6ms. The increased number of parameters and computational cost is compensated by a greater improvement in accuracy.

[0092] Furthermore, using both methods together can further improve detection accuracy with a slight increase in the number of model parameters and inference time. For example, with an mAP@0.5 metric, using both methods together improves the detection accuracy for pedestrians and license plates from 0.513 and 0.677 to 0.542 and 0.695, respectively, and the average accuracy across different categories from 0.618 to 0.648.

[0093] Example 2:

[0094] Secondly, the present invention also provides a small target detection system based on the improved YOLOv7 algorithm, the system comprising:

[0095] The data acquisition module is used to acquire small target data and construct a target detection dataset based on the small target data;

[0096] The model training module is used to train a small object detection model based on the dataset. The small object detection model includes: adding a small object detection head to the YOLOv7 model and performing a 4-fold downsampling feature on the small object data based on the small object detection head; and adding an adaptive weight to the bounding box regression loss of the YOLOv7 model.

[0097] The small object detection module is used to detect small objects based on the trained and optimized small object 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: deduplication, low-quality image filtering, format conversion and resizing, and category balancing; labeling includes: labeling 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: the YOLOv7-tiny model.

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

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

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

[0104] Preferably, the bounding box regression loss function with an added adaptive weight can be expressed as follows:

[0105]

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

[0107] Where bbox_loss represents the bounding box loss; N is the batch size; w and h are vectors composed of the width and height of the bounding boxes of all objects in a whole batch predicted by the model; i represents the number of each object in a whole batch, with values ​​from 1 to N; iou is a vector composed of the CIoU between the model's predicted box and the ground truth box; γ i γ represents the adaptive weighting coefficient; the larger the target size, the greater the γ. i The smaller the value, the smaller the target size, and thus the smaller the γ value. i The larger the value, the greater the value; w.max() represents the maximum width of all bounding boxes in the entire batch; h.max() represents the maximum height of all bounding boxes in the entire batch; w i h represents the width of the i-th bounding box. i This 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 higher levels are fused into the newly added detection head, and the ELAN structure is used multiple times to extract the fused features.

[0109] It is understood that the small target detection system based on the improved YOLOv7 algorithm provided in this embodiment of the invention corresponds to the small target detection method based on the improved YOLOv7 algorithm described above. The explanations, examples, and beneficial effects of the relevant content can be referred to the corresponding content in the small target detection method based on the improved YOLOv7 algorithm, and will not be repeated here.

[0110] Example 3:

[0111] Thirdly, the present invention also 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] Acquire small target data and construct a target detection dataset based on the small target data; train a small target detection model based on the dataset, 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.

[0113] Small object detection is performed based on the trained and optimized small object detection model.

[0114] It is understood that the small target detection storage medium based on the improved YOLOv7 algorithm provided in this embodiment of the invention corresponds to the small target detection method based on the improved YOLOv7 algorithm described above. The explanations, examples, and beneficial effects of the relevant content can be referred to the corresponding content in the small target detection method based on the improved YOLOv7 algorithm, and will not be repeated here.

[0115] Example 4:

[0116] Fourthly, the present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the steps of the small target detection method based on the improved YOLOv7 algorithm as described in any of the foregoing embodiments, the method comprising:

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

[0118] A small object detection model is trained based on the dataset. The small object detection model includes: adding a small object detection head to the YOLOv7 model, and performing a 4-fold downsampling feature on the small object data based on the small object detection head; and adding an adaptive weight to the bounding box regression loss of the YOLOv7 model.

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

[0120] It is understood that the small target detection electronic device based on the improved YOLOv7 algorithm provided in this embodiment of the invention corresponds to the small target detection method based on the improved YOLOv7 algorithm described above. The explanations, examples, and beneficial effects of the relevant content can be referred to the corresponding content in the small target detection method based on the improved YOLOv7 algorithm, and will not be repeated here.

[0121] In summary, compared with existing technologies, it has the following beneficial effects:

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

[0123] 2. This invention improves the bounding box regression loss weight in the loss function of the YOLOv7 model by adaptively adjusting its proportion in the total loss according to the target size. The smaller the target, the larger the proportion of its bounding box loss in the total loss, and thus it is given more importance during backpropagation. This achieves the goal of improving the detection accuracy of small targets in the model without changing the model network structure.

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

[0125] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0126] The above embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate 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 includes: Acquire small target data and construct a target detection dataset based on the small target data; A small object detection model is trained based on the dataset. The small object detection model includes: adding a small object detection head to the YOLOv7 model, and performing a 4-fold downsampling feature on the small object data based on the small object detection head; and adding an adaptive weight to the bounding box regression loss of the YOLOv7 model. Small object detection is performed based on the trained and optimized small object detection model.

2. The method as described in any one of claims 1, characterized in that, The YOLOv7 model includes the YOLOv7-tiny model.

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

4. The method as described in claim 3, characterized in that, The bounding box regression loss function after adding an adaptive weight can be expressed by the following formula: γ i =min(2,(1+w.max()*h.max()-w i *h i )) Where bbox_loss represents the bounding box loss; N is the batch size; w and h are vectors composed of the width and height of the bounding boxes of all objects in a whole batch predicted by the model; i represents the index of each object in the whole batch, with values ​​from 1 to N; iou is a vector composed of the CIoU between the model's predicted box and the ground truth box; γ i γ represents the adaptive weighting coefficient; the larger the target size, the greater the γ. i The smaller the value, the smaller the target size, and thus the smaller the γ value. i The larger the value, the greater the value; w.max() represents the maximum width of all bounding boxes in the entire batch; h.max() represents the maximum height of all bounding boxes in the entire batch; w i h represents the width of the i-th bounding box. i This 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 includes: The data acquisition module is used to acquire small target data and construct a target detection dataset based on the small target data; The model training module is used to train a small object detection model based on the dataset. The small object detection model includes: adding a small object detection head to the YOLOv7 model and performing a 4-fold downsampling feature on the small object data based on the small object detection head; and adding an adaptive weight to the bounding box regression loss of the YOLOv7 model. The small object detection module is used to detect small objects based on the trained and optimized small object detection model.

6. The system as described in any one of claims 5, characterized in that, The YOLOv7 model in the model training module includes the YOLOv7-tiny model.

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

8. The system as described in claim 7, characterized in that, The bounding box regression loss function after adding an adaptive weight can be expressed by the following formula: γ i =min(2,(1+w.max()*h.max()-w i *h i )) Where bbox_loss represents the bounding box loss; N is the batch size; w and h are vectors composed of the width and height of the bounding boxes of all objects in a whole batch predicted by the model; i represents the number of each object in a whole batch, with values ​​from 1 to N; iou is a vector composed of the CIoU between the model's predicted box and the ground truth box; γ i γi represents the adaptive weighting coefficient; the larger the target size, the smaller γi, and the smaller the target size, the larger γi. 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. i h represents the width of the i-th bounding box. i This 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 executed by a processor, the computer program implements the steps of the small target detection method based on the improved YOLOv7 algorithm as described in any one of claims 1 to 4.

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, it implements the steps of the small target detection method based on the improved YOLOv7 algorithm as described in any one of claims 1 to 4.