A method for detecting and counting dense crowd distribution in videos

Through the deep neural network of multi-scale feature fusion and attention mechanism combined with the grid clustering method, the accuracy problem of crowd counting in scenes with occlusion and complex backgrounds is solved, and high-precision detection and counting of dense crowd distribution is achieved, and the crowd display is Distribution.

CN114005085BActive Publication Date: 2024-09-27WUHAN UNIV
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202111259984.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-10-28
Publication Date
2024-09-27
Estimated Expiration
2041-10-28

AI Technical Summary

Technical Problem

Existing crowd counting methods perform poorly in scenes with severe occlusion and complex backgrounds, are difficult to accurately detect dense crowd distribution, and ignore spatial information.

Method used

A deep neural network using multi-scale feature fusion and attention mechanism is used to predict crowd density through crowd density maps and attention maps in video images, and is combined with the grid hierarchical density spatial clustering method to identify groups and generate high-quality density maps and Group information.

Benefits of technology

It effectively eliminates the influence of camera perspective distortion, improves counting accuracy and stability, suppresses background noise, intuitively displays crowd distribution, and enhances counting accuracy and density map quality.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114005085B
    Figure CN114005085B
Patent Text Reader

Abstract

The present invention proposes a method for detecting and counting dense crowd distribution in a video. First, a large number of videos containing crowds of different densities are obtained to construct a data set; then a deep neural network with multi-scale feature fusion and attention mechanism is constructed, the training set is input into the network, the corresponding crowd density map and the prediction result of the attention map are output, and the loss function model is constructed in combination with the real density map and the attention map for training to generate an optimized network; the density map of the crowd video image is obtained by predicting the optimized deep neural network with multi-scale feature fusion and attention mechanism, and the estimated density map is further clustered by a grid-based hierarchical density space clustering method to identify groups, and the number of people and location information of the group are quickly obtained. The present invention can solve the problems of camera perspective distortion, scale change and background noise, and improve the counting accuracy and stability; at the same time, the crowd is divided into groups, and the distribution of the crowd can be intuitively displayed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to a crowd detection method in an intelligent video surveillance neighborhood, and in particular to a dense crowd distribution detection and counting method in a video. Background Art

[0002] With the increasing demand for security in public safety, traffic scenarios and other fields, intelligent video surveillance has gradually replaced traditional video surveillance. Crowd distribution detection and counting is a research hotspot in the field of intelligent video surveillance, which has important social significance and market application prospects. For example, in public places where crowds are likely to gather, crowd information can be used to warn of safety issues such as trampling, and crowd distribution information can help to reasonably allocate human and material resources, thereby reducing casualties and even avoiding accidents; for urban public transportation systems, the number of trains can be flexibly increased or decreased according to the number of passengers, and reasonable vehicle schedules can be formulated, which can avoid crowded platforms and long waiting times while ensuring vehicle utilization; for large shopping malls, the number, type and location of stores can be adjusted according to the distribution of passenger flow in different stores, and better marketing strategies can be formulated to improve economic benefits.

[0003] At present, crowd counting methods can be mainly divided into three categories: detection-based methods, regression-based methods, and density map estimation-based methods. Detection-based methods use sliding window-based person or head detectors on images, extract manual features from the head or body with low-level descriptors, and directly estimate the number of people by detecting individuals. However, such methods perform poorly in crowded scenes with severe occlusion. In order to overcome the occlusion problem, some works have introduced regression-based methods. These methods regard the crowd as a whole and directly learn the mapping relationship between image features and the number of people in the image. Feature-based regression methods usually first perform foreground segmentation on the image to separate the crowd from the background, then extract global features or local features, and finally use regression models to learn the mapping function for crowd counting. These methods have the ability to count high-density crowds, but ignore spatial information. Density map estimation-based methods generate crowd density maps by learning the mapping between crowd features and corresponding densities. The integral of the density map is the number of people. Compared with directly outputting the number of people, crowd density maps can show the distribution characteristics of the crowd, which helps to obtain more accurate and comprehensive information.

[0004] There are two difficulties in achieving accurate crowd counting: (1) camera perspective distortion. Pedestrians at different distances from the camera have different sizes, and the scale of pedestrians in an image varies significantly; (2) the background in the scene is complex. Crowd scenes usually have background noise such as buildings and trees. Summary of the invention

[0005] In order to solve the problems existing in the above technologies, the present invention proposes a method for detecting and counting dense crowd distribution in a video.

[0006] The technical solution provided by the present invention is a method for detecting and counting dense crowd distribution in a video, which is characterized by comprising the following steps:

[0007] Step 1: Obtain a large number of videos containing people of different densities to build a dataset;

[0008] Step 2: Construct a deep neural network with multi-scale feature fusion and attention mechanism, input the training sample set constructed in step 1.1 into the deep neural network with multi-scale feature fusion and attention mechanism in sequence, output the prediction results of the crowd density map and attention map corresponding to the training sample set, further combine the real density map corresponding to the training sample set in step 1.2 and the real attention map corresponding to the training sample set in step 1.3 to construct a loss function model, and use the loss function model for training until the loss of the loss function model is reduced to a certain extent and the training reaches the maximum number of iterations, generating an optimized deep neural network with multi-scale feature fusion and attention mechanism;

[0009] Step 3: For crowd video images, the crowd density map is obtained through the deep neural network prediction of the multi-scale feature fusion and attention mechanism optimized in step 2. The output estimated crowd density map is further clustered using a grid-based hierarchical density space clustering method to identify groups and quickly obtain the number of people and location information in the group.

[0010] Preferably, the specific implementation method of obtaining a large number of videos containing people of different densities to construct a data set in step 1 is as follows:

[0011] Step 1.1: Label the crowd image;

