Crowd counting method, device, equipment and readable storage medium in complex scenes

By introducing the pyramid multi-scale module and multi-column variance loss function into the crowd counting algorithm, the problem of feature similarity and limited scale of the multi-column model is solved, and the accuracy of crowd counting and the quality of density map generation are improved.

CN114494194BActive Publication Date: 2024-09-24WUHAN UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210093740.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-01-26
Publication Date
2024-09-24
Estimated Expiration
2042-01-26

AI Technical Summary

Technical Problem

Existing crowd counting algorithms are limited by the feature similarity and limited scale of multi-column models, resulting in the inability to further improve crowd counting accuracy and density map generation quality.

Method used

The pyramid multi-scale module and multi-column variance loss function are used to make each column cooperate with each other through the message passing mechanism and attention mechanism, improve the multi-scale feature extraction capability, and optimize the model parameters through the joint loss function.

Benefits of technology

It achieves more efficient multi-scale advanced feature extraction, reduces the problem of feature similarity and scale limitation, and improves the accuracy of crowd counting and the quality of density map generation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114494194B
    Figure CN114494194B
Patent Text Reader

Abstract

The present invention provides a method, device, equipment and readable storage medium for counting people in complex scenes. The method for counting people in complex scenes comprises: obtaining a crowd density map corresponding to a crowd picture through an improved crowd density map generation model, and then completing crowd counting based on the crowd density map, wherein a new multi-column structure, namely a pyramid multi-scale module, is adopted in the crowd density map generation model. Compared with the traditional multi-column structure in which each column is independent of each other, each column of the pyramid multi-scale module cooperates with each other, so that the number of scales corresponding to the pyramid multi-scale module is much larger than the number of columns, thereby realizing more efficient extraction of multi-scale high-level features. At the same time, the training of the pyramid multi-scale module is guided based on the multi-column variance loss, so that each column is prompted to learn different high-level pedestrian features, thereby improving the detection accuracy, solving the problem of feature similarity and limited scale in the traditional multi-column structure, and further improving the accuracy of crowd counting and the generation quality of the crowd density map.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the fields of artificial intelligence and security, and in particular to a crowd counting method, device, equipment and readable storage medium in complex scenarios. Background Art

[0002] With the advancement of large-scale urbanization in my country, the size of cities has expanded dramatically, and the population density has increased significantly. Cities are facing greater challenges in public management. Excessive crowd density can easily lead to disorder. Large-scale stampedes with more than 100 deaths occur every year around the world.

[0003] If the crowd density can be estimated and analyzed in real time and reasonable guidance can be carried out in time, the occurrence of similar incidents will be greatly reduced or even completely avoided. On the other hand, crowd density itself is also very important and meaningful information, which has important applications in the fields of smart city construction such as security warning, urban planning, smart business, and traffic dispatch. For example, for urban public transportation systems, the vehicle schedule can be flexibly adjusted by timely obtaining the spatial and temporal distribution of passengers.

[0004] With the development of deep learning technology, crowd counting algorithms based on convolutional neural networks (CNNs) have achieved excellent performance and significantly reduced counting errors. However, in actual application scenarios, existing algorithms still face many challenges, such as crowd scale changes, occlusion, background interference, and non-uniform crowd distribution.

[0005] The current mainstream crowd counting algorithms mainly use multi-column models to deal with the above challenges. Multi-column models contain multi-column CNNs, and usually different columns correspond to receptive fields of different sizes, which effectively solves the multi-scale problem. Then the output features of multi-column CNNs are fused together to generate the final crowd counting estimate.

[0006] However, there are two problems with multi-column models: feature similarity and limited scale, which limit further improvement of their performance. First, feature similarity: it is generally believed that multi-column models may lead to serious information redundancy between each column, that is, different columns often behave similarly without obvious differences. This is completely inconsistent with the design motivation behind the multi-column model; second, limited scale: due to structural limitations, each column of the multi-column model is independent of each other. From a global perspective, the number of scales corresponding to the multi-column model is equal to the number of columns. From a local perspective, each column can only work normally at the corresponding scale, and the performance at other scales drops sharply. Summary of the invention

[0007] The main purpose of the present invention is to provide a crowd counting method, device, equipment and readable storage medium in complex scenarios, aiming to solve the technical problem in the prior art that the crowd counting algorithm is limited by the feature similarity and scale limitation of the multi-column model adopted, resulting in the inability to further improve the accuracy of crowd counting and the quality of density map generation.

[0008] In a first aspect, the present invention provides a method for counting people in a complex scene, and the method for counting people in a complex scene comprises the following steps:

[0009] Input the crowd image to be detected into the backbone network of the trained crowd density map generation model to obtain the first feature vector;

[0010] Inputting the first feature vector into a pyramid multi-scale network in a trained crowd density map generation model to obtain a second feature vector, wherein the pyramid multi-scale network includes a preset number of pyramid multi-scale modules, the pyramid multi-scale modules are connected in series, each of the pyramid multi-scale modules includes a message passing module and an attention module, the message passing module includes a multi-column full convolution structure using a message passing mechanism, and the attention module includes a global pooling layer and a convolution layer using an attention mechanism;

[0011] Inputting the second feature vector into a generation network in a trained crowd density map generation model to obtain a crowd density map corresponding to the crowd image to be detected;

[0012] The target pixel values ​​of the region of interest of the crowd density map are integrated and summed to obtain the total number of people in the region of interest.

[0013] Optionally, the step of inputting the first feature vector into a pyramid multi-scale network in a trained crowd density map generation model to obtain a second feature vector includes:

[0014] Inputting the first feature vector into a first pyramid multi-scale module of a pyramid multi-scale network in a trained crowd density map generation model, and obtaining an attention vector based on an attention module in the first pyramid multi-scale module;

[0015] Based on the full convolution structure of each column of the message passing module in the first pyramid multi-scale module, an initial feature vector group is obtained, where the initial feature vector group includes initial feature vectors of a preset number of columns;

[0016] Repeat the steps of concatenating the initial feature vector generated by the full convolution structure of the current column in the initial feature vector group with the initial feature vector generated by the full convolution structure of the previous column, and inputting them into a convolution layer for fusion to obtain the output feature vector of the current column, until the output feature vectors of all columns are obtained;

[0017] Input the output feature vectors of all the columns into a convolutional layer, and fuse them to obtain a first fused feature vector;

[0018] Fusing the first fused feature vector with the attention vector to obtain a second fused feature vector, where the second fused feature vector is a feature vector output by the first pyramid multi-scale module;

[0019] The feature vector output by the first pyramid multi-scale module is input into the second pyramid multi-scale module to obtain a feature vector output by the second pyramid multi-scale module, and so on until a feature vector output by a last pyramid multi-scale module is obtained, wherein the feature vector output by the last pyramid multi-scale module is the second feature vector.

[0020] Optionally, before the step of inputting the crowd picture into the backbone network of the trained crowd density map generation model to obtain the first feature vector, the step includes:

[0021] Constructing a paired training data set, the training data set comprising a number of crowd sample images and a crowd sample density map corresponding to the crowd sample images;

[0022] Inputting the crowd sample pictures in the training data set into the backbone network in the crowd density map generation model to be trained to obtain a first sample feature vector;

[0023] Inputting the first sample feature vector into a first pyramid multi-scale module of a pyramid multi-scale network in a crowd density map generation model to be trained, and obtaining a sample attention vector based on an attention module in the first pyramid multi-scale module;

[0024] Based on the full convolution structure of each column of the message passing module in the first pyramid multi-scale module, an initial sample feature vector group is obtained, wherein the initial sample feature vector group includes initial sample feature vectors of a preset number of columns;

[0025] Repeat the steps of concatenating the initial feature sample vector generated by the full convolution structure of the current column in the initial sample feature vector group with the initial sample feature vector generated by the full convolution structure of the previous column, and inputting them into a convolution layer for fusion to obtain the sample output feature vector of the current column, until the sample output feature vectors of all columns are obtained;

