Traffic Flow Prediction Method, Device, Equipment and Medium Based on Attention Mechanism

Through the traffic flow prediction method based on the attention mechanism, the traffic flow diagram is processed using the spatiotemporal encoder and the multi-head self-attention mechanism to generate the traffic flow prediction value at the next moment, solving the problems of cumbersome acquisition process and manual intervention in the existing technology, and achieving efficient and reliable prediction.

CN119741834BActive Publication Date: 2025-07-25湖南工商大学
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510228757.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-02-28
Publication Date
2025-07-25
Estimated Expiration
2045-02-28

AI Technical Summary

Technical Problem

The process of obtaining traffic flow prediction values of the existing target traffic flow chart at the next moment is cumbersome, consuming a lot of human resources and time, and being easily affected by manual intervention, resulting in inefficiency.

Method used

The traffic flow prediction method based on the attention mechanism is adopted, and the preset traffic flow diagram and the enhanced preset traffic flow diagram are processed through the spatiotemporal encoder and the multi-head self-attention mechanism, and the traffic flow prediction value of the target traffic flow diagram at the next moment is generated. The model parameter adjustment and loss value optimization are used to reduce manual intervention.

Benefits of technology

It improves the efficiency of obtaining traffic flow predicted values, reduces acquisition time, and improves the reliability of predicted values, avoiding the impact of manual intervention.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119741834B_ABST
    Figure CN119741834B_ABST
Patent Text Reader

Abstract

The present invention relates to the fields of intelligent transportation and artificial intelligence, and discloses a traffic flow prediction method, device, equipment and medium based on an attention mechanism. The method includes: processing a preset traffic flow map and an enhanced preset traffic flow map through a spatio-temporal encoder and a multi-head self-attention mechanism in a traffic flow prediction model to obtain a first positive sample pair, a first negative sample pair, a second positive sample pair, and a second negative sample pair; splicing the feature vectors of the first positive sample pair and the second positive sample pair to obtain a first spliced feature, and determining a third loss value based on the first spliced feature; adding the first loss value, the second loss value, and the third loss value to obtain a target loss value; selecting a traffic flow prediction model using the adjusted model parameters as the target model, and generating a traffic flow prediction value for the target traffic flow map at the next moment through the target model. The present invention is beneficial to improving the prediction performance of the traffic flow prediction model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the fields of intelligent transportation and artificial intelligence, and particularly to a traffic flow prediction method, device, equipment and medium based on an attention mechanism. Background Art

[0002] Today, with the continuous progress of intelligent transportation systems, the importance of traffic prediction has become increasingly prominent. How to alleviate traffic congestion without increasing the number of roads has become an urgent challenge to be solved. To address this challenge, the intelligent transportation system needs to obtain the predicted traffic flow value of the target traffic flow map at the next moment, because the predicted traffic flow value of the target traffic flow map at the next moment can help the intelligent transportation system anticipate road congestion in advance and optimize the signal control strategy, thereby effectively alleviating traffic pressure.

[0003] However, the existing process of obtaining the predicted traffic flow value of the target traffic flow map at the next moment is cumbersome, which is not conducive to improving the acquisition efficiency of the predicted traffic flow value of the target traffic flow map at the next moment. The reason is that the existing technology mainly uses the manual acquisition method to obtain the predicted traffic flow value of the target traffic flow map at the next moment, and the manual acquisition method will consume a large amount of human and time resources, increase the acquisition time of the predicted traffic flow value of the target traffic flow map at the next moment, and is easily affected by manual intervention. Therefore, it is not conducive to improving the acquisition efficiency of the predicted traffic flow value of the target traffic flow map at the next moment. Summary of the Invention

[0004] The present invention provides a traffic flow prediction method, device, computer equipment and storage medium based on an attention mechanism to solve the technical problem that the existing process of obtaining the predicted traffic flow value of the target traffic flow map at the next moment is cumbersome and not conducive to improving the acquisition efficiency of the predicted traffic flow value of the target traffic flow map at the next moment.

[0005] In a first aspect, a traffic flow prediction method based on an attention mechanism is provided, including:

[0006] Obtain a preset traffic flow map and an enhanced preset traffic flow map;

[0007] Process the preset traffic flow map and the enhanced preset traffic flow map through a spatio-temporal encoder and a multi-head self-attention mechanism in the traffic flow prediction model to obtain a first positive sample pair, a first negative sample pair, a second positive sample pair, and a second negative sample pair;

[0008] Determine a first loss value according to the first positive sample pair and the first negative sample pair, and determine a second loss value according to the second positive sample pair and the second negative sample pair;

[0009] Concatenate the feature vectors of the first positive sample pair and the second positive sample pair to obtain a first concatenated feature, and determine a third loss value based on the first concatenated feature and a predefined determination method;

[0010] Add the first loss value, the second loss value, and the third loss value to obtain a target loss value, and adjust the model parameters to obtain a reduced target loss value;

[0011] When the reduced target loss value meets the preset conditions, select the traffic flow prediction model using the adjusted model parameters as the target model, and generate the traffic flow prediction value of the target traffic flow map at the next moment through the target model.

[0012] Further, the process of processing the preset traffic flow map and the enhanced preset traffic flow map through the spatio-temporal encoder and the multi-head self-attention mechanism in the traffic flow prediction model to obtain the first positive sample pair, the first negative sample pair, the second positive sample pair, and the second negative sample pair includes:

[0013] Encode the preset traffic flow map through the spatio-temporal encoder in the traffic flow prediction model to obtain a first data matrix, and encode the enhanced target traffic flow map to obtain a second data matrix;

[0014] Use the multi-head self-attention mechanism to select adjacent road segments at the same intersection in the first data matrix and the second data matrix as the first positive sample pair, select non-adjacent road segments at the same intersection in the first data matrix and the second data matrix as the first negative sample pair, select the same time period at the same intersection in the first data matrix and the second data matrix as the second positive sample pair, and select different time periods at the same intersection in the first data matrix and the second data matrix as the second negative sample pair.

[0015] Further, the process of determining the first loss value according to the first positive sample pair and the first negative sample pair, and determining the second loss value according to the second positive sample pair and the second negative sample pair includes:

[0016] Generate a first loss value according to the cosine similarity between the first positive sample pair and the first negative sample pair and the contrast loss function;

[0017] Generate a second loss value according to the cosine similarity between the second positive sample pair and the second negative sample pair and the contrast loss function.

[0018] Further, the process of concatenating the feature vectors of the first positive sample pair and the second positive sample pair to obtain a first concatenated feature, and determining a third loss value based on the first concatenated feature and a predefined determination method includes:

[0019] Concatenate the feature vectors of the first positive sample pair and the second positive sample pair to obtain a first concatenated feature. Input the first concatenated feature into the multi-layer perceptron in the traffic flow prediction model. Through the multi-layer perceptron in the traffic flow prediction model, process the first concatenated feature to generate the predicted inflow value of the preset traffic flow map at the next moment and the predicted outflow value of the preset traffic flow map at the next moment.

[0020] Obtain a first difference between the predicted inflow value of the preset traffic flow map at the next moment and the actual inflow value, and obtain a second difference between the predicted outflow value of the preset traffic flow map at the next moment and the actual outflow value. Add the absolute value of the first difference and the absolute value of the second difference to obtain a third loss value.