[0012] The video is cut into K frames. In the kth frame, the pixel coordinates of the center point of the i-th head are recorded as (x k,i ,y k,i ), in the k-th frame image, (x k,i ,y k,i ) is marked as 1, and the impulse function δ(x k -x k,i ) means, k∈[1,K], i∈[1,N k ], K represents the number of frames in the video, N k represents the number of people in the k-th frame image, x k represents the pixel in the k-th frame image, x k,i The x-axis coordinate of the pixel coordinate of the center point of the i-th head in the k-th frame image, y k,i The Y-axis coordinate of the pixel coordinate of the center point of the i-th head in the k-th frame image;

[0013] In the kth frame image, except (x k,i,y k,i ) The pixel values ​​at the other pixel coordinates are marked as 0;

[0014] Randomly select 2K / 3 frames of images from the annotated K frames as the training sample set, and the remaining K / 3 frames of images as the test sample set;

[0015] Step 1.2: Convert the labeled crowd image into a crowd density map;

[0016] Convolve the labeled crowd image with a geometrically adaptive Gaussian kernel to generate a crowd density map As a true density map;

[0017] in, is the variance of the Gaussian kernel corresponding to the k-th frame image, is the center point x of the head in the kth frame image k,i The mean distance between the center points of the m nearest heads, Indicates the midpoint x of the k-th frame image k,i The distance between its jth nearest neighbor;

[0018] Step 1.3: The real density map F(x k ) where the pixel values ​​are less than the pixel threshold, the pixel values ​​of the points are set to 0, and the pixel values ​​of the remaining points are set to 1 to generate a real attention map;

[0019] Preferably, the deep neural network of multi-scale feature fusion and attention mechanism in step 2 is composed of a multi-scale feature map extractor, a multi-scale feature fusion module, and an attention module connected in series in sequence;

[0020] The multi-scale feature map extractor is used to extract deep, large-scale feature maps and shallow, small-scale feature maps from the crowd image as input to the multi-scale feature fusion module;

[0021] The multi-scale feature fusion module is used to fuse the deep, large-scale feature map and the shallow, small-scale feature map, and generate a feature map F containing multi-scale feature information and multi-level semantic information;

[0022] The attention module is used to distinguish the crowd area and the background area in the feature map F and generate an attention map M att , using the attention map M att Optimize the feature map F to obtain the feature map F constrained by attention refine ;

[0023] Finally, the feature map F refine Return high-resolution, high-quality density map F final ;

[0024] The specific construction method of the multi-scale feature map extractor is:

[0025] Use the first 13 convolutional layers and 4 pooling layers of VGG16_bn;

[0026] The multi-scale feature map extractor is composed of a first group of convolutional layers, a first pooling layer, a second group of convolutional layers, a second pooling layer, a third group of convolutional layers, a third pooling layer, a fourth group of convolutional layers, a fourth pooling layer, and a fifth group of convolutional layers, which are sequentially connected in series;

[0027] The first group of convolutional layers consists of two convolutional layers with a convolution kernel size of 3×3 and 64 convolution kernels connected in series;

[0028] The second group of convolutional layers is composed of two convolutional layers with a convolution kernel size of 3×3 and a number of convolution kernels of 128 connected in series;

[0029] The third group of convolutional layers is composed of three convolutional layers with a convolution kernel size of 3×3 and a number of 256 convolution kernels connected in series;

[0030] The fourth group of convolutional layers and the fifth group of convolutional layers are both composed of three convolutional layers with a convolution kernel size of 3×3 and a number of 512 convolution kernels connected in series;

[0031] The specific network structure of the multi-scale feature map extractor is:

[0032] C(64,3)×2-PC(128,3)×2-PC(256,3)×3-PC(512,3)×3-PC(512,3)×3

[0033] Among them, C(n,3) represents a convolution layer with a convolution kernel size of 3×3 and n convolution kernels, and P represents a maximum pooling layer with a window size of 2×2. The multi-scale feature map extractor is divided into one stage before each pooling operation, and is divided into five stages in total: Conv1_2, Conv2_2, Conv3_3, Conv4_3, and Conv5_3. Each stage obtains feature maps of sizes 1, 1 / 2, 1 / 4, 1 / 8, and 1 / 16 respectively; the output feature maps of the four stages Conv2_2-Conv5_3 are input into the corresponding stages of the multi-scale feature fusion module;

[0034] The multi-scale feature fusion module is specifically constructed as follows:

[0035] The multi-scale feature fusion module is composed of a first upsampling layer, a first group of convolutional layers, a second upsampling layer, a second group of convolutional layers, a third upsampling layer, and a third group of convolutional layers connected in series in sequence. The specific network structure is:

[0036] UC(256,1)-C(256,3)-UC(128,1)-C(128,3)-UC(64,1)-C(64,3)-C(32,3)

[0037] Among them, C(n,m) represents a convolutional layer with a kernel size of m×m and n kernels, and U represents a bilinear upsampling layer with a sampling rate of 2. This module is divided into 1 stage before each upsampling operation, and a total of 3 stages. In each stage, the input feature map is connected to the low-level feature map output by the corresponding stage of the multi-scale feature map extractor in the channel dimension after upsampling, and then passes through the convolution layer group and is input to the next stage. The top layer of the module outputs a feature map F containing multi-scale feature information and multi-level semantic information, which is input into the attention module;

[0038] The specific construction method of the attention module is:

[0039] The attention module generates an attention map M att , the formula is:

[0040] M att =Sigmoid(W⊙F+b)

[0041] Where W is the weight matrix of the 1×1×1 convolutional layer, b is the bias of the 1×1×1 convolutional layer, ⊙ represents the multiplication of corresponding elements, and Sigmoid represents the sigmoid activation function;

[0042] Using the attention map M att Optimize the feature map F, the formula is:

[0043]

[0044] in, Indicates the multiplication of corresponding elements of two matrices;

[0045] The feature map F constrained by attention refine A high-quality, high-resolution crowd density map F is generated through a 1×1×1 convolutional layer final ;

[0046] The loss function model constructed in step 2 is:

[0047] For the generation of crowd density maps, the difference between the estimated density map output by the Euclidean distance supervision network and the corresponding true density map generated in step 1.2 is used. The density map loss function is expressed as:

[0048]