[0026] Based on the sample output feature vectors of all the columns, obtaining a first attention vector corresponding to each column of each message passing module;

[0027] Based on the first attention vector corresponding to each column, calculate the variance loss function values ​​of multiple columns;

[0028] Inputting the sample output feature vectors of all the columns into a convolutional layer, and fusing them to obtain a first sample fused feature vector;

[0029] Fusing the first sample fusion feature vector with the sample attention vector to obtain a second sample fusion feature vector, where the second sample fusion feature vector is a sample feature vector output by the first pyramid multi-scale module;

[0030] Inputting the sample feature vector output by the first pyramid multi-scale module into the second pyramid multi-scale module to obtain the sample feature vector output by the second pyramid multi-scale module, and so on, until the sample feature vector output by the last pyramid multi-scale module is obtained, wherein the sample feature vector output by the last pyramid multi-scale module is the second sample feature vector;

[0031] Inputting the second sample feature vector into a generation network in a crowd density map generation model to be trained to obtain a crowd density map corresponding to the crowd sample image;

[0032] Based on the crowd density map obtained by the crowd density map generation model to be trained and the crowd sample density map corresponding to the crowd sample image in the training data set, a Euclidean loss function value is calculated;

[0033] Obtaining a joint loss function value based on the multi-column variance loss function value and the Euclidean loss function value;

[0034] Back-propagating the joint loss function value to the crowd density map generation model to be trained, and adjusting the parameters of the crowd density map generation model based on the joint loss function value;

[0035] Check whether the joint loss function value of the crowd density map generation model converges;

[0036] If the joint loss function value of the crowd density map generation model has not converged, a new crowd sample picture in the training data set is used as the crowd sample picture, and the step of inputting the crowd sample picture in the training data set into the backbone network in the crowd density map generation model to be trained is returned to obtain a first sample feature vector;

[0037] If the joint loss function value of the crowd density map generation model converges, the latest crowd density map generation model is used as the trained crowd density map generation model.

[0038] Optionally, the step of calculating multiple columns of variance loss function values ​​based on the first attention vector includes:

[0039] Substitute the first eigenvector corresponding to each column into the calculation formula of the multi-column variance loss function to obtain the multi-column variance loss function value, wherein the calculation formula of the multi-column variance loss function is:

[0040]

[0041] in:

[0042]

[0043] Among them, L M is the multi-column variance loss function value, represents the first attention vector of the jth column corresponding to the i-th message passing module in the pyramid scale network, represents the average of the first attention vectors of the columns except the jth column in the i-th message passing module, S represents the number of columns corresponding to the message passing module, K represents the number of message passing modules in the pyramid multi-scale network, ||·|| represents the modulus of the vector, ∈ is used to avoid division by zero, and N represents the number of input crowd sample images.

[0044] Optionally, the step of calculating the Euclidean loss function value based on the crowd density map obtained by the crowd density map generation model to be trained and the crowd sample density map corresponding to the crowd sample image in the training data set includes:

[0045] Substitute the crowd density map obtained by the crowd density map generation model to be trained and the crowd sample density map corresponding to the crowd sample image in the training data set into the calculation formula of the Euclidean loss function to obtain the Euclidean loss function value. The calculation formula of the Euclidean loss function is:

[0046]

[0047] Among them, L E is the value of the Euclidean loss function, θ represents the parameters of the crowd density map generation model to be trained, X n represents the nth input crowd sample picture, G(X n ; θ) represents the crowd density map obtained by the crowd density map generation model to be trained, Represents a population sample density map corresponding to the population sample image in the training data set.

[0048] Optionally, the step of obtaining a joint loss function value based on the multi-column variance loss function values ​​and the Euclidean loss function values ​​includes:

[0049] Substitute the multi-column variance loss function value and the Euclidean loss function value into the calculation formula of the joint loss function to obtain the joint loss function value, wherein the calculation formula of the joint loss function is:

[0050] L=L E +λL M

[0051] Among them, L is the value of the joint loss function, L M is the multi-column variance loss function value, L E is the Euclidean loss function value, and λ is the balance L E and L M The weight is a hyperparameter.

[0052] In a second aspect, the present invention further provides a crowd counting device in a complex scene, the crowd counting device in a complex scene comprising:

[0053] A first feature extraction module is used to input the crowd image to be detected into the backbone network of the trained crowd density map generation model to obtain a first feature vector;

[0054] A second feature extraction module is used to input the first feature vector into a pyramid multi-scale network in a trained crowd density map generation model to obtain a second feature vector, wherein the pyramid multi-scale network includes a preset number of pyramid multi-scale modules, the pyramid multi-scale modules are connected in series, each of the pyramid multi-scale modules includes a message passing module and an attention module, the message passing module includes a multi-column full convolution structure using a message passing mechanism, and the attention module includes a global pooling layer and a convolution layer using an attention mechanism;

[0055] A generating module, configured to input the second feature vector into a generating network in a trained crowd density map generating model to obtain a crowd density map corresponding to the crowd image to be detected;

[0056] The counting module is used to integrate and sum the target pixel values ​​of the area of ​​interest of the crowd density map to obtain the total number of people in the area of ​​interest.

[0057] Optionally, the second feature extraction module is used to:

[0058] Inputting the first feature vector into a first pyramid multi-scale module of a pyramid multi-scale network in a trained crowd density map generation model, and obtaining an attention vector based on an attention module in the first pyramid multi-scale module;

[0059] Based on the full convolution structure of each column of the message passing module in the first pyramid multi-scale module, an initial feature vector group is obtained, where the initial feature vector group includes initial feature vectors of a preset number of columns;

[0060] Repeat the steps of concatenating the initial feature vector generated by the full convolution structure of the current column in the initial feature vector group with the initial feature vector generated by the full convolution structure of the previous column, and inputting them into a convolution layer for fusion to obtain the output feature vector of the current column, until the output feature vectors of all columns are obtained;

[0061] Input the output feature vectors of all the columns into a convolutional layer, and fuse them to obtain a first fused feature vector;

[0062] Fusing the first fused feature vector with the attention vector to obtain a second fused feature vector, where the second fused feature vector is a feature vector output by the first pyramid multi-scale module;

[0063] The feature vector output by the first pyramid multi-scale module is input into the second pyramid multi-scale module to obtain a feature vector output by the second pyramid multi-scale module, and so on until a feature vector output by a last pyramid multi-scale module is obtained, wherein the feature vector output by the last pyramid multi-scale module is the second feature vector.

[0064] Optionally, the crowd counting device in complex scenes further includes a training module for:

[0065] Constructing a paired training data set, the training data set comprising a number of crowd sample images and a crowd sample density map corresponding to the crowd sample images;

[0066] Inputting the crowd sample pictures in the training data set into the backbone network in the crowd density map generation model to be trained to obtain a first sample feature vector;

[0067] Inputting the first sample feature vector into a first pyramid multi-scale module of a pyramid multi-scale network in a crowd density map generation model to be trained, and obtaining a sample attention vector based on an attention module in the first pyramid multi-scale module;

[0068] Based on the full convolution structure of each column of the message passing module in the first pyramid multi-scale module, an initial sample feature vector group is obtained, wherein the initial sample feature vector group includes initial sample feature vectors of a preset number of columns;

[0069] Repeat the steps of concatenating the initial feature sample vector generated by the full convolution structure of the current column in the initial sample feature vector group with the initial sample feature vector generated by the full convolution structure of the previous column, and inputting them into a convolution layer for fusion to obtain the sample output feature vector of the current column, until the sample output feature vectors of all columns are obtained;

[0070] Based on the sample output feature vectors of all the columns, obtaining a first attention vector corresponding to each column of each message passing module;

[0071] Based on the first attention vector corresponding to each column, calculate the variance loss function values ​​of multiple columns;

[0072] Inputting the sample output feature vectors of all the columns into a convolutional layer, and fusing them to obtain a first sample fused feature vector;

