A dense small target detection method and system based on weighted attention mechanism
By introducing a weighted attention mechanism and a multi-scale feature fusion strategy, and optimizing the loss function, the problem of insufficient accuracy in dense small target detection is solved, and target detection results with high accuracy and high recall are achieved.
Patent Information
- Application Number
- CN202411869337.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-18
- Publication Date
- 2025-10-28
- Estimated Expiration
- 2044-12-18
AI Technical Summary
Existing target detection algorithms lack accuracy in dense small target scenes, making it difficult to effectively distinguish and locate small targets, and are easily affected by background noise.
By introducing a weighted attention mechanism and fusing multi-scale features and optimizing the loss function, the model's ability to distinguish between small targets and background features is enhanced, thereby improving detection accuracy and robustness.
It significantly improves the detection accuracy and recall rate of dense small targets, especially performing well in dense small target scenarios, while maintaining high computational efficiency.
Smart Images

Figure CN119693773B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of detection technology, specifically to a method and system for detecting dense small targets based on a weighted attention mechanism. Background Technology
[0002] Detecting densely packed small targets has always been a challenging task in the field of object detection. Traditional object detection methods typically focus on identifying targets with large size or simple backgrounds, but existing algorithms often perform poorly in scenarios with densely packed small targets. Densely packed small targets are often disturbed by background noise, and the close proximity of adjacent targets makes it difficult for traditional detection frameworks to effectively distinguish and locate these targets. Furthermore, due to the small size of the targets and the limited amount of information they contain, detection accuracy and recall are easily affected.
[0003] In recent years, deep learning, especially convolutional neural networks (CNNs), has made significant progress in object detection. However, CNNs still have limitations when dealing with small objects. To address this issue, researchers have proposed various techniques to enhance the expressive power of models, such as multi-scale feature fusion and contextual information modeling. However, these methods often overlook the subtle differences between small objects, resulting in unsatisfactory performance in dense small object detection. Therefore, effectively utilizing attention mechanisms to enhance the model's focus on key information has become an important research direction for improving the accuracy of dense small object detection. Summary of the Invention
[0004] To address the aforementioned technical challenges, this paper presents a method and system for detecting dense small targets based on a weighted attention mechanism. This aims to overcome the insufficient accuracy of existing target detection algorithms in dense small target scenes. By introducing a weighted attention mechanism, the model's ability to distinguish between small targets and background features is effectively enhanced, improving detection accuracy and robustness.
[0005] To achieve the above objectives, the technical solution adopted by the present invention is as follows:
[0006] In a first aspect of the present invention, a method for detecting dense small targets based on a weighted attention mechanism is provided, comprising:
[0007] Feature extraction is performed on the input image by progressively extracting low-level and high-level features through multiple convolutional layers (Conv1, Conv2, etc.) to obtain a set of feature maps;
[0008] A multi-scale feature fusion strategy is introduced to accurately locate dense small targets in images;
[0009] Based on the multi-scale feature fusion strategy, a weighted attention mechanism is introduced to obtain the final weighted feature map;
[0010] The loss function of traditional object detection is optimized to enhance the detection capability of dense small targets.
[0011] Preferably, the input image is X∈R H×W×C , where H, W and C represent the height, width and number of channels of the image, respectively.
[0012] Preferably, after feature extraction, a set of feature maps is obtained. in It is the feature map of the i-th layer, and N is the number of feature layers.
[0013] Preferably, the features after the multi-scale feature fusion strategy are: The fusion process is defined as follows:
[0014]
[0015] Where Resize(· i (H,W) indicates that the feature map is adjusted to a uniform resolution of H×W, where w i Let be the fusion weights of the feature maps of the i-th layer.
[0016] Preferably, the definitions of channel attention and spatial attention in the weighted attention mechanism are as follows:
[0017]
[0018] Where σ(·) is the Sigmoid function, GAP(·) represents global average pooling, W1 and W2 are learnable parameters for channel attention, * represents the convolution operation, and W s Here are the convolution kernel weights for spatial attention, and channel attention A. c ∈R 1×1×C Spatial attention A focuses on the importance of features in different channels. s ∈R H×W×1 Focus on key locations in the feature map.
[0019] Preferably, the final weighted feature map is:
[0020]
[0021] Where · represents element-wise multiplication, weighted feature map It effectively enhances the salience of small targets while suppressing background noise.
[0022] Preferably, the loss function for traditional object detection typically consists of a classification loss L. cls and positioning loss L IOU composition:
[0023]
[0024] The target box set is as follows: The corresponding set of prediction boxes is The weights are assigned to the bounding boxes, with smaller bounding boxes receiving higher weights to enhance the model's ability to learn about smaller targets.
[0025] Preferably, the optimized loss function is:
[0026] L=λ cls L cls +λ loc L loc +λ IoU L IoU
[0027] Where, λ IoU This is the balance coefficient for weighted IoU loss.
[0028] In a second aspect of the invention, a dense small target detection system based on a weighted attention mechanism is proposed, comprising:
[0029] The feature extraction module is used to extract features from the input image by progressively extracting low-level and high-level features through multiple convolutional layers (Conv1, Conv2, etc.) to obtain a set of feature maps.
[0030] The feature fusion module is used to introduce a multi-scale feature fusion strategy to accurately locate dense small targets in the image;
[0031] The weighting module is used to introduce a weighted attention mechanism on the basis of the multi-scale feature fusion strategy to obtain the final weighted feature map;
[0032] An optimization module is used to optimize the loss function of traditional target detection, thereby enhancing the detection capability of dense small targets.
[0033] In a third aspect of the invention, an electronic device is provided. The electronic device includes at least one processor; and a memory communicatively connected to the at least one processor; the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method of the first aspect of the invention.
[0034] Compared with existing technologies, this invention provides a method and system for detecting dense small targets based on a weighted attention mechanism, which has the following beneficial effects:
[0035] This invention significantly improves the detection capability for densely packed small targets through the aforementioned improvement strategies. Experimental results on public datasets demonstrate that the algorithm of this invention outperforms existing methods in both accuracy and recall, especially excelling in densely packed small target detection scenarios. Furthermore, the algorithm exhibits high computational efficiency, making it suitable for widespread application in real-world scenarios. Attached Figure Description
[0036] Figure 1 This is a schematic diagram of the dense small target detection method based on weighted attention mechanism in this invention;
[0037] Figure 2 Example diagram of the dataset used in the algorithm of this invention;
[0038] Figure 3 The correlation scatter matrix of the dataset used in this invention;
[0039] Figure 4 This is a graph showing the metrics during the baseline training process based on YOLOv10 in this invention.
[0040] Figure 5 The figure shows the experimental results of the baseline test based on YOLOv10 for this invention;
[0041] Figure 6 This is a PR diagram of the baseline of this invention based on YOLOv10;
[0042] Figure 7 This is the F1-Confidence curve of the baseline based on YOLOv10 in this invention;
[0043] Figure 8 This is a diagram showing the confusion matrix result of the YOLOv10 baseline of this invention;
[0044] Figure 9 A block diagram of an exemplary electronic device capable of implementing embodiments of the present invention is shown.
[0045] Among them, 800 is an electronic device, 801 is a computing unit, 802 is a ROM, 803 is a RAM, 804 is a bus, 805 is an I / O interface, 806 is an input unit, 807 is an output unit, 808 is a storage unit, and 809 is a communication unit. Detailed Implementation
[0046] The following description is intended to disclose the invention and enable those skilled in the art to implement it. The preferred embodiments described below are merely examples, and other obvious variations will occur to those skilled in the art.
[0047] Example 1
[0048] Please refer to Figures 1-8 As shown, a method for detecting dense small targets based on a weighted attention mechanism includes:
[0049] S100. Extract features from the input image by progressively extracting low-level and high-level features through multiple convolutional layers (Conv1, Conv2, etc.) to obtain a set of feature maps.
[0050] S200: Introducing a multi-scale feature fusion strategy to accurately locate dense small targets in images;
[0051] S300. Based on the multi-scale feature fusion strategy, a weighted attention mechanism is introduced to obtain the final weighted feature map.
[0052] S400 optimizes the loss function of traditional target detection, enhancing the detection capability of dense small targets.
[0053] The input image is X∈R H×W×C , where H, W and C represent the height, width and number of channels of the image, respectively.
[0054] After feature extraction, a set of feature maps is obtained. in It is the feature map of the i-th layer, and N is the number of feature layers.
[0055] The features after the multi-scale feature fusion strategy are: The fusion process is defined as follows:
[0056]
[0057] Where Resize(· i (H,W) indicates that the feature map is adjusted to a uniform resolution of H×W, where w i Let be the fusion weights of the feature maps of the i-th layer.
[0058] The definitions of channel attention and spatial attention in the weighted attention mechanism are as follows:
[0059]
[0060] Where σ(·) is the Sigmoid function, GAP(·) represents global average pooling, W1 and W2 are learnable parameters for channel attention, * represents the convolution operation, and W s Here are the convolution kernel weights for spatial attention, and channel attention A. c ∈R 1×1×C Spatial attention A focuses on the importance of features in different channels. s ∈R H×W×1 Focus on key locations in the feature map.
[0061] The final weighted feature map is as follows:
[0062]
[0063] Where · represents element-wise multiplication, weighted feature map It effectively enhances the salience of small targets while suppressing background noise.
[0064] The loss function for traditional object detection is typically composed of classification loss L. cls and positioning loss L IOU composition:
[0065]
[0066] The target box set is as follows: The corresponding set of prediction boxes is The weights are assigned to the bounding boxes, with smaller bounding boxes receiving higher weights to enhance the model's ability to learn about smaller targets.
[0067] The optimized loss function is:
[0068] L=λ cls L cls +λ loc L loc +λ IoU L IoU
[0069] Where, λ IoU This is the balance coefficient for weighted IoU loss.
[0070] As those skilled in the art will understand, using a real-world example, the experimental environment was first set up on a high-performance server equipped with an NVIDIA 4090D GPU, running Ubuntu 20.04. The PyTorch framework and the official YOLOv8 code repository were installed to ensure the pre-trained model weights could be loaded. During the data preparation phase, small object categories from the VisDrone dataset were selected for detection.
[0071] At the start of the experiment, the YOLOv8 configuration file was modified, replacing the backbone network with a version that incorporates an attention mechanism. The attention mechanism module is embedded in the mid-to-high-level parts of the feature extraction network, focusing on improving the ability to extract features from small targets. After completing the model configuration, the training script was started via command line, setting training parameters including the learning rate, batch size, and maximum number of training epochs. During training, the model's training logs were monitored using TensorBoard, including changes in the loss value and improvements in training accuracy. After training, the generated weight file was used for subsequent validation.
[0072] During the validation phase, the improved YOLOv8 model weights were loaded, and inference was performed on the test set images. OpenCV was used to draw detection bounding boxes, with a focus on the detection performance in dense target regions. The inference results were saved as images and JSON format detection result files for subsequent analysis and visualization.
[0073] In this experiment, the environment was set up using Python 3.8 and CUDA 11.3, and the official YOLOv5 repository code was used. Similarly, the VisDrone dataset was also used in this experiment.
[0074] During the model configuration phase, the detection head of YOLOv5 was improved by introducing a weighted attention module. Specifically, a dedicated attention layer was added after the output layer of CSPNet, focusing on enhancing the extraction of salient features from small targets. The modified model configuration file was saved in a designated directory, and the training script was set to multi-GPU mode to improve training speed. Dataset loading was performed using PyTorch's Dataset class to ensure that data was fed into the training model in batches.
[0075] During the training phase, a step-by-step strategy was adopted: the first phase froze the backbone network and trained only the newly added attention module; the second phase unfroze all layers and performed global fine-tuning using a small learning rate. After training, the model weights were saved and training logs were recorded. During the inference phase, an inference script was written to call the model, perform inference on each image in the test set, and save the detection results in a visual form, while also recording the category and location information of each target.
[0076] In the YOLOv10-based experiments, the publicly available VisDrone dataset was chosen as the primary data source. This dataset contains densely distributed small targets such as pedestrians, vehicles, and cyclists. Before the experiments began, the original dataset was cleaned and preprocessed, including removing blurry or low-quality images and checking and correcting the labels of each image. Subsequently, all data was converted to a YOLO-supported format, the YOLOv10 code repository was downloaded, the configuration files were modified, and the experiments were conducted.
[0077] During the model configuration phase, pre-trained weights from YOLOv10 were loaded, and the network structure was optimized, particularly by adding an enhanced small object detection module to the feature extraction network. Multi-scale training was used in the experiments, with input image sizes randomly selected to enhance the model's adaptability to targets of different sizes. Model training was performed on an NVIDIA 4090D GPU with a batch size of 32 and 300 training epochs, dynamically adjusting the learning rate using a learning rate scheduler. After training, the model was applied to the VisDrone test set to perform inference on each image, and the output detection results were saved as a JSON file for subsequent evaluation and visualization.
[0078] In a second aspect of the invention, a dense small target detection system based on a weighted attention mechanism is proposed, comprising:
[0079] The feature extraction module is used to extract features from the input image. It extracts low-level and high-level features step by step through multiple convolutional layers (Conv1, Conv2, etc.) to obtain a set of feature maps.
[0080] The feature fusion module is used to introduce a multi-scale feature fusion strategy to accurately locate dense small targets in the image.
[0081] The weighting module is used to introduce a weighted attention mechanism on the basis of the multi-scale feature fusion strategy to obtain the final weighted feature map;
[0082] The optimization module is used to optimize the loss function of traditional object detection, thereby enhancing the detection capability of dense small targets.
[0083] In a third aspect of the invention, an electronic device is provided. The electronic device includes at least one processor; and a memory communicatively connected to the at least one processor; the memory stores instructions executable by the at least one processor, which, when executed by the at least one processor, enable the at least one processor to perform the method of the first aspect of the invention.
[0084] like Figure 9 A schematic block diagram of an electronic device 800 that can be used to implement embodiments of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.
[0085] Electronic device 800 includes a computing unit 801, which can perform various appropriate actions and processes according to a computer program stored in read-only memory (ROM) 802 or a computer program loaded from storage unit 808 into random access memory (RAM) 803. The RAM 803 may also store various programs and data required for the operation of electronic device 800. The computing unit 801, ROM 802, and RAM 803 are interconnected via bus 804. An input / output (I / O) interface 805 is also connected to bus 804.
[0086] Multiple components in electronic device 800 are connected to I / O interface 805, including: input unit 806, such as keyboard, mouse, etc.; output unit 807, such as various types of displays, speakers, etc.; storage unit 808, such as disk, optical disk, etc.; and communication unit 809, such as network card, modem, wireless transceiver, etc. Communication unit 809 allows electronic device 800 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0087] The computing unit 801 can be various general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 801 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 801 performs the various methods and processes described above, such as methods S100 to S600. For example, in some embodiments, methods S100 to S600 can be implemented as computer software programs tangibly contained in a machine-readable medium, such as storage unit 808. In some embodiments, part or all of the computer program can be loaded and / or installed on the electronic device 800 via ROM 802 and / or communication unit 809. When the computer program is loaded into RAM 803 and executed by the computing unit 801, one or more steps of methods S100 to S600 described above can be performed. Alternatively, in other embodiments, the computing unit 801 may be configured to execute methods S100 to S600 by any other suitable means (e.g., by means of firmware).
[0088] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0089] The program code used to implement the methods of the present invention can be written in any combination of one or more programming languages. This program code can be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing device, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code can be executed entirely on the machine, partially on the machine, as a standalone software package partially on the machine and partially on a remote machine, or entirely on a remote machine or server.
[0090] In the context of this invention, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. Machine-readable media can include, but are not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0091] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0092] The systems and techniques described herein can be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network (LAN), a wide area network (WAN), and the Internet.
[0093] Computer systems can include clients and servers. Clients and servers are generally located far apart and typically interact via communication networks. Client-server relationships are created by computer programs running on the respective computers and having a client-server relationship with each other. Servers can be cloud servers, servers in distributed systems, or servers incorporating blockchain technology.
[0094] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.
[0095] In summary, this invention significantly improves the detection capability for densely packed small targets through the aforementioned improvement strategies. Experimental results on public datasets demonstrate that the algorithm of this invention outperforms existing methods in both accuracy and recall, especially excelling in densely packed small target detection scenarios. Furthermore, this algorithm exhibits high computational efficiency, making it suitable for widespread application in real-world scenarios.
[0096] The foregoing has shown and described the basic principles, main features, and advantages of the present invention. Those skilled in the art should understand that the present invention is not limited to the above embodiments. The embodiments and descriptions in the specification are merely principles of the invention. Various changes and modifications can be made to the invention without departing from its spirit and scope, and all such changes and modifications fall within the scope of the claimed invention. The scope of protection claimed by the appended claims and their equivalents is defined.
Claims
1. A method for detecting dense small targets based on a weighted attention mechanism, characterized in that, include: Feature extraction is performed on the input image by progressively extracting low-level and high-level features through multiple convolutional layers to obtain a set of feature maps; A multi-scale feature fusion strategy is introduced to accurately locate dense small targets in images; Based on the multi-scale feature fusion strategy, a weighted attention mechanism is introduced to obtain the final weighted feature map; The loss function of traditional object detection is optimized to enhance the detection capability of dense small targets; The features after the multi-scale feature fusion strategy are: The fusion process is defined as follows: ; in This indicates that the feature maps will be adjusted to a uniform resolution. , For the first The fusion weights of the layer feature maps; The definitions of channel attention and spatial attention in the weighted attention mechanism are as follows: ; ; in It is the Sigmoid function. Indicates global average pooling. and These are learnable parameters for channel attention. This represents the convolution operation. For spatial attention, the convolution kernel weights are used; for channel attention, the channel weights are used. Spatial attention focuses on the importance of features in different channels. Focus on key locations in the feature map; The loss function of traditional object detection is usually composed of classification loss. and positioning loss composition: ; The target box set is as follows: The corresponding set of prediction boxes is , The weights are assigned to the bounding boxes, with smaller bounding boxes receiving higher weights to enhance the model's ability to learn about small targets. The input image is ,in and These represent the image's height, width, and number of channels, respectively. After feature extraction, a set of feature maps is obtained. ,in It is the first Layer feature map, Number of feature layers; The final weighted feature map is as follows: ; Where · represents element-wise multiplication, weighted feature map It effectively enhances the salience of small targets while suppressing background noise; The optimized loss function is: ; in, This is the balance coefficient for weighted IoU loss.
2. A dense small target detection system based on a weighted attention mechanism, used to implement the dense small target detection method based on a weighted attention mechanism as described in claim 1, characterized in that, include: The feature extraction module is used to extract features from the input image by progressively extracting low-level and high-level features through multiple convolutional layers (Conv1, Conv2, etc.) to obtain a set of feature maps. The feature fusion module is used to introduce a multi-scale feature fusion strategy to accurately locate dense small targets in the image; The weighting module is used to introduce a weighted attention mechanism on the basis of the multi-scale feature fusion strategy to obtain the final weighted feature map; An optimization module is used to optimize the loss function of traditional target detection, thereby enhancing the detection capability of dense small targets.
3. An electronic device, comprising at least one processor; and a memory communicatively connected to said at least one processor; characterized in that, The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method of claim 1.
Citation Information
Patent Citations
Target detection method based on multi-scale feature fusion
CN114118284A
Remote sensing small target detection method, system and device based on fusion cascade attention mechanism and medium
CN116385896A