Abnormal trajectory detection method and system based on self-attention mechanism neural network

By constructing a TPRNN model based on a self-attention mechanism neural network, the problem of low recognition rate of abnormal taxi trajectories in existing technologies is solved, and efficient and accurate abnormal trajectory detection is achieved under complex road network structures.

CN117290754BActive Publication Date: 2026-02-13GUIZHOU MINZU UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311218453.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-09-20
Publication Date
2026-02-13
Estimated Expiration
2043-09-20

AI Technical Summary

Technical Problem

Existing methods have low recognition rates when identifying abnormal taxi trajectories, require a large amount of computation, and do not fully consider the contextual information of the trajectory sequence, especially under complex road network structures.

Method used

A method based on a self-attention mechanism neural network is adopted. By acquiring and preprocessing vehicle trajectory data, a Transformer parallel recurrent neural network model (TPRNN) is constructed to extract trajectory sequence features and contextual information, and to distinguish between normal and abnormal trajectories.

Benefits of technology

It improves the abnormal trajectory recognition rate, reduces equipment performance requirements, and enhances the accuracy and reliability of detection results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117290754B_ABST
    Figure CN117290754B_ABST
Patent Text Reader

Abstract

The application provides an abnormal trajectory detection method and system based on a self-attention mechanism neural network, wherein the method comprises the following steps: obtaining original moving trajectory data of a vehicle, preprocessing the original moving trajectory data to obtain moving trajectory data; obtaining a driving trajectory data set of the vehicle under a passenger-carrying state according to the moving trajectory data, and performing trajectory map matching, gridding, same starting point trajectory pair extraction and trajectory enhancement processing on the driving trajectory data set to obtain a target trajectory data set; constructing a parallel recurrent neural network model based on a Transformer according to the target trajectory data set to obtain a TPRNN model, and using the TPRNN model for detection of vehicle target moving trajectory data to obtain an abnormal trajectory detection result. The application can realize identification of trajectories with different starting points, improve the identification rate, reduce the performance requirement of equipment, and improve the accuracy and reliability of the abnormal trajectory detection result.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of intelligent transportation, and in particular to an abnormal trajectory detection method and system based on a self-attention mechanism neural network, an electronic device, and a computer readable storage medium. BACKGROUND

[0002] Trajectory anomaly generally refers to deviation from other trajectories in space or occurrence of certain behaviors deviating from expectations, such as detour behavior of a taxi, hurricane with sudden wind direction change, circling aircraft, and fishing boat frequently changing course. As one of the main means of transportation in the city, taxis bring great convenience to citizens. However, individual taxi drivers maliciously choose routes longer than normal routes to obtain more benefits, which disrupts the normal service market and infringes on the legitimate interests of passengers. Therefore, detecting abnormal situations of passenger travel trajectories based on mobile trajectory big data has important guiding significance and practical application value for improving the service quality of taxis and protecting the basic interests of passengers.

[0003] Existing methods usually achieve abnormal trajectory recognition based on trajectory similarity, but such methods need to use historical trajectory data of the same starting point to effectively detect abnormal trajectories. Obviously, this is too limited for complex road network structures, resulting in low recognition rate of the above method. At the same time, calculating trajectory similarity needs to access the historical database of trajectories, which will bring a huge amount of calculation and network burden, and requires high server computing performance and data storage capacity in actual application. In addition, the abnormal trajectory detection method based on recurrent neural network does not fully consider the context information of trajectory sequences.

[0004] Therefore, there is an urgent need for an abnormal trajectory detection method that can identify different starting points, has high recognition rate, low device performance requirement, and fully considers the context information of trajectory sequences. SUMMARY

[0005] Therefore, it is necessary to provide an abnormal trajectory detection method, system, electronic device, and computer readable storage medium based on a self-attention mechanism neural network to solve the above technical problems.

[0006] An abnormal trajectory detection method based on a self-attention mechanism neural network includes the following steps:

[0007] Obtaining original mobile trajectory data of a vehicle, preprocessing the original mobile trajectory data to obtain mobile trajectory data;

[0008] According to the moving trajectory data, the driving trajectory data set of the vehicle in the passenger-carrying state is obtained, and the driving trajectory data set is subjected to trajectory map matching, gridding, same starting point trajectory pair extraction and trajectory enhancement processing to obtain a target trajectory data set, including: according to the moving trajectory data, the trajectory driving data set of the vehicle in the passenger-carrying state is obtained, and the vehicle ID is sorted to find the trajectory data with the same vehicle ID and continuous operation state of 111…10, wherein the operation state includes the passenger-carrying state and the empty vehicle state, and the passenger-carrying state is recorded as 1 and the empty vehicle state is recorded as 0; the trajectory data with the continuous operation state of 111…10 is subjected to data elimination, and the latitude and longitude and time data of the vehicle driving trajectory in the passenger-carrying state are reserved as processing data; the processing data is subjected to map matching to obtain the driving trajectory data of the vehicle on the actual road network; the road network is gridded according to the driving trajectory data obtained by matching to obtain gridded sequence trajectory data; the driving trajectory data sets with the same starting point grid are defined as trajectory pairs, and the driving trajectory in the trajectory pair is subjected to enhancement processing to obtain a grid mapping trajectory represented by a continuous grid sequence;