[0073] Fusing the first sample fusion feature vector with the sample attention vector to obtain a second sample fusion feature vector, where the second sample fusion feature vector is a sample feature vector output by the first pyramid multi-scale module;

[0074] Inputting the sample feature vector output by the first pyramid multi-scale module into the second pyramid multi-scale module to obtain the sample feature vector output by the second pyramid multi-scale module, and so on, until the sample feature vector output by the last pyramid multi-scale module is obtained, wherein the sample feature vector output by the last pyramid multi-scale module is the second sample feature vector;

[0075] Inputting the second sample feature vector into a generation network in a crowd density map generation model to be trained to obtain a crowd density map corresponding to the crowd sample image;

[0076] Based on the crowd density map obtained by the crowd density map generation model to be trained and the crowd sample density map corresponding to the crowd sample image in the training data set, a Euclidean loss function value is calculated;

[0077] Obtaining a joint loss function value based on the multi-column variance loss function value and the Euclidean loss function value;

[0078] Back-propagating the joint loss function value to the crowd density map generation model to be trained, and adjusting the parameters of the crowd density map generation model based on the joint loss function value;

[0079] Check whether the joint loss function value of the crowd density map generation model converges;

[0080] If the joint loss function value of the crowd density map generation model has not converged, a new crowd sample picture in the training data set is used as the crowd sample picture, and the step of inputting the crowd sample picture in the training data set into the backbone network in the crowd density map generation model to be trained is returned to obtain a first sample feature vector;

[0081] If the joint loss function value of the crowd density map generation model converges, the latest crowd density map generation model is used as the trained crowd density map generation model.

[0082] Optionally, the training module is used to:

[0083] Substitute the first eigenvector corresponding to each column into the calculation formula of the multi-column variance loss function to obtain the multi-column variance loss function value, wherein the calculation formula of the multi-column variance loss function is:

[0084]

[0085] in:

[0086]

[0087] Among them, L M is the multi-column variance loss function value, represents the first attention vector of the jth column corresponding to the i-th message passing module in the pyramid scale network, represents the average of the first attention vectors of the columns except the jth column in the i-th message passing module, S represents the number of columns corresponding to the message passing module, K represents the number of message passing modules in the pyramid multi-scale network, ||·|| represents the modulus of the vector, ∈ is used to avoid division by zero, and N represents the number of input crowd sample images.

[0088] Optionally, the training module is used to:

[0089] Substitute the crowd density map obtained by the crowd density map generation model to be trained and the crowd sample density map corresponding to the crowd sample image in the training data set into the calculation formula of the Euclidean loss function to obtain the Euclidean loss function value. The calculation formula of the Euclidean loss function is:

[0090]

[0091] Among them, L E is the value of the Euclidean loss function, θ represents the parameters of the crowd density map generation model to be trained, X n represents the nth input crowd sample picture, G(X n ; θ) represents the crowd density map obtained by the crowd density map generation model to be trained, Represents a population sample density map corresponding to the population sample image in the training data set.

[0092] Optionally, the training module is used to:

[0093] Substitute the multi-column variance loss function value and the Euclidean loss function value into the calculation formula of the joint loss function to obtain the joint loss function value, wherein the calculation formula of the joint loss function is:

[0094] L=L E +λL M

[0095] Among them, L is the value of the joint loss function, L M is the multi-column variance loss function value, L E is the Euclidean loss function value, and λ is the balance L E and L M The weight is a hyperparameter.

[0096] In a third aspect, the present invention also provides a crowd counting device for complex scenes, the crowd counting device for complex scenes comprising a processor, a memory, and a crowd counting program for complex scenes stored in the memory and executable by the processor, wherein when the crowd counting program for complex scenes is executed by the processor, the steps of the crowd counting method for complex scenes as described above are implemented.

[0097] In a fourth aspect, the present invention further provides a readable storage medium, on which a crowd counting program for complex scenes is stored, wherein when the crowd counting program for complex scenes is executed by a processor, the steps of the crowd counting method for complex scenes as described above are implemented.

[0098] The present invention obtains a crowd density map corresponding to a crowd picture through an improved crowd density map generation model, and then completes crowd counting based on the crowd density map, wherein a new multi-column structure, namely a pyramid multi-scale module, is adopted in the crowd density map generation model. Compared with the traditional multi-column structure in which each column is independent of each other, each column of the pyramid multi-scale module cooperates with each other, so that the number of scales corresponding to the pyramid multi-scale module is much larger than the number of columns, thereby realizing more efficient extraction of multi-scale high-level features. At the same time, the training of the pyramid multi-scale module is guided based on the multi-column variance loss, so that each column is prompted to learn different features, thereby improving the detection accuracy, solving the problem of feature similarity and scale limitation existing in the traditional multi-column structure, and further improving the accuracy of crowd counting and the generation quality of the crowd density map. BRIEF DESCRIPTION OF THE DRAWINGS

[0099] Figure 1A schematic diagram of the hardware structure of a crowd counting device in a complex scenario involved in an embodiment of the present invention;

[0100] Figure 2 It is a flow chart of an embodiment of a crowd counting method in a complex scene of the present invention;

[0101] Figure 3 The figure is a functional module diagram of an embodiment of a crowd counting device for complex scenes according to the present invention.

[0102] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0103] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.

[0104] In a first aspect, an embodiment of the present invention provides a crowd counting device in a complex scenario.

[0105] Reference Figure 1 , Figure 1 Schematic diagram of the hardware structure of a crowd counting device in a complex scenario involved in the embodiment of the present invention. In the embodiment of the present invention, the crowd counting device in a complex scenario may include a processor 1001 (e.g., a central processing unit, CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. Among them, the communication bus 1002 is used to realize the connection and communication between these components; the user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard); the network interface 1004 may optionally include a standard wired interface, a wireless interface (such as a wireless fidelity WIreless-FIdelity, WI-FI interface); the memory 1005 may be a high-speed random access memory (random access memory, RAM), or a stable memory (non-volatile memory), such as a disk storage, and the memory 1005 may optionally be a storage device independent of the aforementioned processor 1001. Those skilled in the art will understand that Figure 1 The hardware structure shown in the figure does not constitute a limitation of the present invention, and may include more or less components than those shown in the figure, or combine certain components, or arrange the components differently.

[0106] Continue to refer to Figure 1 , Figure 1The memory 1005 as a computer storage medium may include an operating system, a network communication module, a user interface module, and a crowd counting program in a complex scene. The processor 1001 may call the crowd counting program in a complex scene stored in the memory 1005, and execute the crowd counting method in a complex scene provided by the embodiment of the present invention.

[0107] In a second aspect, an embodiment of the present invention provides a method for counting people in a complex scenario.

[0108] Reference Figure 2 , Figure 2 The figure is a flow chart of an embodiment of a crowd counting method in a complex scene according to the present invention.

[0109] In an embodiment of a crowd counting method in a complex scene of the present invention, the crowd counting method in a complex scene includes:

[0110] Step S10, inputting the crowd picture to be detected into the backbone network in the trained crowd density map generation model to obtain a first feature vector;

[0111] In this embodiment, the crowd image to be detected is input into the backbone network in the trained crowd density map generation model, and low-level features such as texture and edge corresponding to the pedestrian position in the crowd image to be detected are extracted to obtain the first feature vector output by the backbone network. Considering the balance between computational cost and accuracy, the backbone network can be composed of the first 13 layers (Conv1-Conv4) of the VGG-16 network, including 10 convolutional layers and 3 maximum pooling layers.

[0112] Step S20, inputting the first feature vector into a pyramid multi-scale network in a trained crowd density map generation model to obtain a second feature vector, wherein the pyramid multi-scale network includes a preset number of pyramid multi-scale modules, the pyramid multi-scale modules are connected in series, each of the pyramid multi-scale modules includes a message passing module and an attention module, the message passing module includes a multi-column full convolution structure using a message passing mechanism, and the attention module includes a global pooling layer and a convolution layer using an attention mechanism;