[0021] Further, the adding the first loss value, the second loss value, and the third loss value to obtain a target loss value and adjusting the model parameters to obtain a reduced target loss value includes:

[0022] Add the first loss value, the second loss value, and the third loss value to obtain a target loss value, and determine whether the target loss value is less than a preset loss value;

[0023] When the target loss value is not less than the preset loss value, reduce the target loss value by adjusting the model parameters of the traffic flow prediction model to obtain a reduced target loss value.

[0024] Further, the when the reduced target loss value meets the preset conditions, selecting the traffic flow prediction model using the adjusted model parameters as the target model, and generating the traffic flow prediction value of the target traffic flow map at the next moment through the target model includes:

[0025] When the reduced target loss value is less than the preset loss value, stop adjusting the model parameters, save the adjusted model parameters, and select the traffic flow prediction model using the adjusted model parameters as the target model;

[0026] Obtain the traffic flow map corresponding to the target moment, select the traffic flow map corresponding to the target moment as the target traffic flow map, encode the target traffic flow map to obtain a third data matrix, encode the enhanced target traffic flow map to obtain a fourth data matrix, concatenate the third data matrix and the fourth data matrix to obtain a second concatenated feature, and input the second concatenated feature into the target model;

[0027] Process the second splicing feature through the target model to generate the predicted inflow value of the target traffic flow map at the next moment and the predicted outflow value of the target traffic flow map at the next moment, and combine the predicted inflow value of the target traffic flow map at the next moment and the predicted outflow value of the target traffic flow map at the next moment to form the predicted traffic flow value of the target traffic flow map at the next moment.

[0028] Further, when the reduced target loss value meets the preset conditions, select the traffic flow prediction model using the adjusted model parameters as the target model. After generating the predicted traffic flow value of the target traffic flow map at the next moment through the target model, the traffic flow prediction method includes:

[0029] Connect to the intelligent transportation system and push the predicted traffic flow value of the target traffic flow map at the next moment to the intelligent transportation system.

[0030] In a second aspect, a traffic flow prediction device based on an attention mechanism is provided, including:

[0031] An acquisition module for acquiring a preset traffic flow map and an enhanced preset traffic flow map;

[0032] A processing module for processing the preset traffic flow map and the enhanced preset traffic flow map through a spatio-temporal encoder and a multi-head self-attention mechanism in the traffic flow prediction model to obtain a first positive sample pair, a first negative sample pair, a second positive sample pair, and a second negative sample pair;

[0033] A first determination module for determining a first loss value according to the first positive sample pair and the first negative sample pair, and determining a second loss value according to the second positive sample pair and the second negative sample pair;

[0034] A second determination module for splicing the feature vectors of the first positive sample pair and the second positive sample pair to obtain a first splicing feature, and determining a third loss value based on the first splicing feature and a predefined determination method;

[0035] An adjustment module for adding the first loss value, the second loss value, and the third loss value to obtain a target loss value, and adjusting the model parameters to obtain a reduced target loss value;

[0036] A prediction module for selecting the traffic flow prediction model using the adjusted model parameters as the target model when the reduced target loss value meets the preset conditions, and generating the predicted traffic flow value of the target traffic flow map at the next moment through the target model.

[0037] In a third aspect, a computer device is provided, 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, the steps of the above traffic flow prediction method are implemented.

[0038] In a fourth aspect, a computer-readable storage medium is provided. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the above traffic flow prediction method are implemented.

[0039] This application provides a traffic flow prediction method, device, computer device, and storage medium based on an attention mechanism. A preset traffic flow map and an enhanced preset traffic flow map are obtained; through a spatio-temporal encoder and a multi-head self-attention mechanism in the traffic flow prediction model, the preset traffic flow map and the enhanced preset traffic flow map are processed to obtain a first positive sample pair, a first negative sample pair, a second positive sample pair, and a second negative sample pair; according to the first positive sample pair and the first negative sample pair, a first loss value is determined, and according to the second positive sample pair and the second negative sample pair, a second loss value is determined; the feature vectors of the first positive sample pair and the second positive sample pair are concatenated to obtain a first concatenated feature, and based on the first concatenated feature and a predefined determination method, a third loss value is determined; the first loss value, the second loss value, and the third loss value are added together to obtain a target loss value, and the model parameters are adjusted to obtain a reduced target loss value; when the reduced target loss value meets a preset condition, the traffic flow prediction model using the adjusted model parameters is selected as the target model, and through the target model, a traffic flow prediction value for the target traffic flow map at the next moment is generated. The beneficial effects are in two aspects. On the one hand, when the reduced target loss value meets the preset condition, the traffic flow prediction model using the adjusted model parameters is selected as the target model, and through the target model, a traffic flow prediction value for the target traffic flow map at the next moment is generated. Since it is not necessary to obtain it manually, the acquisition time of the traffic flow prediction value for the target traffic flow map at the next moment is reduced, which is beneficial to improving the acquisition efficiency of the traffic flow prediction value for the target traffic flow map at the next moment. On the other hand, since the target model is not affected by manual intervention, it is beneficial to improve the reliability of the traffic flow prediction value for the target traffic flow map at the next moment obtained. Description of the Drawings

[0040] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for the description of the embodiments of the present invention will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0041] Figure 1It is a schematic diagram of an application environment of a traffic flow prediction method in an embodiment of the present invention;

[0042] Figure 2 It is a schematic flowchart of a traffic flow prediction method provided by an embodiment of the present invention;

[0043] Figure 3 It is Figure 2 a schematic flowchart of a specific implementation manner of step S23 in;

[0044] Figure 4 It is Figure 2 a schematic flowchart of a specific implementation manner of step S25 in;

[0045] Figure 5 It is Figure 2 a schematic flowchart of a specific implementation manner of step S26 in;

[0046] Figure 6 It is a schematic structural diagram of a traffic flow prediction device in an embodiment of the present invention;

[0047] Figure 7 It is a schematic structural diagram of a computer device in an embodiment of the present invention. Specific Embodiment

[0048] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.

[0049] Please refer to Figure 1 , Figure 1 which is a schematic diagram of an application environment of a traffic flow prediction method in an embodiment of the present invention. The traffic flow prediction method provided by the embodiment of the present invention can be applied to an application environment such as Figure 1 . Among them, the intelligent transportation system includes a client and a server, and the client communicates with the server through a network.

[0050] The server obtains a preset traffic flow map and an enhanced preset traffic flow map through the client;

[0051] Through the spatio-temporal encoder and the multi-head self-attention mechanism in the traffic flow prediction model, the preset traffic flow map and the enhanced preset traffic flow map are processed to obtain a first positive sample pair, a first negative sample pair, a second positive sample pair, and a second negative sample pair;

[0052] Determine the first loss value according to the first positive sample pair and the first negative sample pair, and determine the second loss value according to the second positive sample pair and the second negative sample pair;

[0053] Concatenate the feature vectors of the first positive sample pair and the feature vectors of the second positive sample pair to obtain a first concatenated feature, and determine a third loss value based on the first concatenated feature and a predefined determination method;

