Crowd density estimation method based on deep learning
Extract crowd features and generate density maps through ResNet and U-net networks, combined with the mean square error loss function and root mean square error evaluation, to solve the problem of large density estimation errors in high-density crowds and achieve high-accuracy crowd density estimation. .
Patent Information
- Application Number
- CN202410043296.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-11
- Publication Date
- 2024-08-30
- Estimated Expiration
- 2044-01-11
AI Technical Summary
Existing methods for estimating the number of people in high-density crowds based on deep learning have large errors in estimating density due to pedestrian occlusion and overlap in high-density crowds.
The ResNet network model is used to extract crowd features, and the feature map is converted into a crowd density map through the U-net structure generation network. The mean square error loss function is designed to train and optimize the model, and the root mean square error is used to evaluate the accuracy of the density map.
It improves the accuracy and performance of crowd density estimation, improves data quality, provides objective evaluation criteria, and enhances the reliability and effectiveness of the method.
Smart Images

Figure CN117994720B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of crowd density estimation, and in particular to a crowd density estimation method based on deep learning. Background Art
[0002] With the acceleration of urbanization and the rapid growth of crowd size, crowd density estimation has become an important analytical tool. Accurately estimating crowd density can help urban planners and security departments better understand crowd flow, effectively manage crowd flow, and improve urban safety and convenience.
[0003] The patent with publication number CN108563975B discloses a method for estimating the number of people in a high-density crowd based on deep learning. The method uses a mixed Gaussian model to extract the foreground and background images of the video and perform preprocessing operations; collects thermal images, and uses a thermal imager to obtain the RGB thermal image corresponding to the foreground image. Then, the values of all R channels in the thermal image are extracted to generate a thermal matrix; grayscale images are collected; a convolutional neural network model is trained; the population thermal matrix in step 4 is tested with the trained crowd estimation model to obtain the results of the model feedback, and finally the estimated number of people is obtained.
[0004] It can be seen that the high-density crowd estimation method based on deep learning has the following problems:
[0005] The problem of large errors in estimated density is caused by occlusion and overlap between pedestrians in a high-density crowd. Summary of the invention
[0006] To this end, the present invention provides a crowd density estimation method based on deep learning to overcome the problem in the prior art that the estimated density has large errors due to occlusion and overlap between pedestrians in a high-density crowd.
[0007] To achieve the above object, the present invention provides a crowd density estimation method based on deep learning, comprising the following steps:
[0008] S1. Collect an image data set, and perform preprocessing operations on a number of images to be processed in the image data set, each of the images to be processed contains a crowd;
[0009] S2. Using a ResNet network model, extracting features of a crowd from any image to be processed to form a feature map;
[0010] S3, using a U-net structure to generate a network to convert the feature map into a crowd density map;
[0011] S4. Design a loss function to obtain a mean square error loss function;
[0012] S5, using 70% of the crowd density map as a training data set and the mean square error loss function to train the first ACSCP model to obtain a second ACSCP model;
[0013] S6, subjecting the new image to be processed to steps S2 and S3 to obtain a crowd density map corresponding to the new image to be processed;
[0014] S7, inputting the crowd density map corresponding to the new image to be processed into the second ACSCP model, and the second ACSCP model outputs a third density map;
[0015] S8. Evaluate the third density map using a root mean square error.
[0016] Furthermore, the step S1 includes the following steps:
[0017] S11, adjusting the size of the plurality of images to be processed to a preset size value, and using the nearest neighbor interpolation function in OpenCV to implement an image scaling operation to form a scaled image;
[0018] S12, cropping the zoomed image according to a preset cropping value to form a cropped image;
[0019] S13: De-noise the cropped image using mean filtering to form a pre-processed image.
[0020] Furthermore, the step S2 includes the following steps:
[0021] S21. Use the torchvision library in PyTorch to load the ResNet model.
[0022] S22, inputting the preprocessed image into the ResNet model, and obtaining a feature vector of the image by forward propagation calculation;
[0023] S23. Perform a reshape operation on the eigenvector to reshape the eigenvector into a eigenmap form of a two-dimensional matrix.
[0024] Furthermore, the S3 step includes the following steps:
[0025] S31, preparing a group of training samples with labeled crowd density maps, each training sample including a feature map and a corresponding crowd density map;
[0026] S32. Construct a U-net structure generation network including an encoder and a decoder;
[0027] S33, define a mean square error loss function;
[0028] S34, using the prepared training data and the defined loss function, optimizing the network parameters through the back propagation algorithm to train the U-net structure generation network;
[0029] S35. After the training is completed, the trained U-net structure is used to generate a network, the feature map is input into the U-net structure to generate a network, and a crowd density map is obtained by forward propagation calculation.
[0030] Furthermore, the S4 step includes the following steps:
[0031] S41, calculating the square of the difference between the predicted value and the true value to obtain the error;
[0032] S42, averaging the errors of all samples to obtain an average error;
[0033] S43. Taking the average error as the value of the loss function, the mean square error loss function is expressed as: L(y, y') = 1 / N × Σ(y-y')2, where L represents the loss function, y represents the true value, y' represents the predicted value of the model, N represents the number of samples, and Σ represents the summation operation.
[0034] Furthermore, the step S5 includes the following steps:
[0035] S51, selecting 70% of the samples from the population density map as training data, and performing normalization and balancing sample data preprocessing;
[0036] S52, initializing the weights and biases of the ResNet network model and the U-net structure generation network;
[0037] S53. Select the Adam optimizer and use randomly initialized learning rate, momentum, and weight decay hyperparameters.
[0038] S54, iteratively training the first ACSCP model using images in the training data set, and adjusting the learning rate, momentum and weight decay hyperparameters using a minimization mean square error loss function to obtain a second ACSCP model;
[0039] S57. Repeat steps S54 to S56 until the maximum number of iterations is reached.
[0040] Furthermore, the step S54 includes the following steps:
[0041] S541, obtaining a feature map of the image in the training data set through a ResNet network model, and then using a U-net structure to generate a network to convert the feature map into a crowd density map;
[0042] S542, according to the head position information in the annotation file containing the number of heads and the two-dimensional coordinates in the image to be processed, set the pixel points at the corresponding position on the image to 1, and set the other pixel points to 0 to obtain a binary image, and use a Gaussian kernel function to convolve the binary image to obtain a true density map, and calculate the value of the mean square error loss function by comparing the crowd density map with the true density map;
[0043] S543. According to the value of the loss function, the back propagation algorithm is used to calculate the gradient and update the parameters of the model;
[0044] S544. According to the gradient information, use the Adam optimizer to update the values of the learning rate, momentum and weight decay hyperparameters;
[0045] S545. Repeat steps S541 to S544 until a predetermined number of iterations is reached.
[0046] Furthermore, the step S6 includes the following steps:
[0047] S61, input the feature map and perform multiple convolution operations through the encoder part, and extract image features using convolution kernels of different scales;
[0048] S62, after each convolutional layer of the encoder part, a downsampling operation is performed to increase the receptive field and reduce the size of the feature map;
[0049] S63, passing the feature map obtained by the last layer of the encoder to the decoder part;
[0050] S64, the decoder part gradually performs upsampling operations to restore the size of the feature map to the size of the original input image;
[0051] S65, in the process of upsampling, fusing the feature map in the encoder with the feature map in the decoder to combine information of different scales;
[0052] S66. Convert the output of the decoder into a crowd density map representing different areas in the image with the same size as the input image through a convolutional layer.
[0053] Furthermore, the step S7 includes the following steps:
[0054] S71, inputting the crowd density map corresponding to the generated new image to be processed into the second ACSCP model for forward propagation to obtain a second density map;
[0055] S72. Set the pixel points in the crowd density map that are below or above a certain threshold to 0 to remove noise; use a Gaussian filter to smooth the second density map to remove noise and irregular details; use histogram equalization and contrast enhancement to process the second density map to obtain a modified third density map.
[0056] Furthermore, the step S8 includes the following steps:
[0057] S81, according to the head position information in the ACSCP annotation file containing the number of heads and two-dimensional coordinates in the new image to be processed, setting the pixel points at the corresponding position on the image to be 1 and the other pixel points to 0 to obtain a binary image, and convolving the binary image with a Gaussian kernel function to obtain a true ACSCP density map;
[0058] S82, calculating the difference between each pixel value in each of the real ACSCP density maps and the third density map, and obtaining the root mean square error, which represents the crowd density estimation accuracy of the model. The specific calculation formula is as follows:
[0059] Among them, sum represents the sum operation, and N represents the total number of pixels;
[0060] S83. Calculate the average value of the root mean square error as an indicator for evaluating model performance. If the average value of the root mean square error is less than or equal to a preset average threshold, it is evaluated that the density estimation result is consistent with the actual situation.
[0061] Compared with the prior art, the present invention has the following beneficial effects:
[0062] Crowd density estimation is performed using deep learning technology. By collecting image data sets and preprocessing them, the ResNet network model is used to extract crowd features, and then the U-net structure is used to generate a density map. The second model is obtained by training through the design of the loss function, and the model is used to process new images to be processed and output the third density map. Finally, the root mean square error is used to evaluate the accuracy of the third density map. This crowd density estimation method based on deep learning can estimate crowd density with high accuracy by preprocessing image data, extracting crowd features and generating density maps using deep networks, designing reasonable loss functions, training and evaluating models, while also improving data quality, optimizing model structure and parameters, and providing objective evaluation criteria.
[0063] Furthermore, through the preprocessing operation, the quality of the original image can be improved and more accurate input can be provided for the subsequent steps, thereby enhancing the effect and reliability of the entire crowd density estimation method.
[0064] Furthermore, by using the ResNet network model to extract crowd features in the image and converting them into feature maps, accurate and rich feature inputs are provided for subsequent steps, thereby improving the performance and effect of the entire crowd density estimation method.
[0065] Furthermore, by using the U-net structure to generate a network to convert the feature map into a density map, more informative and accurate crowd density estimation results can be provided.
[0066] Furthermore, the mean square error loss function designed by this method can quantify the prediction accuracy, obtain the average error value and use it as a measure of the loss function, which is convenient for model training and optimization and improves the accuracy and performance of crowd density estimation.
[0067] Furthermore, by selecting 70% of the training data, performing data preprocessing, initializing the model, selecting a suitable optimizer and minimizing the mean square error loss function, performing iterative training and controlling the number of iterations, the training quality and performance of the model can be effectively improved, and it performs well in terms of the accuracy and generalization ability of crowd density estimation, providing reliable support for the implementation and application of this method.
[0068] Furthermore, by using ResNet to extract image features and using U-net to generate a density map, generating a true density map by annotating a file, calculating the value of the mean square error loss function, using the back propagation algorithm to calculate the gradient and update the model parameters, using the Adam optimizer to update the learning rate, momentum and weight decay hyperparameters, and repeatedly iterating these steps until a predetermined number of iterations is reached, it helps to optimize the training process of the model, improve the accuracy of the density map, and enable the model to better estimate the crowd density and have better generalization ability.
[0069] Furthermore, through multiple convolution operations and downsampling, convolution kernels of different scales are used to extract image features, increase the receptive field and reduce the size of the feature map. Then, the feature map of the last layer in the encoder part is passed to the decoder part, and the feature map size is restored to the size of the original input image through step-by-step upsampling operations. In the upsampling process, the feature maps of the encoder and decoder are fused to combine information of different scales. Finally, through a layer of convolution, the output of the decoder is converted into a density map representing different areas in the image with the same size as the input image, which can better extract feature information of different scales, retain the details of the image, and effectively restore the size of the density map and maintain the spatial relationship, thereby improving the accuracy and detail of crowd density estimation.
[0070] Furthermore, by processing the density map, the accuracy of the density map can be improved, noise and irregular details can be removed, and the visual effect of the image can be enhanced, thereby obtaining a more reliable and accurate crowd density estimation result.
[0071] Furthermore, by selecting the average value of the root mean square error to evaluate the density map, the accuracy and performance of the model can be quantitatively evaluated, providing a reliable indicator to judge the consistency of the density estimation results, thereby making the density estimation of the model more reliable and practical. BRIEF DESCRIPTION OF THE DRAWINGS
[0072] Figure 1 This is a flowchart of the crowd density estimation method based on deep learning according to the present invention;
[0073] Figure 2 This is a flowchart of step S1 of the crowd density estimation method based on deep learning of the present invention;
[0074] Figure 3 This is a flowchart of step S2 of the crowd density estimation method based on deep learning of the present invention;
[0075] Figure 4 This is a flowchart of step S3 of the crowd density estimation method based on deep learning described in the present invention. DETAILED DESCRIPTION
[0076] In order to make the objects and advantages of the present invention more clearly understood, the present invention is further described below in conjunction with embodiments; 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.
[0077] The preferred embodiments of the present invention are described below with reference to the accompanying drawings. It should be understood by those skilled in the art that these embodiments are only used to explain the technical principles of the present invention and are not intended to limit the protection scope of the present invention.
[0078] It should be noted that, in the description of the present invention, terms such as "up", "down", "left", "right", "inside" and "outside" indicating directions or positional relationships are based on the directions or positional relationships shown in the drawings. This is merely for the convenience of description and does not indicate or imply that the device or element must have a specific orientation, be constructed and operated in a specific orientation. Therefore, it cannot be understood as a limitation on the present invention.
[0079] In addition, it should be noted that in the description of the present invention, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be the internal communication of two components. For those skilled in the art, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0080] See also Figure 1-4 As shown, Figure 1 It is a flowchart of the crowd density estimation method based on deep learning described in the embodiment of the present invention; Figure 2 It is a flowchart of step S1 of the crowd density estimation method based on deep learning of the present invention in the embodiment; Figure 3 It is a flowchart of step S2 of the crowd density estimation method based on deep learning of the present invention in the embodiment; Figure 4 This is a flowchart of step S3 of the crowd density estimation method based on deep learning described in the embodiment of the present invention.
[0081] like Figure 1 As shown, a crowd density estimation method based on deep learning includes the following steps:
[0082] S1. Collect an image data set, and perform preprocessing operations on a number of images to be processed in the image data set, each of the images to be processed contains a crowd;
[0083] S2. Using a ResNet network model, extracting features of a crowd from any image to be processed to form a feature map;
[0084] S3, using a U-net structure to generate a network to convert the feature map into a crowd density map;
[0085] S4. Design a loss function to obtain a mean square error loss function;
[0086] S5, using 70% of the crowd density map as a training data set and the mean square error loss function to train the first ACSCP model to obtain a second ACSCP model;
[0087] S6, subjecting the new image to be processed to steps S2 and S3 to obtain a crowd density map corresponding to the new image to be processed;
[0088] S7, inputting the crowd density map corresponding to the new image to be processed into the second ACSCP model, and the second ACSCP model outputs a third density map;
[0089] S8. Evaluate the third density map using a root mean square error.
[0090] First, collect image datasets containing crowds, and preprocess these images to be processed to prepare training data. Next, use the ResNet network model to extract the features of the crowd for each image to be processed and generate a feature map. Then, the feature map is converted into a corresponding crowd density map through the U-net structure generation network to reflect the density distribution of the crowd. In order to optimize the generated crowd density map, a mean square error loss function is designed to measure the difference between the generated crowd density map and the true density map. Use 70% of the crowd density map as the training data set and train on the first ACSCP model to obtain the second ACSCP model. Next, extract features and generate crowd density maps for the new image to be processed to obtain the crowd density map corresponding to the new image to be processed. Then, input the crowd density map corresponding to the new image to be processed into the second ACSCP model, and obtain the third density map through forward propagation. Finally, use the root mean square error as an evaluation indicator to evaluate the third density map to measure the performance of the model and the accuracy of density estimation. Through this process, crowd density estimation can be effectively performed and the performance of the model can be optimized.
[0091] Crowd density estimation is performed using deep learning technology. By collecting image data sets and preprocessing them, the ResNet network model is used to extract crowd features, and then the U-net structure is used to generate a crowd density map. The second model is obtained by training through the design of the loss function, and the model is used to process new images to be processed and output the third density map. Finally, the root mean square error is used to evaluate the accuracy of the third density map. This crowd density estimation method based on deep learning can estimate crowd density with high accuracy by preprocessing image data, extracting crowd features and generating crowd density maps using deep networks, designing reasonable loss functions, training and evaluating models, while also improving data quality, optimizing model structure and parameters, and providing objective evaluation criteria.
[0092] like Figure 2 As shown, further, the S1 step includes the following steps:
[0093] S11, adjusting the size of the plurality of images to be processed to a preset size value, and using the nearest neighbor interpolation function in OpenCV to implement an image scaling operation to form a scaled image;
[0094] S12, cropping the zoomed image according to a preset cropping value to form a cropped image;
[0095] S13: De-noise the cropped image using mean filtering to form a pre-processed image.
[0096] First, the sizes of the plurality of images to be processed are adjusted to a preset size value, and then the scaled images are cropped according to a preset cropping value, and finally the cropped images are denoised using a mean filter.
[0097] Through the preprocessing operation, the quality of the original image can be improved and more accurate input can be provided for the subsequent steps, thereby enhancing the effect and reliability of the entire crowd density estimation method.
[0098] like Figure 3 As shown, further, the S2 step includes the following steps:
[0099] S21. Use the torchvision library in PyTorch to load the ResNet model.
[0100] S22, inputting the preprocessed image into the ResNet model, and obtaining a feature vector of the image by forward propagation calculation;
[0101] S23. Perform a reshape operation on the eigenvector to reshape the eigenvector into a eigenmap form of a two-dimensional matrix.
[0102] First, use the torchvision library in PyTorch to load the ResNet model to prepare for crowd feature extraction. Then, input the preprocessed image into the ResNet model and calculate through forward propagation to obtain the feature vector of the image. Next, reshape the obtained feature vector to reshape it into the feature map form of a two-dimensional matrix.
[0103] Through the preprocessing operation, the quality of the original image can be improved and more accurate input can be provided for the subsequent steps, thereby enhancing the effect and reliability of the entire crowd density estimation method.
[0104] like Figure 4 As shown, further, the S3 step includes the following steps:
[0105] S31, preparing a group of training samples with labeled crowd density maps, each training sample including a feature map and a corresponding crowd density map;
[0106] S32. Construct a U-net structure generation network including an encoder and a decoder;
[0107] S33, define a mean square error loss function;
[0108] S34, using the prepared training data and the defined loss function, optimizing the network parameters through the back propagation algorithm to train the U-net structure generation network;
[0109] S35. After the training is completed, the trained U-net structure is used to generate a network, the feature map is input into the U-net structure to generate a network, and a crowd density map is obtained by forward propagation calculation.
[0110] First, prepare a set of training samples with labeled crowd density maps. Each training sample includes a feature map and a corresponding crowd density map. Then, build a U-net structure generation network containing an encoder and a decoder to generate a crowd density map. Define a mean square error loss function to measure the difference between the generated crowd density map and the true density map. Next, use the prepared training data and the defined loss function to optimize the network parameters through the back propagation algorithm and train the U-net structure generation network. Finally, after the training is completed, use the trained U-net structure generation network, input the feature map into the network, and calculate through forward propagation to obtain the corresponding crowd density map.
[0111] By using the ResNet network model to extract crowd features in the image and converting them into feature maps, accurate and rich feature inputs are provided for subsequent steps, thereby improving the performance and effect of the entire crowd density estimation method.
[0112] Furthermore, the S4 step includes the following steps:
[0113] S41, calculating the square of the difference between the predicted value and the true value to obtain the error;
[0114] S42, averaging the errors of all samples to obtain an average error;
[0115] S43. Taking the average error as the value of the loss function, the mean square error loss function is expressed as: L(y, y') = 1 / N × Σ(y-y') 2 , where L represents the loss function, y represents the true value, y' represents the predicted value of the model, N represents the number of samples, and Σ represents the summation operation.
[0116] First, the square of the difference between the predicted value and the true value is calculated to obtain the error. Then, the errors of all samples are averaged to obtain the average error. The average error is used as the value of the loss function. The mean square error loss function is expressed as: L(y, y') = 1 / N × Σ(y-y') 2 , where L represents the loss function, y represents the true value, y' represents the predicted value of the model, N represents the number of samples, and Σ represents the summation operation.
[0117] By using the U-net structure to generate a network to convert the feature map into a crowd density map, it can provide more informative and accurate crowd density estimation results.
[0118] Furthermore, the step S5 includes the following steps:
[0119] S51, selecting 70% of the samples from the population density map as training data, and performing normalization and balancing sample data preprocessing;
[0120] S52, initializing the weights and biases of the ResNet network model and the U-net structure generation network;
[0121] S53. Select the Adam optimizer and use randomly initialized learning rate, momentum, and weight decay hyperparameters.
[0122] S54, iteratively training the first ACSCP model using images in the training data set, and adjusting the learning rate, momentum and weight decay hyperparameters using a minimization mean square error loss function to obtain a second ACSCP model;
[0123] S57. Repeat steps S54 to S56 until the maximum number of iterations is reached.
[0124] First, 70% of the samples from the crowd density map are selected as training data, and the normalized and balanced sample distribution data preprocessing is performed. Then, the weights and biases of the ResNet network model and the U-net structure generation network are initialized. The Adam optimizer is selected, and the learning rate, momentum, and weight decay hyperparameters are randomly initialized. The first ACSCP model is iteratively trained using the images in the training dataset, and the learning rate, momentum, and weight decay hyperparameters are adjusted by minimizing the mean square error loss function to obtain the second ACSCP model. This iterative training process is repeated until the preset maximum number of iterations is reached.
[0125] The mean square error loss function designed by this method can quantify the prediction accuracy, obtain the average error value and use it as a measure of the loss function, which is convenient for model training and optimization and improves the accuracy and performance of crowd density estimation.
[0126] Furthermore, the step S54 includes the following steps:
[0127] S541, obtaining a feature map of the image in the training data set through a ResNet network model, and then using a U-net structure to generate a network to convert the feature map into a crowd density map;
[0128] S542, according to the head position information in the annotation file containing the number of heads and the two-dimensional coordinates in the image to be processed, set the pixel points at the corresponding position on the image to 1, and set the other pixel points to 0 to obtain a binary image, and use a Gaussian kernel function to convolve the binary image to obtain a true density map, and calculate the value of the mean square error loss function by comparing the crowd density map with the true density map;
[0129] S543. According to the value of the loss function, the back propagation algorithm is used to calculate the gradient and update the parameters of the model;
[0130] S544. According to the gradient information, use the Adam optimizer to update the values of the learning rate, momentum and weight decay hyperparameters;
[0131] S545. Repeat steps S541 to S544 until a predetermined number of iterations is reached.
[0132] First, the images in the training data set are passed through the ResNet network model to obtain feature maps, and then the U-net structure is used to generate a network to convert the feature maps into crowd density maps. According to the head position information in the annotation file containing the number of heads and two-dimensional coordinates in the image to be processed, the pixels at the corresponding positions on the image are set to 1, and the remaining pixels are set to 0 to obtain a binary image. The binary image is convolved using the Gaussian kernel function to obtain the true density map. By comparing the generated crowd density map with the true density map, the value of the mean square error loss function is calculated. According to the value of the loss function, the gradient is calculated using the back propagation algorithm, and the parameters of the model are updated. According to the gradient information, the Adam optimizer is used to update the values of the learning rate, momentum, and weight decay hyperparameters. This process of converting the image into a crowd density map, calculating the loss, and updating the parameters and hyperparameters is repeated until the predetermined number of iterations is reached.
[0133] By selecting 70% of the training data, performing data preprocessing, initializing the model, selecting a suitable optimizer and minimizing the mean square error loss function, performing iterative training and controlling the number of iterations, the training quality and performance of the model can be effectively improved. It performs well in terms of the accuracy and generalization ability of crowd density estimation, providing reliable support for the implementation and application of this method.
[0134] Furthermore, the step S6 includes the following steps:
[0135] S61, input the feature map and perform multiple convolution operations through the encoder part, and extract image features using convolution kernels of different scales;
[0136] S62, after each convolutional layer of the encoder part, a downsampling operation is performed to increase the receptive field and reduce the size of the feature map;
[0137] S63, passing the feature map obtained by the last layer of the encoder to the decoder part;
[0138] S64, the decoder part gradually performs upsampling operations to restore the size of the feature map to the size of the original input image;
[0139] S65, in the process of upsampling, fusing the feature map in the encoder with the feature map in the decoder to combine information of different scales;
[0140] S66. Convert the output of the decoder into a crowd density map representing different areas in the image with the same size as the input image through a convolutional layer.
[0141] First, the input feature map is convolved multiple times through the encoder part, and image features are extracted using convolution kernels of different scales. After each convolution layer of the encoder part, a downsampling operation is performed to increase the receptive field and reduce the size of the feature map. Then, the feature map obtained by the last layer of the encoder is passed to the decoder part. The decoder part gradually performs upsampling operations to restore the size of the feature map to the size of the original input image. During the upsampling process, the feature map in the encoder is fused with the feature map in the decoder to combine information of different scales. Finally, the output of the decoder is converted into a crowd density map representing different areas in the image with the same size as the input image through a convolution layer.
[0142] Through multiple convolution operations and downsampling, convolution kernels of different scales are used to extract image features, increase the receptive field and reduce the size of the feature map. Then, the feature map of the last layer in the encoder part is passed to the decoder part, and the feature map size is restored to the size of the original input image through step-by-step upsampling operations. In the upsampling process, the feature maps of the encoder and decoder are fused to combine information of different scales. Finally, through a layer of convolution, the output of the decoder is converted into a crowd density map representing different areas in the image with the same size as the input image, which can better extract feature information of different scales, retain the details of the image, and effectively restore the size of the crowd density map and maintain the spatial relationship, thereby improving the accuracy and detail of crowd density estimation.
[0143] Furthermore, the step S7 includes the following steps:
[0144] S71, inputting the crowd density map corresponding to the generated new image to be processed into the second ACSCP model for forward propagation to obtain a second density map;
[0145] S72. Set the pixel points in the crowd density map that are below or above a certain threshold to 0 to remove noise; use a Gaussian filter to smooth the second density map to remove noise and irregular details; use histogram equalization and contrast enhancement to process the second density map to obtain a modified third density map.
[0146] First, the crowd density map corresponding to the generated new image to be processed is input into the second ACSCP model for forward propagation to obtain the second density map. Then, the pixels below or above a certain threshold in the crowd density map are set to 0 to remove noise. The second density map is smoothed using a Gaussian filter to remove noise and irregular details. Next, the second density map is processed using histogram equalization and contrast enhancement methods to obtain a modified third density map.
[0147] By processing the crowd density map, the accuracy of the crowd density map can be improved, noise and irregular details can be removed, and the visual effect of the image can be enhanced, thereby obtaining a more reliable and accurate crowd density estimation result.
[0148] Furthermore, the step S8 includes the following steps:
[0149] S81, according to the head position information in the ACSCP annotation file containing the number of heads and two-dimensional coordinates in the new image to be processed, setting the pixel points at the corresponding position on the image to be 1 and the other pixel points to 0 to obtain a binary image, and convolving the binary image with a Gaussian kernel function to obtain a true ACSCP density map;
[0150] S82, calculating the difference between each pixel value in each of the real ACSCP density maps and the third density map, and obtaining the root mean square error, which represents the crowd density estimation accuracy of the model. The specific calculation formula is as follows:
[0151] Among them, sum represents the sum operation, and N represents the total number of pixels;
[0152] S83. Calculate the average value of the root mean square error as an indicator for evaluating model performance. If the average value of the root mean square error is less than or equal to a preset average threshold, it is evaluated that the density estimation result is consistent with the actual situation.
[0153] First, according to the head position information in the ACSCP annotation file containing the number of heads and two-dimensional coordinates in the new image to be processed, the pixels at the corresponding position on the image are set to 1, and the remaining pixels are set to 0 to obtain a binary image. Then the binary image is convolved using the Gaussian kernel function to obtain the true ACSCP density map. Next, the difference between each pixel value in each true ACSCP density map and the third density map is calculated, and the root mean square error is obtained as an evaluation indicator of the accuracy of the model's crowd density estimation. The root mean square error is calculated by summing the squared error of each pixel and dividing it by the square root of the total number of pixels. Finally, the average value of the root mean square error is calculated as an indicator for evaluating the performance of the model. If the average value of the root mean square error is less than or equal to the preset average threshold, it can be evaluated that the density estimation result is consistent with the actual situation.
[0154] By selecting the average value of the root mean square error to evaluate the population density map, the accuracy and performance of the model can be quantitatively evaluated, providing a reliable indicator to judge the consistency of the density estimation results, thereby making the density estimation of the model more credible and practical.
[0155] So far, the technical solutions of the present invention have been described in conjunction with the preferred embodiments shown in the accompanying drawings. However, it is easy for those skilled in the art to understand that the protection scope of the present invention is obviously not limited to these specific embodiments. Without departing from the principle of the present invention, those skilled in the art can make equivalent changes or substitutions to the relevant technical features, and the technical solutions after these changes or substitutions will fall within the protection scope of the present invention.
[0156] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A crowd density estimation method based on deep learning, It is characterized in that The following steps are involved: S1. Collect an image data set, and perform preprocessing operations on a number of images to be processed in the image data set, each of the images to be processed contains a crowd; S2. Use the ResNet network model to extract the features of the crowd from any image to be processed to form a feature map; S3, using a U-net structure to generate a network to convert the feature map into a crowd density map; S4. Design a loss function to obtain a mean square error loss function; S5. Using 70% of the crowd density map as a training data set and the mean square error loss function to train the first ACSCP model to obtain a second ACSCP model; S6, subjecting the new image to be processed to steps S2 and S3 to obtain a crowd density map corresponding to the new image to be processed; S7, inputting the crowd density map corresponding to the new image to be processed into the second ACSCP model, and the second ACSCP model outputs a third density map; S8. Evaluate the third density map using a root mean square error; The S3 step includes the following steps: S31, preparing a group of training samples with labeled crowd density maps, each training sample including a feature map and a corresponding crowd density map; S32. Construct a U-net structure generation network including an encoder and a decoder; S33, define a mean square error loss function; S34, using the prepared training data and the defined loss function, optimizing the network parameters through the back propagation algorithm to train the U-net structure generation network; S35. After the training is completed, the trained U-net structure is used to generate a network, the feature map is input into the U-net structure generation network, and a crowd density map is obtained by forward propagation calculation; The S5 step includes the following steps: S51, selecting 70% of the samples from the population density map as training data, and performing normalization and balancing sample data preprocessing; S52, initializing the weights and biases of the ResNet network model and the U-net structure generation network; S53. Select the Adam optimizer and use randomly initialized learning rate, momentum, and weight decay hyperparameters. S54, iteratively training the first ACSCP model using images in the training data set, and adjusting the learning rate, momentum and weight decay hyperparameters using a minimization mean square error loss function to obtain a second ACSCP model; S55, repeat step S54 until the maximum number of iterations is reached; The step S54 includes the following steps: S541, obtaining a feature map of the image in the training data set through a ResNet network model, and then using a U-net structure to generate a network to convert the feature map into a crowd density map; S542, according to the head position information in the annotation file containing the number of heads and the two-dimensional coordinates in the image to be processed, set the pixel points at the corresponding position on the image to 1, and set the other pixel points to 0 to obtain a binary image, and use a Gaussian kernel function to convolve the binary image to obtain a true density map, and calculate the value of the mean square error loss function by comparing the crowd density map with the true density map; S543. According to the value of the loss function, the back propagation algorithm is used to calculate the gradient and update the parameters of the model; S544. According to the gradient information, use the Adam optimizer to update the values of the learning rate, momentum and weight decay hyperparameters; S545, repeating steps S541 to S544 until a predetermined number of iterations is reached; The step S6 comprises the following steps: S61, input the feature map and perform multiple convolution operations through the encoder part, and extract image features using convolution kernels of different scales; S62, after each convolutional layer of the encoder part, a downsampling operation is performed to increase the receptive field and reduce the size of the feature map; S63, passing the feature map obtained by the last layer of the encoder to the decoder part; S64, the decoder part gradually performs upsampling operations to restore the size of the feature map to the size of the original input image; S65, in the process of upsampling, fusing the feature map in the encoder with the feature map in the decoder to combine information of different scales; S66, converting the output of the decoder into a crowd density map representing different areas in the image having the same size as the input image through a convolutional layer; The S7 step includes the following steps: S71, inputting the crowd density map corresponding to the generated new image to be processed into the second ACSCP model for forward propagation to obtain a second density map; S72, setting the pixel points in the crowd density map that are lower or higher than a certain threshold to 0 to remove noise; using a Gaussian filter to smooth the second density map to remove noise and irregular details; Processing the second density map using histogram equalization and contrast enhancement to obtain a modified third density map; The step S8 comprises the following steps: S81, according to the head position information in the ACSCP annotation file containing the number of heads and two-dimensional coordinates in the new image to be processed, setting the pixel points at the corresponding position on the image to be 1 and the other pixel points to 0 to obtain a binary image, and convolving the binary image with a Gaussian kernel function to obtain a true ACSCP density map; S82, calculating the difference between each pixel value in each of the real ACSCP density maps and the third density map, and obtaining the root mean square error, which represents the crowd density estimation accuracy of the model. The specific calculation formula is as follows: Root Mean Square Error = , where sum represents the sum operation and N represents the total number of pixels; S83. Calculate the average value of the root mean square error as an indicator for evaluating model performance. If the average value of the root mean square error is less than or equal to a preset average threshold, it is evaluated that the density estimation result is consistent with the actual situation.
2. The crowd density estimation method based on deep learning according to claim 1, It is characterized in that The S1 step includes the following steps: S11, adjusting the size of the plurality of images to be processed to a preset size value, and using the nearest neighbor interpolation function in OpenCV to implement an image scaling operation to form a scaled image; S12, cropping the zoomed image according to a preset cropping value to form a cropped image; S13: De-noise the cropped image using mean filtering to form a pre-processed image.
3. The crowd density estimation method based on deep learning according to claim 2, It is characterized in that The S2 step includes the following steps: S21. Use the torchvision library in PyTorch to load the ResNet model. S22, inputting the preprocessed image into the ResNet model, and obtaining a feature vector of the image by forward propagation calculation; S23. Perform a reshape operation on the eigenvector to reshape the eigenvector into a eigenmap form of a two-dimensional matrix.
4. The crowd density estimation method based on deep learning according to claim 3, It is characterized in that The S4 step includes the following steps: S41, calculating the square of the difference between the predicted value and the true value to obtain the error; S42, averaging the errors of all samples to obtain an average error; S43. Taking the average error as the value of the loss function, the mean square error loss function is expressed as: L(y, y')=1 / N×Σ(y-y')², where L represents the loss function, y represents the true value, y' represents the predicted value of the model, N represents the number of samples, and Σ represents the summation operation.
Citation Information
Patent Citations
A Deep Learning-Based Method for Estimating the Number of People in High-Density Crowds
CN108563975B
Crowd counting method
CN115830537A