[0113] In this embodiment, the first feature vector is input into the pyramid multi-scale network in the trained crowd density map generation model, and multi-scale high-level features are further extracted based on low-level features such as texture and edge corresponding to the position of pedestrians in the crowd picture to be detected extracted by the backbone network to obtain a second feature vector. Since the performance of different columns in the multi-column structure for extracting high-level features in the prior art is similar and has no obvious difference, the message passing mechanism and the attention mechanism are used in the pyramid multi-scale network to improve the multi-column structure in the pyramid multi-scale network. The improved pyramid multi-scale network can extract multi-scale high-level features more efficiently and expand the scope of scale extraction, and the crowd counting performance can also be improved based on the obtained second feature vector.

[0114] Specifically, the pyramid multi-scale network in the improved and trained crowd density map generation model includes a preset number of pyramid multi-scale modules, wherein each pyramid multi-scale module is connected in series, and the output of the previous pyramid multi-scale module is used as the input of the current pyramid multi-scale module. Each pyramid multi-scale module includes a message passing module and an attention module. The message passing module includes multiple columns of full convolution structures using a message passing mechanism, wherein the full convolution structure of each column includes convolution layers with different receptive field sizes, and the attention module includes a global pooling layer and a convolution layer using an attention mechanism.

[0115] Compared with the multi-column structures in the existing crowd counting methods, which work independently of each other, resulting in serious information redundancy between each column, the full convolution structure using the message passing mechanism works in collaboration between the columns through the message passing mechanism, and the number of corresponding scales in the multi-column full convolution structure is much larger than the number of columns. At the same time, the attention module using the attention mechanism can be used to provide global contextual attention guidance for the multi-scale high-level feature vector output by the message passing module. Therefore, the improved pyramid multi-scale network using the message passing mechanism and the attention mechanism after training can solve the technical problem that the crowd counting algorithm is limited by the feature similarity and limited scale of the multi-column model used in the prior art, resulting in the technical problem that the accuracy of crowd counting and the quality of density map generation cannot be further improved, thereby achieving the technical effect of more efficiently extracting high-level features at multiple scales.

[0116] Furthermore, in one embodiment, step S20 includes:

[0117] Inputting the first feature vector into a first pyramid multi-scale module of a pyramid multi-scale network in a trained crowd density map generation model, and obtaining an attention vector based on an attention module in the first pyramid multi-scale module;

[0118] Based on the full convolution structure of each column of the message passing module in the first pyramid multi-scale module, an initial feature vector group is obtained, where the initial feature vector group includes initial feature vectors of a preset number of columns;

[0119] Repeat the steps of concatenating the initial feature vector generated by the full convolution structure of the current column in the initial feature vector group with the initial feature vector generated by the full convolution structure of the previous column, and inputting them into a convolution layer for fusion to obtain the output feature vector of the current column, until the output feature vectors of all columns are obtained;

[0120] Input the output feature vectors of all the columns into a convolutional layer, and fuse them to obtain a first fused feature vector;

[0121] Fusing the first fused feature vector with the attention vector to obtain a second fused feature vector, where the second fused feature vector is a feature vector output by the first pyramid multi-scale module;

[0122] The feature vector output by the first pyramid multi-scale module is input into the second pyramid multi-scale module to obtain a feature vector output by the second pyramid multi-scale module, and so on until a feature vector output by a last pyramid multi-scale module is obtained, wherein the feature vector output by the last pyramid multi-scale module is the second feature vector.

[0123] In this embodiment, the step of obtaining a second feature vector based on the pyramid multi-scale network in the trained crowd density map generation model specifically includes: inputting the first feature vector obtained based on the backbone network in the trained crowd density map generation model into the first pyramid multi-scale module of the pyramid multi-scale network in the trained crowd density map generation model, and obtaining an attention vector based on the attention module in the first pyramid multi-scale module, which is used to provide global context attention guidance for the multi-scale high-level feature vector output by the message passing module.

[0124] Wherein, the message passing module in each pyramid multi-scale module includes a full convolution structure of multiple columns using a message passing mechanism, and the step of obtaining a multi-scale high-level feature vector based on the message passing module specifically includes: obtaining an initial feature vector group based on the full convolution structure of each column of the message passing module in the first pyramid multi-scale module, wherein the initial feature vector group includes initial feature vectors of a preset number of columns. Repeating the steps of splicing the initial feature vector generated by the full convolution structure of the current column in the initial feature vector group with the initial feature vector generated by the full convolution structure of the previous column, and inputting them into a convolution layer for fusion to obtain the output feature vector of the current column, until the output feature vectors of all columns are obtained. Wherein, the output feature vectors of all columns obtained are multi-scale high-level feature vectors obtained based on the message passing module. In the message passing module in the pyramid multi-scale module of the trained crowd density map generation model, the number of scales corresponding to the full convolution structure of multiple columns is much larger than the number of columns, and the feature distinction between the feature vectors of all columns generated based on the message passing module is higher than the feature distinction between the column vectors obtained by the existing multi-column structure.

[0125] The output feature vectors of all the columns are input into a convolution layer, and a first fused feature vector can be obtained by fusion. The first fused feature vector is fused with the attention vector obtained based on the attention module in the first pyramid multi-scale module to obtain a second fused feature vector, and the second fused feature vector is the feature vector output by the first pyramid multi-scale module. Among them, the pyramid multi-scale module includes a preset number of pyramid multi-scale networks, and each pyramid multi-scale module is connected in series, and the output of the previous pyramid multi-scale module is used as the input of the current pyramid multi-scale module. Therefore, after obtaining the feature vector output by the first pyramid multi-scale module, the feature vector output by the first pyramid multi-scale module is input into the second pyramid multi-scale module to obtain the feature vector output by the second pyramid multi-scale module, and so on, until the feature vector output by the last pyramid multi-scale module is obtained, and the feature vector output by the last pyramid multi-scale module is the second feature vector. Among them, the trained pyramid multi-scale network solves the problem of feature similarity and limited scale of feature vectors extracted by multi-column structures in the prior art, and has better performance in feature detection and extraction of different pedestrians in crowd pictures under complex scenes.

[0126] Step S30, inputting the second feature vector into a generation network in a trained crowd density map generation model to obtain a crowd density map corresponding to the crowd picture to be detected;

[0127] In this embodiment, the second feature vector obtained based on the pyramid multi-scale network in the trained crowd density map generation model is input into the generation network in the trained crowd density map generation model, and the generation network first completes the coarse-grained construction of the crowd density map, then completes its fine-grained construction, and finally outputs the crowd density map corresponding to the crowd image to be detected. Among them, the generation network in the trained crowd density map generation model is composed of several convolutional layers, the convolution kernel size of the last convolutional layer is 1×1, the convolution kernel size of other convolutional layers is 3×3, and the number of channels of the last layer is 1.

[0128] Step S40, integrating and summing the target pixel values ​​of the region of interest of the crowd density map to obtain the total number of people in the region of interest.

[0129] In this embodiment, the total number of people in the area of ​​interest may be obtained by integrating and summing the target pixel values ​​of the area of ​​interest of the crowd density map generated based on the crowd density map generation model.

[0130] Furthermore, in one embodiment, the step before step S10 includes:

[0131] Constructing a paired training data set, the training data set comprising a number of crowd sample images and a crowd sample density map corresponding to the crowd sample images;

[0132] Inputting the crowd sample pictures in the training data set into the backbone network in the crowd density map generation model to be trained to obtain a first sample feature vector;

[0133] Inputting the first sample feature vector into a first pyramid multi-scale module of a pyramid multi-scale network in a crowd density map generation model to be trained, and obtaining a sample attention vector based on an attention module in the first pyramid multi-scale module;

[0134] Based on the full convolution structure of each column of the message passing module in the first pyramid multi-scale module, an initial sample feature vector group is obtained, wherein the initial sample feature vector group includes initial sample feature vectors of a preset number of columns;

