Multi-scale bird flock target counting and positioning method, system and application based on double-branch fusion and dynamic mask
By employing a dual-branch fusion and dynamic masking method, combined with YOLOv8 and DC-Net models, the problems of density map ambiguity and insufficient adaptability in bird flock counting are solved, achieving accurate counting and positioning of bird flock targets. This method is suitable for ecological monitoring and anti-drone target counting.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CHINESE PEOPLES LIBERATION ARMY INFORMATION SUPPORT CORPS ENGINEERING UNIVERSITY
- Filing Date
- 2026-03-23
- Publication Date
- 2026-07-07
AI Technical Summary
Existing technologies for bird flock counting suffer from problems such as inaccurate location due to blurred density maps, insufficient adaptability of joint learning methods for location and counting, and insufficient datasets, making it difficult to meet the needs of ecological monitoring.
A dual-branch architecture based on the YOLOv8 detection model and the DC-Net regression model is adopted, combined with dynamic masking technology. The mask image is generated adaptively by the area of the detection box. The results of the detection and regression branches are fused, and the cKD tree is used for deduplication to achieve accurate counting and localization of bird flock targets.
It improves the accuracy and adaptability of bird flock target counting, reduces labor costs, and is suitable for ecological monitoring and anti-drone target counting and positioning in complex environments.
Smart Images