[0009] According to the target trajectory data set, a parallel recurrent neural network model based on Transformer is constructed to obtain a TPRNN model, including: inputting the target trajectory data set into an embedding layer to obtain trajectory embedding features, and extracting trajectory sequence features and context information through a Transformer encoding module; hidden features in the trajectory embedding features are extracted through a parallel recurrent neural network model, and the hidden features are used to distinguish normal trajectories and abnormal trajectories; all hidden features are fused through a linear neural network to construct a TPRNN model;

[0010] The TPRNN model is used to detect the target moving trajectory data of the vehicle to obtain an abnormal trajectory detection result.

[0011] In one of the embodiments, the target trajectory data set is input into an embedding layer to obtain trajectory embedding features, and trajectory sequence features and context information are extracted through a Transformer encoding module, including: the gridded sequence trajectory data is input into an embedding layer to obtain trajectory embedding features, and the formula is:

[0012] TrajectoryEmbedding=Embedding Layer(Tr) (1)

[0013] In the formula, T r is gridded sequence trajectory data, and TrajectoryEmbedding∈R n×d, d is the dimension of the trajectory embedding feature; each sequence and dimension of the trajectory embedding feature is positionally encoded by a Transformer encoder, and the formula is:

[0014]

[0015] In the formula, PositionEncoding∈R n×d , PE represents position encoding, pos represents the position of the trajectory embedding feature, and i represents the dimension position of the trajectory embedding feature; the position encoding and the trajectory embedding feature are combined to obtain an enhanced trajectory sequence feature, i.e., a TP embedding feature, and the formula is:

[0016] TPEmbedding=PositionEncoding+TrajectoryEmbedding (3)

[0017] The TP embedding feature is input into a Transformer encoding module, and a TT embedding feature is calculated, and the formula is:

[0018]

[0019] In the formula, TTEmbedding∈R n×d ; the context information of the target trajectory dataset is extracted by the Transformer encoding module.

[0020] In one of the embodiments, the Transformer encoding module is composed of two Transformer encoders connected in series, and the Transformer encoder includes a multi-head attention mechanism and a feedforward neural network; wherein the multi-head attention mechanism obtains the outputs of multiple attention mechanisms through a multi-head mechanism, and the outputs are concatenated and linearly transformed to obtain the final output, and the calculation formula of the multi-head attention mechanism is:

[0021]

[0022] In the formula, W o ∈R tdv×d is input data, the dimension tdv is the product of t and dv, and each head i in the multi-head attention mechanism is the output of an independent self-attention layer, t is the total number of heads of the multi-head attention, and dv is the dimension of the output of a single self-attention layer; in the self-attention layer, the input data X is linearly transformed to obtain Q, K and V, the attention score is calculated by using softmax, and the output head∈R n×dv of the attention mechanism is obtained by matrix multiplication with V; the calculation formula of the self-attention layer is:

[0023]

[0024] In the formula, W q ∈R d×dq W k ∈R d×dk W v ∈R d×dv The weight matrix is ​​for linear transformation, and the output Q∈R n×dq , V∈R n ×dk , K∈R n×dv The dimensions dq, dk, and dv are all equal to the dimension d of the trajectory embedding features; the output X of the multi-head attention mechanism is... atth The output is calculated using a feedforward neural network, which includes two linear neural networks and a ReLU activation function. The output of the feedforward neural network is then connected to the input via a jump connection to obtain X. FC X FC The calculation formula is:

[0025]

[0026] In the formula, W1∈R d×d1 W2∈R d×d2 b1∈R d1 and b2∈R d2 All of these are network weights obtained during training, and d1 and d2 are hyperparameters.

[0027] In one embodiment, the extraction of hidden features from trajectory embeddings using a parallel recurrent neural network model, wherein the hidden features are used to distinguish between normal and abnormal trajectories, includes: the parallel recurrent neural network model consisting of a four-layer long short-term memory network, with two sets of trajectory embeddings as input, including TP embedding features and TT embedding features; and the calculation of the hidden feature h of each layer through the four-layer long short-term memory network. i ; Concatenate all the hidden features to obtain vector h, calculated using the following formula:

[0028]

[0029] In one embodiment, the step of fusing all hidden features through a linear neural network to construct the TPRNN model includes: using the obtained vector h, employing a linear neural network to output the abnormal trajectory detection result y, thus completing the construction of the TPRNN model. The calculation formula for the detection result y is:

[0030] y=softmax(Linear(ReLU(Linear(h)))) (9)

[0031] In the formula, h is obtained through two layers of linear neural networks, a ReLU activation function, and a softmax activation function to obtain a final probability output y e R 2 wherein the two values of y are probabilities of normal trajectories and abnormal trajectories, respectively.