[0135] Repeat the steps of concatenating the initial feature sample vector generated by the full convolution structure of the current column in the initial sample feature vector group with the initial sample feature vector generated by the full convolution structure of the previous column, and inputting them into a convolution layer for fusion to obtain the sample output feature vector of the current column, until the sample output feature vectors of all columns are obtained;

[0136] Based on the sample output feature vectors of all the columns, obtaining a first attention vector corresponding to each column of each message passing module;

[0137] Based on the first attention vector corresponding to each column, calculate the variance loss function values ​​of multiple columns;

[0138] Inputting the sample output feature vectors of all the columns into a convolutional layer, and fusing them to obtain a first sample fused feature vector;

[0139] Fusing the first sample fusion feature vector with the sample attention vector to obtain a second sample fusion feature vector, where the second sample fusion feature vector is a sample feature vector output by the first pyramid multi-scale module;

[0140] Inputting the sample feature vector output by the first pyramid multi-scale module into the second pyramid multi-scale module to obtain the sample feature vector output by the second pyramid multi-scale module, and so on, until the sample feature vector output by the last pyramid multi-scale module is obtained, wherein the sample feature vector output by the last pyramid multi-scale module is the second sample feature vector;

[0141] Inputting the second sample feature vector into a generation network in a crowd density map generation model to be trained to obtain a crowd density map corresponding to the crowd sample image;

[0142] Based on the crowd density map obtained by the crowd density map generation model to be trained and the crowd sample density map corresponding to the crowd sample image in the training data set, a Euclidean loss function value is calculated;

[0143] Obtaining a joint loss function value based on the multi-column variance loss function value and the Euclidean loss function value;

[0144] Back-propagating the joint loss function value to the crowd density map generation model to be trained, and adjusting the parameters of the crowd density map generation model based on the joint loss function value;

[0145] Check whether the joint loss function value of the crowd density map generation model converges;

[0146] If the joint loss function value of the crowd density map generation model has not converged, a new crowd sample picture in the training data set is used as the crowd sample picture, and the step of inputting the crowd sample picture in the training data set into the backbone network in the crowd density map generation model to be trained is returned to obtain a first sample feature vector;

[0147] If the joint loss function value of the crowd density map generation model converges, the latest crowd density map generation model is used as the trained crowd density map generation model.

[0148] In this embodiment, a paired training data set is constructed, and the training data set includes a number of crowd sample images and a crowd sample density map corresponding to the crowd sample images. The step of constructing a paired training data set includes: collecting a number of high-definition real crowd sample images, and using point annotation to mark the center of the pedestrian's head in the collected high-definition real crowd sample images. Based on the marked center coordinates, a two-dimensional Gaussian kernel convolution is used to construct a real crowd sample density map corresponding to the crowd sample image, wherein, according to the different crowd densities in the crowd sample image, the crowd sample image can be divided into two categories: a high-density group and a low-density group. The high-density group uses a geometrically adaptive-sized Gaussian kernel to generate a corresponding high-quality density map, and the low-density group uses a fixed-size Gaussian kernel to generate a corresponding high-quality density map. Specifically, based on the marked center coordinates, the step of constructing a real crowd sample density map corresponding to the crowd sample image using a two-dimensional Gaussian kernel convolution includes: convolving the pedestrian's head pixel x i It is expressed as the incremental function δ(xx i ), so the crowd density map F(x) corresponding to the picture with N head tags can be expressed as: Among them, G σ (x) is a two-dimensional Gaussian kernel convolution, and σ is its width parameter.

[0149] After the paired training data set is constructed, the crowd sample images in the training data set are input into the backbone network in the crowd density map generation model to be trained to obtain the first sample feature vector. The first sample feature vector is input into the first pyramid multi-scale module of the pyramid multi-scale network in the crowd density map generation model to be trained, and a sample attention vector is obtained based on the attention module in the first pyramid multi-scale module. Based on the full convolution structure of each column of the message passing module in the first pyramid multi-scale module, an initial sample feature vector group is obtained, and the initial sample feature vector group contains a pre-column number of initial sample feature vectors. Repeat the steps of splicing the initial feature sample vector generated by the full convolution structure of the current column in the initial sample feature vector group with the initial sample feature vector generated by the full convolution structure of the previous column, and inputting them into a convolution layer for fusion to obtain the sample output feature vector of the current column, until the sample output feature vectors of all columns are obtained.

[0150] Based on the sample output feature vectors of all the columns, the first attention vector corresponding to each column of each message passing module is obtained. Specifically, the first attention vector corresponding to the jth column of the ith message passing module in the pyramid scale network is set to For the sample output feature vector of the jth column corresponding to the i-th message passing module in the pyramid scale network First, apply the average pooling operation along the channel axis to obtain the corresponding attention map Then flatten the attention map The final first attention vector can be obtained When the first attention vector corresponding to each column of each message passing module is obtained, the multi-column variance loss can be used to measure the similarity between these first attention vectors, so that each column tries to learn different features. That is, based on the first attention vector corresponding to each column, the multi-column variance loss function value is calculated.

[0151] The obtained sample output feature vectors of all columns are input into a convolution layer, and the first sample fusion feature vector is obtained by fusion. The obtained first sample fusion feature vector is fused with the obtained sample attention vector to obtain a second sample fusion feature vector, which is the sample feature vector output by the first pyramid multi-scale module. The obtained sample feature vector output by the first pyramid multi-scale module is input into the second pyramid multi-scale module to obtain the sample feature vector output by the second pyramid multi-scale module, and so on, until the sample feature vector output by the last pyramid multi-scale module is obtained, and the sample feature vector output by the last pyramid multi-scale module is the second sample feature vector.

[0152] The second sample feature vector is input into a generation network in a crowd density map generation model to be trained to obtain a crowd density map corresponding to the crowd sample image. Based on the crowd density map obtained by the crowd density map generation model to be trained and the crowd sample density map corresponding to the crowd sample image in the training data set, a Euclidean loss function value is calculated.

[0153] Based on the multi-column variance loss function value and the Euclidean loss function value, a joint loss function value is obtained. The obtained joint loss function value is back-propagated to the crowd density map generation model to be trained, and the parameters of the crowd density map generation model are adjusted based on the joint loss function value. And at each new joint loss function value, whether the joint loss function value of the crowd density map generation model converges is detected.

[0154] If the joint loss function value of the crowd density map generation model to be trained has not converged, a new crowd sample picture in the training data set is used as the crowd sample picture, and the step of inputting the crowd sample picture in the training data set into the backbone network of the crowd density map generation model to be trained is returned to obtain the first sample feature vector, and retraining is performed. If the joint loss function value of the crowd density map generation model to be trained converges, the training ends, and the latest crowd density map generation model is used as the trained crowd density map generation model.

[0155] After the training is completed, the model performance of the crowd counting method can be evaluated based on the test set using two indicators: MAE and MSE. The MAE evaluation indicator is: The MSE evaluation index is: Among them, MAE represents the accuracy of crowd estimation, while MSE represents the robustness of crowd estimation; N represents the number of test images, C i represents the predicted crowd count, Represents the real crowd count. Based on the evaluation of MAE and MSE, it can be judged that the accuracy and robustness of crowd estimation by the crowd counting method are improved.

[0156] Furthermore, in one embodiment, the step of calculating multiple columns of variance loss function values ​​based on the first attention vector includes:

[0157] Substitute the first attention vector corresponding to each column into the calculation formula of the multi-column variance loss function to obtain the multi-column variance loss function value, wherein the calculation formula of the multi-column variance loss function is:

[0158]

[0159] in:

[0160]

[0161] Among them, L M is the multi-column variance loss function value, represents the first attention vector of the jth column corresponding to the i-th message passing module in the pyramid scale network, represents the average of the first attention vectors of the columns except the jth column in the i-th message passing module, S represents the number of columns corresponding to the message passing module, K represents the number of message passing modules in the pyramid multi-scale network, ||·|| represents the modulus of the vector, ∈ is used to avoid division by zero, and N represents the number of input crowd sample images.

