Trajectory basis estimation model training method and device, equipment and readable storage medium
By mapping trajectory data on a map and dividing it into grids, combined with neural network training, the accuracy problem of trajectory cardinality estimation models is solved, enabling lightweight deployment and efficient trajectory querying on mobile devices.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- WUHAN UNIV
- Filing Date
- 2024-05-08
- Publication Date
- 2026-07-24
AI Technical Summary
Existing trajectory cardinality estimation models cannot fully capture the characteristics of trajectory information, resulting in inaccurate estimation results.
By mapping the trajectory dataset onto a map, an inverted index of edges and vertices is established, and grid division is performed. Trajectory feature data in the grid are statistically analyzed, and a trajectory cardinality estimation model is trained using a neural network, including a feature fusion module, a depthwise separable residual module, and a multi-head attention module. The model is then validated and deployed in a lightweight manner.
It improves the prediction accuracy of the trajectory cardinality estimation model and makes the model suitable for lightweight deployment on mobile devices, thereby improving trajectory query performance and resource management efficiency.
Smart Images

Figure CN118467659B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of database query optimization technology, and in particular to a method, apparatus, device and readable storage medium for training a trajectory cardinality estimation model. Background Technology
[0002] From a micro perspective, the characteristics of trajectory data are difficult to capture. Its inherent inconsistencies in sampling intervals, diverse path lengths, complex road network structures, and uncertainties in user behavior patterns all contribute to its complexity. From a macro perspective, the density of the trajectory dataset and the sampling pattern of the dataset also contribute to its complexity.
[0003] Cardinality estimation is the process of estimating the number of distinct numbers in a set. As a crucial part of database query optimization, cardinality estimation plays a vital role in generating database query plans. Accurate trajectory cardinality estimation is essential for improving trajectory query performance. Conventional cardinality estimation is usually only applicable to data with simple structures, and commonly uses traditional and simple heuristic methods such as linear counting, histograms, simple sampling, bitmaps, and the HyperLogLog cardinality estimation algorithm. Currently, some methods for trajectory cardinality estimation using deep learning models have also emerged.
[0004] However, current trajectory cardinality estimation models merely apply traditional cardinality estimation methods to trajectory information, failing to fully capture the characteristics of trajectory information, resulting in inaccurate trajectory cardinality estimation results. Summary of the Invention
[0005] This application provides a trajectory cardinality estimation model training method, apparatus, device, and readable storage medium, aiming to solve the technical problem that current trajectory cardinality estimation models only apply traditional cardinality estimation methods to trajectory information, and cannot fully capture the characteristics of trajectory information, resulting in inaccurate trajectory cardinality estimation results.
[0006] In a first aspect, embodiments of this application provide a method for training a trajectory cardinality estimation model, the method comprising:
[0007] Obtain the trajectory dataset and map each trajectory in the dataset onto a map;
[0008] Number the edges and vertices of the map, and create an inverted index of the relative trajectories of the edges and vertices;
[0009] Divide the map into grids according to preset dimensions and create a grid index;
[0010] Based on the inverted index and grid index, the trajectory feature data in each grid is statistically analyzed;
[0011] Each training data set consists of trajectory query input, trajectory feature data, and a preset grid query range. The label of each training data set is the true cardinality of the trajectory query input within the preset grid query range.
[0012] The neural network is trained using multiple training data sets to obtain a trajectory basis estimation model.
[0013] Optionally, the neural network includes a feature fusion module, a depthwise separable residual module, a multi-head attention module, and a fully connected output layer.
[0014] Optionally, after training the neural network using multiple training data sets to obtain the trajectory cardinality estimation model, the process includes:
[0015] When the loss function of the neural network converges, the neural network at which the loss function converges is used as the trained trajectory basis estimation model.
[0016] The trained trajectory cardinality estimation model was validated using a validation dataset, and the loss metric between the predicted and actual values of the trajectory cardinality estimation model based on the validation dataset was obtained.
[0017] If the loss index is less than the preset loss index, the verified trajectory basis estimation model will be used as the final trajectory basis estimation model.
[0018] Optionally, the trajectory cardinality estimation model is trained and validated based on the PyTorch framework. After using the validated trajectory cardinality estimation model as the final trajectory cardinality estimation model, the following steps are included:
[0019] The trajectory cardinality estimation model trained and validated based on the PyTorch framework is converted into an intermediate deployment model in ONNX format;
[0020] The intermediate deployment model in ONNX format is converted to a Keras model. During the conversion, the data type of the parameters in the activation layer is converted from single-precision floating-point numbers to 16-bit integers, and the data type of the parameters outside the activation layer is converted from single-precision floating-point numbers to 8-bit integers.
[0021] Optionally, after converting the intermediate deployment model in ONNX format to a Keras model, the following steps are included:
[0022] Using the TensorFlow Lite tool, the Keras model is converted into a trajectory cardinality estimation model suitable for lightweight deployment on mobile devices.
[0023] Secondly, embodiments of this application provide a trajectory cardinality estimation model training device, the trajectory cardinality estimation model training device comprising:
[0024] The acquisition module is used to acquire the trajectory dataset and map each trajectory in the trajectory dataset onto a map;
[0025] The first module is used to number the edges and vertices of the map and to create an inverted index of the relative trajectories of the edges and vertices.
[0026] The second module is used to divide the map into grids according to preset length and width, and to create a grid index;
[0027] The statistics module is used to statistically analyze trajectory feature data in each grid based on the inverted index and the grid index.
[0028] The component module is used to compose each training data with trajectory query input, trajectory feature data and preset grid query range, wherein the label of each training data is the true cardinality of the trajectory query input within the preset grid query range;
[0029] The training module is used to train a neural network using multiple training data sets to obtain a trajectory basis estimation model.
[0030] Optionally, the neural network includes a feature fusion module, a depthwise separable residual module, a multi-head attention module, and a fully connected output layer.
[0031] Optionally, the trajectory cardinality estimation model training device further includes a verification module, used for:
[0032] When the loss function of the neural network converges, the neural network at which the loss function converges is used as the trained trajectory basis estimation model.
[0033] The trained trajectory cardinality estimation model was validated using a validation dataset, and the loss metric between the predicted and actual values of the trajectory cardinality estimation model based on the validation dataset was obtained.
[0034] If the loss index is less than the preset loss index, the verified trajectory basis estimation model will be used as the final trajectory basis estimation model.
[0035] Thirdly, embodiments of this application provide a trajectory cardinality estimation model training device, the trajectory cardinality estimation model training device including a processor, a memory, and a trajectory cardinality estimation model training program stored in the memory and executable by the processor, wherein when the trajectory cardinality estimation model training program is executed by the processor, the steps of the trajectory cardinality estimation model training method as described above are implemented.
[0036] Fourthly, embodiments of this application provide a readable storage medium storing a trajectory cardinality estimation model training program, wherein when the trajectory cardinality estimation model training program is executed by a processor, it implements the steps of the trajectory cardinality estimation model training method as described above.
[0037] The beneficial effects of the technical solutions provided in this application include:
[0038] In this embodiment, a trajectory dataset is acquired, and each trajectory in the dataset is mapped onto a map. The edges and vertices of the map are numbered, and an inverted index of edges and vertices relative to the trajectories is established. The map is divided into grids according to a preset length and width, and a grid index is established. Based on the inverted index and the grid index, trajectory feature data in each grid is statistically analyzed. Each training data set is composed of the trajectory query input, trajectory feature data, and a preset grid query range, where the label of each training data set is the true cardinality of the trajectory query input within the preset grid query range. Multiple training data sets are used to train a neural network to obtain a trajectory cardinality estimation model. This embodiment establishes a mapping between trajectories and maps, divides the map into grids, and statistically analyzes the trajectory feature data in each grid. The trajectory feature data includes the number of trajectories, the number of vertices, the number of edges, and the relationships between grids, among other behavioral feature data related to the trajectories. A matrix composed of the trajectory query input, trajectory feature data, and the preset grid query range is used as each training data set to train the neural network. Since the input training data contains the feature data of the trajectories, the trajectory cardinality estimation model can accurately capture the behavioral features of the trajectories, thus improving the prediction accuracy of the trajectory cardinality estimation model. Attached Figure Description
[0039] Figure 1 This is a flowchart illustrating an embodiment of the trajectory cardinality estimation model training method of this application;
[0040] Figure 2 This is a schematic diagram of map trajectory mapping, representing an embodiment of the trajectory cardinality estimation model training method of this application.
[0041] Figure 3 A schematic diagram illustrating the trajectory feature data structure of an embodiment of the trajectory cardinality estimation model training method of this application;
[0042] Figure 4 This is a schematic diagram of the model training input data for an embodiment of the trajectory cardinality estimation model training method of this application;
[0043] Figure 5 This is a schematic diagram of the neural network framework of an embodiment of the trajectory cardinality estimation model training method of this application;
[0044] Figure 6This is a schematic diagram of the model conversion process in one embodiment of the trajectory cardinality estimation model training method of this application;
[0045] Figure 7 This is a schematic diagram of the overall process of an embodiment of the trajectory cardinality estimation model training method of this application;
[0046] Figure 8 This is a schematic diagram of the functional modules of an embodiment of the trajectory basis estimation model training device of this application;
[0047] Figure 9 This is a schematic diagram of the hardware structure of the trajectory basis estimation model training device involved in the embodiment of this application. Detailed Implementation
[0048] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present application.
[0049] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.
[0050] In a first aspect, embodiments of this application provide a method for training a trajectory basis estimation model.
[0051] In one embodiment, reference is made to Figure 1 , Figure 1 This is a flowchart illustrating an embodiment of the trajectory cardinality estimation model training method of this application, as shown below. Figure 1 As shown, the training methods for the trajectory cardinality estimation model include:
[0052] Step S10: Obtain the trajectory dataset and map each trajectory in the trajectory dataset onto the map.
[0053] In this embodiment, refer to Figure 2 , Figure 2 This is a schematic diagram of map trajectory mapping, representing an embodiment of the trajectory cardinality estimation model training method of this application. Figure 2 As shown, the demonstration map includes multiple trajectories from the trajectory dataset. Figure 2 V in i,j T represents the number of map points within the grid. i,j This represents the number of trajectories passing through the grid. This represents the number of map points within the grid through which a trajectory passes. It's important to note that in the field of database query optimization, accurate trajectory cardinality estimation is crucial for improving trajectory query performance, primarily in three aspects: First, optimizing query performance: Trajectory data typically involves a large amount of spatiotemporal information. Accurate trajectory cardinality estimation helps predict how much data a query will return, allowing the database optimizer to choose the most efficient query execution strategy, such as selecting appropriate indexes or determining whether to perform a full table scan. Second, reducing resource consumption: By accurately estimating the size of the trajectory dataset, the database can better manage memory usage and disk I / O (Input / Output), avoiding high resource consumption caused by querying large amounts of data. This is especially important for ensuring the efficiency of mobile devices and resource-constrained systems. Third, improving query plans: In complex queries involving multiple trajectory data sources or various query conditions (such as time ranges and geographical boundaries), accurate trajectory cardinality estimation helps the optimizer determine the order and method of query operations, especially when executing path queries and range queries. For example, in statistical queries like `count()`, where accuracy is not required, cardinality estimates can directly and quickly return results.
[0054] Step S20: Number the edges and vertices of the map, and create an inverted index of the relative trajectories of the edges and vertices.
[0055] In this embodiment, the edges and vertices of the map are numbered to facilitate the establishment of an inverted index of the relative trajectories of the edges and vertices. The inverted index, also known as the reverse index, inverted archive, or reverse archive, is an indexing method used to store the mapping of the storage location of a word in a document or a group of documents under full-text search. It is the most commonly used data structure in document retrieval systems. Through the inverted index, a list of documents containing a word can be quickly obtained. The inverted index mainly consists of two parts: a word dictionary and an inverted file.
[0056] Step S30: Divide the map into grids according to preset length and width, and create a grid index.
[0057] In this embodiment, for example, the map can be divided into multiple grids of 100 meters * 100 meters, each grid can be numbered, and a grid index can be established.
[0058] Step S40: Based on the inverted index and grid index, statistically analyze the trajectory feature data in each grid.
[0059] In this embodiment, the trajectory feature data includes trajectory-related behavioral feature data such as the number of trajectories, the number of vertices, the number of edges, and the relationships between grids. The established inverted index and grid index are used to improve the efficiency of statistical analysis of trajectory feature data for each grid. For example, when statistical analysis of the number of trajectories in each grid and the number of vertices through which trajectories pass, the use of inverted index and grid index can effectively improve the efficiency of the analysis.
[0060] Step S50: Each training data is composed of trajectory query input, trajectory feature data and preset grid query range, wherein the label of each training data is the true base of the trajectory query input within the preset grid query range.
[0061] In this embodiment, each training data is a matrix composed of trajectory query input, trajectory feature data, and a preset grid query range. The trajectory query input can be, for example, a path query or a range query for a trajectory. The preset grid query range is the road network where the trajectory to be queried is located. For example, each grid is a 100m x 100m range. The preset grid query range can be set to the range of 32 grids near the trajectory to be queried. Taking the grid division of a Wuhan city map as an example, to query a trajectory at a street intersection, the preset grid query range can be the 32 grids near the street intersection. These 32 grids represent the road network range within 3.2 kilometers of the street intersection. The trajectory feature data includes the number of trajectories, the number of vertices, the number of edges, and the relationships between grids, etc., which are related behavioral feature data of the trajectory. Specifically, the data structure of each training data is, for example, a 14*32*32 matrix, where 1 in 14 represents the trajectory query input, 13 in 14 represents the trajectory feature data, and 32 represents the 32 grids near the queried trajectory. Figure 3 , Figure 3 This is a schematic diagram illustrating the trajectory feature data structure of an embodiment of the trajectory cardinality estimation model training method of this application, as shown below. Figure 3 As shown, Figure 3 The first row contains trajectory feature data within the grid, comprising 4 elements; the second row contains trajectory feature data related to adjacent grids, comprising 8 elements; and the third row contains global trajectory feature data, comprising 1 element, namely global KDE (kernel density estimation), for a total of 13 elements, representing 13 categories of trajectory feature data. The label for each training data point is the true cardinality of the trajectory query input within the preset grid query range. The true cardinality can be obtained by querying and statistically analyzing a real database.
[0062] Step S60: Train the neural network using multiple training data sets to obtain the trajectory basis estimation model.
[0063] In this embodiment, since the input training data includes trajectory feature data, training the neural network with multiple training data sets enables the trained trajectory cardinality estimation model to accurately capture the behavioral features of the trajectory, thereby improving the prediction accuracy of the trajectory cardinality estimation model. (Refer to...) Figure 4 , Figure 4 This is a schematic diagram of the model training input data for an embodiment of the trajectory cardinality estimation model training method of this application, as shown below. Figure 4 As shown, a 1*32*32 trajectory query matrix is formed by range queries or path queries of the trajectory. A 13*32*32 background information matrix is formed by trajectory feature data of 32 grids near the trajectory query, such as the number of trajectories, the number of vertices, the number of edges, and the relationship between grids. The 1*32*32 trajectory query matrix and the 13*32*32 background information matrix are concatenated to form a 14*32*32 matrix, which is used as the training data for inputting the neural network.
[0064] In this embodiment, a mapping between trajectories and maps is established, and the map is divided into grids. Inverted indexes and grid indexes are used to improve the efficiency of statistically analyzing trajectory feature data for each grid. The trajectory feature data includes the number of trajectories, the number of vertices, the number of edges, and the relationships between grids, as well as other relevant behavioral feature data of the trajectories. A matrix composed of trajectory query input, trajectory feature data, and a preset grid query range is used as each training data to train the neural network. Since the input training data contains the feature data of the trajectories, the trajectory cardinality estimation model can accurately capture the behavioral features of the trajectories, thereby improving the prediction accuracy of the trajectory cardinality estimation model.
[0065] Furthermore, in one embodiment, the neural network includes a feature fusion module, a depthwise separable residual module, a multi-head attention module, and a fully connected output layer.
[0066] In this embodiment, refer to Figure 5 , Figure 5 This is a schematic diagram of the neural network framework flow of an embodiment of the trajectory cardinality estimation model training method of this application, as shown below. Figure 5As shown, after receiving 14*32*32 training data input, the neural network first expands the features of the input training data from 14*32*32 to 128*32*32 through a feature fusion module with an attention mechanism to improve the internal correlation of the input features. Then, it enters the deep separable residual module. Compared with conventional convolutional neural networks, the deep separable residual module significantly reduces the number of parameters. By adding a new branch to the input data through the residual neural network, the original input merges with this branch after passing through the deep separable network, thus better learning the features of the data. The model is flattened before input to the multi-head attention layer to reduce dimensionality, significantly decreasing the number of parameters. The multi-head attention mechanism enhances the model's generalization ability, enabling it to predict well on trajectory datasets with varying sparsity. A fully connected layer is then used for output, incorporating Dropout to improve generalization and prevent overfitting. HuberLoss is used as the loss function to better handle outliers in the real dataset. The HuberLoss loss function is defined as follows: The HuberLoss loss function combines the sensitivity of squared error loss with the robustness of absolute error loss, providing excellent handling of outliers while maintaining the stability of the optimization process.
[0067] Further, in one embodiment, the process after step S60 includes:
[0068] When the loss function of the neural network converges, the neural network at which the loss function converges is used as the trained trajectory basis estimation model.
[0069] The trained trajectory cardinality estimation model was validated using a validation dataset, and the loss metric between the predicted and actual values of the trajectory cardinality estimation model based on the validation dataset was obtained.
[0070] If the loss index is less than the preset loss index, the verified trajectory basis estimation model will be used as the final trajectory basis estimation model.
[0071] In this embodiment, the trained trajectory cardinality estimation model is validated using a validation dataset different from that used in the training phase to evaluate the model's generalization ability. This yields a loss metric between the predicted and actual values of the trajectory cardinality estimation model based on the validation dataset. Standard evaluation metrics, such as mean absolute error (MAE) and Huber loss, can be used to quantify the model's prediction accuracy. The model's response time and resource consumption can also be evaluated to ensure it meets the requirements for cross-platform lightweight design. Based on feedback from real-world application scenarios, the model is fine-tuned, such as adjusting the delta value of the Huber loss function and the learning rate (a factor used to update neural network weights during training). If the preset loss metric is not met, the neural network can continue to be trained until the optimal result is achieved, thereby improving the accuracy and practicality of the trajectory cardinality estimation model.
[0072] Further, in one embodiment, the trajectory cardinality estimation model is trained and validated based on the PyTorch framework. After using the validated trajectory cardinality estimation model as the final trajectory cardinality estimation model, the following steps are included:
[0073] The trajectory cardinality estimation model trained and validated based on the PyTorch framework is converted into an intermediate deployment model in ONNX format;
[0074] The intermediate deployment model in ONNX format is converted to a Keras model. During the conversion, the data type of the parameters in the activation layer is converted from single-precision floating-point numbers to 16-bit integers, and the data type of the parameters outside the activation layer is converted from single-precision floating-point numbers to 8-bit integers.
[0075] In this embodiment, the trajectory cardinality estimation model can be trained and validated based on the PyTorch framework. PyTorch is an open-source Python (a programming language) machine learning library. Based on Torch, it is used for applications such as natural language processing. PyTorch can be viewed as NumPy (an open-source numerical computing extension of Python) with GPU (graphics processing unit) support, and also as a powerful deep neural network with automatic differentiation capabilities. The trajectory cardinality estimation model trained and validated based on the PyTorch framework is converted into an intermediate deployment model in ONNX format. ONNX (Open Neural Network Exchange) is an open neural network exchange format proposed by Microsoft for converting and exchanging models between different deep learning frameworks. Its design goal is to provide an intermediate representation format that allows users to seamlessly convert models between different deep learning training and inference frameworks. Next, the intermediate deployment model in ONNX format is converted to a Keras model. Keras is an open-source artificial neural network library written in Python. It serves as a high-level application interface for TensorFlow Lite (a mobile library for deploying models on mobile devices, microcontrollers, and other edge devices), Microsoft-CNTK (an open-source toolkit from Microsoft for commercial distributed deep learning), and Theano (a Python library for numerical computation that provides a set of functions for mathematical calculations). It is used for the design, debugging, evaluation, application, and visualization of deep learning models. During the conversion from the ONNX format intermediate deployment model to a Keras model, the data type of the parameters in the activation layers is converted from single-precision floating-point numbers to 16-bit integers, and the data type of the parameters outside the activation layers is converted from single-precision floating-point numbers to 8-bit integers. By reducing the data type of the model parameters, the model can be reduced to one-quarter of its original size, greatly facilitating deployment.
[0076] Further, in one embodiment, after converting the intermediate deployment model in ONNX format to a Keras model, the following steps are included:
[0077] Using the TensorFlow Lite tool, the Keras model is converted into a trajectory cardinality estimation model suitable for lightweight deployment on mobile devices.
[0078] In this embodiment, refer to Figure 6 , Figure 6 This is a schematic diagram of the model conversion process in one embodiment of the trajectory cardinality estimation model training method of this application, as shown below. Figure 6As shown, the PyTorch trajectory cardinality estimation model trained and validated based on the PyTorch framework is first converted into an intermediate deployment model in ONNX format, then converted into a Keras model, and then converted into a trajectory cardinality estimation model suitable for lightweight deployment on mobile devices using the TensorFlow Lite tool. This makes the final trajectory cardinality estimation model lightweight and suitable for mobile deployment, overcoming the shortcomings of existing trajectory cardinality estimation models that are too large to be deployed on mobile devices.
[0079] In this embodiment, refer to Figure 7 , Figure 7 This is a schematic diagram of the overall process of an embodiment of the trajectory cardinality estimation model training method of this application, as shown below. Figure 7 As shown, trajectory datasets and map data are collected and mapped. By building inverted indexes, grid indexes, and performing statistical analysis on grid trajectory feature data, training and validation datasets are constructed. The training dataset is used to train a neural network including a feature fusion module, a deep separable residual module, a multi-head attention module, and a fully connected output layer. When the loss function converges, a trained trajectory cardinality estimation model is obtained. The training trajectory cardinality estimation model is further validated using the validation dataset. After passing the validation, the trajectory cardinality estimation model is lightweighted and transformed into a model suitable for mobile deployment. Therefore, this application effectively collects and analyzes map and trajectory information through grid indexing, accurately captures trajectory behavior patterns, and improves data processing efficiency and analysis accuracy. Through an attention-based feature fusion algorithm, it effectively captures the internal correlations of input data, laying a solid foundation for in-depth data feature extraction. Through a deep separable residual neural network, it effectively learns data features while significantly reducing the number of network parameters, aligning with the invention's goal of lightweight and cross-platform compatibility. Through a multi-head attention mechanism, it demonstrates good performance on trajectory datasets with varying sparsity, achieving the invention's goal of capturing trajectory characteristics. By employing parameter quantization, the original model's float32-bit parameters are replaced with int8 (8-bit) and int16 (16-bit) parameters, reducing the model's footprint and meeting the lightweight requirements of mobile devices. This allows the model to be reduced to 1 / 4 of its original size. Using the mobile deep learning model framework (Tensorflow Lite), the goal of cross-platform compatibility and lightweight design is ultimately achieved.
[0080] Secondly, embodiments of this application also provide a trajectory basis estimation model training device.
[0081] In one embodiment, reference is made to Figure 8 , Figure 8This is a functional module diagram of an embodiment of the trajectory basis estimation model training device of this application, as shown below. Figure 8 As shown, the trajectory cardinality estimation model training device includes:
[0082] Module 10 is used to acquire the trajectory dataset and map each trajectory in the trajectory dataset onto a map.
[0083] The first module 20 is used to number the edges and vertices of the map and to create an inverted index of the relative trajectories of the edges and vertices.
[0084] The second module 30 is used to divide the map into grids according to preset length and width, and to create a grid index;
[0085] The statistics module 40 is used to statistically analyze the trajectory feature data in each grid based on the inverted index and the grid index.
[0086] The component module 50 is used to compose each training data with trajectory query input, trajectory feature data and preset grid query range, wherein the label of each training data is the true cardinality of the trajectory query input within the preset grid query range;
[0087] Training module 60 is used to train a neural network using multiple training data sets to obtain a trajectory basis estimation model.
[0088] Furthermore, in one embodiment, the neural network includes a feature fusion module, a depthwise separable residual module, a multi-head attention module, and a fully connected output layer.
[0089] Furthermore, in one embodiment, the trajectory cardinality estimation model training device further includes a verification module, used for:
[0090] When the loss function of the neural network converges, the neural network at which the loss function converges is used as the trained trajectory basis estimation model.
[0091] The trained trajectory cardinality estimation model was validated using a validation dataset, and the loss metric between the predicted and actual values of the trajectory cardinality estimation model based on the validation dataset was obtained.
[0092] If the loss index is less than the preset loss index, the verified trajectory basis estimation model will be used as the final trajectory basis estimation model.
[0093] Furthermore, in one embodiment, the trajectory cardinality estimation model is trained and validated based on the PyTorch framework, and the trajectory cardinality estimation model training device further includes a first conversion module, used for:
[0094] The trajectory cardinality estimation model trained and validated based on the PyTorch framework is converted into an intermediate deployment model in ONNX format;
[0095] The intermediate deployment model in ONNX format is converted to a Keras model. During the conversion, the data type of the parameters in the activation layer is converted from single-precision floating-point numbers to 16-bit integers, and the data type of the parameters outside the activation layer is converted from single-precision floating-point numbers to 8-bit integers.
[0096] Furthermore, in one embodiment, the trajectory cardinality estimation model training device further includes a second conversion module, used for:
[0097] Using the TensorFlow Lite tool, the Keras model is converted into a trajectory cardinality estimation model suitable for lightweight deployment on mobile devices.
[0098] The functions of each module in the above-mentioned trajectory basis estimation model training device correspond to the steps in the above-mentioned trajectory basis estimation model training method embodiment, and their functions and implementation processes will not be described in detail here.
[0099] Thirdly, embodiments of this application provide a trajectory basis estimation model training device.
[0100] Reference Figure 9 , Figure 9 This is a schematic diagram of the hardware structure of the trajectory cardinality estimation model training device involved in the embodiments of this application. In the embodiments of this application, the trajectory cardinality estimation model training device may include a processor, a memory, a communication interface, and a communication bus.
[0101] The communication bus can be of any type and is used to interconnect the processor, memory, and communication interface.
[0102] The communication interface includes input / output (I / O) interfaces, physical interfaces, and logical interfaces used for interconnecting devices within the trajectory cardinality estimation model training device, as well as interfaces used for interconnecting the trajectory cardinality estimation model training device with other devices (such as other computing devices or user equipment). Physical interfaces can be Ethernet interfaces, fiber optic interfaces, ATM interfaces, etc.; user equipment can be displays, keyboards, etc.
[0103] Memory can be various types of storage media, such as random access memory (RAM), read-only memory (ROM), non-volatile RAM (NVRAM), flash memory, optical storage, hard disk, programmable ROM (PROM), erasable PROM (EPROM), electrically erasable PROM (EEPROM), etc.
[0104] The processor can be a general-purpose processor, which can call the trajectory cardinality estimation model training program stored in memory and execute the trajectory cardinality estimation model training method provided in the embodiments of this application. For example, the general-purpose processor can be a central processing unit (CPU). The method executed when the trajectory cardinality estimation model training program is called can refer to the various embodiments of the trajectory cardinality estimation model training method of this application, and will not be repeated here.
[0105] Those skilled in the art will understand that Figure 9 The hardware structure shown does not constitute a limitation of this application and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0106] Fourthly, embodiments of this application also provide a readable storage medium.
[0107] The present application stores a trajectory cardinality estimation model training program on a readable storage medium, wherein when the trajectory cardinality estimation model training program is executed by a processor, it implements the steps of the trajectory cardinality estimation model training method described above.
[0108] The method implemented when the trajectory cardinality estimation model training program is executed can be referred to in various embodiments of the trajectory cardinality estimation model training method of this application, and will not be repeated here.
[0109] It should be noted that the sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0110] The terms "comprising" and "having," and any variations thereof, in the specification, claims, and accompanying drawings of this application are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to such process, method, product, or apparatus. The terms "first," "second," and "third," etc., are used to distinguish different objects, etc., and do not indicate a sequence, nor do they limit "first," "second," and "third" to different types.
[0111] In the description of the embodiments of this application, terms such as "exemplary," "for example," or "for instance" are used to indicate examples, illustrations, or explanations. Any embodiment or design described as "exemplary," "for example," or "for instance" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or designs. Specifically, the use of terms such as "exemplary," "for example," or "for instance" is intended to present the relevant concepts in a concrete manner.
[0112] In the description of the embodiments of this application, unless otherwise stated, " / " means "or". For example, A / B can mean A or B. The "and / or" in the text is merely a description of the relationship between related objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist simultaneously, and B exists alone. In addition, in the description of the embodiments of this application, "multiple" means two or more.
[0113] In some processes described in the embodiments of this application, multiple operations or steps are included in a specific order. However, it should be understood that these operations or steps may not be executed in the order they appear in the embodiments of this application, or they may be executed in parallel. The sequence number of the operation is only used to distinguish different operations, and the sequence number itself does not represent any execution order. In addition, these processes may include more or fewer operations, and these operations or steps may be executed sequentially or in parallel, and these operations or steps may be combined.
[0114] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes several instructions to cause a terminal device to execute the methods described in the various embodiments of this application.
[0115] The above are merely preferred embodiments of this application and do not limit the patent scope of this application. Any equivalent structural or procedural transformations made using the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of this application.
Claims
1. A method for training a trajectory cardinality estimation model, characterized in that, The training method for the trajectory cardinality estimation model includes: Obtain the trajectory dataset and map each trajectory in the dataset onto a map; Number the edges and vertices of the map, and create an inverted index of the relative trajectories of the edges and vertices; Divide the map into grids according to preset dimensions and create a grid index; Based on the inverted index and grid index, the trajectory feature data in each grid is statistically analyzed; Each training data set consists of trajectory query input, trajectory feature data, and a preset grid query range. The label of each training data set is the true cardinality of the trajectory query input within the preset grid query range. The neural network is trained using multiple training data sets to obtain a trajectory basis estimation model.
2. The trajectory cardinality estimation model training method as described in claim 1, characterized in that, The neural network includes a feature fusion module, a depthwise separable residual module, a multi-head attention module, and a fully connected output layer.
3. The trajectory cardinality estimation model training method as described in claim 2, characterized in that, After training the neural network using multiple training data sets to obtain the trajectory cardinality estimation model, the process includes: When the loss function of the neural network converges, the neural network at which the loss function converges is used as the trained trajectory basis estimation model. The trained trajectory cardinality estimation model was validated using a validation dataset, and the loss metric between the predicted and actual values of the trajectory cardinality estimation model based on the validation dataset was obtained. If the loss index is less than the preset loss index, the verified trajectory basis estimation model will be used as the final trajectory basis estimation model.
4. The trajectory cardinality estimation model training method as described in claim 3, characterized in that, The trajectory cardinality estimation model is trained and validated based on the PyTorch framework. After using the validated trajectory cardinality estimation model as the final trajectory cardinality estimation model, the following steps are included: The trajectory cardinality estimation model trained and validated based on the PyTorch framework is converted into an intermediate deployment model in ONNX format; The intermediate deployment model in ONNX format is converted to a Keras model. During the conversion, the data type of the parameters in the activation layer is converted from single-precision floating-point numbers to 16-bit integers, and the data type of the parameters outside the activation layer is converted from single-precision floating-point numbers to 8-bit integers.
5. The trajectory cardinality estimation model training method as described in claim 4, characterized in that, After converting the intermediate deployment model in ONNX format to a Keras model, the following steps are included: Using the TensorFlow Lite tool, the Keras model is converted into a trajectory cardinality estimation model suitable for lightweight deployment on mobile devices.
6. A trajectory basis estimation model training device, characterized in that, The trajectory cardinality estimation model training device includes: The acquisition module is used to acquire the trajectory dataset and map each trajectory in the trajectory dataset onto a map; The first module is used to number the edges and vertices of the map and to create an inverted index of the relative trajectories of the edges and vertices. The second module is used to divide the map into grids according to preset length and width, and to create a grid index; The statistics module is used to statistically analyze trajectory feature data in each grid based on the inverted index and the grid index. The component module is used to compose each training data with trajectory query input, trajectory feature data and preset grid query range, wherein the label of each training data is the true cardinality of the trajectory query input within the preset grid query range; The training module is used to train a neural network using multiple training data sets to obtain a trajectory basis estimation model.
7. The trajectory basis estimation model training device as described in claim 6, characterized in that, The neural network includes a feature fusion module, a depthwise separable residual module, a multi-head attention module, and a fully connected output layer.
8. The trajectory basis estimation model training device as described in claim 7, characterized in that, The trajectory cardinality estimation model training device further includes a verification module, used for: When the loss function of the neural network converges, the neural network at which the loss function converges is used as the trained trajectory basis estimation model. The trained trajectory cardinality estimation model was validated using a validation dataset, and the loss metric between the predicted and actual values of the trajectory cardinality estimation model based on the validation dataset was obtained. If the loss index is less than the preset loss index, the verified trajectory basis estimation model will be used as the final trajectory basis estimation model.
9. A trajectory basis estimation model training device, characterized in that, The trajectory cardinality estimation model training device includes a processor, a memory, and a trajectory cardinality estimation model training program stored in the memory and executable by the processor, wherein when the trajectory cardinality estimation model training program is executed by the processor, it implements the steps of the trajectory cardinality estimation model training method as described in any one of claims 1 to 5.
10. A readable storage medium, characterized in that, The readable storage medium stores a trajectory cardinality estimation model training program, wherein when the trajectory cardinality estimation model training program is executed by a processor, it implements the steps of the trajectory cardinality estimation model training method as described in any one of claims 1 to 5.