[0049] Where D and D represent the set of true density maps generated in step 1.2 and the set of estimated density maps output by the network, respectively.i is the value of all pixels in the ith estimated density map, D i is the value of all pixels in the i-th true density map, and N is the number of images in the training set.

[0050] For the generation of the attention map, the difference between the estimated attention map generated by the binary cross entropy supervised attention module and the corresponding true attention map generated in step 1.3 is used. The attention map loss function is expressed as:

[0051]

[0052] Where M and M represent the set of real attention maps generated in step 1.3 and the set of estimated attention maps generated by the attention module, respectively. i is the value of all pixels in the i-th true attention map, M i is the value of all pixels in the i-th estimated attention map, and N is the number of images in the training set.

[0053] The total loss function of the network is: L = L(D,D) + λL(M,M)

[0054] The specific implementation of the deep neural network for generating multi-scale feature fusion and attention mechanism described in step 2 is as follows:

[0055] Step 2.1: The training sample set constructed in step 1 is processed in sequence by uniform short side length and random scaling, random image block cropping, random horizontal flipping, and gamma contrast transformation. For data sets with grayscale images, the color images are also randomly transformed into grayscale images;

[0056] Step 2.2: Set the network initial weight parameters and training parameters, including training sample input batch, optimization algorithm, learning rate, momentum, and iteration cycle;

[0057] Step 2.4: Train the deep neural network with multi-scale feature fusion and attention mechanism in step 2;

[0058] In each iteration cycle, the training sample set processed in step 2.1 is input into the deep neural network with multi-scale feature fusion and attention mechanism, the loss function L described in step 2 is calculated, and the weight parameters of the network are updated until the training is completed after all iteration cycles are completed; when the value of the loss function L decreases with the increase of the iteration cycle, it means that the training is effective;

[0059] Preferably, the specific implementation of the clustering method in step 3 is as follows:

[0060] Step 3.1: For the k-th frame image, the crowd density Figure 2 The dimension space is Ω k, the set of points whose pixel values ​​are not 0 is represented as the sample set X k ={x k,1 , x k,2 , …, x k,n}, where x k,i is a two-dimensional vector, the loss function model x k,i ={x k,i1 , x k,i2}. Set the parameter s, and change Ω k Divide it into s intervals in each dimension, so that Ω k Divided into s 2 non-intersecting rectangular units {u k,11 , ..., u k,1s , ..., u k,ss}.

[0061] Step 3.2: For the k-th frame image, traverse its sample set X k , taking the samples in each cell as a class, we get the sample set {c k,11 , c k,12 …, c k,ss}, calculate the density of each cell.

[0062] Step 3.3: Set the density threshold τ, mark the grids with cell density greater than the threshold as dense, and obtain the dense grid set U k = {u k,1 , ..., u k,2 , ..., u k,n}; Set class collection

[0063] Step 3.4: From U k = {u k,1 , ..., u k,2 , ..., u k,n}Select a grid u k,i Start by initializing a set C k,j for u k,i The corresponding sample set c k,pq , that is, C k,j =c k,pq .

[0064] Step 3.5: Pair with u k,i The adjacent dense grids are traversed in breadth first, the traversed grids are marked as "visited", and their corresponding sample sets are added to the set C k,j In; after the breadth traversal is completed, the set C k,j Add to class set C k middle.

[0065] Step 3.6: If Uk If there are still elements not visited, go to step 3.4, otherwise go to the next step.

[0066] Step 3.7: For set C k,j The sample point p in k,i , the distance between it and the lth nearest neighbor sample point is called the core distance, expressed as:

[0067] core l (p k,i ) = d(x, N l (p k,i ))

[0068] Two sample points p k,i and p k , j The mutual reach distance between them is expressed as:

[0069] d mreach-l (p k,i , p k,j )=max{core l (p k,i ), core l (p k,j ), d(p k,i , p k,j )}

[0070] d(·) represents the straight-line distance between two sample points.

[0071] Step 3.8: Use mutual reach distance to represent the distance between two sample points, and construct a minimum spanning tree using Prim's algorithm.

[0072] Step 3.9: Build a clustering hierarchy. Arrange all the edges in the tree in ascending order, then select each edge in turn, merge the two subgraphs linked by the edge, and generate a clustering tree.

[0073] Step 3.10: Determine the minimum cluster size for clustering. A set C obtained in step 3.5 k,j There are m grids in it, and the set of sample points in each grid is recorded as N k ={n k,1 , n k,2 ,…,n k,m}, the population density map integral in the grid is D k ={d k,1 , d k,2 , ..., d k,m}, then for grid i, its density is recorded as Assuming that at least K people form a group, for grid i, the number of sample points contained in the minimum group should be Take the minimum number of sample points in the grid with the smallest crowd density as the minimum cluster size B k , expressed as:

[0074]

[0075] Step 3.11: Compress the clustering tree. Traverse the clustering tree from top to bottom. When each node is split, compare the size relationship between the number of samples of the left and right child nodes and the minimum number of cluster samples. If the number of samples in one of the two child nodes is less than the minimum number of cluster samples, delete the child node directly, and use the other child node to retain the identity of the parent node; if the number of samples in both child nodes is less than the minimum number of cluster samples, delete both child nodes, that is, the current node will no longer split downward; if the number of samples in both child nodes is greater than the minimum number of cluster samples, perform normal splitting, that is, keep the original clustering tree unchanged.

[0076] Step 3.12: Extract clusters. For each node in the tree, define two variables: λ birth Represents the inverse of the length of the disconnected edge when the current node is generated by splitting, λ death Represents the inverse of the length of the disconnected edge when the current node is split into two child nodes; for each sample point a in each node k,i ,definition is the sample point a k,i The stability of a node is expressed as the inverse of the length of the disconnected edge when the split leaves the node:

[0077]

[0078] Each leaf node of the clustering tree is selected as a cluster, and the entire tree is traversed from bottom to top, and the stability of the current node is compared with the sum of the stability of its two child nodes. If the stability of the current node is less than the sum of the stability of its two child nodes, the sum of the stability of the two child nodes is set as the stability of the current node; otherwise, the current node is defined as a cluster and all child nodes are deleted.