[0032] An abnormal trajectory detection system based on a self-attention mechanism neural network is used to implement the abnormal trajectory detection method based on a self-attention mechanism neural network as described above, and comprises: a data preprocessing module configured to obtain original mobile trajectory data of a vehicle, and preprocess the original mobile trajectory data to obtain mobile trajectory data; a data set acquisition module configured to acquire a driving trajectory data set of the vehicle in a passenger-carrying state according to the mobile trajectory data, and perform trajectory map matching, gridding, same starting point trajectory pair extraction, and trajectory enhancement processing on the driving trajectory data set to obtain a target trajectory data set, including: acquiring a trajectory driving data set of the vehicle in the passenger-carrying state according to the mobile trajectory data, and sorting according to vehicle ID to find trajectory data with the same vehicle ID and continuous operation state of 111…10, wherein the operation state includes a passenger-carrying state and an empty vehicle state, and the passenger-carrying state is recorded as 1 and the empty vehicle state is recorded as 0; performing data elimination on the trajectory data with the continuous operation state of 111…10, and retaining the latitude and longitude and time data of the vehicle driving trajectory in the passenger-carrying state as to-be-processed data; performing map matching according to the to-be-processed data to obtain driving trajectory data of the vehicle on an actual road network; performing gridding on the road network according to the driving trajectory data obtained by matching to obtain gridded sequence trajectory data; defining a set of driving trajectory data with the same starting point grid as a trajectory pair, and performing enhancement processing on the driving trajectory in the trajectory pair to obtain a grid mapping trajectory represented by a continuous grid sequence; a model construction module configured to construct a parallel recurrent neural network model based on a Transformer according to the target trajectory data set to obtain a TPRNN model, including: inputting the target trajectory data set into an embedding layer to obtain trajectory embedding features, and extracting trajectory sequence features and context information through a Transformer encoding module; extracting hidden features in the trajectory embedding features through a parallel recurrent neural network model, the hidden features being used to distinguish normal trajectories and abnormal trajectories; and constructing the TPRNN model by fusing all hidden features through a linear neural network; and an abnormal trajectory detection module configured to detect target mobile trajectory data of the vehicle using the TPRNN model to obtain an abnormal trajectory detection result.

[0033] An electronic device comprises a memory, a processor, and a computer program stored on the memory and executable on the processor, and the processor implements the steps of the abnormal trajectory detection method based on a self-attention mechanism neural network described in each of the embodiments when executing the program.

[0034] A computer readable storage medium, having stored thereon a computer program, which, when executed by a processor, implements the steps of the abnormal trajectory detection method based on the self-attention mechanism neural network in each of the above embodiments.

[0035] Compared with the prior art, the advantages and beneficial effects of the present application are that: by acquiring original moving trajectory data of a vehicle, the original moving trajectory data is preprocessed to obtain moving trajectory data; according to the moving trajectory data, driving trajectory data set of the vehicle in the passenger-carrying state is acquired, and the driving trajectory data set is subjected to trajectory map matching, gridding, same starting point trajectory pair extraction and trajectory enhancement processing to obtain a target trajectory data set; according to the target trajectory data set, a TPRNN model based on a parallel recurrent neural network model of Transformer is constructed to obtain a TPRNN model, the target moving trajectory data of the vehicle is detected by using the TPRNN model to obtain an abnormal trajectory detection result, so as to realize identification of abnormal trajectories with different starting points, improve the identification rate, reduce the performance requirement for the equipment, and the hidden vector and context information of the trajectory sequence can be acquired through the parallel recurrent neural network model and the Transformer, so as to improve the accuracy and reliability of the abnormal trajectory detection result. BRIEF DESCRIPTION OF DRAWINGS

[0036] Figure 1 It is a flowchart of an abnormal trajectory detection method based on a self-attention mechanism neural network in one embodiment;

[0037] Figure 2 It is a processing flowchart of the driving trajectory data set in one embodiment;

[0038] Figure 3 It is an abnormal trajectory example diagram in one embodiment;

[0039] Figure 4 It is a gridded trajectory example diagram in one embodiment;

[0040] Figure 5 It is a flowchart of the TPRNN model construction in one embodiment;

[0041] Figure 6 It is a flowchart of feature and context information extraction in one embodiment;

[0042] Figure 7 It is a structure diagram of the TPRNN model in one embodiment;

[0043] Figure 8 It is a flowchart of trajectory embedding vector extraction in one embodiment;

[0044] Figure 9A structural schematic diagram of a Transformer encoder in an embodiment;

[0045] Figure 10 A structural schematic diagram of a Parallel RNN in an embodiment

[0046] Figure 11 A structural schematic diagram of an abnormal trajectory detection system based on a self-attention mechanism neural network in an embodiment;

[0047] Figure 12 A structural schematic diagram of an electronic device in an embodiment. DETAILED DESCRIPTION

[0048] In order to make the objects, technical solutions and advantages of the present application clearer, further detailed description will be made to the present application by specific embodiments in combination with the drawings. It should be understood that the specific embodiments described herein are only used to explain the present application, and are not used to limit the present application.

[0049] In an embodiment, as shown in Figure 1 A self-attention mechanism neural network-based abnormal trajectory detection method is provided, comprising the following steps:

[0050] Step S110, obtaining original moving trajectory data of a vehicle, and preprocessing the original moving trajectory data to obtain moving trajectory data.

[0051] Specifically, the terminal collects original moving trajectory data generated by the vehicle in movement through GPS, and preprocesses the original moving trajectory data, for example, data cleaning, missing value completion, repeated value elimination, data standardization, etc., to obtain processed moving trajectory data for subsequent use.

[0052] Step S120, obtaining a driving trajectory data set of the vehicle in a passenger-carrying state according to the moving trajectory data, and performing trajectory map matching, gridding, same starting point trajectory pair extraction and trajectory enhancement processing on the driving trajectory data set to obtain a target trajectory data set.

[0053] Specifically, according to the moving trajectory data obtained after preprocessing, driving trajectory data of the vehicle in a passenger-carrying state is screened to obtain a driving trajectory data set, and all data obtained is combined to form the driving trajectory data set, and all data in the driving data set is subjected to trajectory map matching, gridding, same starting point trajectory pair extraction and trajectory enhancement processing, so as to obtain the target trajectory data set.

[0054] Step S130, constructing a parallel recurrent neural network model based on Transformer according to the target trajectory data set to obtain a TPRNN model.

[0055] Specifically, according to the target trajectory data set obtained after processing, a parallel recurrent neural network model based on Transformer, that is, a TPRNN model, is constructed and trained, hidden vectors between different trajectories are learned through the parallel recurrent neural network, so as to realize accurate abnormal trajectory detection; at the same time, trajectory embedding training is performed by using the Transformer, so as to effectively learn the context information of the trajectory sequence, and further improve the accuracy of abnormal trajectory detection.

[0056] In step S140, the target moving trajectory data of the vehicle is detected by using the TPRNN model, and an abnormal trajectory detection result is obtained.

[0057] Specifically, the target moving trajectory data of the vehicle on the actual road network is obtained, and the TPRNN model is used for detection to obtain the detection result of the abnormal trajectory, so as to obtain the judgment result of whether the taxi is detoured, and realize the abnormal trajectory in the trajectory sequence of different starting points, and solve the defect that the existing trajectory similarity method can only identify the abnormal trajectory in the trajectory sequence of a single starting point.

[0058] In the embodiment, the original moving trajectory data of the vehicle is obtained, the original moving trajectory data is preprocessed to obtain moving trajectory data, the driving trajectory data set of the vehicle in the passenger-carrying state is obtained according to the moving trajectory data, and the trajectory map matching, gridding, same starting point trajectory pair extraction and trajectory enhancement processing are performed on the driving trajectory data set to obtain a target trajectory data set. According to the target trajectory data set, a parallel recurrent neural network model based on Transformer is constructed to obtain a TPRNN model, the target moving trajectory data of the vehicle is detected by using the TPRNN model, and an abnormal trajectory detection result is obtained, so as to realize the identification of trajectories of different starting points, improve the identification rate, reduce the performance requirement of the equipment, and enable the hidden vectors and context information of the trajectory sequence to be obtained through the parallel recurrent neural network model and the Transformer, and improve the accuracy and reliability of the abnormal trajectory detection result.

[0059] In one embodiment, in the Python framework, as shown in Figure 2 The step S120 specifically includes:

[0060] In step S210, the trajectory driving data set of the vehicle in the passenger-carrying state is obtained according to the moving trajectory data set, and the trajectory data with the same vehicle ID and continuous running state of 111…10 is found by sorting according to the vehicle ID, wherein the operation state includes the passenger-carrying state and the empty vehicle state, and the passenger-carrying state is recorded as 1 and the empty vehicle state is recorded as 0.

[0061] Step S220: Remove trajectory data with continuous running status 111...10, and retain the latitude, longitude and time data of the vehicle's driving trajectory under passenger status as the data to be processed.

[0062] Step S230: Perform map matching based on the data to be processed to obtain the vehicle's driving trajectory data on the actual road network.

[0063] Step S240: Based on the matched driving trajectory data, the road network is rasterized to obtain gridded sequence trajectory data.

[0064] Step S250: Define the set of driving trajectory data with the same starting point grid as a trajectory pair, and perform enhancement processing on the driving trajectory in the trajectory pair to obtain a grid mapping trajectory represented by a continuous grid sequence.

[0065] In this embodiment, since the present invention mainly detects whether the driver's trajectory shows abnormal detour behavior while carrying passengers, such as... Figure 3 The image shows an example of anomaly trajectories, where T1 and T2 are abnormal trajectories, and R1 and R2 are normal trajectories. Therefore, the first step is to obtain a dataset of vehicle trajectories under passenger-carrying conditions from the acquired motion trajectory dataset. The data is then sorted based on vehicle ID for easier searching later. Trajectories with the same vehicle ID and consecutive operating states of 111…10 are searched within this dataset. Operating states include passenger-carrying and empty states, with passenger-carrying state denoted as 1 and empty state as 0. The searched data undergoes data filtering, retaining only the latitude, longitude, and time data of the vehicle trajectories under passenger-carrying conditions as the data to be processed, improving the efficiency of subsequent data processing. Map matching is then performed on the acquired data to be processed to determine the vehicle's trajectory data on the actual road network. Based on the matched trajectory data, the road network is rasterized. Through the rasterized road network, gridded sequence trajectory data is obtained, as shown below. Figure 4 As shown, a set of driving trajectory data with the same starting grid is defined as a trajectory pair. The driving trajectory is enhanced by the trajectory pair to obtain a grid-mapped trajectory represented by a continuous grid sequence.