[0162] In this embodiment, the multi-column variance loss is implemented based on cosine similarity. Cosine similarity is a measure that quantifies the similarity between two or more vectors. It is measured by the cosine of the angle between the two vectors and determines how close the pointing directions of the two vectors are. The calculation formula for defining the multi-column variance loss function is: Among them, L M is the multi-column variance loss function value, Represents the first attention vector of the jth column corresponding to the i-th message passing module in the pyramid scale network. represents the average of the first attention vectors of the columns except the jth column in the i-th message passing module, where S represents the number of columns corresponding to the message passing module, K represents the number of message passing modules in the pyramid multi-scale network, ||·|| represents the modulus of the vector, ∈ is used to avoid division by zero, and N represents the number of input crowd sample images. The value range of the multi-column variance loss is [0,1]. The larger the multi-column variance loss, the higher the feature similarity between each column.

[0163] Therefore, based on the first attention vector, the step of calculating the multi-column variance loss function value specifically includes: substituting the first attention vector corresponding to each column into the calculation formula of the multi-column variance loss function to obtain the multi-column variance loss function value.

[0164] Furthermore, in one embodiment, the step of calculating the Euclidean loss function value based on the crowd density map obtained by the crowd density map generation model to be trained and the crowd sample density map corresponding to the crowd sample image in the training data set comprises:

[0165] Substitute the crowd density map obtained by the crowd density map generation model to be trained and the crowd sample density map corresponding to the crowd sample image in the training data set into the calculation formula of the Euclidean loss function to obtain the Euclidean loss function value. The calculation formula of the Euclidean loss function is:

[0166]

[0167] Among them, L E is the value of the Euclidean loss function, θ represents the parameters of the crowd density map generation model to be trained, X n represents the nth input crowd sample picture, G(X n ; θ) represents the crowd density map obtained by the crowd density map generation model to be trained, Represents a population sample density map corresponding to the population sample image in the training data set.

[0168] In this embodiment, the Euclidean loss is used to measure the pixel-level difference between the predicted density map and the true density map, guiding the model to generate a predicted density map that is indistinguishable from the true density map. The calculation formula for defining the Euclidean loss function is: Among them, L E is the value of the Euclidean loss function, θ represents the parameters of the crowd density map generation model to be trained, X n represents the nth input crowd sample picture, G(X n ; θ) represents the crowd density map obtained by the crowd density map generation model to be trained, Represents a population sample density map corresponding to the population sample image in the training data set.

[0169] The crowd density map obtained by the crowd density map generation model to be trained and the crowd sample density map corresponding to the crowd sample image in the training data set are substituted into the calculation formula of the Euclidean loss function to obtain the Euclidean loss function value.

[0170] Furthermore, in one embodiment, the step of obtaining a joint loss function value based on the multi-column variance loss function value and the Euclidean loss function value includes:

[0171] Substitute the multi-column variance loss function value and the Euclidean loss function value into the calculation formula of the joint loss function to obtain the joint loss function value, wherein the calculation formula of the joint loss function is:

[0172] L=L E +λL M

[0173] Among them, L is the value of the joint loss function, L M is the multi-column variance loss function value, L E is the Euclidean loss function value, and λ is a hyperparameter used to balance L E and L M The weight of .

[0174] In this embodiment, the goal is to reduce the joint loss function in the crowd density map generation model to be trained, and the back propagation algorithm is used to input the paired real crowd sample images and high-quality crowd sample density maps in the training data set into the model for training. The calculation formula for the joint loss function is defined as: L = L E +λL M . Among them, L is the value of the joint loss function, L M is the multi-column variance loss function value, L E is the value of the Euclidean loss function, λ is a hyperparameter, and is not required to be trained by the crowd density map generation model to be trained. It is used to balance L E and L M The step of obtaining a joint loss function value based on the multi-column variance loss function value and the Euclidean loss function value includes: substituting the multi-column variance loss function value and the Euclidean loss function value into a calculation formula of the joint loss function to obtain a joint loss function value.

[0175] In this embodiment, the crowd density map corresponding to the crowd picture is obtained by the improved crowd density map generation model, and then the crowd counting is completed based on the crowd density map, wherein the new multi-column structure, namely the pyramid multi-scale module, is adopted in the crowd density map generation model. Compared with the traditional multi-column structure in which each column is independent of each other, each column of the pyramid multi-scale module cooperates with each other, so that the number of scales corresponding to the pyramid multi-scale module is much larger than the number of columns, thereby realizing more efficient extraction of multi-scale advanced pedestrian features. At the same time, the training of the pyramid multi-scale module is guided based on the multi-column variance loss, so that each column is prompted to learn different pedestrian features, thereby improving the detection accuracy, solving the problem of feature similarity and scale limitation in the traditional multi-column structure, and further improving the accuracy of crowd counting and the generation quality of the crowd density map. Among them, the pyramid multi-scale module and the multi-column variance loss proposed by the present invention can be easily directly applied to other existing multi-column structures as plug-ins, significantly improving the performance of other multi-column structures. And the present invention can not only estimate the number of people more accurately for people in a variety of complex scenes, but also can be migrated to other target counting fields, such as cell microscopy, vehicle counting, etc.

[0176] In a third aspect, an embodiment of the present invention further provides a crowd counting device in a complex scenario.

[0177] Reference Figure 3 , a schematic diagram of functional modules of an embodiment of a crowd counting device in a complex scene.

[0178] A first feature extraction module is used to input the crowd image to be detected into the backbone network of the trained crowd density map generation model to obtain a first feature vector;

[0179] A second feature extraction module is used to input the first feature vector into a pyramid multi-scale network in a trained crowd density map generation model to obtain a second feature vector, wherein the pyramid multi-scale network includes a preset number of pyramid multi-scale modules, the pyramid multi-scale modules are connected in series, each of the pyramid multi-scale modules includes a message passing module and an attention module, the message passing module includes a multi-column full convolution structure using a message passing mechanism, and the attention module includes a global pooling layer and a convolution layer using an attention mechanism;

[0180] A generating module, configured to input the second feature vector into a generating network in a trained crowd density map generating model to obtain a crowd density map corresponding to the crowd image to be detected;

[0181] The counting module is used to integrate and sum the target pixel values ​​of the area of ​​interest of the crowd density map to obtain the total number of people in the area of ​​interest.

[0182] Furthermore, in one embodiment, the second feature extraction module is used to:

[0183] Inputting the first feature vector into a first pyramid multi-scale module of a pyramid multi-scale network in a trained crowd density map generation model, and obtaining an attention vector based on an attention module in the first pyramid multi-scale module;

[0184] Based on the full convolution structure of each column of the message passing module in the first pyramid multi-scale module, an initial feature vector group is obtained, where the initial feature vector group includes initial feature vectors of a preset number of columns;

[0185] Repeat the steps of concatenating the initial feature vector generated by the full convolution structure of the current column in the initial feature vector group with the initial feature vector generated by the full convolution structure of the previous column, and inputting them into a convolution layer for fusion to obtain the output feature vector of the current column, until the output feature vectors of all columns are obtained;

[0186] Input the output feature vectors of all the columns into a convolutional layer, and fuse them to obtain a first fused feature vector;

[0187] Fusing the first fused feature vector with the attention vector to obtain a second fused feature vector, where the second fused feature vector is a feature vector output by the first pyramid multi-scale module;

[0188] The feature vector output by the first pyramid multi-scale module is input into the second pyramid multi-scale module to obtain a feature vector output by the second pyramid multi-scale module, and so on until a feature vector output by a last pyramid multi-scale module is obtained, wherein the feature vector output by the last pyramid multi-scale module is the second feature vector.

[0189] Furthermore, in one embodiment, the crowd counting device in a complex scene further includes a training module for:

[0190] Constructing a paired training data set, the training data set comprising a number of crowd sample images and a crowd sample density map corresponding to the crowd sample images;