Figure CN122347696A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of bird flock target counting and localization technology in image processing, and more specifically, to a multi-scale bird flock target counting and localization method, system and application based on bi-branch fusion and dynamic masking. Background Technology
[0002] Bird flock counting, as an important branch of dense target counting in computer vision, has irreplaceable application value in fields such as ecological monitoring, biodiversity conservation, and natural resource management. Its core task is to accurately estimate the number and spatial distribution of bird flocks from a single image or video sequence, providing data support for research and decision-making in related fields. Traditional counting methods often rely on manual feature extraction or target detection techniques. However, bird flocks are inherently non-rigid, exhibiting significant morphological variations, dynamic poses, large scale variations, and strong heterogeneity in appearance among species. Furthermore, in real-world scenarios, they often face problems such as severe occlusion, variable scale, and extremely dense distribution, severely limiting the performance of traditional methods and making it difficult to meet the demands of accurate counting. With the rise of deep learning, especially the rapid development of convolutional neural networks (CNNs) and Transformer architectures, the research paradigm in dense target counting has undergone a fundamental shift, moving from direct detection and counting to more efficient approaches such as density map regression, joint learning of localization and counting, and multimodal fusion. Bird flock counting, as a subfield of dense target counting, draws heavily on the technological achievements of related fields such as crowd counting, while continuously optimizing and innovating to suit its own task characteristics, gradually forming a research direction with its own unique technical path.
[0003] Current bird flock counting techniques are primarily based on the mainstream framework of dense target counting, and have evolved into two core implementation paths when combined with bird flock characteristics: ① Density map regression scheme: As the most basic implementation, this scheme continues the core idea of early dense target counting. It transforms the point annotations of individual birds into a Gaussian density map, trains the model to learn the mapping function from the image to the density map, and finally obtains the total number of birds by integrating the density map. Some studies optimize the loss function to address the large morphological differences among bird flocks, such as introducing density-guided structural similarity (DSSIM) loss to adapt to multi-scale problems. ② Joint learning scheme for localization and counting: Borrowing the design idea of the FIDT (Focal Inverse Distance Transform) map in crowd counting, it generates a clear and narrow peak map through inverse distance transformation, ensuring that each bird's position corresponds to a unique peak. Combined with a local maximum detection strategy, it achieves joint optimization of counting and localization. These two schemes are directly borrowed or customized for bird flock counting scenarios, but many key problems still exist: ① The density map regression method suffers from the fuzzy nature of the Gaussian kernel, which makes it impossible for the density map to accurately correspond to the actual location of individual birds in the flock. It can only achieve the total number estimation, which is difficult to meet the needs of ecological monitoring for the analysis of the spatial distribution of individuals. In scenarios where the flock is extremely dense and the overlap of individuals is high, the Gaussian density map will have serious overlap, resulting in the deviation of the density value estimation and a sharp increase in the counting error. ② The localization-counting joint learning method optimized for bird flocks is not adaptable to bird flock targets at different scales. Large-scale sparse bird flocks may miss detections. Moreover, the network model is based on the HRnet network structure for lightweight deployment, and the model network structure can be further optimized. ③ Currently, there are few publicly available bird datasets, and most of them are based on bird target detection and classification. The number of bird targets in the images is small, the size is large, and there are few dense scenes, so the datasets cannot be used for current research methods. Summary of the Invention
[0004] To address at least one deficiency or improvement need in existing technologies, this invention provides a multi-scale bird flock target counting and localization method, system, and application based on dual-branch fusion and dynamic masking. By developing a bird flock target counting and localization method that can adapt to scene changes and accurately solve multi-scale adaptability, it has significant practical implications for improving ecological monitoring efficiency and reducing labor costs. The method of this invention has good generalization performance and can provide technical reference for target counting and localization in other related scenarios, such as anti-drone applications.
[0005] To achieve the above objectives, according to a first aspect of the present invention, a multi-scale bird flock target counting and localization method based on dual-branch fusion and dynamic masking is provided, the method comprising: S1. Construct a dual-branch architecture based on the YOLOv8 detection model and the DC-Net regression model. The DC-Net regression model includes an input layer, a feature extraction layer, a feature enhancement layer, a multi-scale fusion layer, and a density prediction layer. S2, input the preprocessed image into the YOLOv8 detection model to detect bird targets in the image, output the coordinates and confidence scores of all detection boxes, filter valid detection boxes based on the confidence scores of the detection boxes, adaptively generate a dynamic mask map based on the area of the valid detection boxes, and calculate the center point coordinates of all detection boxes to construct a full set of detection box center points; S3, input the preprocessed image into the DC-Net regression model, and output the FIDT density map through feature extraction, feature enhancement, multi-scale fusion and density prediction operations; use the local maximum detection algorithm to post-process the FIDT density map to extract the initial regression bird point coordinates and counts of bird targets; S4, input the initial regression bird point coordinates into the dynamic mask image, retain bird points in the non-occluded areas according to the mask value, filter out duplicate points that have been covered by the detection model branches, and obtain the filtered regression bird point set; S5, merge the filtered regression bird point set with the full detection box center point set to form a fusion point set with complementary dual-branch results; S6. Convert the fusion point set into a NumPy array and construct a cKD tree index; find all neighboring points through the cKD tree and mark them as duplicate points; delete duplicate points to obtain the final deduplicated bird point coordinate set and bird flock target count result.
[0006] Furthermore, in the above-mentioned multi-scale bird flock target counting and localization method, the construction of the YOLOv8 detection model in the dual-branch architecture specifically includes: The YOLOv8 detection model is trained based on an open-source bird detection dataset, and the optimal parameters of the detection model are saved. The coordinates of the detection box and its confidence score are output. After the YOLOv8 detection model is loaded, it enters inference mode by default and turns off gradient calculation.
[0007] Furthermore, in the above-mentioned multi-scale bird flock target counting and localization method, the feature extraction layer of the DC-Net regression model specifically includes: Using DualGenBlock as the basic feature extraction unit, a dual-branch path of main path and auxiliary path is constructed to achieve feature complementarity: the main path is used to extract global semantic features and identify the overall features of bird targets; the auxiliary path adopts a lightweight structure of 1×1 convolution and grouped convolution to capture the edge and texture details of small targets and enhance the feature response of small targets. The output of the dual-branch path adaptively adjusts the weights through a dynamic weighted fusion mechanism, and assigns higher weights to smaller target regions.
[0008] Furthermore, in the above-mentioned multi-scale bird flock target counting and localization method, the feature enhancement layer of the DC-Net regression model specifically includes: The feature map of the previous stage is upsampled and then fused with the feature map of the current stage by residual connection, and dynamic weight parameters are introduced to adaptively adjust the feature ratio of each stage. The hole rate is adaptively set according to the feature map scale at each stage to achieve global coverage of densely distributed birds.
[0009] Furthermore, in the above-mentioned multi-scale bird flock target counting and localization method, the multi-scale fusion layer of the DC-Net regression model specifically includes: The three-level feature maps are adjusted to a unified channel through 1×1 convolution; Based on the largest scale feature map, other scale feature maps are upsampled through bilinear interpolation to achieve scale alignment of the feature maps; A lightweight channel attention mechanism is introduced to adaptively allocate the weights of features at each scale, and to assign higher weights to scale features with a high proportion of small targets, while integrating global information from large-scale features.
[0010] Furthermore, in the above-mentioned multi-scale bird flock counting and localization method, the density prediction layer of the DC-Net regression model specifically includes: The regression head employs a lightweight design based on ConvBNReLU, Dropout, and 1×1 convolutions: The ConvBNReLU layer refines the fused features and filters bird density-related features; the Dropout layer randomly discards some neurons to suppress overfitting; and the 1×1 convolution maps multi-channel features to a single-channel density map, ensuring that the spatial resolution of the density map is consistent with the input image.
[0011] Furthermore, in step S2 of the above-mentioned multi-scale bird flock target counting and localization method, the dynamic mask map is adaptively generated based on the area of the effective detection box, specifically including: Define a base area threshold equal to the effective detection frame area threshold, and calculate the area ratio of each effective detection frame based on the base area threshold and the current detection frame area; The expansion ratio of the detection frame is calculated based on the area ratio of the effective detection frame, and the area of the detection frame is linearly correlated with the expansion ratio. Using the center of the effective detection box as a reference, the width and height of the detection box are expanded synchronously according to the area ratio of the effective detection box to obtain the expanded occlusion area; a mask map with the same size as the input image is constructed, and the expanded occlusion area is selectively retained in the mask map to generate the final dynamic mask map.
[0012] Furthermore, in step S3 of the above-mentioned multi-scale bird flock target counting and localization method, a local maximum detection algorithm is used to post-process the FIDT density map to extract the initial regression bird point coordinates and counts of the bird targets, specifically including: Max pooling is performed on the density map using a sliding window to filter out local peak points in the density map and retain the coordinate information of the peak points. A screening threshold is calculated based on local peak points in the density map, and weak response points below the screening threshold are filtered out. If the maximum value of the density map is less than the preset value, the current image is determined to be a birdless image, and the output count result is 0 and an empty coordinate set; if the maximum value of the density map is greater than or equal to the preset value, the output is the initial regression bird point coordinate set after filtering and the corresponding count result.
[0013] According to a second aspect of the present invention, a multi-scale bird flock target counting and localization system based on dual-branch fusion and dynamic masking is also provided, comprising: A dual-branch architecture building module is configured to build a dual-branch architecture based on a YOLOv8 detection model and a DC-Net regression model. The DC-Net regression model includes an input layer, a feature extraction layer, a feature enhancement layer, a multi-scale fusion layer, and a density prediction layer. The detection model processing module is configured to input the preprocessed image into the YOLOv8 detection model, detect bird targets in the image, output the coordinates and confidence scores of all detection boxes, filter valid detection boxes based on the confidence scores of the detection boxes, adaptively generate a dynamic mask map based on the area of the valid detection boxes, and calculate the center point coordinates of all detection boxes to construct a full set of detection box center points. The regression model processing module is configured to input the preprocessed image into the DC-Net regression model, and output a FIDT density map through feature extraction, feature enhancement, multi-scale fusion and density prediction operations; and use a local maximum detection algorithm to post-process the FIDT density map to extract the initial regression bird point coordinates and counts of bird targets. The mask filtering module is configured to input the initial regression bird point coordinates into the dynamic mask image, retain bird points in non-occluded areas according to the mask value, filter duplicate points that have been covered by the detection model branches, and obtain a filtered regression bird point set. A point set merging module is configured to merge the filtered regression bird point set with the full detection box center point set to form a fusion point set with complementary dual-branch results; The deduplication module is configured to convert the fused point set into a NumPy array and construct a cKD tree index; find all neighboring points through the cKD tree and mark them as duplicate points; delete duplicate points to obtain the final deduplicated bird point coordinate set and bird flock target count result.
[0014] According to a third aspect of the present invention, a computer program product is also provided, comprising a computer program / instructions, characterized in that, when executed by a processor, the computer program / instructions implement the steps of any of the methods described above.
[0015] In summary, compared with the prior art, the above-described technical solutions conceived by this invention can achieve the following beneficial effects: (1) The dual-branch complementary design effectively makes up for the shortcomings of the single branch. The DC-Net model of the regression branch accurately captures small target birds through dual-path feature extraction and multi-scale fusion, which supplements the missed detection of the detection branch. The detection branch has a better effect on the detection and recognition of large-scale bird targets, which supplements the missed detection of the regression branch.
[0016] (2) The dynamic mask adaptively adjusts the occlusion range according to the detection box area. DC-Net can adapt to accurately detect small-scale bird targets and different distribution densities by fusing hierarchical dilated convolution with attention. The model has strong robustness to changes in lighting and mild occlusion, and can be applied to complex environments such as field ecological monitoring and agricultural and forestry park inspections.
[0017] (3) The lightweight design of YOLOv8 and DC-Net is adopted, and KD tree is used for fast deduplication to ensure batch processing efficiency; multi-view visualization and detailed data storage facilitate result verification and subsequent analysis, reducing the threshold for practical application. Attached Figure Description
[0018] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0019] Figure 1 A flowchart illustrating the multi-scale bird flock target counting and localization method based on dual-branch fusion and dynamic masking provided in this application embodiment; Figure 2 A flowchart illustrating another multi-scale bird flock target counting and localization method based on dual-branch fusion and dynamic masking provided for embodiments of this application; Figure 3 This is a schematic diagram of the DC-Net network structure provided in an embodiment of this application; Figure 4 A schematic diagram of the structure of a multi-scale bird flock target counting and localization system based on dual-branch fusion and dynamic masking provided in an embodiment of this application; Detailed Implementation To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention. Furthermore, the technical features involved in the various embodiments of this invention described below can be combined with each other as long as they do not conflict with each other.
[0020] The terms "first," "second," "third," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish different objects, not to describe a specific order. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or apparatuses.
[0021] This invention provides a method for accurate bird counting and localization based on dual-branch fusion and dynamic masking, as shown in the appendix. Figure 2 As shown, by constructing a detection-regression dual-branch model architecture and combining dynamic mask generation technology with an efficient point fusion strategy, accurate counting and localization of bird targets can be achieved. This scheme specifically includes key technical modules such as regression branch model construction and training, detection branch pre-trained model loading and detection branch training, dynamic mask generation, regression branch processing, and dual-branch fusion optimization. These modules work collaboratively to complete the bird flock target counting and localization task. The specific scheme is as follows: As one implementation method, the present invention provides a multi-scale bird flock target counting and localization method based on dual-branch fusion and dynamic masking, as shown in the appendix. Figure 1 As shown, the method includes: S1. Construct a dual-branch architecture based on a YOLOv8 detection model and a DC-Net regression model. The DC-Net regression model includes an input layer, a feature extraction layer, a feature enhancement layer, a multi-scale fusion layer, and a density prediction layer. It should be noted that for the detection branch model (YOLOv8 detection model), a pre-trained YOLOv8 object detection model is loaded. This model is pre-trained based on an open-source bird detection dataset and saves its optimal parameters, possessing efficient bird object detection capabilities and directly outputting the coordinates of the detection boxes and their corresponding confidence scores. After loading, the model defaults to inference mode, disabling gradient calculation to improve running efficiency. For the regression branch model (DC-Net regression model), a pre-trained DC-Net (Dynamic Cascade Net) density map regression model is loaded. The core design of this model revolves around three major objectives: "dynamic feature enhancement - multi-scale information fusion - accurate density mapping." Addressing the core challenge of counting dense, small bird flocks, it strengthens the feature representation of small birds and suppresses background noise through the synergistic effect of the DualGenBlock feature generation module and the ScaleFuser multi-scale fusion module, achieving accurate density map regression for dense / small bird flocks. This invention also designs a DC-Net network structure specifically for solving the problem of counting small bird flocks in dense environments. The overall architecture adopts a five-level structure: input layer, feature extraction layer, feature enhancement layer, multi-scale fusion layer, and density prediction layer. Through module-level innovation, it achieves enhanced capture of small target features and density differentiation in dense scenes. A schematic diagram of the network structure is attached. Figure 3 As shown.
[0022] S2, the preprocessed image is input into the YOLOv8 detection model to detect bird targets in the image, outputting the coordinates and confidence scores of all detection boxes, filtering valid detection boxes based on their confidence scores, and adaptively generating a dynamic mask image based on the area of the valid detection boxes; calculating the center point coordinates of all detection boxes to construct a full set of detection box center points; it should be noted that bird target detection and detection box processing mainly include: inputting the preprocessed image into the YOLOv8 detection model, the model detecting bird targets in the image, and outputting the coordinates of all detection boxes ( The detection results are then categorized as follows: First, all detection boxes are retained. All detection box data are collected for subsequent counting and center point extraction to avoid missing potential bird targets. Second, valid detection boxes are selected. Valid detection boxes are selected based on preset thresholds, retaining only those with a confidence level ≥ 0.3 and a detection box area ≥ 100 pixels² for subsequent dynamic mask generation. Finally, the center point of each detection box is calculated. The center point coordinates of all detection boxes are calculated. The calculation formula is: The calculation results are rounded and constrained within the image size range to ensure coordinate validity. Then, a dynamic mask is adaptively generated based on the area of the effective detection box to achieve accurate occlusion of the detected area.
[0023] S3. The preprocessed image is input into the DC-Net regression model. Through feature extraction, feature enhancement, multi-scale fusion, and density prediction operations, a FIDT density map is output. A Local Maximum Detection (LMDS) algorithm is then used to post-process the FIDT density map to extract the initial regression bird point coordinates and counts. It should be noted that the FIDT density map is generated first by inputting the preprocessed image into the DC-Net regression model. The model performs a series of operations including feature extraction, feature enhancement, multi-scale fusion, and density prediction to output a FIDT density map, with the density map size matching the input image size. Thanks to DC-Net's dual-path feature extraction and attention fusion mechanism designed for dense, small targets, the matching accuracy between density map peaks and real bird positions is improved, effectively suppressing background noise interference. Simultaneously, it can clearly distinguish adjacent bird targets in dense scenes, reducing the risk of duplicate counting. Then, density map post-processing (LMDS algorithm) is performed, using the LMDS local maximum detection algorithm to post-process the FIDT density map and extract the initial coordinates and counts of the bird targets.
[0024] S4, input the initial regression bird point coordinates into the dynamic mask image, retain bird points in non-occluded areas based on the mask value, and filter out duplicate points covered by the detection model branch to obtain the filtered regression bird point set. It should be noted that, to fully leverage the advantages of the detection branch's large-target accuracy and precise localization, and the regression branch's sensitivity to small targets, a dual-branch point fusion strategy is designed, firstly performing mask filtering. Input the initial regression bird point coordinates output by the regression branch into the dynamic mask image, retain only bird points with a mask value of 1 (non-occluded areas), and filter out duplicate points covered by the detection branch to obtain the filtered regression bird point set.
[0025] S5, merge the filtered regression bird point set with the full detection box center point set to form a fused point set with complementary dual-branch results; it should be noted that this step is used to merge the point sets. Merging the "filtered regression bird point set" with the "detection branch full detection box center point set" to form a fused point set achieves the complementarity of dual-branch results.
[0026] S6, convert the fused point set into a NumPy array and construct a cKD tree index; find all neighboring points through the cKD tree and mark them as duplicate points; delete the duplicate points to obtain the final deduplicated bird point coordinate set and bird flock target count result. It should be noted that this step is used to achieve fast point deduplication. The cKD tree algorithm is used to efficiently deduplicate the fused point set. First, the fused point set is converted into a NumPy array and a cKD tree index is constructed; traverse each point, quickly find all neighboring points less than 6 pixels away through the cKD tree, and mark them as duplicate points; retain only the current point as a unique representative, delete the remaining duplicate points, and finally obtain the final deduplicated bird point coordinate set and bird flock target count result.
[0027] Furthermore, in the above-mentioned multi-scale bird flock target counting and localization method, the construction of the YOLOv8 detection model in the dual-branch architecture specifically includes: The YOLOv8 detection model is trained on an open-source bird detection dataset, and its optimal parameters are saved. It outputs the bounding box coordinates and their confidence scores. Upon loading, the YOLOv8 detection model defaults to inference mode and disables gradient calculation. It should be noted that for the detection branch model, i.e., the YOLOv8 detection model, a pre-trained YOLOv8 object detection model is loaded. This model is pre-trained on the open-source bird detection dataset and its optimal parameters are saved. It possesses efficient bird object detection capabilities and can directly output the bounding box coordinates (x1, y1, x2, y2) and their corresponding confidence scores. Upon loading, the model defaults to inference mode and disables gradient calculation to improve operational efficiency.
[0028] Furthermore, in the above-mentioned multi-scale bird flock target counting and localization method, the feature extraction layer of the DC-Net regression model specifically includes: Using DualGenBlock as the basic feature extraction unit, DC-Net constructs a dual-branch path (main path + auxiliary path) to achieve feature complementarity. The main path extracts global semantic features, identifying the overall characteristics of bird targets. The auxiliary path employs a lightweight structure of 1×1 convolutions and grouped convolutions to capture the detailed features of small targets' edges and textures, enhancing their feature response. The outputs of the dual-branch paths adaptively adjust weights through a dynamic weighted fusion mechanism, assigning higher weights to small target regions. It's worth noting that the DualGenBlock dual-path design addresses the challenge of weak features in small targets. Bird targets have a low pixel count and weak feature information, easily drowned out by background noise, making them difficult to capture effectively with traditional single-path convolution modules. DC-Net uses DualGenBlock as the basic feature extraction unit, achieving feature complementarity through a parallel dual-branch design of "main path + auxiliary path": the main path extracts global semantic features, ensuring overall bird target recognition; the auxiliary path uses a lightweight structure of "1×1 convolution + grouped convolutions," focusing on capturing the detailed features of small targets' edges and textures, enhancing their feature response. Meanwhile, the dual-path output adaptively adjusts the weights through a dynamic weighted fusion mechanism, assigning higher weights to smaller target regions to further enhance the expressive power of small target features. Furthermore, the feature extraction layer employs a three-level progressive downsampling process, gradually improving the semantic level of features while preserving small target feature information at various scales, laying the foundation for subsequent fusion.
[0029] Furthermore, in the above-mentioned multi-scale bird flock target counting and localization method, the feature enhancement layer of the DC-Net regression model specifically includes: By using residual connections, the feature maps from the previous stage are upsampled and fused with the feature maps from the current stage. Dynamic weight parameters are introduced to adaptively adjust the feature proportions of each stage. The dilation rate is adaptively set according to the scale of the feature maps at each stage to achieve global coverage of densely distributed birds. It should be noted that dynamic weight fusion and hierarchical dilated convolution solve the feature confusion problem in dense scenes. In dense bird scenes, severe target overlap leads to mutual interference of features, and it is necessary to simultaneously consider the receptive field matching of large targets at close range and small targets at far range. DC-Net adopts two core designs in the feature enhancement layer: First, cross-stage dynamic weight fusion, which uses residual connections to upsample the feature maps from the previous stage and fuse them with the feature maps from the current stage, and introduces dynamic weight parameters to adaptively adjust the feature proportions of each stage, avoiding interference of deep features with small target details, while strengthening the complementarity of features from different stages; Second, hierarchical dilated convolution, which adaptively sets the dilation rate according to the scale of the feature maps at each stage, significantly expanding the receptive field without increasing the computational cost, achieving global coverage of densely distributed birds, while avoiding the loss of small target features due to a large dilation rate, effectively distinguishing the boundary features of overlapping targets, and alleviating the density confusion problem in dense scenes.
[0030] Furthermore, in the above-mentioned multi-scale bird flock target counting and localization method, the multi-scale fusion layer of the DC-Net regression model specifically includes: The three-level feature maps are adjusted to a unified channel using 1×1 convolution. Based on the largest scale feature map, other scale feature maps are upsampled using bilinear interpolation to achieve scale alignment. A lightweight channel attention mechanism is introduced to adaptively allocate weights to features at each scale, assigning higher weights to scale features with a high proportion of small targets, while integrating global information from large-scale features. It should be noted that the ScaleFuser module adapts to multi-size target distributions; in dense bird scenes, the bird sizes vary significantly, making it difficult for a single scale feature to adapt simultaneously. The ScaleFuser module achieves efficient fusion of multi-scale features through three steps: "channel unification - scale alignment - attention-weighted fusion". First, a 1×1 convolution is used to uniformly adjust the three-level feature maps to 128 channels, eliminating fusion noise caused by differences in channel dimensions. Second, based on the largest scale feature map, bilinear interpolation is used to upsample the Stage2 and Stage3 feature maps to ensure scale consistency and prevent small target features from being compressed. Finally, a lightweight channel attention mechanism is introduced to adaptively allocate the weights of features at each scale, assigning higher weights to scale features with a high proportion of small targets to enhance the fusion effect of small target features. At the same time, it integrates global information of large-scale features to achieve comprehensive adaptation to bird targets of different sizes and improve density discrimination accuracy in dense scenes.
[0031] Furthermore, in the above-mentioned multi-scale bird flock counting and localization method, the density prediction layer of the DC-Net regression model specifically includes: The regression head employs a lightweight design based on ConvBNReLU, Dropout, and 1×1 convolution. The ConvBNReLU layer refines the fused features, filtering for bird density-related features; the Dropout layer randomly discards some neurons to suppress overfitting; and the 1×1 convolution maps multi-channel features to a single-channel density map, ensuring the spatial resolution of the density map matches the input image. It's important to note that this lightweight regression head ensures accurate mapping. To avoid blurred density map boundaries caused by complex structures, the regression head uses a lightweight design of "ConvBNReLU + Dropout + 1×1 convolution": the ConvBNReLU layer refines the fused features, further filtering for bird density-related features; the Dropout layer randomly discards some neurons to suppress overfitting and avoid false positive density peaks in dense scenes; and the 1×1 convolution maps multi-channel features to a single-channel density map, ensuring the spatial resolution of the density map matches the input image, accurately corresponding to the bird distribution intensity at each pixel location, providing precise density support for subsequent small target bird point extraction.
[0032] Furthermore, in step S2 of the above multi-scale bird flock target counting and localization method, a dynamic mask map is adaptively generated based on the area of the effective detection box. That is, a dynamic mask is adaptively generated based on the area of the effective detection box to achieve accurate occlusion of the detected area. The specific steps are as follows: First, the area ratio is calculated. A base area threshold is defined as equal to the effective detection frame area threshold. The area ratio of each effective detection frame is calculated based on this base area threshold and the current detection frame area. It should be noted that defining the base area threshold as equal to the effective detection frame area threshold, and then calculating the area ratio of each effective detection frame... ),Right now ,make sure .
[0033] Second, the expansion ratio is calculated. The expansion ratio of the detection frame is calculated based on the area ratio of the effective detection frame, and a linear relationship is established between the detection frame area and the expansion ratio. It should be noted that this is achieved through the formula... Calculate the expansion ratio of the detection frame to achieve a linear relationship between the area of the detection frame and the expansion ratio. Limited to Within the range, avoid excessive or insufficient shading in extreme cases.
[0034] Third, mask generation. Using the center of the effective detection bounding box as a reference, the width and height of the detection bounding box are synchronously expanded according to the area ratio of the effective detection bounding box to obtain the expanded occlusion region. A mask image with the same size as the input image is constructed, and the expanded occlusion region is selectively retained in the mask image to generate the final dynamic mask image. It should be noted that, using the center of the effective detection bounding box as a reference, according to... The width and height of the detection box are simultaneously expanded to obtain the expanded occlusion region. A mask map with the same size as the input image is constructed. The expanded occlusion region is set to 0 (indicating occlusion) in the mask map, while the remaining regions are kept at 1 (indicating preservation), generating the final dynamic mask.
[0035] Furthermore, in step S3 of the above-mentioned multi-scale bird flock target counting and localization method, a local maximum detection algorithm is used to post-process the FIDT density map to extract the initial regression bird point coordinates and counts of the bird targets, specifically including: Max pooling is performed on the density map using a sliding window to filter out local peaks and retain their coordinate information. It should be noted that this step is used for local maxima detection. A 5×5 sliding window is constructed to perform max pooling on the density map, filtering out local peaks and retaining their coordinate information.
[0036] A screening threshold is calculated based on local peak points in the density map, and weak response points below the screening threshold are filtered out to reduce the probability of false positives.
[0037] As can be seen, this invention solves the problems in existing bird flock target counting and localization through detection-regression dual-branch fusion and dynamic masking technology. The technical effects are as follows: (1) Detection-Regression Dual-Branch Complementary Fusion Strategy. A three-step fusion process of “mask filtering-point set merging-fast deduplication” is designed to organically combine the center point of the detection box with the regression bird point. This not only leverages the advantages of the detection branch in accurate identification and localization of large-scale bird targets, but also utilizes the strong counting characteristics of the regression branch DC-Net for small targets, achieving a “1+1>2” counting and localization effect.
[0038] (2) Innovative architecture of DC-Net for regression branch. A DualGenBlock dual-path feature generation module and a ScaleFuser attention fusion module are proposed. By combining dynamic weight adjustment and hierarchical dilated convolution, the feature capture capability of small target birds and the accuracy of density map generation are improved on the basis of lightweight design, providing high-quality regression results to support dual-branch fusion.
[0039] (3) Dynamic mask generation method based on detection box area. An innovative mask generation logic is proposed that adaptively calculates the expansion ratio based on the detection box area. Through the dynamic correlation of area_ratio and expand_ratio, accurate occlusion of the detected area is achieved, which solves the problem of over-occlusion or under-occlusion of fixed-size masks and provides a cleaner input environment for the regression branch.
[0040] According to a second aspect of the present invention, a multi-scale bird flock target counting and localization system based on dual-branch fusion and dynamic masking is also provided, comprising: A dual-branch architecture building module is configured to build a dual-branch architecture based on a YOLOv8 detection model and a DC-Net regression model. The DC-Net regression model includes an input layer, a feature extraction layer, a feature enhancement layer, a multi-scale fusion layer, and a density prediction layer. The detection model processing module is configured to input the preprocessed image into the YOLOv8 detection model, detect bird targets in the image, output the coordinates and confidence scores of all detection boxes, filter valid detection boxes based on the confidence scores of the detection boxes, adaptively generate a dynamic mask map based on the area of the valid detection boxes, and calculate the center point coordinates of all detection boxes to construct a full set of detection box center points. The regression model processing module is configured to input the preprocessed image into the DC-Net regression model, and output a FIDT density map through feature extraction, feature enhancement, multi-scale fusion and density prediction operations; and use a local maximum detection algorithm to post-process the FIDT density map to extract the initial regression bird point coordinates and counts of bird targets. The mask filtering module is configured to input the initial regression bird point coordinates into the dynamic mask image, retain bird points in non-occluded areas according to the mask value, filter duplicate points that have been covered by the detection model branches, and obtain a filtered regression bird point set. A point set merging module is configured to merge the filtered regression bird point set with the full detection box center point set to form a fusion point set with complementary dual-branch results; The deduplication module is configured to convert the fused point set into a NumPy array and construct a cKD tree index; find all neighboring points through the cKD tree and mark them as duplicate points; delete duplicate points to obtain the final deduplicated bird point coordinate set and bird flock target count result.
[0041] It should be noted that the multi-scale bird flock target counting and localization system based on dual-branch fusion and dynamic masking of the present invention is implemented in accordance with the steps in the aforementioned multi-scale bird flock target counting and localization method based on dual-branch fusion and dynamic masking, and will not be repeated here.
[0042] This application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the above-described method. The computer-readable storage medium may include, but is not limited to, any type of disk, including floppy disks, optical disks, DVDs, CD-ROMs, microdrives, as well as magneto-optical disks, ROMs, RAMs, EPROMs, EEPROMs, DRAMs, VRAMs, flash memory devices, magnetic cards or optical cards, nanosystems (including molecular memory ICs), or any type of medium or device suitable for storing instructions and / or data.
[0043] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to this application.
[0044] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.
[0045] In the several embodiments provided in this application, it should be understood that the disclosed apparatus can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some service interface; the indirect coupling or communication connection between devices or units may be electrical or other forms.
[0046] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0047] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0048] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage device (CMD). Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a memory and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned memory includes various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.
[0049] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be implemented by a program instructing related hardware. The program can be stored in a computer-readable storage medium, which may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, etc.
[0050] The foregoing description is merely an exemplary embodiment of this disclosure and should not be construed as limiting the scope of this disclosure. Any equivalent changes and modifications made in accordance with the teachings of this disclosure shall still fall within the scope of this disclosure. Those skilled in the art will readily conceive of embodiments of this disclosure upon considering the specification and practicing the disclosure herein. This application is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not described herein. The specification and embodiments are to be considered exemplary only, and the scope and spirit of this disclosure are defined by the claims.
[0051] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0052] Those skilled in the art will readily understand that the above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A multi-scale bird flock target counting and localization method based on dual-branch fusion and dynamic masking, characterized in that, The method includes the following steps: S1. Construct a dual-branch architecture based on the YOLOv8 detection model and the DC-Net regression model. The DC-Net regression model includes an input layer, a feature extraction layer, a feature enhancement layer, a multi-scale fusion layer, and a density prediction layer. S2, input the preprocessed image into the YOLOv8 detection model to detect bird targets in the image, output the coordinates and confidence scores of all detection boxes, filter valid detection boxes based on the confidence scores of the detection boxes, adaptively generate a dynamic mask map based on the area of the valid detection boxes, and calculate the center point coordinates of all detection boxes to construct a full set of detection box center points; S3, input the preprocessed image into the DC-Net regression model, and output the FIDT density map through feature extraction, feature enhancement, multi-scale fusion and density prediction operations; use the local maximum detection algorithm to post-process the FIDT density map to extract the initial regression bird point coordinates and counts of bird targets; S4, input the initial regression bird point coordinates into the dynamic mask image, retain bird points in the non-occluded areas according to the mask value, filter out duplicate points that have been covered by the detection model branches, and obtain the filtered regression bird point set; S5, merge the filtered regression bird point set with the full detection box center point set to form a fusion point set with complementary dual-branch results; S6. Convert the fusion point set into a NumPy array and construct a cKD tree index; find all neighboring points through the cKD tree and mark them as duplicate points; delete duplicate points to obtain the final deduplicated bird point coordinate set and bird flock target count result.
2. The multi-scale bird flock target counting and localization method as described in claim 1, characterized in that, The construction of the YOLOv8 detection model in the dual-branch architecture specifically includes: The YOLOv8 detection model is trained based on an open-source bird detection dataset, and the optimal parameters of the detection model are saved. The coordinates of the detection box and its confidence score are output. After the YOLOv8 detection model is loaded, it enters inference mode by default and turns off gradient calculation.
3. The multi-scale bird flock target counting and localization method as described in claim 1, characterized in that, The feature extraction layer of the DC-Net regression model specifically includes: Using DualGenBlock as the basic feature extraction unit, a dual-branch path of main path and auxiliary path is constructed to achieve feature complementarity: the main path is used to extract global semantic features and identify the overall features of bird targets; the auxiliary path adopts a lightweight structure of 1×1 convolution and grouped convolution to capture the edge and texture details of small targets and enhance the feature response of small targets. The output of the dual-branch path adaptively adjusts the weights through a dynamic weighted fusion mechanism, and assigns higher weights to smaller target regions.
4. The multi-scale bird flock target counting and localization method as described in claim 1, characterized in that, The feature enhancement layer of the DC-Net regression model specifically includes: The feature map of the previous stage is upsampled and then fused with the feature map of the current stage by residual connection, and dynamic weight parameters are introduced to adaptively adjust the feature ratio of each stage. The hole rate is adaptively set according to the feature map scale at each stage to achieve global coverage of densely distributed birds.
5. The multi-scale bird flock target counting and localization method as described in claim 1, characterized in that, The multi-scale fusion layer of the DC-Net regression model specifically includes: The three-level feature maps are adjusted to a unified channel through 1×1 convolution; Based on the largest scale feature map, other scale feature maps are upsampled through bilinear interpolation to achieve scale alignment of the feature maps; A lightweight channel attention mechanism is introduced to adaptively allocate the weights of features at each scale, and to assign higher weights to scale features with a high proportion of small targets, while integrating global information from large-scale features.
6. The multi-scale bird flock target counting and localization method as described in claim 1, characterized in that, The density prediction layer of the DC-Net regression model specifically includes: The regression head employs a lightweight design based on ConvBNReLU, Dropout, and 1×1 convolutions: The ConvBNReLU layer refines the fused features and filters bird density-related features; the Dropout layer randomly discards some neurons to suppress overfitting; and the 1×1 convolution maps multi-channel features to a single-channel density map, ensuring that the spatial resolution of the density map is consistent with the input image.
7. The multi-scale bird flock target counting and localization method as described in claim 1, characterized in that, In step S2, a dynamic mask image is adaptively generated based on the area of the valid detection box, specifically including: Define a base area threshold equal to the effective detection frame area threshold, and calculate the area ratio of each effective detection frame based on the base area threshold and the current detection frame area; The expansion ratio of the detection frame is calculated based on the area ratio of the effective detection frame, and the area of the detection frame is linearly correlated with the expansion ratio. Using the center of the effective detection box as a reference, the width and height of the detection box are expanded synchronously according to the area ratio of the effective detection box to obtain the expanded occlusion area; a mask map with the same size as the input image is constructed, and the expanded occlusion area is selectively retained in the mask map to generate the final dynamic mask map.
8. The multi-scale bird flock target counting and localization method as described in claim 1, characterized in that, In step S3, the FIDT density map is post-processed using a local maximum detection algorithm to extract the initial regression bird point coordinates and counts of bird targets. Specifically, this includes: Max pooling is performed on the density map using a sliding window to filter out local peak points in the density map and retain the coordinate information of the peak points. A screening threshold is calculated based on local peak points in the density map, and weak response points below the screening threshold are filtered out. If the maximum value of the density map is less than the preset value, the current image is determined to be a birdless image, and the output count result is 0 and an empty coordinate set; if the maximum value of the density map is greater than or equal to the preset value, the output is the initial regression bird point coordinate set after filtering and the corresponding count result.
9. A multi-scale bird flock target counting and localization system based on dual-branch fusion and dynamic masking, characterized in that, The system includes the following modules: A dual-branch architecture building module is configured to build a dual-branch architecture based on a YOLOv8 detection model and a DC-Net regression model. The DC-Net regression model includes an input layer, a feature extraction layer, a feature enhancement layer, a multi-scale fusion layer, and a density prediction layer. The detection model processing module is configured to input the preprocessed image into the YOLOv8 detection model, detect bird targets in the image, output the coordinates and confidence scores of all detection boxes, filter valid detection boxes based on the confidence scores of the detection boxes, adaptively generate a dynamic mask map based on the area of the valid detection boxes, and calculate the center point coordinates of all detection boxes to construct a full set of detection box center points. The regression model processing module is configured to input the preprocessed image into the DC-Net regression model, and output a FIDT density map through feature extraction, feature enhancement, multi-scale fusion and density prediction operations; and use a local maximum detection algorithm to post-process the FIDT density map to extract the initial regression bird point coordinates and counts of bird targets. The mask filtering module is configured to input the initial regression bird point coordinates into the dynamic mask image, retain bird points in non-occluded areas according to the mask value, filter duplicate points that have been covered by the detection model branches, and obtain a filtered regression bird point set. A point set merging module is configured to merge the filtered regression bird point set with the full detection box center point set to form a fusion point set with complementary dual-branch results; The deduplication module is configured to convert the fused point set into a NumPy array and construct a cKD tree index; find all neighboring points through the cKD tree and mark them as duplicate points; delete duplicate points to obtain the final deduplicated bird point coordinate set and bird flock target count result.
10. A computer program product comprising a computer program / instructions, characterized in that, When the computer program / instructions are executed by the processor, they implement the steps of the method according to any one of claims 1 to 8.