[0054] Add the first loss value, the second loss value, and the third loss value to obtain a target loss value, and adjust the model parameters to obtain a reduced target loss value;

[0055] When the reduced target loss value meets the preset condition, select the traffic flow prediction model using the adjusted model parameters as the target model, and generate the traffic flow prediction value of the target traffic flow map at the next moment through the target model.

[0056] In the solution implemented by the above traffic flow prediction method, device, equipment and medium, the beneficial effects are in two aspects. On the one hand, when the reduced target loss value meets the preset condition, select the traffic flow prediction model using the adjusted model parameters as the target model, and generate the traffic flow prediction value of the target traffic flow map at the next moment through the target model. Since it is not necessary to obtain manually, the acquisition time of the traffic flow prediction value of the target traffic flow map at the next moment is reduced, which is beneficial to improving the acquisition efficiency of the traffic flow prediction value of the target traffic flow map at the next moment. On the other hand, since the target model is not affected by manual intervention, it is beneficial to improve the reliability of the traffic flow prediction value of the target traffic flow map obtained at the next moment.

[0057] Among them, the device running the client is simply referred to as: client device.

[0058] Among them, the device running the server is simply referred to as: server device.

[0059] Among them, the client device includes but is not limited to smart phones, personal computers, vehicle networking terminals, tablet computers and portable wearable devices.

[0060] Among them, the server device can be implemented by an independent server or a server cluster composed of multiple servers. The present invention will be described in detail below through specific embodiments. Please refer to Figure 2 , Figure 2 FIG. is a schematic flowchart of a traffic flow prediction method provided by an embodiment of the present invention, including the following steps:

[0061] S21, obtain a preset traffic flow map and an enhanced preset traffic flow map;

[0062] Among them, a traffic flow diagram is a graphical tool used to describe and analyze the flow of vehicles, pedestrians, or other means of transportation in a traffic network. Through a graphical method, the traffic flow diagram clearly shows the traffic flow, flow direction, and traffic density between different roads, intersections, or regions in a logical manner.

[0063] Exemplarily, obtaining a preset traffic flow diagram and an enhanced preset traffic flow diagram includes:

[0064] Obtain the traffic flow diagram corresponding to a preset moment, select the traffic flow diagram corresponding to the preset moment as the preset traffic flow diagram, randomly obtain a first traffic area and a second traffic area in the preset traffic flow diagram, obtain the traffic data vector corresponding to the first traffic area, and obtain the traffic data vector corresponding to the second traffic area;

[0065] According to a preset first formula, the traffic data vector corresponding to the first traffic area, and the traffic data vector corresponding to the second traffic area, generate the similarity in traffic patterns between the first traffic area and the second traffic area;

[0066] When the similarity in traffic patterns between the first traffic area and the second traffic area is greater than a preset value, add a connection edge between the first traffic area and the second traffic area on the preset traffic flow diagram. When the similarity in traffic patterns between the first traffic area and the second traffic area is not greater than the preset value, remove the connection edge between the first traffic area and the second traffic area on the preset traffic flow diagram. Select the preset traffic flow diagram with the added or removed connection edge between the first traffic area and the second traffic area as the enhanced preset traffic flow diagram.

[0067] For the sake of convenience in explanation, an example is given as follows:

[0068] For example, the preset traffic flow diagram is Traffic Flow Diagram A. When the similarity in traffic patterns between the first traffic area and the second traffic area is greater than the preset value, add a connection edge between the first traffic area and the second traffic area on Traffic Flow Diagram A to obtain Traffic Flow Diagram B. When the similarity in traffic patterns between the first traffic area and the second traffic area is not greater than the preset value, remove the connection edge between the first traffic area and the second traffic area on Traffic Flow Diagram A to obtain Traffic Flow Diagram C. Select Traffic Flow Diagram B or Traffic Flow Diagram C as the enhanced preset traffic flow diagram.

[0069] Among them, the first traffic area and the second traffic area are different traffic areas in the preset traffic flow diagram.

[0070] Among them, the first formula is:

[0071] ;

[0072] Indicates the similarity between the first traffic area and the second traffic area;

[0073] Indicates the traffic data vector corresponding to the first traffic area; Indicates the serial number of the first traffic area in the preset traffic flow map;

[0074] Indicates the traffic data vector corresponding to the second traffic area; Indicates the serial number of the second traffic area in the preset traffic flow map;

[0075] Indicates the transpose of;

[0076] Indicates the modulus of the traffic data vector corresponding to the first traffic area;

[0077] Indicates the modulus of the traffic data vector corresponding to the second traffic area.

[0078] For the sake of illustration, the following is an example:

[0079] For example, the motor vehicle flow of the first traffic area is 800 vehicles per hour, the non-motor vehicle flow is 250 vehicles per hour, and the average vehicle speed is 35 km / h. These data form the traffic data vector corresponding to the first traffic area. At this time, is At this time, is [800, 250, 35]. At this time, , is 839;

[0080] For example, the motor vehicle flow of the second traffic area is 700 vehicles per hour, the non-motor vehicle flow is 200 vehicles per hour, and the average vehicle speed is 30 km / h. These data form the traffic data vector corresponding to the first traffic area. At this time, is At this time, , is 728;

[0081] Therefore, substituting into the first formula, it can be known that the similarity between the first traffic area and the second traffic area is 0.995.

[0082] When the preset value is 0.6, the similarity in traffic patterns between the first traffic area and the second traffic area is greater than the preset value, and a connection edge is added between the first traffic area and the second traffic area in the preset traffic flow map;

[0083] When the preset value is 0.998 and the similarity between the first traffic area and the second traffic area in terms of traffic patterns is not greater than the preset value, the connection edge between the first traffic area and the second traffic area is removed from the preset traffic flow map.

[0084] When the similarity between the first traffic area and the second traffic area in terms of traffic patterns is greater than the preset value, it indicates that the connection edge between the first traffic area and the second traffic area is an effective feature of the preset traffic flow map. The connection edge between the first traffic area and the second traffic area is added to the preset traffic flow map so that the traffic network model can capture the effective features of the preset traffic flow map.

[0085] When the similarity between the first traffic area and the second traffic area in terms of traffic patterns is not greater than the preset value, it indicates that the connection edge between the first traffic area and the second traffic area is noise in the preset traffic flow map. The connection edge between the first traffic area and the second traffic area is removed from the preset traffic flow map so that the traffic network model will not be interfered by the noise in the preset traffic flow map, thereby improving the stability of the traffic network model.

[0086] S22, through the spatio-temporal encoder and the multi-head self-attention mechanism in the traffic flow prediction model, process the preset traffic flow map and the enhanced preset traffic flow map to obtain the first positive sample pair, the first negative sample pair, the second positive sample pair, and the second negative sample pair;

[0087] Among them, the multi-head self-attention mechanism includes but is not limited to the time attention mechanism and the space attention mechanism.

[0088] Among them, the process of using the spatio-temporal encoder and the multi-head self-attention mechanism in the traffic flow prediction model to process the preset traffic flow map and the enhanced preset traffic flow map to obtain the first positive sample pair, the first negative sample pair, the second positive sample pair, and the second negative sample pair includes:

[0089] Encode the preset traffic flow map through the spatio-temporal encoder in the traffic flow prediction model to obtain the first data matrix, and encode the enhanced target traffic flow map to obtain the second data matrix;

[0090] Use the multi-head self-attention mechanism to select the adjacent road segments at the same intersection in the first data matrix and the second data matrix as the first positive sample pair, select the non-adjacent road segments at the same intersection in the first data matrix and the second data matrix as the first negative sample pair, select the same time period at the same intersection in the first data matrix and the second data matrix as the second positive sample pair, and select different time periods at the same intersection in the first data matrix and the second data matrix as the second negative sample pair.

[0091] S23. Determine a first loss value according to the first positive sample pair and the first negative sample pair, and determine a second loss value according to the second positive sample pair and the second negative sample pair;

[0092] S24. Concatenate the feature vectors of the first positive sample pair and the feature vectors of the second positive sample pair to obtain a first concatenated feature. Based on the first concatenated feature and a predefined determination method, determine a third loss value;

[0093] Among them, the step of concatenating the feature vectors of the first positive sample pair and the feature vectors of the second positive sample pair to obtain a first concatenated feature, and determining a third loss value based on the first concatenated feature and a predefined determination method includes:

[0094] Concatenate the feature vectors of the first positive sample pair and the feature vectors of the second positive sample pair to obtain a first concatenated feature. Input the first concatenated feature into the multi-layer perceptron in the traffic flow prediction model. Through the multi-layer perceptron in the traffic flow prediction model, process the first concatenated feature to generate a predicted value of the inflow traffic volume at the next moment of the preset traffic flow map and a predicted value of the outflow traffic volume at the next moment of the preset traffic flow map; Obtain a first difference between the predicted value of the inflow traffic volume at the next moment of the preset traffic flow map and the actual value of the inflow traffic volume, obtain a second difference between the predicted value of the outflow traffic volume at the next moment of the preset traffic flow map and the actual value of the outflow traffic volume, and add the absolute value of the first difference and the absolute value of the second difference to obtain a third loss value.

[0095] Among them, the predicted value of the inflow traffic volume is the predicted value of the inflow traffic volume.

[0096] Among them, the actual value of the inflow traffic volume is the actual value of the inflow traffic volume.

[0097] Among them, the predicted value of the outflow traffic volume is the predicted value of the outflow traffic volume.

[0098] Among them, the actual value of the outflow traffic volume is the actual value of the outflow traffic volume.

[0099] Exemplarily, the step of obtaining a first difference between the predicted value of the inflow traffic volume at the next moment of the preset traffic flow map and the actual value of the inflow traffic volume, obtaining a second difference between the predicted value of the outflow traffic volume at the next moment of the preset traffic flow map and the actual value of the outflow traffic volume, and adding the absolute value of the first difference and the absolute value of the second difference to obtain a third loss value includes:

[0100] Obtain the annotation information of the first positive sample pair and the second positive sample pair, read the actual inflow value and the actual outflow value in the annotation information, obtain the first difference between the predicted inflow value and the actual inflow value of the preset traffic flow map at the next moment, obtain the second difference between the predicted outflow value and the actual outflow value of the preset traffic flow map at the next moment, and add the absolute value of the first difference and the absolute value of the second difference to obtain the third loss value.

[0101] The preset traffic flow map at the next moment refers to the next moment of the preset traffic flow map at the preset moment.

[0102] S25, add the first loss value, the second loss value, and the third loss value to obtain the target loss value, and adjust the model parameters to obtain the reduced target loss value;

[0103] Exemplarily, adding the first loss value, the second loss value, and the third loss value to obtain the target loss value includes:

[0104] Adopt a loss value generation model to add the first loss value, the second loss value, and the third loss value to obtain the target loss value.

[0105] Among them, the loss value generation model is:

[0106] ;

[0107] Among them, is the target loss value, is the first loss value, is the second loss value, is the third loss value.

[0108] Among them, the loss value generation model is the generation model of the target loss value.

[0109] Among them, adjusting the model parameters and reducing the target loss value can reduce the first loss value, the second loss value, and the third loss value. By reducing the first loss value, the ability of the traffic flow prediction model to distinguish between the first positive sample pair and the first negative sample pair can be improved. By reducing the second loss value, the ability of the traffic flow prediction model to distinguish between the second positive sample pair and the second negative sample pair can be improved. By reducing the third loss value, the prediction accuracy of the traffic flow prediction model can be significantly improved, so that the predicted inflow value at the next moment output by the traffic flow prediction model is closer to the actual inflow value, and the predicted outflow value at the next moment output by the traffic flow prediction model is closer to the actual outflow value.

[0110] S26. When the reduced target loss value meets the preset condition, select the traffic flow prediction model using the adjusted model parameters as the target model. Through the target model, generate the traffic flow prediction value of the target traffic flow map at the next moment.

[0111] Among them, selecting the traffic flow prediction model using the adjusted model parameters as the target model not only improves the prediction ability of the target model, but also enhances the generalization ability and adaptability of the target model, enabling the target model to maintain stable prediction performance under different urban environments and traffic conditions.

[0112] Among them, after the step of when the reduced target loss value meets the preset condition, select the traffic flow prediction model using the adjusted model parameters as the target model, and through the target model, generate the traffic flow prediction value of the target traffic flow map at the next moment, the traffic flow prediction method includes:

[0113] Connect to the intelligent transportation system and push the traffic flow prediction value of the target traffic flow map at the next moment to the intelligent transportation system.

[0114] Among them, the traffic flow prediction value is the predicted value of the traffic flow.

[0115] Among them, by pushing the traffic flow prediction value of the target traffic flow map at the next moment to the intelligent transportation system, the traffic flow prediction value of the target traffic flow map at the next moment can help the intelligent transportation system to grasp the road congestion situation in real time, plan and implement effective traffic guidance plans in advance, thereby effectively alleviating traffic pressure, reducing vehicle queuing and delay time, and improving road capacity. In addition, based on the traffic flow prediction value of the target traffic flow map at the next moment, the intelligent transportation system can optimize the signal control strategy and automatically adjust the green light duration of the signal according to the real-time traffic conditions to achieve a smooth transition of the traffic flow and further improve the road use efficiency.

[0116] In the embodiment of the present invention, the beneficial effects are in two aspects. On the one hand, when the reduced target loss value meets the preset condition, select the traffic flow prediction model using the adjusted model parameters as the target model, and through the target model, generate the traffic flow prediction value of the target traffic flow map at the next moment. Since it is not necessary to obtain manually, the acquisition time of the traffic flow prediction value of the target traffic flow map at the next moment is reduced, which is beneficial to improving the acquisition efficiency of the traffic flow prediction value of the target traffic flow map at the next moment. On the other hand, since the target model is not affected by manual intervention, it is beneficial to improve the reliability of the traffic flow prediction value of the target traffic flow map at the next moment obtained.

[0117] Please refer to Figure 3 , Figure 3 is Figure 2A schematic flowchart of a specific implementation manner of step S23 is described in detail as follows:

[0118] S31, generate a first loss value according to the cosine similarity between the first positive sample pair and the first negative sample pair and the contrast loss function;