[0191] Inputting the crowd sample pictures in the training data set into the backbone network in the crowd density map generation model to be trained to obtain a first sample feature vector;

[0192] Inputting the first sample feature vector into a first pyramid multi-scale module of a pyramid multi-scale network in a crowd density map generation model to be trained, and obtaining a sample attention vector based on an attention module in the first pyramid multi-scale module;

[0193] Based on the full convolution structure of each column of the message passing module in the first pyramid multi-scale module, an initial sample feature vector group is obtained, wherein the initial sample feature vector group includes initial sample feature vectors of a preset number of columns;

[0194] Repeat the steps of concatenating the initial feature sample vector generated by the full convolution structure of the current column in the initial sample feature vector group with the initial sample feature vector generated by the full convolution structure of the previous column, and inputting them into a convolution layer for fusion to obtain the sample output feature vector of the current column, until the sample output feature vectors of all columns are obtained;

[0195] Based on the sample output feature vectors of all the columns, obtaining a first attention vector corresponding to each column of each message passing module;

[0196] Based on the first attention vector corresponding to each column, calculate the variance loss function values ​​of multiple columns;

[0197] Inputting the sample output feature vectors of all the columns into a convolutional layer, and fusing them to obtain a first sample fused feature vector;

[0198] Fusing the first sample fusion feature vector with the sample attention vector to obtain a second sample fusion feature vector, where the second sample fusion feature vector is a sample feature vector output by the first pyramid multi-scale module;

[0199] Inputting the sample feature vector output by the first pyramid multi-scale module into the second pyramid multi-scale module to obtain the sample feature vector output by the second pyramid multi-scale module, and so on, until the sample feature vector output by the last pyramid multi-scale module is obtained, wherein the sample feature vector output by the last pyramid multi-scale module is the second sample feature vector;

[0200] Inputting the second sample feature vector into a generation network in a crowd density map generation model to be trained to obtain a crowd density map corresponding to the crowd sample image;

[0201] Based on the crowd density map obtained by the crowd density map generation model to be trained and the crowd sample density map corresponding to the crowd sample image in the training data set, a Euclidean loss function value is calculated;

[0202] Obtaining a joint loss function value based on the multi-column variance loss function value and the Euclidean loss function value;

[0203] Back-propagating the joint loss function value to the crowd density map generation model to be trained, and adjusting the parameters of the crowd density map generation model based on the joint loss function value;

[0204] Check whether the joint loss function value of the crowd density map generation model converges;

[0205] If the joint loss function value of the crowd density map generation model has not converged, a new crowd sample picture in the training data set is used as the crowd sample picture, and the step of inputting the crowd sample picture in the training data set into the backbone network in the crowd density map generation model to be trained is returned to obtain a first sample feature vector;

[0206] If the joint loss function value of the crowd density map generation model converges, the latest crowd density map generation model is used as the trained crowd density map generation model.

[0207] Furthermore, in one embodiment, the training module is used to:

[0208] Substitute the first eigenvector corresponding to each column into the calculation formula of the multi-column variance loss function to obtain the multi-column variance loss function value, wherein the calculation formula of the multi-column variance loss function is:

[0209]

[0210] in:

[0211]

[0212] Among them, L M is the multi-column variance loss function value, represents the first attention vector of the jth column corresponding to the i-th message passing module in the pyramid scale network, represents the average of the first attention vectors of the columns except the jth column in the i-th message passing module, S represents the number of columns corresponding to the message passing module, K represents the number of message passing modules in the pyramid multi-scale network, ||·|| represents the modulus of the vector, ∈ is used to avoid division by zero, and N represents the number of input crowd sample images.

[0213] Furthermore, in one embodiment, the training module is used to:

[0214] Substitute the crowd density map obtained by the crowd density map generation model to be trained and the crowd sample density map corresponding to the crowd sample image in the training data set into the calculation formula of the Euclidean loss function to obtain the Euclidean loss function value. The calculation formula of the Euclidean loss function is:

[0215]

[0216] Among them, L E is the value of the Euclidean loss function, θ represents the parameters of the crowd density map generation model to be trained, X nrepresents the nth input crowd sample picture, G(X n ; θ) represents the crowd density map obtained by the crowd density map generation model to be trained, Represents a population sample density map corresponding to the population sample image in the training data set.

[0217] Furthermore, in one embodiment, the training module is used to:

[0218] Substitute the multi-column variance loss function and the Euclidean loss function into the calculation formula of the joint loss function to obtain the value of the joint loss function, wherein the calculation formula of the joint loss function is:

[0219] L=L E +λL M

[0220] Among them, L is the value of the joint loss function, L M is the multi-column variance loss function value, L E is the Euclidean loss function value, and λ is the balance L E and L M The weight is a hyperparameter.

[0221] Among them, the functional implementation of each module in the above-mentioned crowd counting device under complex scenes corresponds to each step in the above-mentioned crowd counting method embodiment under complex scenes, and its functions and implementation processes are no longer described one by one here.

[0222] In a fourth aspect, an embodiment of the present invention further provides a readable storage medium.

[0223] The readable storage medium of the present invention stores a crowd counting program in a complex scene, wherein when the crowd counting program in a complex scene is executed by a processor, the steps of the crowd counting method in a complex scene as described above are implemented.

[0224] Among them, the method implemented when the crowd counting program in a complex scene is executed can refer to the various embodiments of the crowd counting method in a complex scene of the present invention, and will not be repeated here.

[0225] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.

[0226] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.

[0227] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes a number of instructions for a terminal device to execute the methods described in each embodiment of the present invention.

[0228] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.

Claims

1. A crowd counting method in complex scenes, characterized in that: The crowd counting method in the complex scene includes: Input the crowd image to be detected into the backbone network of the trained crowd density map generation model to obtain the first feature vector; Inputting the first feature vector into a pyramid multi-scale network in a trained crowd density map generation model to obtain a second feature vector, wherein the pyramid multi-scale network includes a preset number of pyramid multi-scale modules, the pyramid multi-scale modules are connected in series, each of the pyramid multi-scale modules includes a message passing module and an attention module, the message passing module includes a multi-column full convolution structure using a message passing mechanism, and the attention module includes a global pooling layer and a convolution layer using an attention mechanism; Inputting the second feature vector into a generation network in a trained crowd density map generation model to obtain a crowd density map corresponding to the crowd image to be detected; The target pixel values ​​of the region of interest of the crowd density map are integrated and summed to obtain the total number of people in the region of interest.

2. The crowd counting method in complex scenes as claimed in claim 1, characterized in that: The step of inputting the first feature vector into the pyramid multi-scale network in the trained crowd density map generation model to obtain the second feature vector comprises: Inputting the first feature vector into a first pyramid multi-scale module of a pyramid multi-scale network in a trained crowd density map generation model, and obtaining an attention vector based on an attention module in the first pyramid multi-scale module; Based on the full convolution structure of each column of the message passing module in the first pyramid multi-scale module, an initial feature vector group is obtained, where the initial feature vector group includes initial feature vectors of a preset number of columns; Repeat the steps of concatenating the initial feature vector generated by the full convolution structure of the current column in the initial feature vector group with the initial feature vector generated by the full convolution structure of the previous column, and inputting them into a convolution layer for fusion to obtain the output feature vector of the current column, until the output feature vectors of all columns are obtained; Input the output feature vectors of all the columns into a convolutional layer, and fuse them to obtain a first fused feature vector; Fusing the first fused feature vector with the attention vector to obtain a second fused feature vector, where the second fused feature vector is a feature vector output by the first pyramid multi-scale module; The feature vector output by the first pyramid multi-scale module is input into the second pyramid multi-scale module to obtain a feature vector output by the second pyramid multi-scale module, and so on until a feature vector output by a last pyramid multi-scale module is obtained, wherein the feature vector output by the last pyramid multi-scale module is the second feature vector.