[0079] Step 3.13: Divide the groups according to the clustering results, integrate the density map within each group to get the number of people in the group, and frame the group position on the original image according to the position of the cluster on the density map.

[0080] Compared with the prior art, the advantages and beneficial effects of the present invention are:

[0081] The present invention can adapt to the size changes of pedestrians in the image, eliminate the influence of camera perspective distortion, and improve the counting accuracy and counting stability.

[0082] The present invention can effectively suppress the influence of background noise in crowd images, reduce misidentification, and improve counting accuracy and density map quality.

[0083] The present invention divides the crowd into groups and can intuitively display the distribution of the crowd. BRIEF DESCRIPTION OF THE DRAWINGS

[0084] Figure 1 : is an overall flow chart of an embodiment of the present invention;

[0085] Figure 2 : is a flow chart of a crowd counting method in an embodiment of the present invention;

[0086] Figure 3 : is a schematic diagram of the detection results of an embodiment of the present invention. DETAILED DESCRIPTION

[0087] The present invention will be further described in detail below in conjunction with the accompanying drawings and specific embodiments.

[0088] The schematic diagram of the process of the present invention is as follows Figure 1 As shown, a method for detecting and counting dense crowd distribution in a video, characterized in that it includes the following steps

[0089] Step 1: Obtain a large number of videos containing people of different densities to build a dataset;

[0090] The specific implementation method of obtaining a large number of videos containing people of different densities to construct a data set as described in step 1 is as follows:

[0091] Step 1.1: Label the crowd image;

[0092] The video is cut into K = 100 frames. In the k-th frame, the pixel coordinates of the center point of the i-th head are recorded as (x k,i ,y k,i ), in the k-th frame image, (x k,i ,y k,i) The pixel value at is marked as 1, and the impulse function δ(x k -x k,i ) means, k∈[1,K], i∈[1,N k ], K represents the number of frames in the video, N k represents the number of people in the k-th frame image, x k represents the pixel in the k-th frame image, x k,i The x-axis coordinate of the pixel coordinate of the center point of the i-th head in the k-th frame image, y k,i The Y-axis coordinate of the pixel coordinate of the center point of the i-th head in the k-th frame image;

[0093] In the kth frame image, except (x k,i ,y k,i ) The pixel values ​​at the other pixel coordinates are marked as 0;

[0094] Randomly select 2K / 3 frames of images from the annotated K frames as the training sample set, and the remaining K / 3 frames of images as the test sample set;

[0095] Step 1.2: Convert the labeled crowd image into a crowd density map;

[0096] Convolve the labeled crowd image with a geometrically adaptive Gaussian kernel to generate a crowd density map As a true density map;

[0097] in, is the variance of the Gaussian kernel corresponding to the k-th frame image, β = 0.3; is the center point x of the head in the kth frame image k,i The average of the distances between the center points of the m=3 nearest human heads, Indicates the midpoint x of the k-th frame image k,i The distance between its jth nearest neighbor;

[0098] Step 1.3: The real density map F(x k ) where the pixel values ​​are less than the pixel threshold, the pixel values ​​of the points are set to 0, and the pixel values ​​of the remaining points are set to 1 to generate a real attention map;

[0099] Step 2: Construct a deep neural network with multi-scale feature fusion and attention mechanism, input the training sample set constructed in step 1.1 into the deep neural network with multi-scale feature fusion and attention mechanism in sequence, output the predicted results of the crowd density map and attention map corresponding to the training sample set, further combine the real density map corresponding to the training sample set in step 1.2 and the real attention map corresponding to the training sample set in step 1.3 to construct a loss function model, and use the loss function model for training until the loss of the loss function model is reduced to a certain extent and the training reaches the maximum number of iterations, and generate the optimized deep neural network with multi-scale feature fusion and attention mechanism; the above process is as follows Figure 2 shown.

[0100] The deep neural network of multi-scale feature fusion and attention mechanism described in step 2 is composed of a multi-scale feature map extractor, a multi-scale feature fusion module, and an attention module connected in series in sequence;

[0101] The multi-scale feature map extractor is used to extract deep, large-scale feature maps and shallow, small-scale feature maps from the crowd image as input to the multi-scale feature fusion module;

[0102] The multi-scale feature fusion module is used to fuse the deep, large-scale feature map and the shallow, small-scale feature map, and generate a feature map F containing multi-scale feature information and multi-level semantic information;

[0103] The attention module is used to distinguish the crowd area and the background area in the feature map F and generate an attention map M att , using the attention map M att Optimize the feature map F to obtain the feature map F constrained by attention refine ;

[0104] Finally, the feature map F refine Return high-resolution, high-quality density map F final ;

[0105] The specific construction method of the multi-scale feature map extractor is:

[0106] Use the first 13 convolutional layers and 4 pooling layers of VGG16_bn;

[0107] The multi-scale feature map extractor is composed of a first group of convolutional layers, a first pooling layer, a second group of convolutional layers, a second pooling layer, a third group of convolutional layers, a third pooling layer, a fourth group of convolutional layers, a fourth pooling layer, and a fifth group of convolutional layers, which are sequentially connected in series;

[0108] The first group of convolutional layers consists of two convolutional layers with a convolution kernel size of 3×3 and 64 convolution kernels connected in series;

[0109] The second group of convolutional layers is composed of two convolutional layers with a convolution kernel size of 3×3 and a number of convolution kernels of 128 connected in series;

[0110] The third group of convolutional layers is composed of three convolutional layers with a convolution kernel size of 3×3 and a number of 256 convolution kernels connected in series;

[0111] The fourth group of convolutional layers and the fifth group of convolutional layers are both composed of three convolutional layers with a convolution kernel size of 3×3 and a number of 512 convolution kernels connected in series;

[0112] The specific network structure of the multi-scale feature map extractor is:

[0113] C(64,3)×2-PC(128,3)×2-PC(256,3)×3-PC(512,3)×3-PC(512,3)×3