[0119] Among them, the contrast loss function is a loss function used to train a neural network to distinguish similar and dissimilar samples.

[0120] S32, generate a second loss value according to the cosine similarity between the second positive sample pair and the second negative sample pair and the contrast loss function.

[0121] In the embodiment of the present invention, the first loss value reflects the performance of the traffic flow prediction model in distinguishing the first positive sample pair and the first negative sample pair, and the second loss value reflects the performance of the traffic flow prediction model in distinguishing the second positive sample pair and the second negative sample pair. By reducing the first loss value, the ability of the traffic flow prediction model to distinguish the first positive sample pair and the first negative sample pair can be improved, and by reducing the second loss value, the ability of the traffic flow prediction model to distinguish the second positive sample pair and the second negative sample pair can be improved.

[0122] Please refer to Figure 4 , Figure 4 is Figure 2 A schematic flowchart of a specific implementation manner of step S25 is described in detail as follows:

[0123] S41, add the first loss value, the second loss value, and the third loss value to obtain a target loss value, and determine whether the target loss value is less than a preset loss value;

[0124] S42, when the target loss value is not less than the preset loss value, adjust the model parameters of the traffic flow prediction model to reduce the target loss value and obtain a reduced target loss value.

[0125] In the embodiment of the present invention, by reducing the target loss value, the traffic flow prediction model is controlled to be optimized in the correct direction, which is beneficial to accelerating the training speed of the traffic flow prediction model and reducing the consumption of computing resources of the traffic flow prediction model.

[0126] Please refer to Figure 5 , Figure 5 is Figure 2 A schematic flowchart of a specific implementation manner of step S26 is described in detail as follows:

[0127] S51, when the reduced target loss value is less than the preset loss value, stop adjusting the model parameters, save the adjusted model parameters, and select the traffic flow prediction model using the adjusted model parameters as the target model;

[0128] When the reduced target loss value is less than the preset loss value, stop adjusting the model parameters, save the adjusted model parameters, and select the traffic flow prediction model using the adjusted model parameters as the target model, including:

[0129] When the reduced target loss value is less than the preset loss value, stop adjusting the model parameters, save the adjusted model parameters, and obtain the mean absolute error and mean absolute percentage error of the traffic flow prediction model using the adjusted model parameters on the test set;

[0130] When the mean absolute error is less than the preset first error value and the mean absolute percentage error is less than the preset second error value, select the traffic flow prediction model using the adjusted model parameters as the target model.

[0131] Among them, the first error value and the second error value are different error values.

[0132] Among them, when the mean absolute error is less than the preset first error value and the mean absolute percentage error is less than the preset second error value, it indicates that the performance of the traffic flow prediction model using the adjusted model parameters has reached the preset standard. At this time, selecting the traffic flow prediction model using the adjusted model parameters as the target model can ensure the reliability of the target model.

[0133] S52. Obtain the traffic flow map corresponding to the target moment, select the traffic flow map corresponding to the target moment as the target traffic flow map, encode the target traffic flow map to obtain a third data matrix, encode the enhanced target traffic flow map to obtain a fourth data matrix, splice the third data matrix and the fourth data matrix to obtain a second spliced feature, and input the second spliced feature into the target model;

[0134] Exemplarily, obtaining the traffic flow map corresponding to the target moment, selecting the traffic flow map corresponding to the target moment as the target traffic flow map, encoding the target traffic flow map to obtain a third data matrix, encoding the enhanced target traffic flow map to obtain a fourth data matrix, splicing the third data matrix and the fourth data matrix to obtain a second spliced feature, and inputting the second spliced feature into the target model, including:

[0135] Obtain the traffic flow map corresponding to the target moment, select the traffic flow map corresponding to the target moment as the target traffic flow map, and perform enhancement processing on the target traffic flow map to obtain an enhanced target traffic flow map;

[0136] Through the spatio-temporal encoder in the target model, encode the target traffic flow map to obtain a third data matrix, encode the enhanced target traffic flow map to obtain a fourth data matrix, splice the third data matrix and the fourth data matrix to obtain a second spliced feature, and input the second spliced feature into the target model.

[0137] Exemplarily, obtain the traffic flow map corresponding to the target moment, select the traffic flow map corresponding to the target moment as the target traffic flow map, and perform enhancement processing on the target traffic flow map to obtain the enhanced target traffic flow map, including:

[0138] Obtain the traffic flow map corresponding to the target moment, select the traffic flow map corresponding to the target moment as the target traffic flow map, randomly obtain a third traffic area and a fourth traffic area in the target traffic flow map, obtain the traffic data vector corresponding to the third traffic area, and obtain the traffic data vector corresponding to the fourth traffic area;

[0139] According to the preset second formula, the traffic data vector corresponding to the third traffic area, and the traffic data vector corresponding to the fourth traffic area, generate the similarity in traffic patterns between the third traffic area and the fourth traffic area;

[0140] When the similarity in traffic patterns between the third traffic area and the fourth traffic area is greater than the target value, add a connection edge between the third traffic area and the fourth traffic area on the target traffic flow map. When the similarity in traffic patterns between the third traffic area and the fourth traffic area is not greater than the target value, remove the connection edge between the third traffic area and the fourth traffic area on the target traffic flow map, and select the target traffic flow map with the connection edge added between the third traffic area and the fourth traffic area or the connection edge removed between the third traffic area and the fourth traffic area as the enhanced target traffic flow map.

[0141] For ease of explanation, an example is as follows:

[0142] For example, the target traffic flow map is traffic flow map D. When the similarity in traffic patterns between the third traffic area and the fourth traffic area is greater than the target value, add a connection edge between the third traffic area and the fourth traffic area on traffic flow map D to obtain traffic flow map E. When the similarity in traffic patterns between the third traffic area and the fourth traffic area is not greater than the preset value, remove the connection edge between the third traffic area and the fourth traffic area on traffic flow map D to obtain traffic flow map F, and select traffic flow map D or traffic flow map F as the enhanced target traffic flow map.

[0143] Among them, the third traffic area and the fourth traffic area are different traffic areas in the target traffic flow map.

[0144] Among them, the second formula is:

[0145] ;

[0146] represents the similarity between the third traffic area and the fourth traffic area;

[0147] Represents the traffic data vector corresponding to the third traffic area; Represents the serial number of the third traffic area in the preset traffic flow map;

[0148] Represents the traffic data vector corresponding to the fourth traffic area; Represents the serial number of the fourth traffic area in the preset traffic flow map;

[0149] Represents The transpose of;

[0150] Represents the modulus of the traffic data vector corresponding to the third traffic area;

[0151] Represents the modulus of the traffic data vector corresponding to the fourth traffic area.

[0152] For the convenience of explanation, the following is an example:

[0153] For example, the motor vehicle flow in the third traffic area is 500 vehicles per hour, the non-motor vehicle flow is 150 vehicles per hour, and the average vehicle speed is 25 km / h. These data are used to form the traffic data vector corresponding to the third traffic area. At this time, Is At this time, Is [500, 150, 25]. At this time, Is 522;