3. The crowd counting method in complex scenes as claimed in claim 1, characterized in that: The step of inputting the crowd picture into the backbone network of the trained crowd density map generation model to obtain the first feature vector includes: Constructing a paired training data set, the training data set comprising a number of crowd sample images and a crowd sample density map corresponding to the crowd sample images; Inputting the crowd sample pictures in the training data set into the backbone network in the crowd density map generation model to be trained to obtain a first sample feature vector; Inputting the first sample feature vector into a first pyramid multi-scale module of a pyramid multi-scale network in a crowd density map generation model to be trained, and obtaining a sample attention vector based on an attention module in the first pyramid multi-scale module; Based on the full convolution structure of each column of the message passing module in the first pyramid multi-scale module, an initial sample feature vector group is obtained, wherein the initial sample feature vector group includes initial sample feature vectors of a preset number of columns; Repeat the steps of concatenating the initial feature sample vector generated by the full convolution structure of the current column in the initial sample feature vector group with the initial sample feature vector generated by the full convolution structure of the previous column, and inputting them into a convolution layer for fusion to obtain the sample output feature vector of the current column, until the sample output feature vectors of all columns are obtained; Based on the sample output feature vectors of all the columns, obtaining a first attention vector corresponding to each column of each message passing module; Based on the first attention vector corresponding to each column, calculate the variance loss function values ​​of multiple columns; Inputting the sample output feature vectors of all the columns into a convolutional layer, and fusing them to obtain a first sample fused feature vector; Fusing the first sample fusion feature vector with the sample attention vector to obtain a second sample fusion feature vector, where the second sample fusion feature vector is a sample feature vector output by the first pyramid multi-scale module; Inputting the sample feature vector output by the first pyramid multi-scale module into the second pyramid multi-scale module to obtain the sample feature vector output by the second pyramid multi-scale module, and so on, until the sample feature vector output by the last pyramid multi-scale module is obtained, wherein the sample feature vector output by the last pyramid multi-scale module is the second sample feature vector; Inputting the second sample feature vector into a generation network in a crowd density map generation model to be trained to obtain a crowd density map corresponding to the crowd sample image; Based on the crowd density map obtained by the crowd density map generation model to be trained and the crowd sample density map corresponding to the crowd sample image in the training data set, a Euclidean loss function value is calculated; Obtaining a joint loss function value based on the multi-column variance loss function value and the Euclidean loss function value; Back-propagating the joint loss function value to the crowd density map generation model to be trained, and adjusting the parameters of the crowd density map generation model based on the joint loss function value; Check whether the joint loss function value of the crowd density map generation model converges; If the joint loss function value of the crowd density map generation model has not converged, a new crowd sample picture in the training data set is used as the crowd sample picture, and the step of inputting the crowd sample picture in the training data set into the backbone network in the crowd density map generation model to be trained is returned to obtain a first sample feature vector; If the joint loss function value of the crowd density map generation model converges, the latest crowd density map generation model is used as the trained crowd density map generation model.

4. The crowd counting method in complex scenes as claimed in claim 3, characterized in that: The step of calculating multiple columns of variance loss function values ​​based on the first attention vector includes: Substitute the first eigenvector corresponding to each column into the calculation formula of the multi-column variance loss function to obtain the multi-column variance loss function value, wherein the calculation formula of the multi-column variance loss function is: in: Among them, L M is the multi-column variance loss function value, represents the first attention vector of the jth column corresponding to the i-th message passing module in the pyramid scale network, represents the average of the first attention vectors of the columns except the jth column in the i-th message passing module, S represents the number of columns corresponding to the message passing module, K represents the number of message passing modules in the pyramid multi-scale network, ||·|| represents the modulus of the vector, ∈ is used to avoid division by zero, and N represents the number of input crowd sample images.

5. The crowd counting method in complex scenes as claimed in claim 3, characterized in that: The step of calculating the Euclidean loss function value based on the crowd density map obtained by the crowd density map generation model to be trained and the crowd sample density map corresponding to the crowd sample image in the training data set comprises: Substitute the crowd density map obtained by the crowd density map generation model to be trained and the crowd sample density map corresponding to the crowd sample image in the training data set into the calculation formula of the Euclidean loss function to obtain the Euclidean loss function value. The calculation formula of the Euclidean loss function is: Among them, L E is the value of the Euclidean loss function, θ represents the parameters of the crowd density map generation model to be trained, X n represents the nth input crowd sample picture, G(X n ; θ) represents the crowd density map obtained by the crowd density map generation model to be trained, Represents a population sample density map corresponding to the population sample image in the training data set.

6. The crowd counting method in complex scenes as claimed in claim 3, characterized in that: The step of obtaining a joint loss function value based on the multi-column variance loss function value and the Euclidean loss function value comprises: Substitute the multi-column variance loss function value and the Euclidean loss function value into the calculation formula of the joint loss function to obtain the joint loss function value, wherein the calculation formula of the joint loss function is: L=L E +λL M Among them, L is the value of the joint loss function, L M is the multi-column variance loss function value, L E is the Euclidean loss function value, and λ is the balance L E and L M The weight is a hyperparameter.

7. A crowd counting device in complex scenes, characterized in that: The crowd counting device in the complex scene includes: A first feature extraction module is used to input the crowd image to be detected into the backbone network of the trained crowd density map generation model to obtain a first feature vector; A second feature extraction module is used to input the first feature vector into a pyramid multi-scale network in a trained crowd density map generation model to obtain a second feature vector, wherein the pyramid multi-scale network includes a preset number of pyramid multi-scale modules, the pyramid multi-scale modules are connected in series, each of the pyramid multi-scale modules includes a message passing module and an attention module, the message passing module includes a multi-column full convolution structure using a message passing mechanism, and the attention module includes a global pooling layer and a convolution layer using an attention mechanism; A generating module, configured to input the second feature vector into a generating network in a trained crowd density map generating model to obtain a crowd density map corresponding to the crowd image to be detected; The counting module is used to integrate and sum the target pixel values ​​of the area of ​​interest of the crowd density map to obtain the total number of people in the area of ​​interest.

8. The crowd counting device in complex scenes as claimed in claim 7, characterized in that: The second feature extraction module is used to: Inputting the first feature vector into a first pyramid multi-scale module of a pyramid multi-scale network in a trained crowd density map generation model, and obtaining an attention vector based on an attention module in the first pyramid multi-scale module; Based on the full convolution structure of each column of the message passing module in the first pyramid multi-scale module, an initial feature vector group is obtained, where the initial feature vector group includes initial feature vectors of a preset number of columns; Repeat the steps of concatenating the initial feature vector generated by the full convolution structure of the current column in the initial feature vector group with the initial feature vector generated by the full convolution structure of the previous column, and inputting them into a convolution layer for fusion to obtain the output feature vector of the current column, until the output feature vectors of all columns are obtained; Input the output feature vectors of all the columns into a convolutional layer, and fuse them to obtain a first fused feature vector; Fusing the first fused feature vector with the attention vector to obtain a second fused feature vector, where the second fused feature vector is a feature vector output by the first pyramid multi-scale module; The feature vector output by the first pyramid multi-scale module is input into the second pyramid multi-scale module to obtain a feature vector output by the second pyramid multi-scale module, and so on until a feature vector output by a last pyramid multi-scale module is obtained, wherein the feature vector output by the last pyramid multi-scale module is the second feature vector.

9. A crowd counting device in complex scenes, characterized in that: The crowd counting device for complex scenes includes a processor, a memory, and a crowd counting program for complex scenes stored in the memory and executable by the processor, wherein when the crowd counting program for complex scenes is executed by the processor, the steps of the crowd counting method for complex scenes according to any one of claims 1 to 6 are implemented.

10. A readable storage medium, characterized in that: The readable storage medium stores a crowd counting program for complex scenes, wherein when the crowd counting program for complex scenes is executed by a processor, the steps of the crowd counting method for complex scenes according to any one of claims 1 to 6 are implemented.