[0066] In one embodiment, within a Python framework, such as Figure 5 As shown, step S130 specifically includes:

[0067] Step S310: Input the target trajectory dataset into the embedding layer to obtain trajectory embedding features, and extract trajectory sequence features and context information through the Transformer encoding module.

[0068] Step S320, hidden features of the trajectory embedding are extracted by the parallel recurrent neural network model, and the hidden features are used to distinguish normal trajectories and abnormal trajectories.

[0069] Step S330, features are fused by the linear neural network to construct the TPRNN model.

[0070] In the embodiment, the trajectory embedding features are obtained by inputting the target trajectory dataset into the embedding layer, and the trajectory sequence features and context information are extracted by the Transformer encoding module; the hidden features of the trajectory embedding are extracted by the parallel recurrent neural network Parallel RNN, so as to distinguish normal trajectories and abnormal trajectories; all the features are fused by the linear neural network to obtain the TPRNN model.

[0071] Further, in the Python framework, as shown in Figure 6 , the specific operation steps of step S310 include:

[0072] Step S311, the grid sequence trajectory data are input into the embedding layer to obtain the trajectory embedding features, and the formula is:

[0073] TrajectoryEmbedding=Embedding Layer(Tr) (1)

[0074] In the formula, T r is the grid sequence trajectory data, TrajectoryEmbedding∈R n×d , and d is the dimension of the trajectory embedding features.

[0075] Step S312, the position encoding is performed on each sequence and dimension of the trajectory embedding features by the Transformer encoder, and the formula is:

[0076]

[0077] In the formula, PositionEncoding∈R n×d , PE represents the position encoding, pos represents the position of the trajectory embedding features, and i represents the dimension position of the trajectory embedding features; the enhanced trajectory sequence features, i.e., the TP embedding features, are obtained by combining the position encoding and the trajectory embedding features, and the formula is:

[0078] TPEmbedding=PositionEncoding+TrajectoryEmbedding (3)

[0079] Step S313, the TP embedding features are input into the Transformer encoding module to calculate the TT embedding features, and the formula is:

[0080]

[0081] In the formula, TTEmbedding ∈ R n×d The context information of the target trajectory data set is extracted by the Transformer encoding module.

[0082] Specifically, as shown in Figure 7 and Figure 8 shown, the trajectory data in S120 is input into the Embedding layer to obtain input trajectory embedding, and the grid trajectory sequence data Tr ∈ R n×d is embedded to obtain trajectory embedding TrajectoryEmbedding; the obtained trajectory embedding is added to the position encoding to obtain TPEmbedding. Since the attention mechanism of the Transformer encoder ignores the position information of the trajectory sequence, the position encoding is introduced to record the position information of the trajectory sequence, and each sequence position and dimension of the trajectory embedding is position encoded. The obtained position encoding and TPEmbedding are added to enhance the sequence feature of the trajectory embedding. The obtained TPEmbedding is input into the Transformer encoding module, and TTEmbedding is calculated. Meanwhile, the context information in the target trajectory data set can also be extracted by the Transformer encoding module, thereby improving the accuracy of the abnormal trajectory detection.

[0083] Further, the Transformer encoding module is composed of two Transformer encoders in series, and the Transformer encoder includes a multi-head attention mechanism and a feedforward neural network. The multi-head attention mechanism obtains the outputs of multiple attention mechanisms through a multi-head mechanism, performs splicing, and then performs linear transformation to obtain the final output. The calculation formula of the multi-head attention mechanism is as follows:

[0084]

[0085] In the formula, W o ∈ R tdv×d is input data, the dimension tdv is the product of t and dv, and each head i in the multi-head attention mechanism is the output of an independent self-attention layer. t is the total number of heads of the multi-head attention, and dv is the dimension of the output of a single self-attention layer. In the self-attention layer, the input data X is linearly transformed to obtain Q, K and V. The attention score is calculated by using softmax, and the matrix multiplication is performed with V to obtain the output head ∈ R n×dv of the attention mechanism. The calculation formula of the self-attention layer is as follows:

[0086]

[0087] In the formula, W q ∈R d×dp W k ∈R d×dk W v ∈R d×dv The weight matrix is ​​for linear transformation, and the output Q∈R n×dq V∈R n ×dk , K∈R n×dv The dimensions dq, dk, and dv are all equal to the dimension d of the trajectory embedding features; the output X of the multi-head attention mechanism is... atth The output is calculated using a feedforward neural network, which consists of two linear neural networks and a ReLU activation function. The output of the feedforward neural network is then connected to the input via a jump connection to obtain X. FC X FC The calculation formula is:

[0088]

[0089] In the formula, W1∈R d×d1 W2∈R d×d2 b1∈R d1 and b2∈R d2 All of these are network weights obtained during training, and d1 and d2 are hyperparameters.

[0090] Specifically, such as Figure 9 As shown, the Transformer encoding module consists of two cascaded Transformer encoder layers. The Transformer encoder includes a multi-head attention mechanism and a feedforward neural network module. The input and output data of this Transformer encoding module are TPEmbedding and TTEmbedding, respectively, where the shape of the module's output, TTEmbedding ∈ R, is... n×d .

[0091] The multi-head attention mechanism used in the Transformer encoder obtains the outputs of multiple attention mechanisms, head1, ..., head2, through a multi-head mechanism. h After concatenation, a linear transformation is performed to obtain the final output b1∈R. n×d In a multi-head attention mechanism, each head receives input. i All are outputs of independent self-attention layers.

[0092] In the self-attention layer, the input data X is transformed linearly to obtain Q, K and V, and after the attention score is calculated by using the softmax, the matrix multiplication is performed with V to obtain the output of the attention mechanism. After obtaining the output result of the multi-head attention mechanism, the output is further calculated by the feedforward neural network, which includes two linear neural networks and a ReLU activation function. The output of the feedforward neural network is connected with the input in a skip connection to obtain the output result.

[0093] Further, in the Python framework, the specific operation steps of step S320 include that the parallel recurrent neural network model is composed of four layers of long short-term memory networks, and the input is two groups of trajectory embeddings including TP embedding features and TT embedding features; the hidden features h i of each layer are calculated by the four layers of long short-term memory networks; all the hidden features are spliced to obtain a vector h, and the calculation formula is:

[0094]

[0095] Specifically, as shown in Figure 10 , the Parallel RNN (parallel RNN) module is composed of four layers of LSTM networks, and the Parallel RNN (parallel RNN) input is two groups of trajectory embeddings TPEmbedding and TTEmbedding. The four layers of LSTM are calculated to obtain different hidden states h i of each layer; secondly, all the hidden states are spliced into a vector h, so as to be fused by a linear neural network to obtain an abnormal probability y.

[0096] Further, in the Python framework, the specific operation steps of step S330 include that the vector h is obtained, a linear neural network is used to output an abnormal trajectory detection result y, and the construction of the TPRNN model is completed, and the calculation formula of the detection result y is:

[0097] y=softmax(Linear(ReLU(Linear(h)))) (9)

[0098] In the formula, h is subjected to two layers of linear neural networks, a ReLU activation function and a softmax activation function to obtain a final probability output y∈R 2 , wherein the two values of y are the probabilities of normal trajectories and abnormal trajectories, respectively.

[0099] Specifically, the spatio-temporal features h are obtained, a linear neural network is used to output a detection result y, y includes two values, which are the probabilities of normal trajectories and abnormal trajectories, respectively, that is, the detection result of abnormal trajectories, so as to realize the identification of abnormal trajectory detection and improve the accuracy of abnormal trajectory detection.

[0100] As Figure 11 shown, an abnormal trajectory detection system 10 based on a self-attention mechanism neural network is provided for implementing an abnormal trajectory detection method based on a self-attention mechanism neural network as described above, comprising a data preprocessing module 11, a data set acquisition module 12, a model construction module 13 and an abnormal trajectory detection module 14, wherein:

[0101] The data preprocessing module 11 is configured to acquire original moving trajectory data of a vehicle, preprocess the original moving trajectory data, and obtain moving trajectory data.

[0102] The data set acquisition module 12 is configured to acquire a driving trajectory data set of the vehicle under a passenger-carrying state according to the moving trajectory data, and perform trajectory map matching, gridding, same starting point trajectory pair extraction and trajectory enhancement processing on the driving trajectory data set to obtain a target trajectory data set.

[0103] The model construction module 13 is configured to construct a parallel recurrent neural network model based on Transformer according to the target trajectory data set to obtain a TPRNN model.

[0104] The abnormal trajectory detection module 14 is configured to detect the target moving trajectory data of the vehicle using the TPRNN model to obtain an abnormal trajectory detection result.

[0105] In one embodiment, an electronic device is provided, which can be a server, and an internal structure diagram of the device can be as shown in Figure 12 The device includes a processor, a memory, a network interface and a database connected through a system bus. The processor of the device is configured to provide computing and control capabilities. The memory of the device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operating system and the computer program in the non-volatile storage medium to run. The database of the device is configured to store a configuration template and can also be configured to store target data. The network interface of the device is configured to perform network connection communication with an external terminal. The computer program is executed by the processor to implement an abnormal trajectory detection method based on a self-attention mechanism neural network.

