Crowd detection method and device and storage medium
By using a multi-scale prediction model and an adaptive feature fusion module, the problem of insufficient accuracy and robustness of crowd detection in complex scenarios in existing technologies is solved, achieving more efficient and accurate crowd detection, which is applicable to fields such as public safety and urban management.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-26
- Publication Date
- 2026-04-03
AI Technical Summary
Existing crowd detection methods lack accuracy and robustness in complex scenarios, especially in dense crowds, large scale variations, or complex backgrounds. Single-scale features struggle to accommodate both small and large targets, leading to missed detections or localization errors. Furthermore, they lack adaptive feature fusion and loss function design.
A multi-scale prediction model is adopted, which extracts multi-layer features through the backbone network, combines a feature pyramid decoder and a multi-scale adaptive feature fusion module to fuse features at different scales, and introduces a channel attention submodule and a residual connection structure to design a confidence-guided composite loss function to optimize regression and classification tasks.
It improves the accuracy and stability of crowd detection, better adapts to different crowd densities and perspectives, reduces information loss, enhances the robustness and global consistency of the model, and adapts to the detection needs in complex scenarios.
Smart Images

Figure CN121789134A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image processing technology, and in particular to crowd detection methods, devices and storage media. Background Technology
[0002] With the increasing demand for intelligent video surveillance and urban security management, crowd counting technology has been widely applied in public safety, urban planning, and passenger flow analysis. The core objective of this type of task is to estimate the distribution and density of people in a scene using image or video data. In recent years, deep learning methods, especially convolutional neural networks (CNNs), have made significant progress in the field of crowd counting.
[0003] Among these methods, typical crowd counting models include density map regression-based methods such as MCNN and CSRNet, and point prediction-based detection methods such as P2PNet. P2PNet (Point-to-Point Network) achieves a unified framework for counting and localization by directly predicting the coordinates of each head, exhibiting good end-to-end trainability and interpretability. However, P2PNet only uses a single layer of the feature pyramid network as the prediction input, failing to fully integrate low-level details with high-level semantic information. In dense crowds, scenes with large scale variations, or complex backgrounds, single-scale features struggle to simultaneously capture both small and large targets, leading to missed detections or localization errors. Summary of the Invention
[0004] The main purpose of this application is to provide a crowd detection method, device and storage medium, which aims to solve the technical problem that the existing crowd detection methods are not accurate and robust enough in complex scenarios.
[0005] To achieve the above objectives, this application proposes a population detection method, which includes: Acquire images of the population to be detected, and input the images of the population to be detected into the backbone network of the multi-scale prediction model to extract multi-layer features of the images of the population to be detected, thereby obtaining feature maps at different scales; Feature maps at different scales are input into the feature pyramid decoder in the multi-scale prediction model to generate multi-scale pyramid features. The multi-scale pyramid features are input into the multi-scale adaptive feature fusion module in the multi-scale prediction model, and the fused features are output. The fused features are input into the prediction branch of the multi-scale prediction model, and the crowd detection results are output.
[0006] In one embodiment, the multi-scale adaptive feature fusion module includes: a channel attention submodule and a feature fusion submodule; The step of inputting multi-scale pyramid features into the multi-scale adaptive feature fusion module of the multi-scale prediction model and outputting fused features includes: Multi-scale pyramid features are input into the channel attention submodule of the multi-scale prediction model to concatenate channel dimensions of the same spatial size, generating channel weights for features at each scale. The feature fusion submodule performs feature fusion on the multi-scale pyramid features by using the channel weights of features at each scale, and outputs fused features.
[0007] In one embodiment, the multi-scale adaptive feature fusion module further includes: a local enhancement submodule and a residual connection structure; The step of fusing the multi-scale pyramid features by means of channel weights of features at each scale in the feature fusion submodule and outputting the fused features includes: In the feature fusion submodule, the multi-scale pyramid features are weighted and summed using the channel weights of features at each scale to obtain weighted summed features; The local enhancement submodule performs local feature enhancement on the weighted summation features to obtain locally enhanced features; In the residual connection structure, the local enhancement features and the target pyramid features in the multi-scale pyramid features are added element-wise to output the fused features.
[0008] In one embodiment, the prediction branch includes a regression branch and a classification branch; The step of inputting the fused features into the prediction branch of the multi-scale prediction model and outputting the crowd detection result includes: The fused features are input into the regression branch of the multi-scale prediction model to predict the coordinate offset of each anchor point, thus obtaining the predicted head coordinates. The fused features are input into the classification branch of the multi-scale prediction model to predict the probability of target presence at each anchor point, and the prediction confidence score is obtained. The crowd detection result is obtained based on the predicted head coordinates and the predicted confidence score.
[0009] In one embodiment, after the step of inputting the fused features into the prediction branch of the multi-scale prediction model and outputting the crowd detection result, the method further includes: Based on the population detection results, the predicted head coordinates and predicted confidence scores are obtained. The confidence-weighted regression loss of the regression branch in the prediction branch is calculated based on the predicted head coordinates and the predicted confidence score. The classification loss of the classification branch in the prediction branch is calculated based on the prediction confidence score; Calculate the count consistency loss based on the actual number of people and the predicted confidence score; The comprehensive loss is calculated based on the confidence-weighted regression loss, the classification loss, and the count consistency loss. The training parameters in the multi-scale prediction model are updated using the comprehensive loss to update the multi-scale prediction model, resulting in an updated multi-scale prediction model.
[0010] In one embodiment, the step of calculating the confidence-weighted regression loss of the regression branch in the prediction branch based on the predicted head coordinates and the predicted confidence score includes: Obtain the actual head coordinate offset and preset scaling factor; Calculate the coordinate offset error based on the actual head coordinate offset and the predicted head coordinate; Using the predicted confidence score as the weight, the log-squared error loss of the coordinate offset error is calculated by applying the preset scaling factor, thus obtaining the confidence-weighted regression loss of the regression branch in the prediction branch.
[0011] In one embodiment, the step of calculating the count consistency loss based on the actual number of people and the predicted confidence score includes: The total predicted number of people is obtained by summing the predicted confidence scores of each anchor point based on the predicted confidence scores. The absolute error loss is calculated based on the predicted total number of people and the actual number of people to obtain the counting consistency loss.
[0012] In one embodiment, the step of inputting feature maps of different scales into the feature pyramid decoder in the multi-scale prediction model to generate multi-scale pyramid features includes: Feature maps of different scales are input into the feature pyramid decoder in the multi-scale prediction model. The feature pyramid decoder then performs a lateral connection on the feature maps of different scales to obtain the laterally connected feature map. An upsampling operation is performed on the laterally connected feature map to obtain the upsampled feature map; The upsampled feature map is fused with feature maps of different scales to generate multi-scale pyramid features.
[0013] Furthermore, to achieve the above objectives, this application also proposes a crowd detection device, which includes: The acquisition module is used to acquire images of the population to be detected and input the images of the population to be detected into the backbone network of the multi-scale prediction model to extract multi-layer features of the images of the population to be detected, thereby obtaining feature maps at different scales. The input module is used to input feature maps of different scales into the feature pyramid decoder in the multi-scale prediction model to generate multi-scale pyramid features. The input module is also used to input multi-scale pyramid features into the multi-scale adaptive feature fusion module in the multi-scale prediction model and output fused features; The input module is also used to input the fused features into the prediction branch of the multi-scale prediction model and output the crowd detection results.
[0014] In addition, to achieve the above objectives, this application also proposes a crowd detection device, the device comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the crowd detection method as described above.
[0015] In addition, to achieve the above objectives, this application also proposes a storage medium, which is a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, it implements the steps of the crowd detection method described above.
[0016] In addition, to achieve the above objectives, this application also provides a computer program product, which includes a computer program that, when executed by a processor, implements the steps of the crowd detection method described above.
[0017] One or more technical solutions proposed in this application have at least the following technical effects: 1) By extracting feature maps at different scales through the backbone network, more layers of information can be obtained. Low-level features typically contain detailed information, while high-level features contain more advanced semantic information. Therefore, multi-scale features can more comprehensively represent the different attributes of the population to be detected. The feature pyramid decoder can further process multi-scale features, integrating information from different levels to retain diverse contextual information. The multi-scale adaptive feature fusion module can effectively combine features from different scales to generate a stronger global feature representation. This fusion can reduce information loss caused by scale transformation, thereby improving adaptability to different population densities and perspectives. Inputting the fused features into the prediction branch can significantly improve the accuracy of population detection. With the support of multi-scale features, the model can better identify and distinguish between crowded and sparse regions, thus outputting detection results more accurately.
[0018] 2) The channel attention submodule calculates channel weights for features at various scales, identifying which features are more important to the current task. By adaptively fusing features at different scales, it significantly improves the model's adaptability to dense, sparse, and near / far targets. Furthermore, the module uses 1×1 convolutions and depthwise separable convolutions, resulting in minimal parameter increases and seamless integration into existing frameworks. The introduction of the channel attention submodule makes the feature fusion process more flexible. By weighting features, the model can dynamically adjust the feature combination based on the specific data, enabling it to better adapt to different task requirements. The residual connection structure preserves the stable semantics of the main layer features, making training smoother and gradient propagation more efficient.
[0019] 3) By using the regression branch to predict the head coordinate offset of each anchor point, the location of people can be determined more accurately. Simultaneously, the classification branch provides additional information for each anchor point by predicting the probability of the target's presence, improving recognition accuracy. The multi-scale prediction model can capture head features of different sizes and shapes, thereby improving the detection performance of both small and large crowds. This design can adapt to different scene changes, improving overall detection performance. Parallel processing of regression and classification tasks makes the entire detection process more efficient, facilitating real-time crowd monitoring and analysis, and is suitable for fields requiring rapid decision-making, such as security and traffic management. Attached Figure Description
[0020] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0021] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0022] Figure 1 This is a flowchart illustrating the population detection method of this application in Embodiment 1; Figure 2 A block diagram of the overall structure of a multi-scale prediction model provided in an embodiment of the population detection method of this application; Figure 3 This is a flowchart illustrating Embodiment 2 of the population detection method of this application; Figure 4 A schematic diagram of the structure of a multi-scale adaptive feature fusion module provided in an embodiment of the population detection method of this application; Figure 5 This is a flowchart illustrating Embodiment 3 of the population detection method of this application; Figure 6 This is a schematic diagram of the module structure of the population detection device according to an embodiment of this application; Figure 7 This is a schematic diagram of the device structure of the hardware operating environment involved in the crowd detection method in this application embodiment.
[0023] The purpose, features, and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0024] It should be understood that the specific embodiments described herein are merely illustrative of the technical solutions of this application and are not intended to limit this application.
[0025] To better understand the technical solution of this application, a detailed description will be provided below in conjunction with the accompanying drawings and specific implementation methods.
[0026] Because existing typical crowd counting models include density map regression-based methods such as MCNN and CSRNet, and point prediction-based detection methods such as P2PNet. Among them, P2PNet (Point-to-Point Network) realizes a unified framework for counting and localization by directly predicting the location coordinates of each head, and has good end-to-end trainability and interpretability. The existing P2PNet model mainly consists of three parts: Backbone: used to extract multi-scale features of the image; Feature Pyramid Network (FPN): fused semantic features of different scales; Regression + Classification Branch: used mid-level features to predict the coordinate offset and existence probability of each anchor point. During training, P2PNet uses mean squared error, i.e., MSE loss, to supervise the distance between the predicted point and the real point, and uses cross-entropy loss to handle target classification. This method has achieved good performance in crowd counting tasks, but still has the following technical problems: (1) Insufficient utilization of multi-scale features. P2PNet only selects a single layer of FPN as the prediction input, and fails to fully integrate low-level details and high-level semantic information. In dense crowds, large scale variations, or complex backgrounds, single-scale features are difficult to simultaneously take into account both small and large targets, leading to missed detections or localization errors. (2) The feature fusion method is singular and static. Existing methods, when performing multi-layer fusion, usually use simple weighting or splicing operations without considering the differences in importance of features at different scales. The lack of an adaptive weight allocation mechanism can easily lead to excessive suppression or interference of main layer features, affecting training stability. (3) The regression loss function is sensitive to outliers. The traditional MSE loss will generate excessive gradients for points with large prediction errors, leading to model instability during training. Especially in dense scenes or images with severe occlusion, large error samples appear frequently, making training convergence difficult. (4) All prediction points have the same weight, ignoring confidence differences. In the original model, prediction points with high confidence and low confidence contribute equally to the loss calculation, failing to effectively strengthen the learning of reliable prediction points. This can easily cause the model to overfit low-confidence points, reducing the overall prediction quality. (5) Lack of global counting constraints, only optimizing point-level errors, without explicit constraints on the consistency between the predicted total number of people and the actual number of people; resulting in a large deviation in the total number of people in some scenarios, even though the point location prediction is relatively accurate.
[0027] This application provides a solution that proposes a lightweight multi-scale adaptive feature fusion module and a confidence-guided composite loss function to enhance the model's scale robustness, stability, and global consistency. This solution maintains the network's lightweight nature while achieving adaptive fusion at the feature layer and dynamic weight optimization at the loss layer, which helps improve the accuracy and robustness of crowd counting models in complex scenarios.
[0028] It should be noted that the executing entity in this embodiment can be a computing service device with data processing, network communication, and program execution functions, such as a tablet computer, personal computer, or mobile phone, or an electronic device or crowd detection device capable of performing the above functions. The following description uses a crowd detection device as an example to illustrate this embodiment and the subsequent embodiments.
[0029] Based on this, embodiments of this application provide a method for population detection, referring to... Figure 1 , Figure 1 This is a flowchart illustrating the first embodiment of the population detection method of this application.
[0030] In this embodiment, the population detection method includes steps S10 to S40: Step S10: Obtain the image of the crowd to be detected, and input the image of the crowd to be detected into the backbone network of the multi-scale prediction model to extract multi-layer features of the image of the crowd to be detected, and obtain feature maps of different scales.
[0031] It should be noted that the main application scenarios of this embodiment may include crowd detection in public safety and urban management, crowd detection in smart cities and traffic management, crowd detection in business intelligence and passenger flow analysis, crowd detection in event analysis and emergency response, crowd detection in video surveillance and intelligent vision, and crowd detection in scientific research and data analysis. For example, it can be used for real-time crowd density monitoring and congestion warning in public places such as subway stations, airports, shopping malls, concerts, and stadiums. It can assist security systems in automatically identifying crowd gathering hotspots and supporting dynamic crowd flow control and emergency evacuation decisions. Deployed in urban camera networks, it can be used to analyze pedestrian flow dynamics in areas such as sidewalks, squares, and subway entrances and exits, assisting in optimizing traffic signal control and public resource scheduling. It can also be applied to pedestrian flow statistics and distribution heat map generation in retail malls, scenic spots, and exhibitions, providing businesses with a basis for customer flow analysis and marketing strategy optimization. In large-scale events or emergencies such as fires and stampedes, it can support safety monitoring and emergency response systems through real-time crowd density estimation, improving public safety levels. It can be embedded in smart cameras, edge computing devices, or video analysis platforms to achieve end-to-end crowd density estimation and visualization output. It also serves as the basic algorithm for high-precision crowd density estimation models, used in research in fields such as computer vision, social behavior analysis, and urban studies.
[0032] It should be noted that the images of the crowd to be detected can be images containing crowds collected in various scenarios, and the image sources can be real-time camera captures, video frame extractions, or pre-stored image files, etc. After acquiring the images of the crowd to be detected, they are input into the backbone network of a pre-constructed multi-scale prediction model.
[0033] This meticulously designed backbone network possesses powerful feature extraction capabilities, enabling it to extract features from input images layer by layer, thereby obtaining feature maps at different scales. These feature maps at different scales contain information about the image at different levels. Lower-level feature maps retain more detailed image information, such as edges and textures, while higher-level feature maps contain more advanced semantic information, such as the shape and category of objects. In this way, a rich feature base can be provided for subsequent crowd detection.
[0034] like Figure 2 As shown, Figure 2 This is the overall structural diagram of the multi-scale prediction model, including the backbone network, feature pyramid decoder, multi-scale adaptive feature fusion module, and prediction branch. The backbone network is the main network, which can be a ResNet series convolutional neural network. It is used to convert the input image into feature maps of different levels through layer-by-layer convolution, outputting multi-scale feature maps C3, C4, and C5. The FPN is the feature pyramid decoder, which outputs pyramid feature layers P3, P4, and P5, corresponding one-to-one with C3, C4, and C5. The MSAF_Lite Module is the multi-scale adaptive feature fusion module, used for feature fusion, outputting the fused feature as the fused feature. The Regression Head is the regression branch in the prediction branch, and the Classification Head is the classification branch in the prediction branch. By inputting the fused features into the regression branch and the classification branch respectively, the crowd detection result is output.
[0035] C3, C4, and C5 are the intermediate feature layers output by the backbone network. The subscript numbers represent the spatial scale of the feature map. The larger the number, the smaller the feature map size and the more abstract the semantic information. C3 is a low-level feature that retains more detailed information, such as edges and textures; C4 is a mid-level feature that is used to balance details and semantics; and C5 is a high-level feature that is rich in semantic information but has low spatial resolution.
[0036] Step S20: Input the feature maps at different scales into the feature pyramid decoder in the multi-scale prediction model to generate multi-scale pyramid features.
[0037] After obtaining feature maps C3, C4, and C5 at different scales, the feature maps at different scales can be input into the feature pyramid decoder (Decoder or FPN) in the multi-scale prediction model to perform lateral connection and upsampling on the feature maps at different scales, thereby generating multi-scale pyramid features.
[0038] In one feasible implementation, step S20 may include steps A11 to A13: Step A11: Input the feature maps at different scales into the feature pyramid decoder in the multi-scale prediction model, and then use the feature pyramid decoder to perform lateral connection on the feature maps at different scales to obtain the laterally connected feature maps. It should be noted that the Feature Pyramid Decoder is an FPN, which can horizontally connect high-level features and low-level features of the backbone network to fuse features from different levels and obtain a horizontally connected feature map.
[0039] Step A12: Perform an upsampling operation on the laterally connected feature map to obtain the upsampled feature map; In practice, the feature maps after horizontal connection can be upsampled. Upsampling can be done by bilinear interpolation, deconvolution, etc. Upsampling can increase the size of the feature maps, thereby improving the spatial resolution of high-level features and better integrating them with low-level features to obtain upsampled feature maps. These upsampled feature maps contain information from different levels of fusion, laying the foundation for generating more accurate pyramid features in the future.
[0040] Step A13: Fuse the upsampled feature map with feature maps of different scales to generate multi-scale pyramid features.
[0041] The upsampled feature map is fused with the corresponding low-level feature map. For example, the upsampled high-level feature map is fused with the low-level feature map C3. Fusion methods can include addition, concatenation, etc. This fusion fully utilizes the detailed information of the low-level features and the semantic information of the high-level features to generate multi-scale pyramid features P3, P4, and P5. These features maintain semantic consistency across different scales and contain richer information, better representing crowd features at different scales and improving the accuracy of crowd detection. Specifically, P3 corresponds to the upsampled feature of C3, preserving details; P4 corresponds to the upsampled feature of C4 and is the main feature layer for subsequent prediction; and P5 corresponds to the upsampled feature of C5, enhancing semantic information.
[0042] Step S30: Input the multi-scale pyramid features into the multi-scale adaptive feature fusion module in the multi-scale prediction model and output the fused features.
[0043] Understandably, multi-scale pyramid features can be input into the multi-scale adaptive feature fusion module in the multi-scale prediction model. At the same time, the mid-level feature map C4 and the high-level feature map C5 from the feature maps of different scales can also be input into the multi-scale adaptive feature fusion module to fuse the features and obtain fused features.
[0044] The fused features not only integrate the rich information from the multi-scale pyramid features but also fully utilize the detail and semantic balance characteristics of the mid-level feature map C4 and the rich semantic information of the high-level feature map C5. The multi-scale adaptive feature fusion module adaptively learns the importance weights of features at different scales, dynamically adjusting the contribution of each scale feature in the fusion process, thereby generating more representative and robust fused features. These fused features can better adapt to the crowd detection needs in different scenarios, providing accurate and stable crowd feature representations regardless of whether the scene is densely populated, has large scale variations, or has a complex background.
[0045] Step S40: Input the fused features into the prediction branch of the multi-scale prediction model and output the crowd detection results.
[0046] In practice, the fused features are then input into the prediction branch, which includes a regression branch and a classification branch, to further output the results of crowd detection, thereby achieving accurate crowd counting and localization.
[0047] In one feasible implementation, step S40 may include steps A21 to A23: Step A21: Input the fused features into the regression branch of the multi-scale prediction model to predict the coordinate offset of each anchor point, and obtain the predicted head coordinates; It should be noted that the regression branch is used to predict the coordinate offset of each anchor point. Therefore, the fused features can be input into the regression branch, which then predicts the coordinate offset of each anchor point to obtain the predicted head coordinates. The regression branch typically employs a convolutional neural network structure, learning from a large amount of labeled data to fit the relationship between the coordinate offset and the fused features, thereby accurately predicting the specific location of each head in the image.
[0048] Step A22: Input the fused features into the classification branch of the multi-scale prediction model to predict the target existence probability at each anchor point and obtain the prediction confidence score; The classification branch's role is to predict whether a head exists at each anchor point, essentially performing a binary classification for each anchor point. After the fused features are input into the classification branch, it outputs the probability value of each anchor point belonging to the head category. By setting an appropriate threshold, it can be determined whether the anchor point represents a real head, thus obtaining a prediction confidence score. The classification branch also uses a convolutional neural network structure, learning patterns related to the presence of heads in the fused features through training to accurately distinguish between foreground and background (foreground being the head). This step is crucial for reducing false detections and improving detection accuracy.
[0049] Step A23: Obtain the crowd detection result based on the predicted head coordinates and the predicted confidence score.
[0050] After obtaining the predicted head coordinates and predicted confidence scores, the two are combined to locate each detected head and evaluate its confidence level. Typically, detection results with confidence scores below a preset threshold are filtered out to reduce false positives. Ultimately, the output is a set of head detection boxes with location information and confidence scores. These boxes collectively constitute the crowd detection results, providing foundational data for subsequent tasks such as crowd counting, density analysis, or behavior recognition. In this way, the crowd detection method of this application can achieve efficient and accurate crowd detection and counting in complex scenarios, meeting the needs of various practical applications.
[0051] This embodiment provides a crowd detection method that extracts feature maps at different scales through a backbone network, thereby acquiring more layers of information. Low-level features typically contain detailed information, while high-level features contain more advanced semantic information; therefore, multi-scale features can more comprehensively represent the different attributes of the target crowd. The feature pyramid decoder can further process multi-scale features, integrating information from different levels to preserve diverse contextual information. The multi-scale adaptive feature fusion module can effectively combine features from different scales to generate a stronger global feature representation. This fusion can reduce information loss caused by scale transformation, thereby improving adaptability to different crowd densities and perspectives. Inputting the fused features into the prediction branch can significantly improve the accuracy of crowd detection. With the support of multi-scale features, the model can better identify and distinguish between crowded and sparse regions, thus outputting more accurate detection results.
[0052] Based on the first embodiment of this application, in the second embodiment of this application, the content that is the same as or similar to that in the first embodiment described above can be referred to the above description, and will not be repeated hereafter. Based on this, please refer to... Figure 3 Step S30 includes steps S301 to S302: In this embodiment, the multi-scale adaptive feature fusion module includes: a channel attention submodule and a feature fusion submodule; Step S301: Input the multi-scale pyramid features into the channel attention submodule of the multi-scale prediction model to splice the channel dimensions of the same spatial size to generate the channel weights of features at each scale.
[0053] It should be noted that the channel attention submodule is used to interpolate the multi-scale pyramid features P3, P4, and P5 to the same spatial size and then concatenate them in the channel dimension. Specifically, it generates the channel weights of each scale feature through two layers of 1×1 convolution and ReLU activation, and uses the Sigmoid function combined with normalization to obtain the weight ratio, so as to avoid the main layer features being over-suppressed.
[0054] Step S302: The feature fusion submodule performs feature fusion on the multi-scale pyramid features by using the channel weights of features at each scale, and outputs the fused features.
[0055] In practice, the feature fusion submodule is used to perform weighted summation of the multi-scale pyramid features P3, P4, and P5 according to the channel weights of the features at each scale, thereby generating fused features.
[0056] In one feasible implementation, the multi-scale adaptive feature fusion module further includes a local enhancement submodule and a residual connection structure. Therefore, step S302 may include: the feature fusion submodule performing a weighted summation of the multi-scale pyramid features using the channel weights of features at each scale to obtain a weighted summation feature; the local enhancement submodule performing local feature enhancement on the weighted summation feature to obtain a locally enhanced feature; and the residual connection structure performing element-wise addition of the locally enhanced feature and the target pyramid feature from the multi-scale pyramid features to output a fused feature.
[0057] In practical implementation, the feature fusion submodule performs weighted summation of multi-scale pyramid features based on the channel weights of features at each scale, resulting in a weighted sum feature. This weighted sum feature is then input into the local enhancement submodule, which employs depthwise separable convolution (Depthwise convolution + Pointwise convolution) combined with a BatchNorm layer and ReLU activation function to refine local features and improve representation capabilities. By utilizing depthwise separable convolution to refine local features, locally enhanced features are obtained. After obtaining the locally enhanced features, they are input into the residual connection structure. The target pyramid feature is the main layer feature P4 in the multi-scale pyramid features. By adding the locally enhanced features element-wise to the main layer feature P4, balancing multi-scale information with the semantic stability of the main layer, a fused feature is output.
[0058] The fusion feature is calculated as follows: In the above formula, Indicates fusion features, P4 represents the main pyramid feature. This represents the i-th layer pyramid feature output by the channel attention module. Pi The corresponding channel weights, i.e., after Sigmoid normalization, Let Pi be the feature of the i-th pyramid level, where the value of i ranges from 3 to 5. This indicates an element-wise multiplication operation. This represents the summation and normalization term over all scale channel weights, used to ensure the reasonable weight allocation of features at different scales during the fusion process. The locally enhanced features are added to the main layer feature P4 via residual connections, preserving the diversity of multi-scale information while strengthening the semantic stability of the main layer features. The final output is a fused feature that combines rich detail and semantic robustness. This design enables the model to more accurately capture crowd distribution features in complex scenes, such as areas with drastic scale changes or severe background interference, while maintaining high detection accuracy.
[0059] like Figure 4 As shown, Figure 4 This is a schematic diagram of the multi-scale adaptive feature fusion module. Channel Attention is the channel attention submodule, Weighted Fusion is the weighted fusion submodule, Depthwise & Pointwise Conv is the local enhancement submodule and residual connection structure, and Fused Feature is the final output of the multi-scale adaptive feature fusion module. The channel attention submodule learns the channel weights of each feature layer, such as w3, w4, and w5, and adaptively assigns the importance of P3, P4, and P5. The higher the weight, the greater the contribution of the corresponding feature layer to the fusion result. P3, P4, and P5 are weighted and summed using the channel weights of features at each scale to obtain the weighted summed feature. The local enhancement submodule extracts local features from the weighted summed feature to obtain the local enhanced feature. The residual connection structure is used to perform element-wise analysis on the local enhanced feature and the main layer feature to output the fused feature.
[0060] This embodiment's channel attention submodule calculates channel weights for features at various scales, identifying which features are more important to the current task. By adaptively fusing features at different scales, it significantly improves the model's adaptability to dense, sparse, and near / far targets. Furthermore, the module employs 1×1 convolutions and depthwise separable convolutions, resulting in minimal parameter increases and seamless integration into existing frameworks. The introduction of the channel attention submodule makes the feature fusion process more flexible. By weighting features, the model can dynamically adjust the feature combination based on the specific data, enabling it to better adapt to different task requirements. The residual connection structure preserves the stable semantics of the main layer features, making training smoother and gradient propagation more efficient.
[0061] Based on the first embodiment of this application, in the third embodiment of this application, the content that is the same as or similar to that in Embodiments 1 and 2 described above can be referred to the above description, and will not be repeated hereafter. Based on this, please refer to... Figure 5 After step S40, the crowd detection method further includes steps S41 to S46: Step S41: Obtain the predicted head coordinates and predicted confidence scores based on the crowd detection results.
[0062] It should be noted that after outputting the crowd detection results in step S40, the predicted head coordinates and corresponding prediction confidence scores can be directly extracted. The predicted head coordinates accurately locate the position of each head in the image, while the prediction confidence score reflects the model's confidence in the authenticity of each detected head. This information forms the basis for subsequent tasks such as crowd counting, density analysis, and behavior recognition. By acquiring this information, the model can more accurately understand the distribution of crowds in the image, providing strong support for various practical application scenarios. For example, in surveillance scenarios, the predicted head coordinates and confidence scores can be used to monitor crowd flow in real time and promptly detect abnormal behavior; in public place management, this information can be used to assess the crowding level of the venue, providing a basis for personnel guidance and safety management.
[0063] Step S42: Calculate the confidence-weighted regression loss of the regression branch in the prediction branch based on the predicted head coordinates and the predicted confidence score.
[0064] In practical implementation, a confidence-weighted regression loss function can be designed based on the predicted head coordinates and the predicted confidence score. This loss function, when calculating the loss of the regression branch, not only considers the difference between the predicted coordinates and the true coordinates, but also incorporates the predicted confidence score to weight the loss.
[0065] Confidence-weighted regression loss is used to supervise the prediction of coordinate offset in the regression branch. It can introduce confidence-based dynamic adjustment of weights to solve the problem of traditional MSE loss being sensitive to outliers. At the same time, it can dynamically adjust the loss weights according to the prediction confidence to strengthen the learning of high-confidence points.
[0066] In one feasible implementation, step S42 may include steps B11-B13: Step B11: Obtain the actual head coordinate offset and preset scaling factor; In practice, the actual head coordinate offset can be obtained from the labeled data, which contains the actual position information of each head in the image. The actual head coordinate offset can then be calculated. (Preset scaling factor) It can be set according to actual needs. Its function is to scale and adjust the loss to a certain extent so as to better balance the impact of different parts of the loss on model training.
[0067] Step B12: Calculate the coordinate offset error based on the actual head coordinate offset and the predicted head coordinate; In practical implementation, the coordinate offset error can be calculated based on the actual head coordinate offset and the predicted head coordinate offset, and is expressed as follows: - .
[0068] Step B13: Using the predicted confidence score as the weight, calculate the log-squared error loss of the coordinate offset error using the preset scaling factor to obtain the confidence-weighted regression loss of the regression branch in the prediction branch.
[0069] In practical implementation, the confidence-weighted regression loss can be calculated based on the coordinate offset error, as follows: In the above formula, The confidence-weighted regression loss, To predict confidence scores, The confidence level is the power exponent. The preset scaling factor, Let N be the square of the L2 norm, and N be the total number of detection boxes. This is the predicted head coordinate offset. This represents the actual head coordinate offset. The loss function incorporates a prediction confidence score. Confidence Power Index This allows high-confidence predictions to have a greater weight in the loss calculation, thereby strengthening the model's learning of reliable predictions; at the same time, a preset scaling factor is used. The introduction of L2 loss allows for flexible adjustment of the loss scale, avoiding training instability caused by excessively large or small coordinate offset errors. This design makes the regression branch focus more on high-confidence predictions during training, effectively improving the model's coordinate prediction accuracy and robustness, especially in complex scenarios where it significantly reduces the interference of outliers on model training. By taking the logarithm of the L2 loss, the gradient contribution of large error points is reduced, weakening the impact of outliers and improving regression robustness.
[0070] Step S43: Calculate the classification loss of the classification branch in the prediction branch based on the prediction confidence score.
[0071] It should be noted that the classification loss is used to determine whether the target exists, i.e., whether a head exists. It can be calculated using cross-entropy loss, as shown in the following formula: In the above formula, The loss is for classification, where N is the total number of anchor points. Let be the actual label of the i-th anchor point, where 1 indicates someone is there and 0 indicates no one is there. The probability of the target existing for the classification branch is predicted, i.e., the prediction confidence score.
[0072] Step S44: Calculate the count consistency loss based on the actual number of people and the predicted confidence score.
[0073] In practice, the count consistency loss can be calculated based on the actual number of people and the predicted confidence score. The count consistency loss is used to explicitly constrain the consistency between the predicted total number of people and the actual number of people, thereby solving the problem of "accurate point-level predictions but large global count bias" in traditional methods. In one feasible implementation, step S44 may include steps B21-B22: Step B21: Calculate the sum of the prediction confidence scores for each anchor point based on the prediction confidence scores to obtain the total predicted number of people; In practice, the predicted confidence scores of all anchor points can be summed to obtain the total predicted number of people. This step integrates the scattered predicted confidence scores into a global predicted number of people, providing a basis for subsequent comparison with the actual number of people.
[0074] Step B22: Calculate the absolute error loss based on the predicted total number of people and the actual number of people to obtain the counting consistency loss.
[0075] In practice, the degree of inconsistency between the predicted total number of people and the actual number of people can be quantified by calculating the absolute difference or the squared difference. Then, a counting consistency loss function can be designed based on this difference, such as the mean squared error loss function, to make the predicted total number of people as close as possible to the actual number. The introduction of the counting consistency loss function explicitly constrains the accuracy of the model in global counting, and is calculated as follows: In the above formula, The probability of target existence output by the classification branch is represented by the prediction confidence score after Sigmoid activation. This represents the actual total number of people in the image, i.e., the number of labeled heads. To predict the total number of people, This is the loss due to consistency in counting.
[0076] Step S45: Calculate the comprehensive loss based on the confidence-weighted regression loss, the classification loss, and the count consistency loss.
[0077] In practice, the overall loss can be calculated based on confidence-weighted regression loss, classification loss, and consistency loss, and the weights of each loss can be set. Therefore, the overall loss is calculated as follows: In the above formula, To account for the overall losses, The weights for each loss term can be adjusted according to the experimental settings.
[0078] Step S46: Update the training parameters in the multi-scale prediction model using the comprehensive loss to update the multi-scale prediction model and obtain the updated multi-scale prediction model.
[0079] After obtaining the comprehensive loss, the gradient of the trainable parameters in the multi-scale prediction model, including the backbone network, the multi-scale adaptive feature fusion module, and the trainable parameters of the prediction branch, can be calculated using the comprehensive loss. The gradient value of each parameter is obtained, and the parameters are updated by the optimizer based on the gradient value, thereby minimizing the comprehensive loss. The process of forward propagation, loss calculation, backpropagation, and parameter update is repeated until the multi-scale prediction model converges, resulting in the updated multi-scale prediction model.
[0080] To verify the effectiveness of the crowd counting model based on multi-scale adaptive feature fusion and confidence-weighted composite loss proposed in this application, the applicant conducted a systematic experiment based on a publicly available dataset: (a) Experimental dataset: The experiment was conducted on the ShanghaiTech Part A dataset, which contains 482 high-density crowd images with large crowd density variations and complex backgrounds. It is widely used for performance evaluation of crowd counting algorithms.
[0081] (II) Experimental Setup: Baseline Model: Original P2PNet (for comparison); Improved Model: P2PNet proposed in this invention + MSAF_Lite + improved loss function; Training Environment: GPU: Tesla T4 Deep learning framework: PyTorch; (III) Evaluation Indicators: The experiment used two commonly used indicators: MAE (Mean Absolute Error) and MSE (Mean Squared Error). These measures the average deviation and stability between the predicted number of people and the actual number of people, respectively.
[0082] (iv) Experimental Results The lower the value (↓), the better the performance. Experimental results show that on the ShanghaiTech A dataset, compared to the original P2PNet model, the MAE and MSE of this application are reduced by approximately 1.8% and 1.9%, respectively. The improved multi-scale feature fusion module effectively enhances the perception ability of regions with different densities; the confidence-weighted Log-L2 loss significantly reduces the impact of outliers; the overall results demonstrate that the method of this invention has higher counting accuracy and better generalization ability. Through experimental verification on standard datasets, the scheme of this invention achieves better performance than existing technologies in crowd counting tasks, proving the effectiveness and feasibility of the proposed MSAF_Lite module and composite loss function design.
[0083] This embodiment uses a regression branch to predict the head coordinate offset of each anchor point, enabling more accurate determination of personnel location. Simultaneously, a classification branch provides additional information for each anchor point by predicting the probability of the target's presence, improving recognition accuracy. The multi-scale prediction model can capture head features of different sizes and shapes, thereby improving the detection performance for both small and large crowds. This design adapts to different scene variations, improving overall detection performance. Parallel processing of regression and classification tasks makes the entire detection process more efficient, facilitating real-time crowd monitoring and analysis, and is suitable for fields requiring rapid decision-making, such as security and traffic management.
[0084] It should be noted that the above examples are only for understanding this application and do not constitute a limitation on the population detection method of this application. Any simple modifications based on this technical concept are within the protection scope of this application.
[0085] This application also provides a crowd detection device; please refer to... Figure 6 The crowd detection device includes: The acquisition module 10 is used to acquire images of the population to be detected and input the images of the population to be detected into the backbone network of the multi-scale prediction model to extract multi-layer features of the images of the population to be detected, thereby obtaining feature maps at different scales.
[0086] Input module 20 is used to input feature maps of different scales into the feature pyramid decoder in the multi-scale prediction model to generate multi-scale pyramid features.
[0087] The input module 20 is also used to input multi-scale pyramid features into the multi-scale adaptive feature fusion module in the multi-scale prediction model and output fused features.
[0088] The input module 20 is also used to input the fused features into the prediction branch of the multi-scale prediction model and output the crowd detection results.
[0089] The crowd detection device provided in this application, employing the crowd detection method described in the above embodiments, can solve the technical problem of insufficient accuracy and robustness of existing crowd detection methods in complex scenarios. Compared with the prior art, the beneficial effects of the crowd detection device provided in this application are the same as those of the crowd detection method provided in the above embodiments, and other technical features in the crowd detection device are the same as those disclosed in the methods of the above embodiments, and will not be repeated here.
[0090] This application provides a crowd detection device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, which are executed by the at least one processor to enable the at least one processor to perform the crowd detection method in Embodiment 1 above.
[0091] The following is for reference. Figure 7The diagram illustrates a structural schematic suitable for implementing crowd detection devices according to embodiments of this application. Crowd detection devices in embodiments of this application may include, but are not limited to, mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Description), PMPs (Portable Media Players), in-vehicle terminals (e.g., in-vehicle navigation terminals), and fixed terminals such as digital TVs and desktop computers. Figure 7 The crowd detection device shown is merely an example and should not be construed as limiting the functionality and scope of use of the embodiments of this application.
[0092] like Figure 7 As shown, the crowd detection device may include a processing unit 1001 (e.g., a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to a program stored in ROM (Read Only Memory) 1002 or a program loaded from storage device 1003 into RAM (Random Access Memory) 1004. RAM 1004 also stores various programs and data required for the operation of the crowd detection device. The processing unit 1001, ROM 1002, and RAM 1004 are interconnected via bus 1005. Input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems can be connected to I / O interface 1006: input devices 1007 including, for example, touch screens, touchpads, keyboards, mice, image sensors, microphones, accelerometers, gyroscopes, etc.; output devices 1008 including, for example, LCDs (Liquid Crystal Displays), speakers, vibrators, etc.; storage devices 1003 including, for example, magnetic tapes, hard disks, etc.; and communication devices 1009. Communication device 1009 allows the crowd detection device to communicate wirelessly or wiredly with other devices to exchange data. While the figures show crowd detection devices with various systems, it should be understood that implementation or possession of all the systems shown is not required. More or fewer systems may be implemented alternatively.
[0093] Specifically, according to the embodiments disclosed in this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device, or installed from storage device 1003, or installed from ROM 1002. When the computer program is executed by processing device 1001, it performs the functions defined in the methods of the embodiments disclosed in this application.
[0094] The crowd detection device provided in this application, employing the crowd detection method described in the above embodiments, can solve the technical problem of insufficient accuracy and robustness of existing crowd detection methods in complex scenarios. Compared with the prior art, the beneficial effects of the crowd detection device provided in this application are the same as those of the crowd detection method provided in the above embodiments, and other technical features of this crowd detection device are the same as those disclosed in the previous embodiment method, and will not be repeated here.
[0095] It should be understood that the various parts disclosed in this application can be implemented using hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in any suitable manner in one or more embodiments or examples.
[0096] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
[0097] This application provides a computer-readable storage medium having computer-readable program instructions (i.e., a computer program) stored thereon, the computer-readable program instructions being used to execute the crowd detection method in the above embodiments.
[0098] The computer-readable storage medium provided in this application may be, for example, a USB flash drive, but is not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to: electrical connections having one or more wires, portable computer disks, hard disks, RAM (Random Access Memory), ROM (Read Only Memory), EPROM (Erasable Programmable Read Only Memory or Flash Memory), optical fibers, CD-ROM (CD-Read Only Memory), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, system, or device. The program code contained on the computer-readable storage medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination thereof.
[0099] The aforementioned computer-readable storage medium may be included in the crowd detection device; or it may exist independently and not be assembled into the crowd detection device.
[0100] The aforementioned computer-readable storage medium carries one or more programs that, when executed by a crowd detection device, cause the crowd detection device to: acquire an image of a crowd to be detected; input the image of the crowd to be detected into the backbone network of a multi-scale prediction model to extract multi-layer features of the image of the crowd to be detected, obtaining feature maps at different scales; input the feature maps at different scales into the feature pyramid decoder of the multi-scale prediction model respectively, generating multi-scale pyramid features; input the multi-scale pyramid features into the multi-scale adaptive feature fusion module of the multi-scale prediction model, outputting fused features; and input the fused features into the prediction branch of the multi-scale prediction model, outputting crowd detection results.
[0101] Computer program code for performing the operations of this application can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, and C++, as well as conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including LAN (Local Area Network) or WAN (Wide Area Network)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0102] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0103] The modules described in the embodiments of this application can be implemented in software or hardware. The names of the modules do not necessarily limit the functionality of the unit itself.
[0104] The readable storage medium provided in this application is a computer-readable storage medium that stores computer-readable program instructions (i.e., a computer program) for executing the above-described crowd detection method, which can solve the technical problem of insufficient accuracy and robustness of existing crowd detection methods in complex scenarios. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as those of the crowd detection method provided in the above embodiments, and will not be repeated here.
[0105] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the crowd detection method described above.
[0106] The computer program product provided in this application can solve the technical problem of insufficient accuracy and robustness of existing crowd detection methods in complex scenarios. Compared with the prior art, the beneficial effects of the computer program product provided in this application are the same as those of the crowd detection methods provided in the above embodiments, and will not be repeated here.
[0107] The above description is only a part of the embodiments of this application and does not limit the patent scope of this application. All equivalent structural transformations made under the technical concept of this application and using the contents of the specification and drawings of this application, or direct / indirect applications in other related technical fields, are included in the patent protection scope of this application.
Claims
1. A method for population detection, characterized in that, The population detection method includes: Acquire images of the population to be detected, and input the images into the backbone network of a multi-scale prediction model to extract multi-layer features of the images to obtain feature maps at different scales; Feature maps at different scales are input into the feature pyramid decoder in the multi-scale prediction model to generate multi-scale pyramid features. The multi-scale pyramid features are input into the multi-scale adaptive feature fusion module in the multi-scale prediction model, and the fused features are output. The fused features are input into the prediction branch of the multi-scale prediction model, and the crowd detection results are output.
2. The method as described in claim 1, characterized in that, The multi-scale adaptive feature fusion module includes: a channel attention submodule and a feature fusion submodule; The step of inputting multi-scale pyramid features into the multi-scale adaptive feature fusion module of the multi-scale prediction model and outputting fused features includes: Multi-scale pyramid features are input into the channel attention submodule of the multi-scale prediction model to concatenate channel dimensions of the same spatial size, generating channel weights for features at each scale. The feature fusion submodule performs feature fusion on the multi-scale pyramid features by using the channel weights of features at each scale, and outputs fused features.
3. The method as described in claim 2, characterized in that, The multi-scale adaptive feature fusion module further includes: a local enhancement submodule and a residual connection structure; The step of fusing the multi-scale pyramid features by means of channel weights of features at each scale in the feature fusion submodule and outputting the fused features includes: In the feature fusion submodule, the multi-scale pyramid features are weighted and summed using the channel weights of features at each scale to obtain weighted summed features; The local enhancement submodule performs local feature enhancement on the weighted summation features to obtain locally enhanced features; In the residual connection structure, the local enhancement features and the target pyramid features in the multi-scale pyramid features are added element-wise to output the fused features.
4. The method as described in claim 1, characterized in that, The prediction branches include regression branches and classification branches; The step of inputting the fused features into the prediction branch of the multi-scale prediction model and outputting the crowd detection result includes: The fused features are input into the regression branch of the multi-scale prediction model to predict the coordinate offset of each anchor point, thus obtaining the predicted head coordinates. The fused features are input into the classification branch of the multi-scale prediction model to predict the probability of target presence at each anchor point, and the prediction confidence score is obtained. The crowd detection result is obtained based on the predicted head coordinates and the predicted confidence score.
5. The method as described in claim 1, characterized in that, After the step of inputting the fused features into the prediction branch of the multi-scale prediction model and outputting the crowd detection result, the method further includes: Based on the population detection results, the predicted head coordinates and predicted confidence scores are obtained. The confidence-weighted regression loss of the regression branch in the prediction branch is calculated based on the predicted head coordinates and the predicted confidence score. The classification loss of the classification branch in the prediction branch is calculated based on the prediction confidence score; Calculate the count consistency loss based on the actual number of people and the predicted confidence score; The comprehensive loss is calculated based on the confidence-weighted regression loss, the classification loss, and the count consistency loss. The training parameters in the multi-scale prediction model are updated using the comprehensive loss to update the multi-scale prediction model, resulting in an updated multi-scale prediction model.
6. The method as described in claim 5, characterized in that, The step of calculating the confidence-weighted regression loss of the regression branch in the prediction branch based on the predicted head coordinates and the predicted confidence score includes: Obtain the actual head coordinate offset and preset scaling factor; Calculate the coordinate offset error based on the actual head coordinate offset and the predicted head coordinate; Using the predicted confidence score as the weight, the log-squared error loss of the coordinate offset error is calculated by applying the preset scaling factor, thus obtaining the confidence-weighted regression loss of the regression branch in the prediction branch.
7. The method as described in claim 5, characterized in that, The step of calculating the count consistency loss based on the actual number of people and the predicted confidence score includes: The total predicted number of people is obtained by summing the predicted confidence scores of each anchor point based on the predicted confidence scores. The absolute error loss is calculated based on the predicted total number of people and the actual number of people to obtain the counting consistency loss.
8. The method as described in claim 1, characterized in that, The step of inputting feature maps of different scales into the feature pyramid decoder in the multi-scale prediction model to generate multi-scale pyramid features includes: Feature maps of different scales are input into the feature pyramid decoder in the multi-scale prediction model. The feature pyramid decoder then performs a lateral connection on the feature maps of different scales to obtain the laterally connected feature map. An upsampling operation is performed on the laterally connected feature map to obtain the upsampled feature map; The upsampled feature map is fused with feature maps of different scales to generate multi-scale pyramid features.
9. A crowd detection device, characterized in that, The device includes: The acquisition module is used to acquire images of the population to be detected and input the images of the population to be detected into the backbone network of the multi-scale prediction model to extract multi-layer features of the images of the population to be detected, thereby obtaining feature maps at different scales. The input module is used to input feature maps of different scales into the feature pyramid decoder in the multi-scale prediction model to generate multi-scale pyramid features. The input module is also used to input multi-scale pyramid features into the multi-scale adaptive feature fusion module in the multi-scale prediction model and output fused features; The input module is also used to input the fused features into the prediction branch of the multi-scale prediction model and output the crowd detection results.
10. A storage medium, characterized in that, The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, it implements the steps of the population detection method as described in any one of claims 1 to 8.