[0114] Among them, C(n,3) represents a convolution layer with a convolution kernel size of 3×3 and n convolution kernels, and P represents a maximum pooling layer with a window size of 2×2. The multi-scale feature map extractor is divided into one stage before each pooling operation, and is divided into five stages in total: Conv1_2, Conv2_2, Conv3_3, Conv4_3, and Conv5_3. Each stage obtains feature maps of sizes 1, 1 / 2, 1 / 4, 1 / 8, and 1 / 16 respectively; the output feature maps of the four stages Conv2_2-Conv5_3 are input into the corresponding stages of the multi-scale feature fusion module;

[0115] The multi-scale feature fusion module is specifically constructed as follows:

[0116] The multi-scale feature fusion module is composed of a first upsampling layer, a first group of convolutional layers, a second upsampling layer, a second group of convolutional layers, a third upsampling layer, and a third group of convolutional layers connected in series in sequence. The specific network structure is:

[0117] UC(256,1)-C(256,3)-UC(128,1)-C(128,3)-UC(64,1)-C(64,3)-C(32,3)

[0118] Among them, C(n,m) represents a convolutional layer with a kernel size of m×m and n kernels, and U represents a bilinear upsampling layer with a sampling rate of 2. This module is divided into 1 stage before each upsampling operation, and a total of 3 stages. In each stage, the input feature map is connected to the low-level feature map output by the corresponding stage of the multi-scale feature map extractor in the channel dimension after upsampling, and then passes through the convolution layer group and is input to the next stage. The top layer of the module outputs a feature map F containing multi-scale feature information and multi-level semantic information, which is input into the attention module;

[0119] The specific construction method of the attention module is:

[0120] The attention module generates an attention map M att , the formula is:

[0121] M att =Sigmoid(W⊙F+b)

[0122] Where W is the weight matrix of the 1×1×1 convolutional layer, b is the bias of the 1×1×1 convolutional layer, ⊙ represents the multiplication of corresponding elements, and Sigmoid represents the sigmoid activation function;

[0123] Using the attention map M att Optimize the feature map F, the formula is:

[0124]

[0125] in, Indicates the multiplication of corresponding elements of two matrices;

[0126] The feature map F constrained by attention refine A high-quality, high-resolution crowd density map F is generated through a 1×1×1 convolutional layer final ;

[0127] The loss function model constructed in step 2 is:

[0128] For the generation of crowd density maps, the difference between the estimated density map output by the Euclidean distance supervision network and the corresponding true density map generated in step 1.2 is used. The density map loss function is expressed as:

[0129]

[0130] Where D and D represent the set of true density maps generated in step 1.2 and the set of estimated density maps output by the network, respectively. i is the value of all pixels in the ith estimated density map, D i is the value of all pixels in the i-th true density map, and N is the number of images in the training set.

[0131] For the generation of the attention map, the difference between the estimated attention map generated by the binary cross entropy supervised attention module and the corresponding true attention map generated in step 1.3 is used. The attention map loss function is expressed as:

[0132]

[0133] Where M and M represent the set of real attention maps generated in step 1.3 and the set of estimated attention maps generated by the attention module, respectively. i is the value of all pixels in the i-th true attention map, M i is the value of all pixels in the i-th estimated attention map, and N is the number of images in the training set.

[0134] The total loss function of the network is: L = L(D,D) + λL(M,M)

[0135] The specific implementation of the deep neural network for generating multi-scale feature fusion and attention mechanism described in step 2 is as follows:

[0136] Step 2.1: The training sample set constructed in step 1 is processed in sequence by uniform short side length and random scaling, random image block cropping, random horizontal flipping, and gamma contrast transformation. For data sets with grayscale images, the color images are also randomly transformed into grayscale images;

[0137] Step 2.2: Set the network initial weight parameters and training parameters, including the training sample input batch, optimization algorithm, learning rate, momentum, and iteration cycle; the multi-scale feature map extractor is initialized by the parameters of the VGG-16_bn network pre-trained on the ImageNet dataset, and other parameters are randomly initialized by a Gaussian distribution with a mean of 0 and a standard deviation of 0.01; the input batch size of the training data is 8; the Adam optimization algorithm is used, the learning rate is set to 1e-5, the momentum is set to 5e-3, and the number of iterations is 500.

[0138] Step 2.4: Train the deep neural network with multi-scale feature fusion and attention mechanism in step 2;

[0139] In each iteration cycle, the training sample set processed in step 2.1 is input into the deep neural network with multi-scale feature fusion and attention mechanism, the loss function L described in step 2 is calculated, and the weight parameters of the network are updated until the training is completed after all iteration cycles are completed; when the value of the loss function L decreases with the increase of the iteration cycle, it means that the training is effective;

[0140] After each iteration cycle, the performance of the current network needs to be verified: input the test sample set constructed in step 1.1 into the current network, obtain the number of people in the test set image, evaluate the network performance, and save the current best network model. In a training, the model with the best performance in all iteration cycles is the deep neural network with the optimal multi-scale feature fusion and attention mechanism for this training. If the network performance is poor after a training, adjust the training parameters in step 3.2, repeat step 3.4, and retrain until the ideal performance is achieved.

[0141] The above model performance evaluation uses two evaluation indicators: mean absolute error MAE and root mean square error RMSE, which respectively evaluate the counting accuracy and counting stability of the model. The definitions of the two evaluation indicators are as follows:

[0142]

[0143]

[0144] in, represents the number of people estimated by the model in the i-th image of the test set, which is obtained by integrating the density map output by the model. represents the actual number of people in the i-th image of the test set, and N is the number of images in the test set.

[0145] Step 3: For crowd video images, the crowd density map is obtained through the deep neural network prediction of the multi-scale feature fusion and attention mechanism optimized in step 2. The output estimated crowd density map is further clustered using a grid-based hierarchical density space clustering method to identify groups and quickly obtain the number of people and location information in the group.

[0146] Furthermore, the specific implementation of the clustering method in step 3 is as follows:

[0147] Step 3.1: For the k-th frame image, the crowd density Figure 2 The dimension space is Ω k , the set of points whose pixel values ​​are not 0 is represented as the sample set X k ={x k,1 , x k,2 , ..., x k,n}, where x k,i is a two-dimensional vector, the loss function model x k,i ={x k,i1 , x k,i2}. Set the parameter s, and change Ω k Divide it into s intervals in each dimension, so that Ω k Divided into s 2 non-intersecting rectangular units {u k,11 , ..., u j,1s ,…,u k,ss}.

[0148] Step 3.2: For the k-th frame image, traverse its sample set X k , taking the samples in each cell as a class, we get the sample set {c k,11 , c k,12 …, c k,ss}, calculate the density of each cell.

[0149] Step 3.3: Set the density threshold τ, mark the grids with cell density greater than the threshold as dense, and obtain the dense grid set U k = {u k,1 , ..., u k,2 , ..., u k,n}; Set class collection

[0150] Step 3.4: From U k = {u k,1 , ..., u k,2 , ..., u k,n}Select a grid u k,i Start by initializing a set C k,j for u k,i The corresponding sample set ck,pq , that is, C k,j =c k,pq .

[0151] Step 3.5: Pair with u k,i The adjacent dense grids are traversed in breadth first, the traversed grids are marked as "visited", and their corresponding sample sets are added to the set C k,j In; after the breadth traversal is completed, the set C k,j Add to class set C k middle.

[0152] Step 3.6: If U k If there are still elements not visited, go to step 3.4, otherwise go to the next step.

[0153] Step 3.7: For set C k,j The sample point p in k,i , the distance between it and the lth nearest neighbor sample point is called the core distance, expressed as:

[0154] core l (p k,i ) = d(x, N l (p k,i ))

[0155] Two sample points p k,i and p k,j The mutual reach distance between them is expressed as:

[0156] d mreach-l (p k,i , p k,j )=max{core l (p k,i ), core l (p k,j ), d(p k,i , p k,j )}

[0157] d(·) represents the straight-line distance between two sample points.

[0158] Step 3.8: Use mutual reach distance to represent the distance between two sample points, and construct a minimum spanning tree using Prim's algorithm.

[0159] Step 3.9: Build a clustering hierarchy. Arrange all the edges in the tree in ascending order, then select each edge in turn, merge the two subgraphs linked by the edge, and generate a clustering tree.

[0160] Step 3.10: Determine the minimum cluster size for clustering. A set C obtained in step 3.5 k,j There are m grids in it, and the set of sample points in each grid is recorded as Nk ={n k,1 , n k,2 , ..., n k,m}, the population density map integral in the grid is D k ={d k,1 , d k,2 , ..., d k,m}, then for grid i, its density is recorded as Assuming that at least K people form a group, for grid i, the number of sample points contained in the minimum group should be Take the minimum number of sample points in the grid with the smallest crowd density as the minimum cluster size B k , expressed as:

[0161]

[0162] Step 3.11: Compress the clustering tree. Traverse the clustering tree from top to bottom. When each node is split, compare the size relationship between the number of samples of the left and right child nodes and the minimum number of cluster samples. If the number of samples in one of the two child nodes is less than the minimum number of cluster samples, delete the child node directly, and use the other child node to retain the identity of the parent node; if the number of samples in both child nodes is less than the minimum number of cluster samples, delete both child nodes, that is, the current node will no longer split downward; if the number of samples in both child nodes is greater than the minimum number of cluster samples, perform normal splitting, that is, keep the original clustering tree unchanged.

[0163] Step 3.12: Extract clusters. For each node in the tree, define two variables: λ birth Represents the inverse of the length of the disconnected edge when the current node is generated by splitting, λ death Represents the inverse of the length of the disconnected edge when the current node is split into two child nodes; for each sample point a in each node k,i ,definition is the sample point a k,i The stability of a node is expressed as the inverse of the length of the disconnected edge when the split leaves the node:

[0164]

[0165] Each leaf node of the clustering tree is selected as a cluster, and the entire tree is traversed from bottom to top, and the stability of the current node is compared with the sum of the stability of its two child nodes. If the stability of the current node is less than the sum of the stability of its two child nodes, the sum of the stability of the two child nodes is set as the stability of the current node; otherwise, the current node is defined as a cluster and all child nodes are deleted.

[0166] Step 3.13: Divide the groups according to the clustering results, integrate the density map within each group to get the number of people in the group, and frame the group position on the original image according to the location of the cluster in the density map. The crowd density estimation and group recognition results are as follows: Figure 3 shown.

[0167] The specific embodiments described herein are merely examples of the spirit of the present invention. Those skilled in the art may make various modifications or additions to the specific embodiments described or replace them in similar ways, but they will not deviate from the spirit of the present invention or exceed the scope defined by the appended claims.

Claims