[0106] Those skilled in the art can understand that Figure 12 the structure shown in the figure is only a block diagram of part of the structure related to the scheme of the present application, and does not constitute a limitation on the device to which the scheme of the present application is applied. The specific device can include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0107] In one embodiment, a computer readable storage medium storing a computer program can also be provided, the computer program comprising program instructions which, when executed by a computer, cause the computer to perform the method as described in the preceding embodiments, the computer can be part of the above-mentioned abnormal trajectory detection system based on a self-attention mechanism neural network.

[0108] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be completed by instructing the relevant hardware through a computer program, and the program can be stored in a computer readable storage medium. When the program is executed, it can include the processes of the above-mentioned embodiments. The storage medium can be a magnetic disc, an optical disc, a read-only memory (ROM) or a random access memory (RAM), etc.

[0109] Obviously, those skilled in the art should understand that the above-mentioned modules or steps of the present application can be realized based on general computing devices, which can be concentrated on a single computing device or distributed on a network composed of multiple computing devices. Alternatively, they can be realized by program codes executable by a computing device, so that they can be stored in a computer storage medium (ROM / RAM, magnetic disc, optical disc) and executed by a computing device, and in some cases, the steps shown or described can be executed in different order, or they can be made into individual integrated circuit modules, or multiple modules or steps can be made into a single integrated circuit module. Therefore, the present application is not limited to any specific hardware and software combination.

[0110] The above is a further detailed description of the present application in combination with specific embodiments, and the specific implementation of the present application should not be limited to these descriptions. For those skilled in the art, without departing from the idea of the present application, a number of simple deductions or substitutions can be made, which should be considered as falling within the protection scope of the present application.

Claims

1. A method for detecting abnormal trajectories based on a self-attention mechanism neural network, characterized in that, The method comprises the following steps: Obtaining original moving trajectory data of a vehicle, preprocessing the original moving trajectory data to obtain moving trajectory data; According to the moving trajectory data, obtaining a driving trajectory data set of the vehicle in a passenger-carrying state, and performing trajectory map matching, gridding, same starting point trajectory pair extraction and trajectory enhancement processing on the driving trajectory data set to obtain a target trajectory data set, including: according to the moving trajectory data, obtaining a trajectory driving data set of the vehicle in a passenger-carrying state, and sorting according to the vehicle ID to find trajectory data with the same vehicle ID and continuous operation state of 111…10, wherein the operation state includes a passenger-carrying state and an empty vehicle state, and the passenger-carrying state is recorded as 1 and the empty vehicle state is recorded as 0; performing data rejection on the trajectory data with the continuous operation state of 111…10, retaining the latitude and longitude and time data of the vehicle driving trajectory in the passenger-carrying state as processing data; performing map matching according to the processing data to obtain the driving trajectory data of the vehicle on the actual road network; gridding the road network according to the matched driving trajectory data to obtain gridded sequence trajectory data; defining the driving trajectory data set with the same starting point grid as a trajectory pair, and performing enhancement processing on the driving trajectory in the trajectory pair to obtain a grid mapping trajectory represented by a continuous grid sequence; According to the target trajectory data set, a parallel recurrent neural network model based on Transformer is constructed to obtain a TPRNN model, including: inputting the target trajectory data set into an embedding layer to obtain trajectory embedding features, and extracting trajectory sequence features and context information through a Transformer encoding module; extracting hidden features in the trajectory embedding features through a parallel recurrent neural network model, the hidden features being used to distinguish normal trajectories and abnormal trajectories; fusing all hidden features through a linear neural network to construct a TPRNN model; The TPRNN model is used to detect target moving trajectory data of a vehicle to obtain an abnormal trajectory detection result.

2. The method of claim 1, wherein the self-attention mechanism neural network-based abnormal trajectory detection method is characterized by, The inputting of the target trajectory data set into the embedding layer to obtain trajectory embedding features and the extracting of trajectory sequence features and context information through the Transformer encoding module include: Inputting the gridded sequence trajectory data into an embedding layer to obtain trajectory embedding features, the formula being: TrajectoryEmbedding=Embedding Layer(Tr) (1) In the formula, T r is the grid sequence trajectory data, TrajectoryEmbedding∈R n×d , d is the dimension of the trajectory embedding feature; Performing position encoding on each sequence and dimension of the trajectory embedding features through a Transformer encoder, the formula being: In the formula, PositionEncoding∈R n×d , PE represents a position encoding, pos represents a position of a trajectory embedding feature, and i represents a dimension position of the trajectory embedding feature. Combining the position encoding and the trajectory embedding features to obtain enhanced trajectory sequence features, i.e., TP embedding features, the formula being: TPEmbedding=PositionEncoding+TrajectoryEmbedding (3) Inputting the TP embedding features into a Transformer encoding module to calculate TT embedding features, the formula being: In the formula, TTEmbedding ∈ R n×d ; Context information of the target trajectory dataset is extracted by the Transformer encoding module.

