Traffic accident risk assessment method and device based on 2D-CNN deep learning model, and medium
Through the traffic accident risk assessment method based on the 2D-CNN deep learning model, the problem of insufficient traffic accident risk assessment in the existing technology is solved, and the scientific and accurate assessment of traffic accident risks is achieved, and the intuitive risk level probability distribution results are output. .
Patent Information
- Application Number
- CN202410900004.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-05
- Publication Date
- 2025-02-07
AI Technical Summary
It is difficult for the existing technology to conduct in-depth analysis of various factors such as historical data, road conditions, driver behavior, etc. of traffic accidents to identify potential risks, resulting in inaccurate and scientific enough in the assessment of traffic accident risk.
Using the traffic accident risk assessment method based on the 2D-CNN deep learning model, the data of traffic accident case is extracted using chi-square inspection and ANOVA inspection to build a fully connected layer and two-dimensional volume Models of accumulated layers, maximum pooling layers, etc. are trained and tested, and finally output the probability distribution results of traffic accident risk levels.
A more scientific and accurate assessment of traffic accident risks is achieved, and the deep characteristics of traffic accidents can be automatically explored, the generalization ability and calculation depth of the model are improved, and the intuitive risk level probability distribution results are output.
Smart Images

Figure CN119398480A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of traffic management technology, specifically relating to a method, equipment, and medium for assessing traffic accident risks based on a 2D-CNN deep learning model. Background Art
[0002] Traffic accidents are one of the most serious problems facing society today. Traffic accident risk assessment is a crucial link in ensuring road traffic safety. Through in-depth analysis of historical traffic accident data, road conditions, driver behavior, and other factors, potential risks can be identified, and corresponding preventative measures can be developed. This not only helps reduce the occurrence of accidents but also raises public awareness and attention to road traffic safety. However, given the current realities of the traffic system—such as the massive amount of data, fragmented information resources, and complex accident causes—it is necessary to provide more accurate and scientific methods for assessing traffic accident risks by uncovering the deep-seated characteristics of accident causes. Summary of the Invention
[0003] Based on the above background, the present invention provides a method, device and medium for traffic accident risk assessment based on a 2D-CNN deep learning model.
[0004] The technical solution of this invention is as follows:
[0005] A traffic accident risk assessment method based on a 2D-CNN deep learning model includes the following steps:
[0006] S1: Collect traffic accident case data, determine the original risk indicators and original accident types, and obtain raw data;
[0007] The raw data includes information on people, vehicles, environment, and roads related to the traffic accident;
[0008] S2: Process the raw data obtained in step S1, and use the chi-square test and ANOVA test to obtain information data, which includes risk indicators and accident level data.
[0009] S3: Use the information data obtained in step S2 to train and test the traffic accident risk assessment model based on 2D-CNN deep learning.
[0010] The traffic accident risk assessment model includes, in sequence, a fully connected layer, a two-dimensional convolutional layer, a max pooling layer, a two-dimensional convolutional layer, a max pooling layer, and a fully connected layer;
[0011] S4: Use the traffic accident risk assessment model trained and tested in step S3 to assess the traffic accident risk and output the probability distribution with risk level.
[0012] Furthermore, the data information in step S2 is used to train and validate the traffic accident risk assessment model after adaptive sampling.
[0013] Furthermore, the processing of the raw data in step S2 includes the following steps:
[0014] 1) Missing value imputation
[0015] Use k-nearest neighbor interpolation to fill in missing values in the data;
[0016] The specific steps are as follows:
[0017] ① Determine the value of k, that is, select the number of neighboring samples to be used for interpolation. The optimal value of k is usually selected by methods such as cross-validation, and the common range is usually set between 3 and 10.
[0018] ② For each missing value, the distance between it and other samples is calculated using Euclidean distance, and then the imputation value for the missing value is calculated using the KNN algorithm and the missing value is filled.
[0019] Specifically, select the k nearest neighbors and calculate the missing values using the following formula (1). Interpolation:
[0020]
[0021] In the formula: This refers to missing values, v i This represents the data value of the i-th neighbor in the dataset that is closest to the target missing value, and K represents the number of neighbors selected when calculating the missing value;
[0022] For continuous variables: calculate the average of the features corresponding to the k nearest neighbor samples as the interpolation value;
[0023] For discrete variables: select the class with the highest frequency among the k nearest neighbor samples as the interpolation value;
[0024] 2) The data after cleaning in step 1) is normalized using extreme value normalization. The specific formula is as follows: (2)
[0025]
[0026] In the formula: v' represents the normalized data value; v represents the original data value; v min and v max These represent the minimum and maximum values of the risk characteristic data column in the dataset, respectively.
[0027] Furthermore, the processed data from step S2 are subjected to chi-square and ANOVA tests:
[0028] The chi-square test uses the chi2 function to calculate the chi-square value between each discrete feature and the target variable. The larger the chi-square value, the stronger the correlation between the feature and the target variable. The chi2 function is shown in equation (3).
[0029]
[0030] In the formula: X 2 The chi-square value represents the frequency of observation and the frequency of expectation.
[0031] The ANOVA test uses the F-function to calculate the F-value between each continuous feature and the target variable. The larger the F-value, the stronger the correlation between the feature and the target variable. The F-function is shown in equation (4).
[0032]
[0033] In the formula: MS between It is the between-group mean square, representing the variance between different accident types; MS within It is the within-group mean square, representing the variance within the same group of risk indicators.
[0034] Furthermore, in the traffic accident risk assessment model based on 2D-CNN deep learning built in step S3, the following is included:
[0035] 1) Two-dimensional convolutional layer
[0036] Convolution operations are used to extract accident risk features, as shown in equation (5):
[0037]
[0038] In the formula: y k,j This represents the output of the k-th neuron at the j-th position; z s,t The input feature matrix represents the weights at position (s,t); M represents the kernel size; b k represents the bias of the k-th convolutional kernel; f represents the activation function, used to introduce a non-linear function; s and t represent the index variables of the convolutional kernel, indicating the size of the convolutional kernel;
[0039] 2) Fully connected layer
[0040] The complete operation process of the fully connected layer includes linear transformation and nonlinear activation. First, the input is linearly transformed by Equation (6), and then the ReLU activation function of Equation (8) is applied for nonlinear processing.
[0041]
[0042] In the formula: y iThe value of the i-th output neuron is represented by f; f represents the activation function; w ij x j x represents the weight between the i-th output neuron and the j-th input neuron; j b represents the value of the j-th input neuron; i This represents the bias of the i-th output neuron;
[0043] The ReLU activation function is expressed as shown in equation (8):
[0044]
[0045] In the formula: x represents the linear combination result of the convolution operation;
[0046] 3) Pooling layer
[0047] The main features of the data output from the convolutional layer are extracted by the pooling layer, while the feature dimension is compressed. The max pooling formula shown in equation (7) is used:
[0048]
[0049] In the formula: y kij This represents the output value after pooling, located at the (i,j)-th position and the k-th channel of the output matrix; x xpq This represents the value of the input matrix at position (p, q), the k-th channel; R ij This represents the pooling window corresponding to the (i,j)th position in the input matrix.
[0050] Furthermore, the 2D-CNN deep learning model in step S2 also includes a final output layer, which uses the cross-entropy loss function after regression with the Softmax function to obtain the final classification result, thereby outputting the predicted value, i.e. the probability distribution of the traffic accident risk level.
[0051] The expressions for the Softmax function and the cross-entropy loss function are shown in equations (9) and (10) respectively:
[0052]
[0053] In the formula, J represents the cross-entropy loss function; x i This represents the output value of the fully connected layer; y i This indicates three risk assessment levels for traffic accidents: major (especially) accidents, general accidents, and minor accidents; h(x i ) represents the value after regression by the Softmax function, and n is the number of output categories.
[0054] Furthermore, to avoid overfitting, a dropout layer is introduced between the fully connected layer and the output layer. In each training process, the dropout layer randomly drops some neurons and their connections with a certain probability p, where the probability p = 0.5.
[0055] Furthermore, the process of training and testing the traffic accident risk assessment model in step S3 includes the following steps:
[0056] 1) Divide the information data obtained in step S2 into a training set and a test set;
[0057] 2) Adaptive sampling of the training and test sets:
[0058] Training set D tr The proportions of various accident risk levels are uneven, including m groups of samples {x}. i ,y i}, where i = 1, 2, ..., m;
[0059] x i Includes all risk characteristics in Table 1;
[0060] y i ∈Y={0,1,2} is the relationship between x i Corresponding accident risk level labels;
[0061] m s m1 represents the number of samples for the minority accident risk level, and m2 represents the number of samples for the majority accident risk level. s ≤m1,m s +m1=m;x is For the minority class; s is the minority class sample;
[0062] x i1 For the majority class; class imbalance d = m s / m1, d∈(0,1];
[0063] Based on the dataset, general accidents are considered the majority class, while major (especially) accidents and minor accidents are considered the minority class.
[0064] m s It is a scalar representing the number of samples belonging to the minority class, used to describe the number of samples in the dataset that belong to the minority class; x is It is a vector that represents a specific sample of the minority class;
[0065] If d does not satisfy the condition of being less than the preset maximum class imbalance d th Then perform the following calculations:
[0066] ① The total number of accident risk level samples G that needs to be synthesized for each type of accident risk level is required to calculate the corresponding accident risk level:
[0067] G=(m1-m s )β (11)
[0068] In the formula: β∈[0,1], is a parameter used to determine the required balance level;
[0069] ②For the minority class x is That is, major (especially) accidents and minor accidents. Based on the Euclidean distance in n-dimensional space, find K nearest neighbor samples and calculate x. i The proportion of each accident risk level in the K-nearest neighbor sample r i :
[0070]
[0071] In the formula: Δi represents a metric, indicating the performance of the minority class sample x. i Among the K-nearest neighbors, the majority class x i1 The number of samples; K can be any positive integer;
[0072] ③ Comparison ratio r i After standardization, the result is:
[0073]
[0074] In the formula: Indicates the ratio after standardization;
[0075] ④ Calculate x for each minority class sample i The final number of samples to be synthesized, g i for:
[0076]
[0077] ⑤From x i Randomly select one minority class x from its K nearest neighbors. zi The synthetic data sample is as follows:
[0078] s i =x i +(x zi -x i )λ (15)
[0079] In the formula: x zi -x i λ represents the difference component in n-dimensional space; λ is a random number satisfying λ∈[0,1]; s i This represents a new data sample generated through synthesis;
[0080] ⑥ Repeat the synthesis steps until the required number of samples (g) for each minority class sample is met. i ;
[0081] 3) Use the adaptively sampled training and test sets from step 2) to train and test the traffic accident risk assessment model. The specific steps are as follows:
[0082] ① Use the training set to train the convolutional neural network, extract information and learn accident features through the convolutional layer, and use the backpropagation time series algorithm (BPTT) to backpropagate the training error and continuously update the model parameters;
[0083] ② The classification probability of the accident risk level is obtained by using the Softmax function. In order to prevent the model from overfitting, the model parameters are continuously adjusted by gradient descent to obtain the optimal parameters of the 2D-CNN deep learning model.
[0084] ③ Determine whether the number of iterations of the model has reached the preset threshold. If yes, proceed to the next step; otherwise, repeat step ①.
[0085] ④ Verify the performance of the trained model using the test set, calculate the evaluation metrics, and output the evaluation results to complete the process; the evaluation results include the calculation of accuracy, sensitivity, and specificity.
[0086] Furthermore, to prevent the gradient vanishing problem during model training, a batch normalization (BN) layer is added after the second convolutional layer, as shown in equation (11):
[0087]
[0088] In the formula: y i This represents the output after batch normalization; x i Represents input features; Represents the standardized input features; γ represents the scaling parameter; β represents the translation parameter; BN γ,β (x i ) indicates batch normalization operation.
[0089] Based on the same inventive concept, this invention provides a traffic accident risk assessment system based on a 2D-CNN deep learning model, which includes a data acquisition module, a data processing module, a model training module, and an evaluation module.
[0090] The data acquisition module is used to acquire traffic accident case data;
[0091] The data processing module performs missing value imputation, maximum / minimum value normalization, chi-square test and ANOVA test on the data acquired by the data acquisition module, and performs adaptive sampling on the divided training set and test set data.
[0092] The model training module uses the training and test sets processed by the data module to train and test the traffic accident risk assessment model, thereby constructing the traffic accident assessment model.
[0093] The assessment module evaluates the risks of traffic accidents based on traffic accident information using a traffic accident assessment model and outputs the results with a probability distribution of risk levels.
[0094] Based on the same inventive concept, the present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the above-described method for assessing traffic accident risks based on a 2D-CNN deep learning model.
[0095] Based on the same inventive concept, the present invention also provides a computer-readable storage medium storing computer instructions, which are used to cause a processor to execute the above-described method for assessing traffic accident risks based on a 2D-CNN deep learning model.
[0096] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0097] The traffic accident risk assessment model based on 2D-CNN deep learning built in this invention, after training, determines the optimal model parameters, enabling a more scientific and accurate assessment of traffic accident risks. It can automatically mine deep features of traffic accidents through convolutional layers, increasing the computational depth of the convolutional neural network. By adding a batch normalization (BN) layer to regularize the data distribution, the impact of data distribution bias can be reduced. Secondary dimensionality reduction is performed using pooling layers, and dropout is introduced to improve the model's generalization ability. Finally, the accident risk assessment level is determined through the Softmax function, ultimately outputting an intuitive probability distribution result of the traffic accident risk level. Attached Figure Description
[0098] Figure 1 This is a chi-square test chart according to an embodiment of the present invention;
[0099] Figure 2 This is an ANOVA test chart from an embodiment of the present invention;
[0100] Figure 3 This is a flowchart of the traffic accident risk assessment method based on a 2D-CNN deep learning model (including the interface operation process) of the present invention;
[0101] Figure 4 This is an interface diagram of a traffic accident risk assessment system based on a 2D-CNN model, according to an embodiment of the present invention. Detailed Implementation
[0102] To make the objectives, technical solutions, and advantages of the present invention clearer, the present invention will be further described in detail below with reference to its embodiments; it should be understood that the specific embodiments described herein are only for explaining the present invention and are not intended to limit the present invention.
[0103] Example 1: This example uses 20,006 traffic accident cases in Guilin City from 2016 to 2020 as examples to illustrate the implementation of the present invention.
[0104] A traffic accident risk assessment method based on a 2D-CNN deep learning model includes the following steps:
[0105] S1: Collect traffic accident case data, determine the original risk indicators and original accident types to obtain raw data; the raw data includes information on personnel related to the traffic accident (such as gender, age, education level), vehicle information (such as mode of transportation, drunk driving, vehicle speed), environmental information (such as accident time, weather, visibility) and road information (such as central divider, road type, traffic signal method).
[0106] S2: Process the raw data obtained in step S1, and use the chi-square test and ANOVA test to obtain information data, which includes risk indicators and accident level data.
[0107] In this step, the K-nearest neighbor interpolation algorithm is used to fill in missing values and normalize the original data, thus performing data preprocessing to ensure the effectiveness and accuracy of subsequent modeling. The specific steps are as follows:
[0108] 1) Missing value imputation
[0109] Because a large amount of data was missing in the collected traffic accident data, the k-nearest neighbor interpolation algorithm was used to supplement the data.
[0110] Use k-nearest neighbor interpolation to fill in missing values in the data;
[0111] The specific steps are as follows:
[0112] ① Determine the value of k, that is, select the number of neighboring samples to be used for interpolation. The optimal value of k is usually selected by methods such as cross-validation, and the common range is usually set between 3 and 10.
[0113] ② For each missing value, the distance between it and other samples is calculated using Euclidean distance, and then the imputation value for the missing value is calculated using the KNN algorithm and the missing value is filled.
[0114] Specifically, select the k nearest neighbors and calculate the missing values using the following formula (1). Interpolation:
[0115]
[0116] Where: This refers to missing values, v i This represents the data value of the i-th neighbor in the dataset that is closest to the target missing value, and K represents the number of neighbors selected when calculating the missing value;
[0117] For continuous variables: calculate the average of the features corresponding to the k nearest neighbor samples as the interpolation value;
[0118] For discrete variables: select the class with the highest frequency among the k nearest neighbor samples as the interpolation value;
[0119] 2) The data after cleaning in step 1) is normalized using extreme value normalization. The specific formula is as follows: (2)
[0120]
[0121] In the formula: v' represents the normalized data value; v represents the original data value; v min and v max These represent the minimum and maximum values of the data column for this risk characteristic in the dataset, respectively.
[0122] Because the collected traffic accident risk features have a large data dimension, the raw data needs to be normalized before being input into the 2D-CNN model for training. The raw data is transformed into data between [0,1] by the maximum and minimum values, so as to achieve fast convergence of the loss function.
[0123] This step also includes performing chi-square and ANOVA tests on the processed data:
[0124] The traffic accident case dataset in this embodiment contains 49 feature variables. However, most models cannot handle high-dimensional data, necessitating effective feature selection methods to retain the key features as input for the accident risk assessment model. Chi-square test and ANOVA test were used for feature extraction for both discrete and continuous data in the dataset.
[0125] The chi-square test uses the chi2 function to calculate the chi-square value between each discrete feature and the target variable. The larger the chi-square value, the stronger the correlation between the feature and the target variable. The chi2 function is shown in equation (3).
[0126]
[0127] In the formula: Observed is the observed frequency, and Expected is the expected frequency;
[0128] The ANOVA test is used to examine the association between a discrete variable and a continuous variable. Specifically, it uses the F-function to calculate the F-value between each continuous feature and the target variable. The larger the F-value, the stronger the association between the feature and the target variable. The F-function is shown in equation (4).
[0129]
[0130] In the formula: MS between It is the between-group mean square, representing the variance between different accident types; MS within It is the within-group mean square, representing the variance within the same group of risk indicators.
[0131] In this embodiment, based on the basic information of the original risk indicators and accident risk levels, feature selection is performed based on the chi-square value and F value. For discrete features, risk indicators with a chi-square value greater than 10 are retained, while for continuous features, the first two are selected, resulting in a total of 27 high-risk features, as shown in Table 1.
[0132] Table 1. Characteristic Variable Assignments
[0133]
[0134]
[0135] S3: Use the information data obtained in step S2 to train and test the traffic accident risk assessment model based on 2D-CNN deep learning.
[0136] The traffic accident risk assessment model described in this step includes, in sequence, a fully connected layer, a two-dimensional convolutional layer, a max pooling layer, another two-dimensional convolutional layer, a max pooling layer, a fully connected layer, and an output layer;
[0137] Specifically as follows:
[0138] 1) Two-dimensional convolutional layer
[0139] The role of convolutional layers is to perform convolution operations on the input data to extract accident risk features. Each convolutional kernel is regarded as a specific risk feature detector. Each convolutional kernel (weight matrix) traverses the input data with a certain stride, extracting accident features at different spatial locations. Different convolutional kernels extract different risk features, thereby transforming the original traffic data into a feature map containing multiple risk features, resulting in multi-layer matrix data with risk features.
[0140] It is performed as follows (5):
[0141]
[0142] Where: y k,j This represents the output of the k-th neuron at the j-th position; z s,t The input feature weights are represented at position (s,t); M represents the kernel size; b k represents the bias of the k-th convolutional kernel; f represents the activation function, used to introduce a non-linear function; s and t represent the index variables of the convolutional kernel, indicating the size of the convolutional kernel.
[0143] In this embodiment, the number of convolutional kernels is 32, the window size is 4×4, and the stride is 2×2. The number of convolutional kernels was determined by trying different numbers of kernels and selecting the best-performing parameters. The window size is an empirical value; 4×4 is a medium size that captures a lot of spatial features without excessively increasing computational complexity. The stride is also an empirical value; a 2×2 stride strikes a balance between reducing output size and preserving feature details.
[0144] In this embodiment, the ReLU activation function is used after the convolution operation to achieve a nonlinear transformation of the convolutional data, mapping the convolutional data to a new feature space. This enables the model to capture and represent more complex patterns and structures, which helps improve the model's prediction performance. The expression is shown in Equation (6), i.e., a fully connected layer.
[0145] 2) Fully connected layer
[0146] The complete operation of a fully connected layer includes linear transformation and nonlinear activation. First, the input of formula (6) is linearly transformed, and then the activation function ReLU of formula (8) is applied for nonlinear processing. The linear transformation formula (6) represents the output formula of the fully connected layer, reflecting the result of the input after linear transformation and bias adjustment; the nonlinear activation formula (8) represents the activation function ReLU, which is used to perform nonlinear processing on the result of the linear transformation.
[0147] The fused feature vectors are concatenated in a specific order, that is, the risk features extracted by the convolutional layer and the pooling layer are combined and classified, as shown in Equation (6):
[0148]
[0149] In the formula: y i The value of the i-th output neuron is represented by f; f represents the activation function; w ij x j x represents the weight between the i-th output neuron and the j-th input neuron; j b represents the value of the j-th input neuron; iThis represents the bias of the i-th output neuron;
[0150] After the convolution operation, the ReLU activation function is used to achieve a non-linear transformation of the convolutional data, mapping the convolutional data to a new feature space, enabling the model to capture and represent more complex patterns and structures, which helps to improve the model's predictive performance.
[0151] The ReLU activation function is expressed as shown in equation (8):
[0152]
[0153] In the formula: x represents the linear combination result of the convolution operation;
[0154] In a fully connected layer, the values x of all input neurons j After weighting, plus the bias b i Then, the output value y is obtained through the activation function f. i .
[0155] 3) Pooling layer
[0156] The pooling layer extracts the main features from the output data of the convolutional layer while compressing the feature dimensionality, thereby reducing computation and effectively preventing overfitting. The pooling layer uses max pooling, where the convolutional kernel slides across the target data and extracts the maximum value in each region. A stride of 1×1 and a pooling size of 1×2 are set to reduce redundant data by lowering the dimensionality, thus preserving the most relevant information.
[0157] It adopts the maximum pooling formula shown in equation (7):
[0158]
[0159] In the formula: y kij This represents the output value after pooling, located at the (i,j)-th position and the k-th channel of the output matrix; x xpq This represents the value of the input matrix at position (p, q), the k-th channel; R ij This represents the pooling window corresponding to the (i,j)th position in the input matrix.
[0160] 5) Output layer
[0161] The output layer uses the cross-entropy loss function after regression with the Softmax function to obtain the final classification result, and then outputs the predicted value, which is the probability distribution of the traffic accident risk level, ranging from 0 to 1. The category with the highest probability value is taken as the traffic accident risk assessment level to which the sample belongs.
[0162] The expressions for the Softmax function and the cross-entropy loss function are shown in equations (9) and (10) respectively:
[0163]
[0164] In the formula, J represents the cross-entropy loss function; x i This represents the output value of the fully connected layer; y i This indicates three risk assessment levels for traffic accidents: major (especially) accidents, general accidents, and minor accidents; h(x i ) represents the value after regression by the Softmax function, and n is the number of output categories.
[0165] Furthermore, to avoid overfitting, a dropout layer is introduced between the fully connected layer and the output layer. In each training process, the dropout layer randomly discards certain neurons and their connections with a certain probability p. The probability p is configured as 0.5, which eliminates some hidden neurons in the network to improve the model's generalization ability.
[0166] To prevent the vanishing gradient problem during model training, a batch normalization (BN) layer is added after the convolutional layer, as shown in equation (11):
[0167]
[0168] In the formula: y i This represents the output after batch normalization; x i Represents input features; Represents the standardized input features; γ represents the scaling parameter; β represents the translation parameter; BN γ,β (x i ) indicates batch normalization operation.
[0169] The next step is to train and test the traffic accident risk assessment model, which includes the following steps:
[0170] 1) Divide the information data obtained in step S2 into a training set and a test set in an 8:2 ratio;
[0171] 2) Adaptive sampling of the training and testing sets:
[0172] In traffic accident risk assessment, models tend to favor categories with a larger number of predictions. Since general accidents are more common than serious accidents, the model's ability to predict the risk of serious accidents is relatively poor. Therefore, using the ADASYN method can generate more samples of accident risk levels for a smaller number of categories, thereby improving the model's ability to identify all accident risk levels.
[0173] The ADASYN method distributes the difficulty of learning from different minority samples according to weights, synthesizing more training data for the minority of more difficult samples. ADASYN supports both binary and multi-class classification, not only reducing learning bias caused by the original imbalanced data distribution, but also adaptively shifting the decision boundary to focus on the more difficult samples.
[0174] Training set D tr The proportions of various accident risk levels are uneven, including m groups of samples {x}. i ,y i}, where i = 1, 2, ..., m;
[0175] x i Includes all risk characteristics in Table 1;
[0176] y i ∈Y={0,1,2} is the relationship between x i Corresponding accident risk level labels;
[0177] m s m1 represents the number of samples for the minority accident risk level, and m2 represents the number of samples for the majority accident risk level. s ≤m1,m s +m1=m;x is For the minority class, s represents the minority class sample;
[0178] x i1 For the majority class; class imbalance d = m s / m1, d∈(0,1];
[0179] Based on the dataset, general accidents are considered the majority class, while major (especially) accidents and minor accidents are considered the minority class.
[0180] m s It is a scalar representing the number of samples belonging to the minority class, used to describe the number of samples in the dataset that belong to the minority class; x is It is a vector that represents a specific sample of the minority class;
[0181] If d does not satisfy the condition of being less than the preset maximum class imbalance d th Then perform the following calculations:
[0182] ① The total number of accident risk level samples G that needs to be synthesized for each type of accident risk level is required to calculate the corresponding accident risk level:
[0183] G=(m1-m s )β (11)
[0184] In the formula: β∈[0,1], is a parameter used to determine the required balance level;
[0185] ②For the minority class x is That is, major (especially) accidents and minor accidents. Based on the Euclidean distance in n-dimensional space, find K nearest neighbor samples and calculate x. i The proportion of each accident risk level in the K-nearest neighbor sample r i :
[0186]
[0187] In the formula: Δi represents a metric, indicating the performance of the minority class sample x. i Among the K-nearest neighbors, the majority class x i1 The number of samples; K can be any positive integer;
[0188] ③ Comparison ratio r i After standardization, the result is:
[0189]
[0190] In the formula: Indicates the ratio after standardization;
[0191] ④ Calculate x for each minority class sample i The final number of samples to be synthesized, g i for:
[0192]
[0193] ⑤From x i Randomly select one minority class x from its K nearest neighbors. zi The synthetic data sample is as follows:
[0194] s i =x i +(x zi -x i )λ (15)
[0195] In the formula: x zi -x i Let be the difference components in n-dimensional space; λ is a random number satisfying λ∈[0,1], s i This represents a new data sample generated through synthesis;
[0196] ⑥ Repeat the synthesis steps until the required number of samples (g) for each minority class sample is met. i ;
[0197] 3) Use the adaptively sampled training and test sets from step 2) to train and test the traffic accident risk assessment model. The specific steps are as follows:
[0198] ① Use the training set to train the convolutional neural network, extract information and learn accident features through the convolutional layer, and use the backpropagation time series algorithm (BPTT) to backpropagate the training error and continuously update the model parameters;
[0199] ② The classification probability of the accident risk level is obtained by using the Softmax function. In order to prevent the model from overfitting, the model parameters are continuously adjusted by gradient descent to obtain the optimal parameters of the 2D-CNN deep learning model.
[0200] ③ Determine whether the number of iterations of the model has reached the preset threshold. If yes, proceed to the next step; otherwise, repeat step ①.
[0201] ④ Verify the performance of the trained model using the test set, calculate the evaluation metrics, and output the evaluation results. The process ends here. The evaluation results include the calculation of accuracy, sensitivity, and specificity.
[0202] During the training process, the number of iterations (Epoch) was set to 100, the training batch size was 4, and the learning rate was 0.001.
[0203] In this embodiment, after training and testing the 2D-CNN deep learning model, the structure and parameters of the prediction model based on the 2D-CNN deep learning model are shown in Table 2.
[0204] Table 2: Model Structure and Parameter Table
[0205]
[0206] S4: Based on the traffic accident information to be estimated (see appendix) Figure 4 As shown in the interface, the traffic accident risk assessment model trained and tested in step S3 is used to assess the traffic accident risk and give the results of the probability distribution with risk level.
[0207] The traffic accident risk assessment model built in step S3 first extracts risk features from traffic data through convolutional layers, then downsamples these features using pooling layers to reduce feature dimensionality and extract key risk features. Finally, the model integrates these risk features in a fully connected layer and performs classification. The model then uses the Softmax function to transform the output of the fully connected layer into a probability distribution for each risk level, thereby achieving an accurate assessment of traffic accident risk.
[0208] Example 2: This example demonstrates a traffic accident risk assessment method based on a 2D-CNN deep learning model according to the present invention. A system was developed using the PYQT5 development interface, as shown in the attached diagram. Figure 4 As shown, attached Figure 3 The process includes the operation of the system interface.
[0209] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A traffic accident risk assessment method based on a 2D-CNN deep learning model, characterized in that: It includes the following steps: S1: Collect traffic accident case data, determine original risk indicators and original accident types, and obtain original data; the original data includes relevant personnel information, vehicle information, environmental information and road information in the traffic accident; S2: Processing the original data obtained in step S1, and using chi-square test and ANOVA test to obtain information data, the information data including risk indicators and accident level data information; S3: Using the information data obtained in step S2 to train and test the traffic accident risk assessment model based on 2D-CNN deep learning; The traffic accident risk assessment model includes a fully connected layer, a two-dimensional convolutional layer, a maximum pooling layer, a two-dimensional convolutional layer, a maximum pooling layer, and a fully connected layer in sequence; S4: Use the traffic accident risk assessment model trained and tested in step S3 to assess the traffic accident risk, and output a result with a probability distribution of risk levels.
2. A traffic accident risk assessment method based on a 2D-CNN deep learning model according to claim 1, characterized in that: The processing of the original data in step S2 includes the following steps: 1) Missing value filling Use the k nearest neighbor interpolation method to fill in missing values in the data; The specific steps are as follows: ① Determine the value of k, that is, select the number of neighboring samples for interpolation. The k value is generally selected by cross-validation and other methods. The common range is generally set to 3-10; ② For each missing value, use the Euclidean distance to calculate its distance to other samples, then use the KNN algorithm to calculate the filling value of the missing value and fill the missing value; Specifically, select the k nearest neighbors and calculate the missing value using the following formula (1): Interpolation: Where: refers to missing values, v i represents the data value of the i-th neighbor closest to the target missing value in the data set, and K represents the number of neighbors selected when calculating the missing value; For continuous variables: calculate the average value of the corresponding features of the k nearest neighbor samples as the interpolation value; For discrete variables: select the category with the highest frequency among the k nearest neighbor samples as the interpolation value; 2) The data cleaned in step 1) is normalized using the maximum value normalization. The specific formula is as follows (2): In the formula: v' represents the normalized data value; v represents the original data value; v min and v max Respectively represent the minimum and maximum values of the risk feature data column in the data set; The processed data in step S2 are subjected to chi-square test and ANOVA test as follows: The chi-square test is to calculate the chi-square value between each discrete feature and the target variable through the chi2 function. The larger the chi-square value, the stronger the correlation between the feature and the target variable. The chi2 function is specifically shown in formula (3): Where: X 2 is the chi-square value, Observed is the observed frequency, and Expected is the expected frequency; The ANOVA test uses the F function to calculate the F value between each continuous feature and the target variable. The larger the F value, the stronger the correlation between the feature and the target variable. The F function is specifically shown in formula (4): Where: MS between is the between-group mean square, which represents the variance between accident types in different groups; MS within is the within-group mean square, which represents the variance within the same group of risk indicators.
3. The traffic accident risk assessment method based on the 2D-CNN deep learning model according to claim 1 is characterized in that: In the traffic accident risk assessment model based on 2D-CNN deep learning built in step S3; That: 1) 2D convolutional layer The convolution operation extracts the accident risk characteristics, which is performed as follows: Where: y k,j represents the output of the kth neuron at the jth position; z s,t represents the weight of the input feature matrix at position (s, t); M represents the convolution kernel size; b k represents the bias of the kth convolution kernel; f represents the activation function, which is used to introduce nonlinear functions; s and t represent the index variables of the convolution kernel, indicating the size of the convolution kernel; 2) Fully connected layer The fully connected layer includes linear transformation and nonlinear activation. First, the input is linearly transformed by formula (6), and then the activation function ReLU is applied to perform nonlinear processing in formula (8); Where: y i represents the value of the i-th output neuron; f: represents the activation function; w ij x j represents the weight between the i-th output neuron and the j-th input neuron; x j represents the value of the jth input neuron; b i represents the bias of the i-th output neuron; The ReLU activation function is expressed as follows: Where: x represents the linear combination result of the convolution operation; 3) Pooling layer The main features of the data output from the convolutional layer are extracted through the pooling layer, while compressing the feature dimension. The maximum pooling formula shown in the following formula (7) is adopted: Where: y kij Represents the output value after pooling, located at the (i, j)th position of the output matrix, the kth channel; x xpq Represents the value of the input matrix at position (p, q), the kth channel; R ij Represents the pooling window corresponding to the (i, j)th position in the input matrix.
4. The traffic accident risk assessment method based on the 2D-CNN deep learning model according to claim 3 is characterized in that: The traffic accident risk assessment model also includes an output layer, which uses a cross entropy loss function after Softmax function regression to obtain a final classification result, thereby outputting a predicted value, that is, a probability distribution of the traffic accident risk level; The expressions of the Softmax function and the cross entropy loss function are shown in the following equations (9) and (10), respectively: Where J represents the cross entropy loss function; x i Represents the output value of the fully connected layer; y i Indicates the risk assessment levels of three types of traffic accidents, namely major (extraordinary) accidents, general accidents, and minor accidents; h(x i ) represents the value after Softmax function regression, and n is the number of output categories.
5. The traffic accident risk assessment method based on the 2D-CNN deep learning model according to claim 4 is characterized in that: In order to avoid overfitting, a dropout layer is introduced between the fully connected layer and the output layer. That is, during each training process, the dropout layer will randomly drop certain neurons and their connections with a certain probability p, and the configuration probability p = 0.
5.
6. The traffic accident risk assessment method based on the 2D-CNN deep learning model according to claim 1 is characterized in that: The process of training and testing the traffic accident risk assessment model in step S3 includes the following steps: 1) Divide the information data obtained in step S2 into a training set and a test set; 2) Adaptive sampling of training and test sets: Training set D tr , the proportion of various accident risk levels is unbalanced, including m groups of samples {x i ,y i }, where i = 1, 2, ..., m; x i Contains all risk characteristics in Table 1; y i ∈Y={0,1,2} is the same as x i Corresponding accident risk level label; m s is the number of samples of minority accident risk level, m1 is the number of samples of majority accident risk level, and m s ≤m1,m s +m1=m;x is is the minority class; s is the minority class sample; x i1 is the majority class; class imbalance d = m s / m1,d∈(0,1]; According to the data set, general accidents are regarded as the majority class, and major (extraordinary) accidents and minor accidents are regarded as the minority class. m s Is a scalar, which represents the number of samples in the minority class, used to describe the number of samples belonging to the minority class in the data set; x is is a vector representing a specific sample of the minority class; If d does not satisfy the preset maximum class imbalance d th , then perform the following calculations: ① To calculate each type of accident risk level, the total number of samples G corresponding to the accident risk level needs to be synthesized: G=(m1-m s )b (11) Where: β∈[0,1] is the parameter used to formulate the required balance level; ②For the minority class x is , that is, major (extraordinary) accidents and minor accidents, find K nearest neighbor samples according to the Euclidean distance in n-dimensional space, and calculate x i The proportion of each type of accident risk level in the K nearest neighbor samples r i : Where: Δi represents a metric, which means that in the minority class sample x i Among the K nearest neighbors, most of them belong to category x i1 The number of samples; K can be any positive integer; ③ Contrast ratio r i After standardization, we get: Where: represents the ratio after standardized processing; ④ Calculate each minority class sample x i The final number of samples to be synthesized is g i for: ⑤From x i Randomly select a minority class x from the K neighboring samples of zi , the synthetic data samples are as follows: s i =x i +(x zi -x i )λ (15) Where: x zi -x i is the difference in n-dimensional space; λ is a random number, satisfying λ∈[0,1]; s i represents new data samples generated by synthesis; ⑥ Repeat the synthesis steps until the number of samples g required to be synthesized for each minority class sample is met i ; 3) Use the training set and test set after adaptive sampling in step 2) to train and test the traffic accident risk assessment model. The specific steps are as follows: ① Use the training set to train the convolutional neural network, extract information and learn accident characteristics through the convolution layer, and use the back propagation through time series (BPTT) algorithm to back propagate the training error and continuously update the model parameters; ② The classification probability of the accident risk level is obtained by using the Softmax function. In order to prevent the model from overfitting, the parameters of the model are continuously adjusted by gradient descent to obtain the optimal parameters of the 2D-CNN deep learning model; ③ Determine whether the number of iterations of the model reaches the preset threshold. If yes, run the next step, otherwise repeat step ①; ④ The test set verifies the performance of the trained model, calculates the evaluation index, and outputs the evaluation results, then the process ends; the evaluation results include the calculation accuracy, sensitivity and specificity.
7. A traffic accident risk assessment method based on a 2D-CNN deep learning model according to claim 6, characterized in that: In order to prevent the problem of gradient disappearance during model training, batch normalization processing, namely BN layer, is added after the second convolution layer, as shown in the following formula (11): Where: y i represents the output after batch normalization; x i Represents input features; Represents the standardized input features; γ scaling parameter; β translation parameter; BN γ,β (x i ) represents a batch normalization operation.
8. A traffic accident risk assessment system based on a 2D-CNN deep learning model, characterized in that: It includes a data acquisition module, a data processing module, a model training module, and an evaluation module; The data acquisition module is used to acquire traffic accident case data; The data processing module performs missing value filling, maximum value normalization, chi-square test and ANOVA test processing on the data acquired by the data acquisition module, and performs adaptive sampling processing on the divided training set and test set data; The model training module uses the training set and test set data processed by the data module to train and test the traffic accident risk assessment model and build a traffic accident assessment model; The evaluation module evaluates the risk of the traffic accident based on the traffic accident information through the traffic accident evaluation model and outputs the result of the probability distribution with the risk level.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, a traffic accident risk assessment method based on a 2D-CNN deep learning model is implemented as described in any one of claims 1-7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement a traffic accident risk assessment method based on a 2D-CNN deep learning model as described in any one of claims 1 to 7 when executed.