[0154] For example, the motor vehicle flow in the fourth traffic area is 450 vehicles per hour, the non-motor vehicle flow is 120 vehicles per hour, and the average vehicle speed is 25 km / h. These data are used to form the traffic data vector corresponding to the third traffic area. At this time, Is Is 466;

[0155] Therefore, substituting into the first formula, it can be known that the similarity between the third traffic area and the fourth traffic area is 0.997.

[0156] When the preset value is 0.8, the similarity in traffic patterns between the third traffic area and the fourth traffic area is greater than the preset value, and a connection edge is added between the third traffic area and the fourth traffic area on the target traffic flow map;

[0157] When the preset value is 0.998, when the similarity in traffic patterns between the third traffic area and the fourth traffic area is not greater than the preset value, the connection edge between the third traffic area and the fourth traffic area is removed on the target traffic flow map. ​​​

[0158] When the similarity in traffic patterns between the third traffic area and the fourth traffic area is greater than a preset value, it indicates that the connection edge between the third traffic area and the fourth traffic area is an effective feature of the target traffic flow map. Add the connection edge between the third traffic area and the fourth traffic area to the target traffic flow map, so that the target model can capture the effective features of the target traffic flow map.

[0159] When the similarity in traffic patterns between the third traffic area and the fourth traffic area is not greater than the preset value, it indicates that the connection edge between the third traffic area and the fourth traffic area is noise in the target traffic flow map. Remove the connection edge between the third traffic area and the fourth traffic area from the target traffic flow map, so that the target model will not be interfered by the noise of the target traffic flow map, thereby improving the stability of the target model.

[0160] S53. Through the target model, process the second splicing feature to generate the predicted inflow value of the target traffic flow map at the next moment and the predicted outflow value of the target traffic flow map at the next moment. Combine the predicted inflow value of the target traffic flow map at the next moment and the predicted outflow value of the target traffic flow map at the next moment to form the predicted traffic flow value of the target traffic flow map at the next moment.

[0161] The target traffic flow map at the next moment refers to the next moment of the target moment of the target traffic flow map.

[0162] In the embodiment of the present invention, generating the predicted inflow value of the target traffic flow map at the next moment and the predicted outflow value of the target traffic flow map at the next moment, and combining the predicted inflow value of the target traffic flow map at the next moment and the predicted outflow value of the target traffic flow map at the next moment to form the predicted traffic flow value of the target traffic flow map at the next moment. Since it is not necessary to obtain manually, the acquisition time of the predicted traffic flow value of the target traffic flow map at the next moment is reduced, which is beneficial to improving the acquisition efficiency of the predicted traffic flow value of the target traffic flow map at the next moment.

[0163] Please refer to Figure 6 , Figure 6 which is a schematic structural diagram of a traffic flow prediction device in an embodiment of the present invention. As Figure 6 shown, the traffic flow prediction device includes an acquisition module 101, a processing module 102, a first determination module 103, a second determination module 104, an adjustment module 105, and a prediction module 106. The detailed description of each functional module is as follows:

[0164] The acquisition module 101 is used to acquire a preset traffic flow map and an enhanced preset traffic flow map;

[0165] The processing module 102 is configured to process the preset traffic flow map and the enhanced preset traffic flow map through the spatio-temporal encoder and the multi-head self-attention mechanism in the traffic flow prediction model, so as to obtain the first positive sample pair, the first negative sample pair, the second positive sample pair, and the second negative sample pair;

[0166] The first determination module 103 is configured to determine a first loss value according to the first positive sample pair and the first negative sample pair, and determine a second loss value according to the second positive sample pair and the second negative sample pair;

[0167] The second determination module 104 is configured to splice the feature vectors of the first positive sample pair and the feature vectors of the second positive sample pair to obtain a first spliced feature, and determine a third loss value based on the first spliced feature and a predefined determination method;

[0168] The adjustment module 105 is configured to add the first loss value, the second loss value, and the third loss value to obtain a target loss value, and adjust the model parameters to obtain a reduced target loss value;

[0169] The prediction module 106 is configured to, when the reduced target loss value meets a preset condition, select the traffic flow prediction model using the adjusted model parameters as the target model, and generate a traffic flow prediction value for the target traffic flow map at the next moment through the target model.

[0170] In the embodiment of the present invention, the beneficial effects are in two aspects. On the one hand, when the reduced target loss value meets the preset condition, the traffic flow prediction model using the adjusted model parameters is selected as the target model, and the traffic flow prediction value for the target traffic flow map at the next moment is generated through the target model. Since it is not necessary to obtain manually, the acquisition time of the traffic flow prediction value for the target traffic flow map at the next moment is reduced, which is beneficial to improving the acquisition efficiency of the traffic flow prediction value for the target traffic flow map at the next moment. On the other hand, since the target model is not affected by manual intervention, it is beneficial to improve the reliability of the traffic flow prediction value for the target traffic flow map at the next moment obtained.

[0171] For the specific limitations of the traffic flow prediction device, reference may be made to the limitations on the traffic flow prediction method in the above text, which will not be elaborated here.

[0172] Each module in the above traffic flow prediction device can be implemented in whole or in part by software, hardware, and their combination. The above modules can be embedded in the processor in the computer device in hardware form or be independent of it, or can be stored in the memory in the computer device in software form, so that the processor can call and execute the operations corresponding to the above modules.

[0173] Please refer to Figure 7 , Figure 7It is a schematic structural diagram of a computer device in an embodiment of the present invention. In one embodiment, a computer device is provided. The computer device is a server device or a client device, and its internal structure diagram can be as shown in Figure 7 shown. The computer device includes a processor, a memory, a network interface, a display screen, and an input device connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with external devices.

[0174] When the computer program is executed by the processor, the following steps can be implemented:

[0175] Obtain a preset traffic flow map and an enhanced preset traffic flow map;

[0176] Process the preset traffic flow map and the enhanced preset traffic flow map through the spatio-temporal encoder and the multi-head self-attention mechanism in the traffic flow prediction model to obtain a first positive sample pair, a first negative sample pair, a second positive sample pair, and a second negative sample pair;

[0177] Determine a first loss value according to the first positive sample pair and the first negative sample pair, and determine a second loss value according to the second positive sample pair and the second negative sample pair;

[0178] Concatenate the feature vectors of the first positive sample pair and the feature vectors of the second positive sample pair to obtain a first concatenated feature, and determine a third loss value based on the first concatenated feature and a predefined determination method;

[0179] Add the first loss value, the second loss value, and the third loss value to obtain a target loss value, and adjust the model parameters to obtain a reduced target loss value;

[0180] When the reduced target loss value meets a preset condition, select the traffic flow prediction model using the adjusted model parameters as the target model, and generate a traffic flow prediction value for the target traffic flow map at the next moment through the target model.

[0181] In some embodiments, the processor is used to implement:

[0182] Encode the preset traffic flow map through the spatio-temporal encoder in the traffic flow prediction model to obtain a first data matrix, and encode the enhanced target traffic flow map to obtain a second data matrix;

[0183] Using the multi-head self-attention mechanism, adjacent road segments at the same intersection in the first data matrix and the second data matrix are selected as the first positive sample pairs, non-adjacent road segments at the same intersection in the first data matrix and the second data matrix are selected as the first negative sample pairs, the same time period at the same intersection in the first data matrix and the second data matrix is selected as the second positive sample pairs, and different time periods at the same intersection in the first data matrix and the second data matrix are selected as the second negative sample pairs.