3. The method of claim 2, wherein the self-attention mechanism neural network is a Transformer network. The Transformer encoding module is composed of two serial Transformer encoders, and the Transformer encoder includes a multi-head attention mechanism and a feedforward neural network. The multi-head attention mechanism obtains the outputs of multiple attention mechanisms through a multi-head mechanism, performs splicing, and obtains the final output through linear transformation, and the calculation formula of the multi-head attention mechanism is: wherein W o ∈R tdv×d is the input data, the dimension tdv is the product of t and dv, and the input of each head i in the multi-head attention mechanism is the output of an independent self-attention layer, t is the total number of heads of the multi-head attention, and dv is the dimension of the output of a single self-attention layer. In the self-attention layer, the input data X is linearly transformed to obtain Q, K and V, the attention score is calculated by using softmax, and the matrix multiplication is performed with V to obtain the output head of the attention mechanism n×dv The calculation formula of the self-attention layer is: In the formula, W q ∈R d×dq , W k ∈R d×dk , W v ∈R d×dv is a weight matrix of a linear transformation, and output Q∈R n×dq , V∈R n×dk , K∈R n×dv , the dimensions dq, dk and dv are all equal to the dimension d of the trajectory embedding feature; the output result X atth of the multi-head attention mechanism is calculated by a feedforward neural network, the feedforward neural network comprising two linear neural networks and a ReLU activation function, and the output of the feedforward neural network is connected with the input by a skip connection to obtain X FC , and the calculation formula of X FC is: In the formula, W1∈R d×d1 , W2∈R d×d2 , b1∈R d1 and b2∈R d2 are network weights obtained through training, and d1 and d2 are hyperparameters.

4. The method of claim 3, wherein the self-attention mechanism neural network-based abnormal trajectory detection method is characterized by, The hidden features of the trajectory embedding are extracted by the parallel recurrent neural network model, and the hidden features are used to distinguish normal trajectories and abnormal trajectories, including: The parallel recurrent neural network model is composed of four layers of long short-term memory networks, and the input is two groups of trajectory embeddings including TP embedding features and TT embedding features; The hidden features h of each layer are calculated by the four-layer long short-term memory network i ; All the hidden features are spliced to obtain a vector h, and the calculation formula is:

5. The method of claim 4, wherein the self-attention mechanism neural network-based abnormal trajectory detection method is characterized by, All the hidden features are fused by a linear neural network to construct a TPRNN model, including: The vector h is obtained, and a linear neural network is used to output an abnormal trajectory detection result y to complete the construction of the TPRNN model, and the calculation formula of the detection result y is: y=softmax(Linear(ReLU(Linear(h)))) (9) In the formula, h passes through two linear neural networks, a ReLU activation function, and a softmax activation function to obtain a final probability output y e R 2 wherein the two values of y are the probabilities of normal and abnormal trajectories, respectively.

6. An abnormal trajectory detection system based on a self-attention mechanism neural network, characterized by, A neural network-based abnormal trajectory detection method based on a self-attention mechanism is implemented, as claimed in any one of claims 1-5, including: A data preprocessing module is configured to obtain original moving trajectory data of a vehicle, preprocess the original moving trajectory data, and obtain moving trajectory data. A dataset acquisition module is configured to obtain a driving trajectory dataset of the vehicle in a passenger-carrying state based on the moving trajectory data, and perform trajectory map matching, gridding, same starting point trajectory pair extraction, and trajectory enhancement processing on the driving trajectory dataset to obtain a target trajectory dataset, including: obtaining a trajectory driving dataset of the vehicle in the passenger-carrying state based on the moving trajectory data, and sorting based on the vehicle ID to find trajectory data with the same vehicle ID and continuous operation state of 111…10, wherein the operation state includes a passenger-carrying state and an empty vehicle state, and the passenger-carrying state is recorded as 1 and the empty vehicle state is recorded as 0; performing data rejection on the trajectory data with the continuous operation state of 111…10, retaining the latitude and longitude and time data of the vehicle driving trajectory in the passenger-carrying state as to-be-processed data; performing map matching based on the to-be-processed data to obtain driving trajectory data of the vehicle on the actual road network; performing gridding on the road network based on the matched driving trajectory data to obtain gridded sequence trajectory data; defining a set of driving trajectory data with the same starting point grid as a trajectory pair, and performing enhancement processing on the driving trajectory in the trajectory pair to obtain a grid mapping trajectory represented by a continuous grid sequence. A model construction module is configured to construct a parallel recurrent neural network model based on a Transformer according to the target trajectory dataset, to obtain a TPRNN model, including: inputting the target trajectory dataset into an embedding layer to obtain trajectory embedding features, and extracting trajectory sequence features and context information through a Transformer encoding module; extracting hidden features in the trajectory embedding features through a parallel recurrent neural network model, the hidden features being used to distinguish normal trajectories and abnormal trajectories; and fusing all hidden features through a linear neural network to construct the TPRNN model; An abnormal trajectory detection module is configured to detect target moving trajectory data of a vehicle by using the TPRNN model to obtain an abnormal trajectory detection result.

7. An electronic device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, The processor executes the computer program to implement the steps of the method in any one of claims 1 to 5.

8. A computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed by the processor to implement the steps of the method in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Data-driven distributed traffic flow prediction method and system

    CN111860621A

  • Abnormal track detection method and system driven by moving track big data and electronic equipment

    CN115205086A