1. A method for detecting and counting dense crowd distribution in a video, characterized in that: The following steps are involved: Step 1: Obtain a large number of videos containing people of different densities to build a dataset; The specific implementation method of obtaining a large number of videos containing people of different densities to construct a data set as described in step 1 is as follows: Step 1.1: Label the crowd image; The video is cut into K frames. In the kth frame, the pixel coordinates of the center point of the i-th head are recorded as (x k,i ,y k,i ), in the k-th frame image, (x k,i ,y k,i ) is marked as 1, and the impulse function δ(x k -x k,i ) means, k∈[1,K], i∈[1,N k ], K represents the number of frames in the video, N k represents the number of people in the k-th frame image, x k represents the pixel in the k-th frame image, x k,i The x-axis coordinate of the pixel coordinate of the center point of the i-th head in the k-th frame image, y k,i The Y-axis coordinate of the pixel coordinate of the center point of the i-th head in the k-th frame image; In the kth frame image, except (x k,i ,y k,i ) The pixel values ​​at the other pixel coordinates are marked as 0; Randomly select 2K / 3 frames of images from the annotated K frames as the training sample set, and the remaining K / 3 frames of images as the test sample set; Step 1.2: Convert the labeled crowd image into a crowd density map; Convolve the labeled crowd image with a geometrically adaptive Gaussian kernel to generate a crowd density map As a true density map; in, is the variance of the Gaussian kernel corresponding to the k-th frame image, is the center point x of the head in the kth frame image k,i The mean distance between the center points of the m nearest heads, Indicates the midpoint x of the k-th frame image k,i The distance between its jth nearest neighbor; Step 1.3: The real density map F(x k ) where the pixel values ​​are less than the pixel threshold, the pixel values ​​of the points are set to 0, and the pixel values ​​of the remaining points are set to 1 to generate a real attention map; Step 2: Construct a deep neural network with multi-scale feature fusion and attention mechanism, input the training sample set constructed in step 1.1 into the deep neural network with multi-scale feature fusion and attention mechanism in sequence, output the prediction results of the crowd density map and attention map corresponding to the training sample set, further combine the real density map corresponding to the training sample set in step 1.2 and the real attention map corresponding to the training sample set in step 1.3 to construct a loss function model, and use the loss function model for training until the loss of the loss function model is reduced to a certain extent and the training reaches the maximum number of iterations, generating an optimized deep neural network with multi-scale feature fusion and attention mechanism; Step 3: For crowd video images, the crowd density map is obtained by deep neural network prediction with multi-scale feature fusion and attention mechanism optimized in step 2. The output estimated crowd density map is further clustered using a grid-based hierarchical density space clustering method to identify groups and quickly obtain the number of people and location information of the group. The deep neural network of multi-scale feature fusion and attention mechanism described in step 2 is composed of a multi-scale feature map extractor, a multi-scale feature fusion module, and an attention module connected in series in sequence; The multi-scale feature map extractor is used to extract deep, large-scale feature maps and shallow, small-scale feature maps from the crowd image as input to the multi-scale feature fusion module; The multi-scale feature fusion module is used to fuse the deep, large-scale feature map and the shallow, small-scale feature map, and generate a feature map F containing multi-scale feature information and multi-level semantic information; The attention module is used to distinguish the crowd area and the background area in the feature map F and generate an attention map M att , using the attention map M att Optimize the feature map F to obtain the feature map F constrained by attention refine ; Finally, the feature map F refine Return high-resolution, high-quality density map F final ; The specific construction method of the multi-scale feature map extractor is: Use the first 13 convolutional layers and 4 pooling layers of VGG16_bn; The multi-scale feature map extractor is composed of a first group of convolutional layers, a first pooling layer, a second group of convolutional layers, a second pooling layer, a third group of convolutional layers, a third pooling layer, a fourth group of convolutional layers, a fourth pooling layer, and a fifth group of convolutional layers, which are sequentially connected in series; The first group of convolutional layers consists of two convolutional layers with a convolution kernel size of 3×3 and 64 convolution kernels connected in series; The second group of convolutional layers is composed of two convolutional layers with a convolution kernel size of 3×3 and a number of convolution kernels of 128 connected in series; The third group of convolutional layers is composed of three convolutional layers with a convolution kernel size of 3×3 and a number of 256 convolution kernels connected in series; The fourth group of convolutional layers and the fifth group of convolutional layers are both composed of three convolutional layers with a convolution kernel size of 3×3 and a number of 512 convolution kernels connected in series; The specific network structure of the multi-scale feature map extractor is: C(64,3)×2-PC(128,3)×2-PC(256,3)×3-PC(512,3)×3-PC(512,3)×3 Among them, C(n,3) represents a convolution layer with a convolution kernel size of 3×3 and n convolution kernels, and P represents a maximum pooling layer with a window size of 2×2; the multi-scale feature map extractor is divided into one stage before each pooling operation, and is divided into five stages in total: Conv1_2, Conv2_2, Conv3_3, Conv4_3, and Conv5_3, and each stage obtains feature maps of sizes 1, 1 / 2, 1 / 4, 1 / 8, and 1 / 16 respectively; the output feature maps of the four stages Conv2_2-Conv5_3 are input into the corresponding stages of the multi-scale feature fusion module; The multi-scale feature fusion module is specifically constructed as follows: The multi-scale feature fusion module is composed of a first upsampling layer, a first group of convolutional layers, a second upsampling layer, a second group of convolutional layers, a third upsampling layer, and a third group of convolutional layers connected in series in sequence. The specific network structure is: UC(256,1)-C(256,3)-UC(128,1)-C(128,3)-UC(64,1)-C(64,3)-C(32,3) Among them, C(n,m) represents a convolutional layer with a kernel size of m×m and n kernels, and U represents a bilinear upsampling layer with a sampling rate of 2. The module is divided into one stage before each upsampling operation, and a total of three stages. In each stage, the input feature map is connected to the low-level feature map output by the multi-scale feature map extractor in the channel dimension after upsampling, and then passes through the convolution layer group and is input to the next stage. The top layer of the module outputs a feature map F containing multi-scale feature information and multi-level semantic information, which is input to the attention module. The specific construction method of the attention module is: The attention module generates an attention map M att , the formula is: M att =Sigmoid(W⊙F+b) Where W is the weight matrix of the 1×1×1 convolutional layer, b is the bias of the 1×1×1 convolutional layer, ⊙ represents the multiplication of corresponding elements, and Sigmoid represents the sigmoid activation function; Using the attention map M att Optimize the feature map F, the formula is: in, Indicates the multiplication of corresponding elements of two matrices; The feature map F constrained by attention refine A high-quality, high-resolution crowd density map F is generated through a 1×1×1 convolutional layer final ; The loss function model constructed in step 2 is: For the generation of crowd density maps, the difference between the estimated density map output by the Euclidean distance supervision network and the corresponding true density map generated in step 1.2 is used. The density map loss function is expressed as: Where D and D represent the set of true density maps generated in step 1.2 and the set of estimated density maps output by the network, respectively. i is the value of all pixels in the ith estimated density map, D i is the value of all pixels in the i-th true density map, and N is the number of images in the training set; For the generation of the attention map, the difference between the estimated attention map generated by the binary cross entropy supervised attention module and the corresponding true attention map generated in step 1.3 is used. The attention map loss function is expressed as: Where M and M represent the set of real attention maps generated in step 1.3 and the set of estimated attention maps generated by the attention module, respectively. i is the value of all pixels in the i-th true attention map, M i is the value of all pixels in the i-th estimated attention map, and N is the number of images in the training set; The total loss function of the network is: L = L(D,D) + λL(M,M) The specific implementation of the deep neural network for generating multi-scale feature fusion and attention mechanism described in step 2 is as follows: Step 2.1: The training sample set constructed in step 1 is subjected to the following operations: uniform short side length, random scaling, random image block cropping, random horizontal flipping, and gamma contrast transformation. For data sets with grayscale images, the color images are also randomly transformed into grayscale images. Step 2.2: Set the network initial weight parameters and training parameters, including training sample input batch, optimization algorithm, learning rate, momentum, and iteration cycle; Step 2.4: Train the deep neural network with multi-scale feature fusion and attention mechanism in step 2; In each iteration cycle, the training sample set processed in step 2.1 is input into the deep neural network with multi-scale feature fusion and attention mechanism, the loss function L described in step 2 is calculated, and the weight parameters of the network are updated until the training is completed after all iteration cycles are completed; when the value of the loss function L decreases with the increase of the iteration cycle, it means that the training is effective; The specific implementation of the clustering method in step 3 is as follows: Step 3.1: For the k-th frame image, the two-dimensional space of the crowd density map is Ω k , the set of points whose pixel values ​​are not 0 is represented as the sample set X k ={x k,1 , x k,2 , ..., x k,n }, where x k,i is a two-dimensional vector, the loss function model x k,i ={x k,i1 , x k,i2 }; Set the parameter s, and set Ω k Divide it into s intervals in each dimension, so that Ω k Divided into s 2 non-intersecting rectangular units {u k,11 , ..., u k,1s , ..., u k,ss }; Step 3.2: For the k-th frame image, traverse its sample set X k , taking the samples in each cell as a class, we get the sample set {c k,11 , c k,12 ..., c k,ss }, calculate the density of each cell; Step 3.3: Set the density threshold τ, mark the grids with cell density greater than the threshold as dense, and obtain the dense grid set U k = {u k,1 , ..., u k,2 , ..., u k,n }; Set class collection Step 3.4: From U k = {u k,1 , ..., u k,2 , ..., u k,n }Select a grid u k,i Start by initializing a set C k,j for u k,i The corresponding sample set c k,pq , that is, C k,j =C k,pq ; Step 3.5: Pair with u k,i The adjacent dense grids are traversed in breadth first, the traversed grids are marked as "visited", and their corresponding sample sets are added to the set C k,j In; after the breadth traversal is completed, the set C k,j Add to class set C k middle; Step 3.6: If U k If there are still elements not visited, go to step 3.4, otherwise go to the next step; Step 3.7: For set C k,j The sample point p in k,i , the distance between it and the lth nearest neighbor sample point is called the core distance, expressed as: core l (p k,i )=d(x,N l (p k,i )) Two sample points p k,i and p k,j The mutual reach distance between them is expressed as: d mreach-l (p k,i ,p k,j )=max{core l (p k,i ),core l (p k,j ),d(p k,i ,p k,j )} d(·) represents the straight-line distance between two sample points; Step 3.8: Use mutual reach distance to represent the distance between two sample points, and construct a minimum spanning tree using Prim's algorithm; Step 3.9: Build a clustering hierarchy; arrange all the edges in the tree in ascending order, then select each edge in turn, merge the two subgraphs linked by the edge, and generate a clustering tree; Step 3.10: Determine the minimum cluster size for clustering; a set C obtained in step 3.5 k,j There are m grids in it, and the set of sample points in each grid is recorded as N k ={n k,1 , n k,2 , ..., n k,m }, the population density map integral in the grid is D k ={d k,1 , d k,2 , ..., d k,m }, then for grid i, its density is recorded as Assuming that at least K people form a group, for grid i, the number of sample points contained in the minimum group should be Take the minimum number of sample points in the grid with the smallest crowd density as the minimum cluster size B k , expressed as: Step 3.11: Compress the cluster tree; traverse the cluster tree from top to bottom, and when each node is split, compare the size relationship between the number of samples of the left and right child nodes and the minimum number of cluster samples; if the number of samples in one of the two child nodes is less than the minimum number of cluster samples, delete the child node directly, and use the other child node to retain the identity of the parent node; if the number of samples in both child nodes is less than the minimum number of cluster samples, delete both child nodes, that is, the current node will no longer split downward; if the number of samples in both child nodes is greater than the minimum number of cluster samples, perform normal splitting, that is, keep the original cluster tree unchanged; Step 3.12: Extract clusters; for each node in the tree, define two variables: λ birth Represents the inverse of the length of the disconnected edge when the current node is generated by splitting, λ death Represents the inverse of the length of the disconnected edge when the current node is split into two child nodes; for each sample point a in each node k,i ,definition is the sample point a k,i The stability of a node is expressed as the inverse of the length of the disconnected edge when the split leaves the node: Each leaf node of the clustering tree is selected as a cluster, and the entire tree is traversed from bottom to top. The stability of the current node is compared with the sum of the stabilities of its two child nodes. If the stability of the current node is less than the sum of the stabilities of its two child nodes, the sum of the stabilities of the two child nodes is set as the stability of the current node. Otherwise, the current node is defined as a cluster and all child nodes are deleted. Step 3.13: Divide the groups according to the clustering results, integrate the density map within each group to get the number of people in the group, and frame the group position on the original image according to the position of the cluster on the density map.

Citation Information

Patent Citations

  • Group positioning and abnormal behavior detection method in video

    CN110502988A

  • Method for detecting and counting crowd distribution in video based on deep learning

    CN113255430A

  • Inductive and Hierarchical clustering method using Equilibrium-based support vector

    KR1020090020057A