[0184] In some embodiments, a processor is configured to implement:

[0185] Generate a first loss value according to the cosine similarity between the first positive sample pairs and the first negative sample pairs and the contrast loss function;

[0186] Generate a second loss value according to the cosine similarity between the second positive sample pairs and the second negative sample pairs and the contrast loss function.

[0187] In some embodiments, a processor is configured to implement:

[0188] Concatenate the feature vectors of the first positive sample pairs and the feature vectors of the second positive sample pairs to obtain a first concatenated feature, input the first concatenated feature into the multi-layer perceptron in the traffic flow prediction model, and process the first concatenated feature through the multi-layer perceptron in the traffic flow prediction model to generate the predicted inflow value of the preset traffic flow map at the next moment and the predicted outflow value of the preset traffic flow map at the next moment;

[0189] Obtain a first difference between the predicted inflow value of the preset traffic flow map at the next moment and the actual inflow value, obtain a second difference between the predicted outflow value of the preset traffic flow map at the next moment and the actual outflow value, and add the absolute value of the first difference and the absolute value of the second difference to obtain a third loss value.

[0190] In some embodiments, a processor is configured to implement:

[0191] Add the first loss value, the second loss value, and the third loss value to obtain a target loss value, and determine whether the target loss value is less than a preset loss value;

[0192] When the target loss value is not less than the preset loss value, reduce the target loss value by adjusting the model parameters of the traffic flow prediction model to obtain a reduced target loss value.

[0193] In some embodiments, a processor is configured to implement:

[0194] When the reduced target loss value is less than the preset loss value, stop adjusting the model parameters, save the adjusted model parameters, and select the traffic flow prediction model using the adjusted model parameters as the target model;

[0195] Obtain the traffic flow map corresponding to the target moment, select the traffic flow map corresponding to the target moment as the target traffic flow map, encode the target traffic flow map to obtain a third data matrix, encode the enhanced target traffic flow map to obtain a fourth data matrix, splice the third data matrix and the fourth data matrix to obtain a second spliced feature, and input the second spliced feature into the target model;

[0196] Through the target model, process the second spliced feature to generate the predicted inflow value of the target traffic flow map at the next moment and the predicted outflow value of the target traffic flow map at the next moment, and combine the predicted inflow value of the target traffic flow map at the next moment and the predicted outflow value of the target traffic flow map at the next moment to form the predicted traffic flow value of the target traffic flow map at the next moment.

[0197] In some embodiments, the processor is used to implement:

[0198] Connect to the intelligent transportation system and push the predicted traffic flow value of the target traffic flow map at the next moment to the intelligent transportation system.

[0199] An embodiment of the present application provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps in the above-mentioned various method embodiments can be implemented.

[0200] Obtain a preset traffic flow map and an enhanced preset traffic flow map;

[0201] Through the spatio-temporal encoder and the multi-head self-attention mechanism in the traffic flow prediction model, process the preset traffic flow map and the enhanced preset traffic flow map to obtain a first positive sample pair, a first negative sample pair, a second positive sample pair, and a second negative sample pair;

[0202] Determine a first loss value according to the first positive sample pair and the first negative sample pair, and determine a second loss value according to the second positive sample pair and the second negative sample pair;

[0203] Splice the feature vectors of the first positive sample pair and the second positive sample pair to obtain a first spliced feature, and determine a third loss value based on the first spliced feature and a predefined determination method;

[0204] Add the first loss value, the second loss value, and the third loss value to obtain a target loss value, and adjust the model parameters to obtain a reduced target loss value;

[0205] When the reduced target loss value meets the preset conditions, select the traffic flow prediction model using the adjusted model parameters as the target model, and generate the predicted traffic flow value of the target traffic flow map at the next moment through the target model.

[0206] It should be noted that the functions or steps that can be realized by the above computer-readable storage medium or computer device can be correspondingly referred to the relevant descriptions in the foregoing method embodiments. To avoid repetition, they will not be described one by one here.

[0207] The above-mentioned processor can be a general-purpose processor, including a Central Processing Unit (CPU for short), a Graphics Processing Unit (GPU for short), and a Network Processor (NP for short); it can also be a Digital Signal Processor (DSP for short), an Application Specific Integrated Circuit (ASIC for short), a Field-Programmable Gate Array (FPGA for short), or other programmable logic devices, discrete gate or transistor logic devices, and discrete hardware components.

[0208] The above description and the accompanying drawings fully illustrate the embodiments of the present disclosure, enabling those skilled in the art to practice them. In this article, what each embodiment focuses on can be the differences from other embodiments, and the same or similar parts between the embodiments can be referred to each other. For the methods disclosed in the embodiments, if they correspond to the method parts disclosed in the embodiments, the relevant parts can be referred to the descriptions of the method parts.

[0209] Those skilled in the art can realize that the units and algorithm steps of each example described in combination with the embodiments disclosed in this article can be implemented by electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are executed in a hardware or software manner can depend on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods for each specific application to implement the described functions, but such implementation should not be considered to exceed the scope of the embodiments of the present disclosure. Those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working processes of the systems, devices, and units described above can refer to the corresponding processes in the foregoing method embodiments and will not be elaborated here.

[0210] In the embodiments disclosed herein, the device embodiments described above are merely illustrative. For example, the division of units can be merely a logical function division. In actual implementation, there can be other division methods. For example, multiple units or components can be combined or integrated into another system, or some sub-samples can be ignored or not executed. Additionally, the couplings or direct couplings or communication connections shown or discussed among each other can be through some interfaces. The indirect couplings or communication connections of devices or units can be in electrical, mechanical, or other forms. The units described as separate components can be or can not be physically separated. The components shown as units can be or can not be physical units, that is, they can be located in one place or can be distributed to multiple network units. Some or all of the units can be selected according to actual needs to implement this embodiment. Additionally, in the embodiments of the present disclosure, the various functional units can be integrated in one processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The flowcharts and block diagrams in the accompanying drawings show the possible architectures, functions, and operations of systems, methods, and computer programs according to the embodiments of the present disclosure. In this regard, each block in the flowchart or block diagram can represent a module, a program segment, or a part of code, and the module, program segment, or part of code contains one or more executable instructions for implementing the specified logical function. In some alternative implementations, the functions marked in the blocks can also occur in a different order than that marked in the accompanying drawings. For example, two consecutive blocks can actually be executed substantially in parallel, and sometimes they can also be executed in the reverse order, which can depend on the functions involved. In the descriptions corresponding to the flowcharts and block diagrams in the accompanying drawings, the operations or steps corresponding to different blocks can also occur in a different order than that disclosed in the description. Sometimes there is no specific order among different operations or steps. For example, two consecutive operations or steps can actually be executed substantially in parallel, and sometimes they can also be executed in the reverse order, which can depend on the functions involved. Each block in the block diagram and / or flowchart, as well as the combination of blocks in the block diagram and / or flowchart, can be implemented by a dedicated hardware-based system for performing the specified functions or actions, or can be implemented by a combination of dedicated hardware and computer instructions.

Claims

1. A traffic flow prediction method based on the attention mechanism, characterized in that Including: Obtain a preset traffic flow map and an enhanced preset traffic flow map; Encode the preset traffic flow map through the spatio-temporal encoder in the traffic flow prediction model to obtain a first data matrix, encode the enhanced target traffic flow map to obtain a second data matrix, and use the multi-head self-attention mechanism to select the traffic flows of adjacent road segments at the same intersection in the first data matrix and the second data matrix as the first positive sample pair, select the traffic flows of non-adjacent road segments at the same intersection in the first data matrix and the second data matrix as the first negative sample pair, select the traffic flows at the same intersection in the first data matrix and the second data matrix at the same time period as the second positive sample pair, and select the traffic flows at the same intersection in the first data matrix and the second data matrix at different time periods as the second negative sample pair; Generate a first loss value according to the cosine similarity between the first positive sample pair and the first negative sample pair and the contrast loss function, generate a second loss value according to the cosine similarity between the second positive sample pair and the second negative sample pair and the contrast loss function. The contrast loss function is a loss function used to train a neural network to distinguish similar and dissimilar samples. The first loss value reflects the performance of the traffic flow prediction model in distinguishing the first positive sample pair and the first negative sample pair, and the second loss value reflects the performance of the traffic flow prediction model in distinguishing the second positive sample pair and the second negative sample pair; Concatenate the feature vectors of the first positive sample pair and the feature vectors of the second positive sample pair to obtain a first concatenated feature, input the first concatenated feature into the multi-layer perceptron in the traffic flow prediction model to generate the predicted inflow value of the preset traffic flow map at the next moment and the predicted outflow value of the preset traffic flow map at the next moment, obtain the first difference between the predicted inflow value of the preset traffic flow map at the next moment and the actual inflow value, obtain the second difference between the predicted outflow value of the preset traffic flow map at the next moment and the actual outflow value, and add the absolute value of the first difference and the absolute value of the second difference to obtain a third loss value; Add the first loss value, the second loss value, and the third loss value to obtain a target loss value, and adjust the model parameters to obtain a reduced target loss value; When the reduced target loss value meets the preset condition, select the traffic flow prediction model using the adjusted model parameters as the target model, and generate the traffic flow prediction value of the target traffic flow map at the next moment through the target model.

2. The traffic flow prediction method according to claim 1, wherein The step of adding the first loss value, the second loss value, and the third loss value to obtain a target loss value and adjusting the model parameters to obtain a reduced target loss value includes: Add the first loss value, the second loss value, and the third loss value to obtain a target loss value, and determine whether the target loss value is less than the preset loss value; When the target loss value is not less than the preset loss value, reduce the target loss value by adjusting the model parameters of the traffic flow prediction model to obtain a reduced target loss value.

3. The traffic flow prediction method according to claim 1, wherein The step of when the reduced target loss value meets the preset condition, select the traffic flow prediction model using the adjusted model parameters as the target model, and generate the traffic flow prediction value of the target traffic flow map at the next moment through the target model includes: When the reduced target loss value is less than the preset loss value, stop adjusting the model parameters, save the adjusted model parameters, and select the traffic flow prediction model using the adjusted model parameters as the target model; Obtain the traffic flow map corresponding to the target moment, select the traffic flow map corresponding to the target moment as the target traffic flow map, encode the target traffic flow map to obtain a third data matrix, encode the enhanced target traffic flow map to obtain a fourth data matrix, splice the third data matrix and the fourth data matrix to obtain a second spliced feature, and input the second spliced feature into the target model; Through the target model, process the second spliced feature to generate the predicted inflow value of the target traffic flow map at the next moment and the predicted outflow value of the target traffic flow map at the next moment, and combine the predicted inflow value of the target traffic flow map at the next moment and the predicted outflow value of the target traffic flow map at the next moment to form the predicted traffic flow value of the target traffic flow map at the next moment.

4. The traffic flow prediction method according to claim 1, wherein When the reduced target loss value meets the preset conditions, select the traffic flow prediction model using the adjusted model parameters as the target model. After generating the predicted traffic flow value of the target traffic flow map at the next moment through the target model, the traffic flow prediction method includes: Connect to the intelligent transportation system and push the predicted traffic flow value of the target traffic flow map at the next moment to the intelligent transportation system.

5. A traffic flow prediction device based on an attention mechanism, characterized in that, Including: An acquisition module for acquiring a preset traffic flow map and an enhanced preset traffic flow map; A processing module for encoding the preset traffic flow map through a spatio-temporal encoder in the traffic flow prediction model to obtain a first data matrix, encoding the enhanced target traffic flow map to obtain a second data matrix, using a multi-head self-attention mechanism to select the traffic flows of adjacent road segments at the same intersection in the first data matrix and the second data matrix as the first positive sample pair, select the traffic flows of non-adjacent road segments at the same intersection in the first data matrix and the second data matrix as the first negative sample pair, select the traffic flows at the same intersection in the first data matrix and the second data matrix at the same time period as the second positive sample pair, and select the traffic flows at the same intersection in the first data matrix and the second data matrix at different time periods as the second negative sample pair; A first determination module for generating a first loss value according to the cosine similarity between the first positive sample pair and the first negative sample pair and a contrast loss function, generating a second loss value according to the cosine similarity between the second positive sample pair and the second negative sample pair and the contrast loss function. The contrast loss function is a loss function used to train a neural network to distinguish similar and dissimilar samples. The first loss value reflects the performance of the traffic flow prediction model in distinguishing the first positive sample pair and the first negative sample pair, and the second loss value reflects the performance of the traffic flow prediction model in distinguishing the second positive sample pair and the second negative sample pair; A second determination module, configured to splice the feature vectors of the first positive sample pair and the second positive sample pair to obtain a first spliced feature, input the first spliced feature into a multi-layer perceptron in a traffic flow prediction model, generate a predicted value of the inflow traffic volume at the next moment of a preset traffic flow map and a predicted value of the outflow traffic volume at the next moment of the preset traffic flow map, obtain a first difference between the predicted value of the inflow traffic volume at the next moment of the preset traffic flow map and the actual value of the inflow traffic volume, obtain a second difference between the predicted value of the outflow traffic volume at the next moment of the preset traffic flow map and the actual value of the outflow traffic volume, and add the absolute value of the first difference and the absolute value of the second difference to obtain a third loss value; An adjustment module, configured to add the first loss value, the second loss value, and the third loss value to obtain a target loss value, and adjust model parameters to obtain a reduced target loss value; A prediction module, configured to, when the reduced target loss value meets a preset condition, select the traffic flow prediction model using the adjusted model parameters as a target model, and generate a predicted value of the traffic flow volume at the next moment of a target traffic flow map through the target model.

6. A computer 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, the steps of the traffic flow prediction method according to any one of claims 1 to 4 are implemented.

7. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, the steps of the traffic flow prediction method according to any one of claims 1 to 4 are implemented.

Citation Information

Patent Citations

  • Urban traffic flow prediction method and device based on migration comparative learning

    CN115985102A

  • Traffic flow prediction model training method and device, computer equipment and medium

    CN119516786A