Agricultural Machinery Trajectory Data Classification Method, Device, Electronic Equipment and Storage Medium
By combining comparative learning with dynamic negative sample queues, an agricultural machinery trajectory data classification model was constructed, which solved the accuracy and robustness of agricultural machinery trajectory data classification, and achieved efficient classification in complex scenarios.
Patent Information
- Application Number
- CN202510592963.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-09
- Publication Date
- 2025-07-04
- Estimated Expiration
- 2045-05-09
AI Technical Summary
The existing agricultural machinery trajectory data classification methods are difficult to effectively integrate multi-dimensional information, and they lack accuracy and generalization capabilities, and are poorly robust to complex scenarios and outliers.
Using the agricultural machinery trajectory data classification method based on comparison learning and dynamic negative sample queue, the wav2vec comparison learning framework and dynamic negative sample queue idea is used to build a trajectory classification model including encoder network, context network and momentum encoder, and train it using InfoNCE loss function and cross entropy loss function to realize feature extraction and classification.
It improves the accuracy and generalization ability of agricultural machinery trajectory data classification, is suitable for various complex scenarios, reduces dependence on manual annotation data, and enhances the robustness and classification accuracy of the model.
Smart Images

Figure CN120105238B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of agricultural machinery trajectory classification, and specifically relates to a method, device, electronic device and storage medium for classifying agricultural machinery trajectory data. Background Art
[0002] Driven by agricultural Internet of Things, intelligent agricultural machinery equipment and precision agriculture technology, intelligent agricultural machinery equipment such as combine harvesters, seeders, and drones have been widely used, generating a large amount of agricultural machinery trajectory data. Agricultural machinery trajectory data is an important part of agricultural digitization, providing strong support for the intelligent and precise development of agriculture. When agricultural machinery operates in the field, its trajectory data can reflect the operation mode, farmland utilization rate, operation efficiency, and the operating state of the agricultural machinery. Especially in operations such as subsoiling, deep plowing, and land preparation, land subsidies are closely related to the operation area. Accurate trajectory classification can not only improve the accuracy of operation statistics but also provide a scientific basis for subsidy distribution, ensuring the fairness and effectiveness of subsidies.
[0003] In addition, with the development of large-scale agricultural operations, cross-regional operation scheduling of agricultural machinery has become an important means to improve agricultural production efficiency. Intelligent classification based on trajectory data can optimize the allocation of agricultural machinery resources, improve the utilization rate of agricultural machinery, reduce operating costs, and contribute to the intelligent upgrading of modern agriculture.
[0004] However, the original agricultural machinery trajectory data has characteristics such as large spatio-temporal span, complex operation scenarios, multi-source heterogeneity, and is easily interfered by factors such as terrain and crop growth. Classifying agricultural machinery trajectory data faces many challenges. Compared with traditional vehicle trajectories or logistics trajectories, agricultural machinery trajectories have the following characteristics: First, agricultural machinery trajectories have the particularity of operation scenarios. Agricultural machinery trajectories involve two main modes: farmland operation and road driving. Farmland trajectories usually show a pattern of low speed, tortuous, and repetitive coverage, while road trajectories are relatively regular and the speed is relatively stable. This mode difference makes it difficult for traditional trajectory classification methods to apply. Second, agricultural machinery trajectory data is more complex. Affected by factors such as terrain, farmland shape, and crop types, its path has strong randomness and is difficult to classify by fixed rules. In addition, agricultural machinery trajectory data not only includes location (latitude and longitude), but also involves parameters such as operation speed, driving direction, and operation state. How to effectively integrate these multi-dimensional information and improve the classification accuracy is a major challenge. Finally, due to the complex operation environment of agricultural machinery, GNSS trajectory data may be interfered by satellite signals, resulting in more trajectory point drifts, missing values or outliers, which puts higher requirements on the robustness of the classification model.
[0005] Although trajectory data classification has important application values, due to the complexity and diversity of trajectory data, existing classification methods still face many challenges. Currently, trajectory data classification methods can be divided into two categories: traditional methods and deep learning methods.
[0006] Traditional trajectory classification methods mainly rely on manually designed rules or statistical features. Early studies distinguished different objects by setting rules such as speed thresholds and changes in direction angles. For example, highway vehicle types were identified by "average speed exceeding 60 kilometers per hour". Although such methods are intuitive, their feature expression ability is limited, making it difficult to capture complex patterns such as periodic commuting or sudden path offsets. Moreover, they need to readjust the rules for different scenarios, resulting in poor generalization ability.
[0007] Subsequently, methods based on traditional machine learning (such as decision trees, support vector machines (SVMs), naive Bayes, etc.) were widely applied. These methods classify by manually extracting a large number of features (such as speed changes, direction changes, etc.). Although these methods have achieved certain results in some simple scenarios, the manual feature extraction process is cumbersome, time-consuming, and highly dependent on the experience of domain experts. Different experts may extract different feature sets, leading to poor stability and consistency of classification results. In addition, the manually extracted features often fail to comprehensively and accurately reflect the inherent characteristics and complex patterns of trajectory data, limiting the accuracy and generalization ability of classification. Moreover, problems such as outliers and drifts may exist in agricultural machinery trajectory data, and traditional machine learning methods have poor robustness to such data.
[0008] In recent years, deep learning methods have shown significant advantages in feature extraction and pattern recognition for trajectory classification. For example, RNN / LSTM models can capture the time series information of trajectories, but their computational complexity is high, and they may face the problem of gradient vanishing when dealing with long trajectory data. In addition, the Transformer model solves the problem of long sequence modeling through the self-attention mechanism, but has a large computational overhead and is difficult to meet real-time requirements. At the same time, although autoencoders can extract features through data reconstruction, the generated representations mostly focus on the overall distribution and lack discriminative semantics.
[0009] Another example is that Chinese patent document CN119046759A discloses an agricultural machinery trajectory classification method, computer-readable storage medium, and computer program product based on trajectory similarity measurement. According to the agricultural machinery GNSS trajectory data and cleaning it, then using the contrast learning model TrajCL to simultaneously extract the structural features and spatial features of the trajectory and trajectory points from the original trajectory data, calculating the trajectory embedding vector, and then combining the sliding window technology to achieve accurate classification of fields and roads. The TrajCL model used in this method is specifically designed for trajectories, solving the problem of insufficient feature extraction.
[0010] Chinese patent document CN119128719A discloses a classification method, device and storage medium for agricultural machinery trajectory data, which preprocesses agricultural machinery trajectory data and constructs a classification model; extracts short-range features and long-range features from the preprocessed data, and fuses the short-range features and long-range features to obtain comprehensive features; inputs the comprehensive features into a bidirectional long short-term memory network to perform deep temporal pattern learning; inputs the learned features into a classifier to obtain the agricultural machinery trajectory classification results; compares the classification results with the actual results, and optimizes the classification model through the PDW loss function; and uses the optimized classification model to complete the classification of agricultural machinery trajectory data. This method introduces a parameter difference weighted loss function, dynamically adjusts the category weights, optimizes the model performance, and improves the accuracy and generalization ability of agricultural machinery trajectory data classification.
[0011] The above respectively reflect the application of different deep learning methods in trajectory classification.
[0012] In terms of negative sample construction strategies, traditional negative sample strategies usually rely on random sampling or fixed rules. Although simple and direct, they have many limitations, such as difficulty adapting to complex scenarios and changes in sample distribution. In order to break through these bottlenecks, various strategies have emerged. For example, the negative sample enhancement strategy generates negative samples through data enhancement (such as random cropping and noise addition) to improve the model's robustness to outliers and drift. The multi-view positive sample strategy extracts positive samples from different perspectives (such as time, space, and semantics) to enhance the diversity and discriminability of features. The Moco model in contrastive learning takes a different approach. By maintaining a dynamically updated negative sample queue, it increases the number of negative samples and improves the quality of model training signals, effectively solving the problem of insufficient negative samples in small batch training.
[0013] In view of this, the present invention proposes an agricultural machinery trajectory data classification method based on contrastive learning and dynamic negative sample queue. The method uses the wav2vec contrastive learning framework and integrates the idea of dynamic negative sample queue to solve the above technical problems. Summary of the invention
[0014] The present invention aims to overcome at least one defect of the above-mentioned prior art and provide a method for classifying agricultural machinery trajectory data.
[0015] The invention also discloses a device loaded with the agricultural machinery trajectory data classification method.
[0016] The detailed technical scheme of the present invention is as follows:
[0017] A method for classifying agricultural machinery trajectory data, the method comprising:
[0018] S1. Preprocess and perform feature transformation on the original agricultural machinery GNSS trajectory data to obtain continuous and uniform time-series trajectory data. Among them, the original agricultural machinery GNSS trajectory data contains multiple discrete trajectory points, and the features of each discrete trajectory point include longitude, latitude, timestamp, speed, direction, and class label. The classes of trajectory points include field trajectories and road trajectories.
[0019] S2. Construct a trajectory classification model including a feature extraction module and a classification head. The feature extraction module includes an encoder network, a context network, and a momentum encoder, and use the time-series trajectory data as training samples to train the trajectory classification model. The training of the trajectory classification model includes a feature pre-training stage and a classification fine-tuning stage, specifically:
[0020] S21. Use the encoder network to extract features from the time-series trajectory data, and use the context network to capture the long-distance dependence relationship of the extracted features in the context information to construct positive sample pairs.
[0021] S22. Perform data augmentation operations on the time-series trajectory data, input the augmented time-series trajectory data into the momentum encoder to obtain its feature representation, and construct negative sample pairs in combination with the dynamic queue mechanism.
[0022] S23. In the feature pre-training stage, based on the positive sample pairs and negative sample pairs, use the InfoNCE contrast loss function to iteratively train the feature extraction module of the trajectory classification model, and introduce an early stopping mechanism. When the loss values of consecutive multiple training epochs tend to be stable, trigger the early stopping mechanism, use the current feature extraction module to extract the representation vectors of all time-series trajectory data, perform K-means clustering based on this representation vector, and evaluate the clustering quality by calculating the silhouette coefficient to judge the feature learning effect of the current trajectory classification model.
[0023] In the classification fine-tuning stage, freeze the feature extraction module, use the supervised cross-entropy loss to train the classification head, and enable the class label for supervised learning so that the classification head outputs the class probability distribution of the trajectory.
[0024] S3. Deploy the trained trajectory classification model and use it to classify the agricultural machinery trajectory data.
[0025] Preferably according to the present invention, in S1, the preprocessing of the original agricultural machinery GNSS trajectory data includes:
[0026] According to the class labels of the trajectory points in the original agricultural machinery GNSS trajectory data, segment it into several different trajectory segments. Among them, the class label of the trajectory point is 1 or 0, where 1 represents a field trajectory and 0 represents a road trajectory.
[0027] Moreover, resampling and interpolation operations are performed on the segmented trajectory segments, specifically:
[0028] Set the sampling interval , and according to the set sampling interval , construct a new time grid: , where is the start time of the trajectory segment, is the end time of the trajectory segment;
[0029] Arrange the trajectory points in ascending order of time stamps, and set the time stamps of the trajectory points as indices. Use linear interpolation to interpolate each feature of the trajectory points on the newly created time grid. That is, for the time to be interpolated , assume that the two nearest original trajectory points are respectively ([[]] , ), ([[]] , ), then the feature estimated value is:
[0030] (1);
[0031] In formula (1): represents the feature estimated value inserted at the time to be interpolated ;
[0032] In addition, perform a fixed-window segmentation operation on the interpolated agricultural machinery GNSS trajectory data to obtain equal-length trajectory segments. Among them, the window length is set to 200 points, and the sliding step is 100 points to generate overlapping trajectory segments.
[0033] According to the preference of the present invention, in S1, performing feature conversion on the preprocessed original agricultural machinery GNSS trajectory data includes:
[0034] Extract key features from each trajectory point, including longitude, latitude, speed, and direction, and perform standardization processing on this feature; among them, for the standardization processing of the longitude and latitude, specifically:
[0035] Convert the longitude and latitude of each trajectory point to obtain its x coordinate value and y coordinate value in the UTM coordinate system, and calculate its relative displacement relative to the starting point and , and then perform Z-score standardization on the relative displacements and :
[0036] (2);
[0037] (3);
[0038] In formulas (2)-(3): and respectively represent the mean and standard deviation of the feature; and respectively represent the mean and standard deviation of the feature; and respectively represent the relative displacement coordinates after standardization;
[0039] Perform standardization processing on the said direction, specifically:
[0040] Convert the angle of the direction into sine and cosine values:
[0041] (4);
[0042] (5);
[0043] Perform Z-score standardization on the sine and cosine values:
[0044] (6);
[0045] (7);
[0046] In formulas (4)-(7): represents the course of the i-th trajectory point; and respectively represent the sine projection of the direction angle and the cosine projection of the direction angle; and respectively represent the mean of the sine components of all trajectory points and the mean of the cosine components of all trajectory points; and respectively represent the standard deviation of the sine components of all trajectory points and the standard deviation of the cosine components of all trajectory points; and respectively represent the sine component of the standardized course angle and the cosine component of the standardized course angle;
[0047] Moreover, perform a splicing operation on the standardized features to obtain the feature vector representation of each trajectory point, that is, for the trajectory point , its feature vector representation is ; then arrange the feature vectors of all trajectory points in chronological order to form a time series matrix, that is, assuming there are N trajectory points, the formed time series matrix is .
[0048] Preferably according to the present invention, in S21, the encoder network includes three layers of one-dimensional convolution for extracting local features from the time-series trajectory data to obtain the true feature representation at the current time t and the true feature representation at the k-th future time ; the context network uses a temporal convolutional network TCN, which uses three layers of temporal convolution to extract the context representation at the current time t ;
[0049] The context representation is linearly transformed by W to obtain the predicted feature representation , and a positive sample pair is constructed based on the true feature representation and the predicted feature representation as .
[0050] Preferably according to the present invention, in S22, the parameters of the momentum encoder are updated using the momentum update formula, that is:
[0051] (8);
[0052] In formula (8): represents the parameters of the momentum encoder; represents the parameters of the main model; is the momentum coefficient, and its value range is between 0 and 1;
[0053] The construction of negative sample pairs by combining the dynamic queue mechanism is specifically as follows:
[0054] A dual-queue management mechanism is constructed based on the field trajectory and the road trajectory, and two independent negative sample storage channels, namely and , are maintained respectively. Among them, is the field trajectory queue, which is used to store the field category representations generated by the momentum encoder in the recent several batches; is the road trajectory queue, which is used to store the road category representations generated by the momentum encoder in the recent several batches;
[0055] In each round of training, according to the category of the current input trajectory, negative samples are selected from the feature queue corresponding to the other category to construct a cross-category contrast relationship. That is, when the current trajectory sample belongs to the field category, then is randomly selected from the road trajectory queue as the negative sample, and a negative sample pair is formed with the predicted feature representation ; when the current trajectory sample belongs to the road category, then is randomly selected from the field trajectory queue as As negative samples, together with the predicted feature representations constitute negative sample pairs .
[0056] Preferably according to the present invention, in S23, in the feature pre-training stage, if the current trajectory sample is of the field trajectory category, the negative samples are selected from the road trajectory queue. At this time, the InfoNCE loss function is:
[0057] (9);
[0058] In formula (9): represents the road trajectory queue; represents the i-th negative sample in the road trajectory queue; sim is the cosine similarity; represents the feature representation at the future moment predicted by the model, that is, the reference sample; represents the true feature representation at the future moment, that is, the positive sample; is the temperature parameter, used to control the distribution of the similarity;
[0059] If the current trajectory sample is of the road trajectory category, the negative samples are selected from the field trajectory queue. At this time, the InfoNCE loss function is:
[0060] (10);
[0061] In formula (10): represents the road trajectory queue; represents the i-th negative sample from the field trajectory queue.
[0062] Preferably according to the present invention, S23 further includes, in the initial stage of the feature pre-training stage, randomly selecting several field trajectories and road trajectories from the time-series trajectory data respectively as the pre-initialization data set, and performing data augmentation on the pre-initialization data set and then inputting it into the momentum encoder to construct an initial negative sample queue.
[0063] In another aspect of the present invention, there is provided a device for implementing a method for classifying agricultural machinery trajectory data. The device includes:
[0064] A data acquisition module, configured to perform preprocessing and feature conversion operations on the original agricultural machinery GNSS trajectory data to obtain continuous and uniform time-series trajectory data; wherein, the original agricultural machinery GNSS trajectory data includes a plurality of discrete trajectory points, and the features of each discrete trajectory point include longitude, latitude, timestamp, speed, direction, and class label, and the classes of the trajectory points include field trajectories and road trajectories;
[0065] The model construction and training module is used to construct a trajectory classification model including a feature extraction module and a classification head. The feature extraction module includes an encoder network, a context network, and a momentum encoder, and uses the time-series trajectory data as training samples to train the trajectory classification model. The training of the trajectory classification model includes a feature pre-training stage and a classification fine-tuning stage, specifically:
[0066] Use the encoder network to extract features from the time-series trajectory data, and use the context network to capture the long-range dependence of the extracted features in the context information to construct positive sample pairs;
[0067] Perform data augmentation operations on the time-series trajectory data, input the augmented time-series trajectory data into the momentum encoder to obtain its feature representation, and construct negative sample pairs in combination with the dynamic queue mechanism;
[0068] In the feature pre-training stage, based on the positive sample pairs and negative sample pairs, use the InfoNCE contrast loss function to iteratively train the feature extraction module of the trajectory classification model, and introduce an early stopping mechanism. When the loss values of consecutive training epochs tend to be stable, trigger the early stopping mechanism, use the current feature extraction module to extract the representation vectors of all time-series trajectory data, perform K-means clustering based on these representation vectors, and evaluate the clustering quality by calculating the silhouette coefficient to judge the feature learning effect of the current trajectory classification model;
[0069] In the classification fine-tuning stage, freeze the feature extraction module, use the supervised cross-entropy loss to train the classification head, and enable the class labels for supervised learning so that the classification head outputs the class probability distribution of the trajectory;
[0070] The model application module is used to deploy the trained trajectory classification model and use it to classify the agricultural machinery trajectory data.
[0071] In another aspect of the present invention, an electronic device is further provided, including:
[0072] At least one processor; and
[0073] A memory that stores instructions, and when the instructions are executed by the at least one processor, the at least one processor is caused to execute the agricultural machinery trajectory data classification method as described above.
[0074] In another aspect of the present invention, a machine-readable storage medium is further provided, which stores executable instructions, and when the instructions are executed, the machine is caused to execute the agricultural machinery trajectory data classification method as described above.
[0075] Compared with the prior art, the beneficial effects of the present invention are:
[0076] (1) A method for classifying agricultural machinery trajectory data provided by the present invention. During the contrastive learning process of the constructed trajectory classification model, by maximizing the similarity between positive sample pairs and minimizing the similarity between negative sample pairs, complex and key features in the trajectory data can be automatically learned without a large amount of manually labeled data. Compared with the traditional method that relies on manually designed features, this method breaks the limitations of traditional trajectory data classification that depends on manual annotation and manual feature extraction, and it can capture subtle spatio-temporal features in the trajectory data, greatly improving the classification accuracy and generalization ability, and is applicable to trajectory classification tasks in various complex scenarios.
[0077] (2) The present invention uses the idea of a dynamic negative sample queue in the contrastive learning framework to update the negative sample queue in real time, and incorporates newly emerging trajectory data into it in a timely manner, effectively avoiding model overfitting to known data; at the same time, through category-distinguishing dual-queue management, the negative sample queues for field trajectories and road trajectories are maintained separately to ensure the category consistency of negative samples.
[0078] (3) In each round of training of the model, the trajectory classification model selects negative samples from the feature queue corresponding to the other category according to the category of the current input trajectory, constructs a cross-category contrast relationship, and strengthens the model's ability to distinguish different trajectory patterns. This design provides a more reliable solution for trajectory data classification. Brief Description of the Drawings
[0079] Figure 1 is a flowchart of the method for classifying agricultural machinery trajectory data of the present invention.
[0080] Figure 2 is a class classification diagram of the original agricultural machinery GNSS trajectory data in Embodiment 1 of the present invention.
[0081] Figure 3 is an architecture diagram of the trajectory classification model constructed in Embodiment 1 of the present invention.
[0082] Figure 4 is a flowchart of training the trajectory classification model in Embodiment 1 of the present invention. Detailed Description of the Invention
[0083] The present invention will be further described below in conjunction with the drawings and embodiments.
[0084] It should be noted that the following detailed description is exemplary and is intended to provide further illustration of the present invention. Unless otherwise specified, all technical and scientific terms used herein have the same meaning as commonly understood by those of ordinary skill in the technical field to which the present invention belongs.
[0085] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit the exemplary embodiments according to the present invention. As used herein, unless the context clearly indicates otherwise, the singular forms are also intended to include the plural forms. In addition, it should be understood that when the terms "comprising" and / or "including" are used in this specification, they specify the presence of features, steps, operations, devices, components, and / or combinations thereof.
[0086] In the case of no conflict, the embodiments in the present invention and the features in the embodiments can be combined with each other.
[0087] Aiming at the deficiencies of the prior art, the present invention provides a classification method for agricultural machinery trajectory data. The method proposes a contrastive learning framework that fuses a dynamic negative sample queue. This framework draws on the core idea of the wav2vec model and makes adaptive improvements: wav2vec, as a self-supervised learning-based speech feature extraction method, its core lies in capturing the temporal dependencies of speech signals through an encoder network and a context network, and constructing a contrastive task to predict the features of future time steps, so as to learn robust representations from the original data.
[0088] Considering that speech signals are composed of a sequence of sound waves with continuous timestamps, and trajectory data is essentially a serialized expression of spatio-temporal positions evolving over time, both rely on the ability to model long-range temporal relationships. Based on this commonality, this framework transfers the temporal modeling idea of wav2vec to the trajectory learning scenario and optimizes it by combining the construction of multi-scale spatio-temporal contrast tasks with a dynamic negative sample queue. The dynamic negative sample queue expands the scale of negative samples and ensures diversity by maintaining a continuously updated repository, solves the problem of limited number and insufficient diversity of negative samples in trajectory data, and can make more effective use of negative sample information to improve the discrimination ability of the model.
[0089] The following further illustrates the classification method and device for agricultural machinery trajectory data of the present invention in conjunction with specific embodiments.
[0090] Embodiment 1
[0091] Refer Figure 1 , this embodiment provides a classification method for agricultural machinery trajectory data. The method extracts trajectory features through a two-branch structure of an encoder-context network: the encoder captures local spatio-temporal patterns, and the context network uses a spatio-temporal attention mechanism to model long-range dependencies; a dynamic negative sample queue is introduced to continuously store trajectory segments of different categories and different spatio-temporal scenarios in historical training, and is dynamically updated through a first-in-first-out strategy to expand the scale of negative samples and enhance diversity.
[0092] The method specifically includes:
[0093] S1. Preprocess and perform feature transformation on the original agricultural machinery GNSS trajectory data to obtain continuous and uniform time-series trajectory data. Among them, the original agricultural machinery GNSS trajectory data contains multiple discrete trajectory points, and the features of each discrete trajectory point include longitude, latitude, timestamp, speed, direction, and class label. The classes of trajectory points include field trajectories and road trajectories.
[0094] In this embodiment, the GNSS trajectory dataset collected by the Beidou team of China Agricultural University is used for research and verification. This dataset records multi-dimensional information such as the longitude and latitude coordinates, timestamp, speed, and driving direction of agricultural machinery operations through GNSS positioning technology, and has the characteristics of strong spatio-temporal continuity and high data density, and can completely present the regularity of agricultural machinery operation trajectories.
[0095] Based on the requirements of the model used in the method of this embodiment for input data, it is necessary to first preprocess and perform feature transformation on the original agricultural machinery GNSS trajectory data to obtain a data form that can meet the model input requirements.
[0096] Specifically, the wav2vec model was originally designed to process audio data, and its input is usually a continuous one-dimensional floating-point waveform signal with high data continuity and large sampling density. However, there are obvious differences between agricultural machinery GNSS trajectory data and audio data in nature. GNSS trajectory data is generally composed of multiple discrete spatio-temporal data (trajectory) points, and each data point contains information such as longitude, latitude, timestamp, speed, direction, and class label. Although these data points can record the motion state and spatial position of the trajectory, due to the actual conditions of agricultural machinery operations (such as equipment sampling frequency, satellite signal interference, operation intervals), the data often shows characteristics of uneven sampling frequency, sparse and discontinuous data point distribution. This sparsity and discreteness make GNSS trajectory data unable to directly adapt to the model framework of wav2vec originally designed for dense continuous signals.
[0097] Therefore, in order to effectively utilize the time-series modeling ability of wav2vec, it is first necessary to preprocess and perform feature transformation on the original GNSS trajectory data, that is, convert it into a continuous and uniform time series of feature vectors to meet the requirements of the model for the continuity and regularity of input data.
[0098] In this embodiment, the preprocessing and feature transformation operations on the original agricultural machinery GNSS trajectory data are as follows:
[0099] 1) According to the class labels of the trajectory points in the original agricultural machinery GNSS trajectory data, that is, field trajectories and road trajectories, it is segmented into several different trajectory segments.
[0100] In the original agricultural machinery GNSS trajectory data, each trajectory point is associated with a class label, usually "1" representing field trajectories and "0" representing road trajectories. Based on these labels, different types of trajectory segments can be identified. Specifically, by traversing the entire set of original agricultural machinery GNSS trajectory data, when there is a change in the class label, such as from "1" to "0" or from "0" to "1", a new trajectory segment can be demarcated. For example, among consecutive data points of field trajectories (labeled "1"), all data points belong to the same class; when a road trajectory (labeled "0") is encountered, a new trajectory segment begins.
[0101] Each trajectory segment will contain a class label "1" or "0" and form a continuous trajectory fragment according to the time sequence. The classification process is as Figure 2 shown.
[0102] After such processing, the trajectories are divided into two categories: field trajectories and road trajectories. Each trajectory segment can clearly indicate its corresponding trajectory type (field or road), providing clear labels for subsequent feature extraction and model training.
[0103] 2) Resample and interpolate the segmented trajectory segments to obtain continuous and uniform agricultural machinery GNSS trajectory data.
[0104] Aiming at the problems of uneven sampling frequency and sparse data in the original agricultural machinery GNSS trajectory data, to ensure that the model can obtain continuous and unified time-series inputs, this embodiment adopts a resampling method.
[0105] According to the sampling frequency of the original agricultural machinery GNSS trajectory data and the classification task, select a suitable sampling interval. Demonstratively, set the sampling interval = 30 seconds, that is, collect one data point every thirty seconds. Then obtain the start time and end time of each trajectory segment. According to the set sampling interval , construct a new time grid: .
[0106] Specifically, first sort the trajectory points in ascending order of the timestamp and set the timestamp of the original trajectory points as the index. Then use linear interpolation to interpolate each feature of the trajectory points. The interpolation is only performed at the newly created fixed grid points, and the original trajectory points that do not fall on the grid points will not be directly retained. The linear interpolation formula used is as follows:
[0107] For the time to be interpolated , assume that the two nearest original trajectory points on both sides are ([[]] , ), ([[]] , ),then the estimated feature value is:
[0108] (1);
[0109] In formula (1): represents the time to be interpolated where the estimated feature value is inserted
[0110] Finally, each trajectory forms a trajectory sequence that is uniformly sampled at fixed timestamps such as 0 seconds, 30 seconds, 60 seconds, 90 seconds, etc. After resampling, the trajectory data becomes consistent in the time dimension, providing a stable basis for subsequent feature extraction and formatting.
[0111] 3) Perform a fixed-window segmentation operation on the interpolated agricultural machinery GNSS trajectory data to obtain trajectory segments of equal length.
[0112] After the original agricultural machinery GNSS trajectory data is segmented by category, the lengths of trajectory segments of different categories may vary. For example, the trajectory segments of field operations are longer, while those of road driving may be shorter. This length imbalance will affect the input format and training stability of the model. Therefore, it is necessary to use the method of fixed-window segmentation to uniformly process the trajectory segments with uneven lengths into subsequences of equal length to meet the input requirements of the model.
[0113] In this embodiment, the basic idea of data segmentation is: apply the sliding window technique to each trajectory, set the window length to 200 points, and the sliding step size to 100 points to generate overlapping trajectory segments.
[0114] For the remaining part with a length less than 200 points, if its length is greater than or equal to 50 points, these data are retained by padding to 200 points; if its length is less than 50 points, it is directly discarded.
[0115] Each segmented trajectory segment inherits the category label of the original segment to ensure label consistency. Through this method, multiple trajectory segments of fixed length can be generated, which not only retains the temporal context of the trajectory but also enhances the diversity of the trajectory data, providing high-quality input for model training.
[0116] 4) Perform feature extraction and formatting operations on the segmented trajectory segments.
[0117] Feature extraction and formatting are the key steps to transform the original agricultural machinery GNSS trajectory data into a form that can be processed by the model. In this embodiment, key features such as longitude, latitude, speed, and direction are extracted from each trajectory point, and these features are organized into a continuous time series in chronological order.
[0118] First, each trajectory point contains information in multiple dimensions. Among them, longitude and latitude, as geographical coordinates, precisely describe the two-dimensional position of the point on the Earth's surface. Speed reflects how fast a vehicle or device is moving at that point and is an important motion attribute. Direction indicates the orientation of the vehicle, usually represented by the angle relative to the north, ranging from [0, 360] degrees. Extract the features of longitude, latitude, speed, and direction for each trajectory point.
[0119] Then, standardize the features extracted above.
[0120] The numerical ranges of the extracted different features may vary greatly. If not standardized, the model may assign higher weights to features with larger numerical ranges and ignore features with smaller numerical ranges. This will cause the training results of the model to be biased towards features with larger numerical ranges, thus affecting the performance and generalization ability of the model. Therefore, it is necessary to perform Z-score standardization operations on each feature to convert the features into a standard normal distribution with a mean of 0 and a standard deviation of 1.
[0121] At the same time, due to the particularity of spatial coordinates (longitude and latitude) and direction features, certain operations need to be performed on them before standardization. Specifically:
[0122] 4-1) Standardization processing of longitude and latitude:
[0123] To avoid destroying the geographical spatial relationship when directly standardizing longitude and latitude, such as the actual distance of 1° longitude being different at different latitudes, in this embodiment, the UTM projection is used to convert the longitude and latitude coordinates of the trajectory points into a plane coordinate system.
[0124] Specifically, convert the longitude and latitude of each trajectory point to obtain its x (eastward coordinate) and y (northward coordinate) values in the UTM coordinate system, and then calculate its relative displacement relative to the starting point. Demonstratively, for trajectory point i, the relative displacement and represent the planar displacement of this trajectory point relative to the starting point.
[0125] Subsequently, perform Z-score standardization processing on the relative displacement coordinates (i.e., and ), ensuring that each feature is on the same scale. The standardization formula is as follows:
[0126] (2);
[0127] (3);
[0128] In formulas (2)-(3): , respectively represent The mean and standard deviation of the features; and respectively represent the mean and standard deviation of the features; and respectively represent the relative displacement coordinates after standardization.
[0129] Through standardization, the relative displacements of all trajectory points and will all have zero mean and unit variance.
[0130] 4-2) Standardization processing of the direction:
[0131] The direction has periodic characteristics. Directly standardizing the direction may lead to data discontinuity. It is necessary to convert the angle into sine and cosine values, and then perform Z-score standardization on these values. The specific formulas are as follows:
[0132] First, convert to sine and cosine:
[0133] (4);
[0134] (5);
[0135] Perform standardization on the sine and cosine values:
[0136] (6);
[0137] (7);
[0138] In formulas (4)-(7): represents the course angle of the i-th trajectory point; and respectively represent the sine projection of the direction angle and the cosine projection of the direction angle; and respectively represent the mean of the sine components of all trajectory points and the mean of the cosine components of all trajectory points; and respectively represent the standard deviation of the sine components of all trajectory points and the standard deviation of the cosine components of all trajectory points; and respectively represent the sine component of the standardized course angle and the cosine component of the standardized course angle.
[0139] It should be understood that the speed feature does not require special processing and can be directly subjected to Z-score standardization, which will not be elaborated here.
[0140] Based on the above, the standardization processing of all trajectory point features is completed.
[0141] 5) Perform a concatenation operation on the standardized features to obtain continuous and uniform time-series trajectory data.
[0142] Concatenate the standardized features such as longitude, latitude, speed, and direction of each trajectory point to construct a feature vector. Exemplarily, for a trajectory point , its feature vector can be expressed as: , and this feature vector contains all the key information of this trajectory point and can be recognized and learned by the model.
[0143] Subsequently, arrange the feature vectors of all trajectory points in chronological order to form a time series. Assuming there are N trajectory points and these points have been sorted by timestamp, then the time series of the entire trajectory segment can be represented as a matrix:
[0144]
[0145] Each row of the matrix X here corresponds to the feature vector of a trajectory point. The entire matrix X is arranged in chronological order, thus retaining the time-series characteristics of the trajectory.
[0146] Finally, ensure the continuity of the time series, that is, the order of the trajectory points in the matrix must be consistent with the actual time order, so that the subsequent model can correctly capture the trends and patterns of the trajectory changing over time. In this way, the original agricultural machinery GNSS trajectory data is transformed into a structured time-series form to adapt to the input requirements of the model.
[0147] S2. Construct a trajectory classification model including a feature extraction module and a classification head. The feature extraction module includes an encoder network, a context network, and a momentum encoder, and use the time-series trajectory data as training samples to train the trajectory classification model. The training of the trajectory classification model includes a feature pre-training stage and a classification fine-tuning stage.
[0148] Refer Figure 3 , in the feature pre-training stage, it specifically includes:
[0149] S21. Use the encoder network to extract features from the time-series trajectory data, and use the context network to capture the long-range dependencies of the extracted features in the context information to construct positive sample pairs.
[0150] Specifically, the encoder network includes three one-dimensional convolutions for extracting local trajectory features. For the convolutional layers of the encoder network, using different sizes of convolutional kernels and strides can help the model extract features at different time scales. The specific configuration is as follows:
[0151] The first convolutional layer: the convolutional kernel size is 10, the stride is 2, the padding is 3, and the number of output channels is 128;
[0152] The second convolutional layer: the convolutional kernel size is 8, the stride is 2, the padding is 2, and the number of output channels is 256;
[0153] The third convolutional layer: the convolutional kernel size is 6, the stride is 2, the padding is 1, and the number of output channels is 512.
[0154] Each convolutional layer is configured with a ReLU activation function and batch normalization.
[0155] Through multiple convolutional layers, local features are extracted from the time-series trajectory data obtained by preprocessing. After each convolutional operation, the ReLU activation function is used to introduce non-linearity, and the pooling operation further reduces the size of the feature map while retaining the most important feature information. Finally, the true feature representation at the current time t can be obtained as well as the true feature representation at the k-th future time .
[0156] In the processing of trajectory data, it is extremely crucial to accurately capture the long-range dependencies in the context information. In the context network, in this embodiment, a temporal convolutional network (TCN) is used to capture the long-range dependencies in the trajectory data. Traditional networks such as feedforward neural networks are difficult to perceive the time order, and the RNN network is prone to gradient vanishing or explosion when processing long sequences. The temporal convolutional network (TCN) can process sequence data in parallel and extract features through convolutional operations.
[0157] Specifically, the temporal convolutional network (TCN) in this embodiment uses 3 layers of temporal convolution, each with a convolutional kernel size of 3, a stride of 1, and the number of output channels of 512. After each convolutional operation, the ReLU activation function is used to introduce non-linearity. This setting can expand the receptive field and effectively capture the long-range dependencies in the time series of trajectory data, providing strong support for trajectory analysis.
[0158] Based on the above, the constructed trajectory classification model extracts the context representation at the current time t through the encoder network and the context network , which captures the temporal information at the current time and its previous and subsequent times.
[0159] After obtaining the context representation , the model predicts the feature representation at the k-th future time, that is, the model passes the context representation through a series of linear transformations W to obtain the predicted feature representation .
[0160] The objective of this embodiment is to make the predicted feature representation match the true feature representation As similar as possible, so the obtained true feature representation and the predicted feature representation will be used as the positive sample and the reference sample respectively for the calculation of the loss function. The positive sample pair is based on the true feature representation and the predicted feature representation to construct, that is .
[0161] S22. Perform data augmentation operations on the time-series trajectory data, input the augmented time-series trajectory data into the momentum encoder to obtain its feature representation, and construct negative sample pairs in combination with the dynamic queue mechanism.
[0162] In this embodiment, the data augmentation operation is to perform mirror flipping of the trajectory along the vertical axis (equivalent to the y-axis), specifically, take the negative of the longitude of each point in the trajectory and keep the latitude unchanged to generate a new trajectory.
[0163] For contrastive learning to achieve good results, it is necessary to have a negative sample set with a large enough scale and a consistent sample distribution. To improve the scale and diversity of negative sample construction in contrastive learning, this embodiment introduces a dynamic negative sample queue mechanism for storing and updating the trajectory feature representations generated during training. This mechanism overcomes the problems of limited number of negative samples and single sample distribution in traditional methods by constructing a continuously updated feature queue and dynamically maintaining historical sample information during training, significantly improving the model's identification ability for different trajectory categories.
[0164] Specifically, during the model training process, a momentum encoder network is constructed in parallel. Its network structure is the same as that of the main model, but the parameter update method is different. The momentum encoder receives the enhanced trajectory segments, generates the feature representations for contrastive learning, and participates in the loss calculation of contrastive learning together with the output of the main model.
[0165] To ensure the stability and diversity of features, the parameters of the momentum encoder are adjusted using a momentum update strategy based on historical gradient information, so that the direction of parameter update depends not only on the current gradient but also on the previous gradient direction, avoiding frequent parameter changes from disturbing the feature distribution, thereby improving the consistency and quality of negative samples.
[0166] During each training, the parameters of the momentum encoder will be updated using the momentum update formula. The momentum update formula is:
[0167] (8);
[0168] In formula (8): represents the parameters of the momentum encoder; represents the parameters of the main model; is the momentum coefficient, and its value range is usually between 0 and 1. Here, the value of m is set to 0.999, which enables the negative sample features to remain stable and not be affected by the fluctuations of the main model parameters.
[0169] For the two typical patterns of "field trajectory" and "road trajectory" existing in the trajectory data, this embodiment further designs a dual-queue management mechanism for class discrimination, and respectively maintains and two independent negative sample storage channels.
[0170] Among them, is the field trajectory queue, which stores the field class representations generated by the momentum encoder in the recent several batches; is the road trajectory queue, which stores the road class representations generated by the momentum encoder in the recent several batches.
[0171] In each round of training, the model selects negative samples from the feature queue corresponding to the other class according to the class of the current input trajectory, constructs a cross-class contrast relationship, and strengthens the model's ability to distinguish different trajectory patterns. For example, if the current trajectory sample belongs to the field class, then randomly select from the road trajectory queue as a negative sample, and form a negative sample pair with the predicted feature representation. . If the current trajectory sample belongs to the road class, then randomly select from the field trajectory queue as a negative sample, and form a negative sample pair with the predicted feature representation. .
[0172] For each sample, the classification by category has been completed during data preprocessing, and it has a clear category. After the data augmentation operation, the sample is input into the momentum encoder to generate a feature representation.
[0173] After each training, according to the class of the sample, the feature representations are respectively stored in the corresponding class queues. For example: if the sample belongs to the field trajectory, then put the corresponding feature representation into the field queue. Each queue adopts a first-in-first-out strategy with a fixed size of n = 2048 to update. When a new feature is generated, it is added to the corresponding queue in sequence; if the queue is full, the oldest sample feature is removed to keep the queue capacity fixed, the sample diversity rich, and the timeliness strong.
[0174] At the initial stage of training, since there is no historical data yet, both the two negative sample queues, namely the field trajectory queue and the road trajectory queue, are empty. When the first trajectory data is input, the feature representations of the positive sample pairs are obtained through the model. However, since the dynamic negative sample queue is empty, negative samples cannot be obtained from it. Therefore, it is necessary to initialize the two dynamic negative sample queues before the start of training.
[0175] Specifically, during the data preprocessing stage, the data has been divided into two categories, namely "field trajectories" and "road trajectories", according to the prior information of the agricultural machinery trajectory data. Subsequently, a pre-initialized dataset is prepared for each category, that is, about 100 preprocessed field trajectory segments and road trajectory segments are randomly selected to ensure that both categories of data have sufficient sample sizes to fill the queues.
[0176] Each sample in the pre-initialized dataset is input into the momentum encoder after data augmentation to obtain the corresponding feature representation. For each category, according to the set queue capacity, the calculated feature representations are inserted into the corresponding negative sample queue in sequence to complete the initialization of the queue.
[0177] This mechanism not only effectively increases the quantity and coverage of negative samples, but also enhances their spatio-temporal diversity and category discrimination, which helps the model obtain more stable and discriminative representation capabilities during the contrastive learning process, thus significantly improving the accuracy and robustness of trajectory classification.
[0178] S23. In the feature pre-training stage, based on the positive sample pairs and negative sample pairs, the feature extraction module of the trajectory classification model is iteratively trained using the InfoNCE contrast loss function, and an early stopping mechanism is introduced. When the loss values of consecutive multiple training epochs tend to be stable, the early stopping mechanism is triggered. The representation vectors of all temporal trajectory data are extracted using the current feature extraction module, and K-means clustering is performed based on this representation vector, and the clustering quality is evaluated by calculating the silhouette coefficient to judge the feature learning effect of the current trajectory classification model;
[0179] In the classification fine-tuning stage, the feature extraction module is frozen, and the classification head is trained using the supervised cross-entropy loss, and the class labels are enabled for supervised learning so that the classification head outputs the class probability distribution of the trajectory.
[0180] In this embodiment, the features are self-supervised optimized using the InfoNCE contrast loss to maximize the similarity between positive samples and minimize the similarity between negative samples.
[0181] The InfoNCE loss function is as follows:
[0182] Assume that the current sample belongs to the field trajectory category, and negative samples are selected from the road trajectory queue:
[0183] (9);
[0184] In formula (9): represents the road trajectory queue; represents the i-th negative sample in the road trajectory queue; sim is the cosine similarity, represents the feature representation at the future moment predicted by the model, i.e., the benchmark sample; represents the true feature representation at the future moment, i.e., the positive sample; is the temperature parameter, used to control the distribution of similarity.
[0185] Similarly, if the current sample belongs to the road trajectory category, negative samples are selected from the field trajectory queue:
[0186] (10);
[0187] In formula (10): represents the road trajectory queue; represents the i-th negative sample from the field trajectory queue.
[0188] During training, a phased training strategy is adopted. Its core concept is "optimize features first and then classify", aiming to improve the generalization ability and classification accuracy of the model by optimizing features first and then classifying. Specifically, this method is divided into two main stages: the feature pre-training stage and the classification fine-tuning stage.
[0189] Ref. Figure 4 , first preprocess the original agricultural machinery GNSS trajectory data. The original trajectory data contains information such as longitude, latitude, timestamp, speed, direction, and category. After data preprocessing operations, the original features are concatenated into an input form more suitable for the model. At this stage, the data is segmented by category, the length of the input trajectory segment is fixed, the quality of the input data is improved, and each feature is normalized. 100 trajectory segments are selected from each category and integrated into a pre-initialized dataset to fill the negative sample queue before the start of training.
[0190] Each segmented data is used as an independent sample and is sequentially fed into the encoder network and the context network to obtain the positive sample pairs required for contrastive learning. At the same time, the segmented data is fed into the momentum encoder after a data augmentation operation, and combined with the dynamic negative sample queue to obtain the negative samples required for contrastive learning.
[0191] So far, the contrastive learning task is completed.
[0192] Subsequently, through contrastive loss functions such as InfoNCE, the model learns to represent similar trajectory features closer and dissimilar trajectory features farther apart.
[0193] Construct the obtained positive and negative samples into a dataset, and divide the dataset according to the ratio of 70% for training, 15% for validation, and 15% for testing.
[0194] In the feature pre-training stage, through contrastive learning and the dynamic negative sample queue mechanism, the encoder network learns a robust trajectory representation. Set the training batch size to 32 and the total number of training epochs to 50. When necessary, use early stopping or adjust the learning rate. Through the forward propagation of the encoder network, context network, and momentum encoder, perform dynamic queue update and negative sample sampling, and calculate the contrastive loss InfoNCE. Use the AdamW optimizer (learning rate set to 3e-4, weight decay to 0.01) for backpropagation and parameter update, and update the momentum encoder at the same time.
[0195] In the feature pre-training stage, first use the InfoNCE loss as the main optimization objective. By maximizing the feature similarity of positive sample pairs and minimizing the similarity of negative sample pairs, promote the encoder network and context network to continuously improve their ability to identify trajectory patterns. After each training cycle, record the loss value in real time. If there is no significant decrease for several consecutive cycles, such as 5 training cycles, trigger the early stopping mechanism to avoid ineffective training.
[0196] At the same time, in order to introduce an auxiliary evaluation mechanism for the quality of feature distribution in addition to the contrastive loss, after triggering the early stopping mechanism or training completion, extract the representation vectors of all trajectory segments by the current trajectory classification model, and use the K-means algorithm to divide them into two categories: field trajectories and road trajectories. Measure the tightness and separation of the cluster structure by calculating the silhouette coefficient. When the silhouette coefficient reaches or exceeds 0.6, it indicates that the features learned by the model already have good performance in class discrimination, and the subsequent classification task can be considered; if the silhouette coefficient continues to be lower than this threshold, it indicates that the feature clustering effect is poor, and it is necessary to return to the contrastive learning stage to continue optimizing the model parameters or adjusting the hyperparameters.
[0197] The entire process is dominated by the loss decline trend and supplemented by the clustering quality evaluation, organically combining early stopping, K-means clustering, and the silhouette coefficient, enabling the model to not only achieve the best in the contrastive loss but also show clear class boundaries in practical applications, thus laying a solid feature foundation for the downstream transportation mode classification task.
[0198] In the classification fine-tuning stage, a classification head is designed for the model. The classification head is the last part of the model and is responsible for converting the feature representation into a class probability distribution. This part consists of two fully connected layers, and finally, a softmax layer is used to output the probability distribution of the classes. The first fully connected layer maps the output feature map to a lower-dimensional space. Then, the second fully connected layer further maps the intermediate representation output by the first fully connected layer to the number of target classes. The ReLU activation function is used to introduce non-linearity, which helps the model learn more complex feature representations. Finally, the output layer uses the softmax activation function to generate the probability distribution of each class.
[0199] In this stage, the pre-trained feature extractor (including the encoder network, context network, and momentum encoder) is frozen, and only the classification head is trained. The input data is a trajectory segment with a length of 200, and classification labels are enabled for supervised learning. During training, supervised cross-entropy loss is used to guide the model to learn. By comparing the difference between the prediction result and the true label, the parameters of the classification head are dynamically optimized, enabling the model to gradually reduce the prediction error. After such training, the classification head can focus on distinguishing high-level semantic features, thereby effectively improving the classification accuracy.
[0200] During training, each batch of data first passes through the encoder and context network to obtain high-dimensional features, then passes through the classification head to predict the class, and at the same time, the dynamic negative sample queue is used to update the negative samples and calculate the contrast loss.
[0201] Based on the above, the training process of the trajectory classification model is completed.
[0202] S3. Deploy the trained trajectory classification model and use it to classify agricultural machinery trajectory data.
[0203] Finally, apply the trained trajectory classification model to the actual agricultural machinery trajectory classification task to complete the classification of agricultural machinery trajectory data.
[0204] Example 2
[0205] This example provides a device for implementing a method for classifying agricultural machinery trajectory data. The device includes:
[0206] A data acquisition module for preprocessing and feature conversion operations on the original agricultural machinery GNSS trajectory data to obtain continuous and uniform time-series trajectory data; wherein, the original agricultural machinery GNSS trajectory data contains multiple discrete trajectory points, and the features of each discrete trajectory point include longitude, latitude, timestamp, speed, direction, and class label, and the classes of the trajectory points include field trajectories and road trajectories.
[0207] A model construction and training module for constructing a trajectory classification model including a feature extraction module and a classification head. The feature extraction module includes an encoder network, a context network, and a momentum encoder, and uses the time-series trajectory data as training samples to train the trajectory classification model. The training of the trajectory classification model includes a feature pre-training stage and a classification fine-tuning stage, specifically:
[0208] Use the encoder network to extract features from the time-series trajectory data, and use the context network to capture the long-range dependence of the extracted features in the context information to construct positive sample pairs;
[0209] Perform data augmentation operations on the time-series trajectory data, input the augmented time-series trajectory data into the momentum encoder to obtain its feature representation, and construct negative sample pairs in combination with the dynamic queue mechanism;
[0210] In the feature pre-training stage, based on the positive sample pairs and negative sample pairs, use the InfoNCE contrast loss function to iteratively train the feature extraction module of the trajectory classification model, and introduce an early stopping mechanism. When the loss values of consecutive training epochs tend to be stable, trigger the early stopping mechanism, use the current feature extraction module to extract the representation vectors of all time-series trajectory data, perform K-means clustering based on these representation vectors, and evaluate the clustering quality by calculating the silhouette coefficient to judge the feature learning effect of the current trajectory classification model;
[0211] In the classification fine-tuning stage, freeze the feature extraction module, use supervised cross-entropy loss to train the classification head, and enable class labels for supervised learning to make the classification head output the class probability distribution of the trajectory;
[0212] A model application module for deploying the trained trajectory classification model and using it to classify agricultural machinery trajectory data.
[0213] Example 3
[0214] This embodiment also provides an electronic device, including:
[0215] At least one processor; and
[0216] A memory that stores instructions, and when the instructions are executed by the at least one processor, the at least one processor executes the agricultural machinery trajectory data classification method as described above.
[0217] In this embodiment, the electronic device may include, but is not limited to: personal computers, server computers, workstations, desktop computers, laptop computers, notebook computers, mobile computing devices, smart phones, tablet computers, cellular phones, personal digital assistants (PDAs), handheld devices, messaging devices, wearable computing devices, consumer electronic devices, and so on.
[0218] Embodiment 4
[0219] This embodiment also provides a machine-readable storage medium storing executable instructions that, when executed, cause the machine to perform the agricultural machinery trajectory data classification method as described above.
[0220] Specifically, a system or device equipped with a readable storage medium may be provided, on which software program code for implementing the functions of any one of the above embodiments is stored, and the computer or processor of the system or device is caused to read and execute the instructions stored in the readable storage medium.
[0221] In this case, the program code read from the readable medium itself can implement the functions of any one of the above embodiments, and thus the machine-readable code and the readable storage medium storing the machine-readable code constitute a part of this specification.
[0222] Examples of the readable storage medium include floppy disks, hard disks, magneto-optical disks, optical disks (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RAM, DVD-RW, DVD-RW), magnetic tapes, non-volatile memory cards, and ROMs. Alternatively, the program code may be downloaded from a server computer or a cloud via a communication network.
[0223] Those skilled in the art should understand that the embodiments of the present invention may be provided as a method, a system, or a computer program product. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk memories, CD-ROMs, optical memories, etc.) containing computer-usable program code.
[0224] The present invention is described with reference to the flowcharts and / or block diagrams of methods, apparatuses (systems), and computer program products according to embodiments of the present invention. It should be understood that each flow and / or block in the flowcharts and / or block diagrams, as well as the combination of flows and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing devices to generate a machine, such that the instructions executed by the processor of the computer or other programmable data processing devices generate means for implementing the functions specified in one flow Figure 1 one flow or multiple flows and / or blocks Figure 1 or multiple blocks.
[0225] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, such that the instructions stored in the computer-readable memory generate a manufactured article including instruction means that implement the functions specified in one flow Figure 1 one flow or multiple flows and / or blocks Figure 1 or multiple blocks.
[0226] These computer program instructions can also be loaded onto a computer or other programmable data processing device, such that a series of operation steps are executed on the computer or other programmable device to generate a computer-implemented process, so that the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one flow Figure 1 one flow or multiple flows and / or blocks Figure 1 or multiple blocks.
[0227] Obviously, the above embodiments of the present invention are merely examples for clearly illustrating the technical solutions of the present invention, rather than limitations on the specific implementation manners of the present invention. Any modifications, equivalent replacements, and improvements made within the spirit and principle of the claims of the present invention shall be included in the protection scope of the claims of the present invention.
Claims
1. A classification method for agricultural machinery trajectory data, characterized in that, The method includes: S1. Perform preprocessing and feature transformation operations on the original agricultural machinery GNSS trajectory data to obtain continuous and uniform time-series trajectory data. Among them, the original agricultural machinery GNSS trajectory data contains multiple discrete trajectory points, and the features of each discrete trajectory point include longitude, latitude, timestamp, speed, direction, and class label. The classes of trajectory points include field trajectories and road trajectories. S2. Construct a trajectory classification model including a feature extraction module and a classification head. The feature extraction module includes an encoder network, a context network, and a momentum encoder, and use the time-series trajectory data as training samples to train the trajectory classification model. The training of the trajectory classification model includes a feature pre-training stage and a classification fine-tuning stage. Specifically: S21. Use the encoder network to extract features from the time-series trajectory data, and use the context network to capture the long-distance dependence of the extracted features in the context information to construct positive sample pairs. S22. Perform data augmentation operations on the time-series trajectory data, input the augmented time-series trajectory data into the momentum encoder to obtain its feature representation, and construct negative sample pairs in combination with the dynamic queue mechanism. S23. In the feature pre-training stage, based on the positive sample pairs and negative sample pairs, use the InfoNCE contrast loss function to iteratively train the feature extraction module of the trajectory classification model, and introduce an early stopping mechanism. When the loss values of consecutive training epochs tend to be stable, trigger the early stopping mechanism, use the current feature extraction module to extract the representation vectors of all time-series trajectory data, perform K-means clustering based on this representation vector, and evaluate the clustering quality by calculating the silhouette coefficient to judge the feature learning effect of the current trajectory classification model. In the classification fine-tuning stage, freeze the feature extraction module, use the supervised cross-entropy loss to train the classification head, and enable the class label for supervised learning so that the classification head outputs the class probability distribution of the trajectory. S3. Deploy the trained trajectory classification model and use it to classify the agricultural machinery trajectory data.
2. The agricultural machinery trajectory data classification method according to claim 1, characterized in that In S1, the preprocessing of the original agricultural machinery GNSS trajectory data includes: According to the class labels of the trajectory points in the original agricultural machinery GNSS trajectory data, segment it into several different trajectory segments. Among them, the class label of the trajectory point is 1 or 0, where 1 represents a field trajectory and 0 represents a road trajectory. And perform resampling and interpolation operations on the segmented trajectory segments. Specifically: Set the sampling interval , and according to the set sampling interval , construct a new time grid: , where is the start time of the trajectory segment, is the end time of the trajectory segment; Arrange the trajectory points in ascending order of timestamps, set the timestamps of the trajectory points as indices, and perform interpolation processing on each feature of the trajectory points on the newly created time grid. That is, for the time to be interpolated , assume that the two nearest original trajectory points are ([[]] , ), ( , ), then the feature estimated value is: (1); In formula (1): represents the time to be interpolated and the estimated value of the inserted feature at that location; And perform fixed-window segmentation operations on the interpolated agricultural machinery GNSS trajectory data to obtain equal-length trajectory segments. Among them, the window length is set to 200 points, and the sliding step is 100 points to generate overlapping trajectory segments.
3. The agricultural machinery trajectory data classification method according to claim 1, wherein In S1, the feature transformation of the preprocessed original agricultural machinery GNSS trajectory data includes: Extract key features from each trajectory point, including longitude, latitude, speed, and direction, and perform standardization processing on this feature. Among them, the standardization processing of the longitude and latitude is specifically: Convert the longitude and latitude of each trajectory point to obtain its x - coordinate value and y - coordinate value in the UTM coordinate system, and calculate its relative displacement relative to the starting point and , then perform Z - score standardization on the relative displacement and : (2); (3); In formulas (2)-(3): and respectively represent the mean and standard deviation of the feature; and respectively represent the mean and standard deviation of the feature; and respectively represent the relative displacement coordinates after standardization; The standardization processing of the direction is specifically: Convert the angle of the direction into sine and cosine values: (4); (5); Perform Z-score normalization on sine and cosine values: (6); (7); In formulas (4)-(7): represents the heading angle of the i-th trajectory point; , respectively represent the sine projection of the direction angle and the cosine projection of the direction angle; , respectively represent the mean value of the sine components of all trajectory points and the mean value of the cosine components of all trajectory points; , respectively represent the standard deviation of the sine components of all trajectory points and the standard deviation of the cosine components of all trajectory points; , respectively represent the sine component of the normalized heading angle and the cosine component of the normalized heading angle; Furthermore, perform a concatenation operation on the standardized features to obtain the feature vector representation of each trajectory point. That is, for the trajectory point , its feature vector representation is ; then arrange the feature vectors of all trajectory points in chronological order to form a time series matrix. That is, assuming there are N trajectory points, the formed time series matrix is .
4. The agricultural machinery trajectory data classification method according to claim 1, characterized in that In S21, the encoder network includes three layers of one-dimensional convolutions for extracting local features from the temporal trajectory data to obtain the true feature representation at the current time t and the true feature representation at the k-th future time ; the context network uses a temporal convolutional network (TCN) with three layers of temporal convolutions for extracting the context representation at the current time t ; Represent the context to obtain a predicted feature representation through a linear transformation W , and based on the true feature representation and the predicted feature representation construct positive sample pairs as .
5. The agricultural machinery trajectory data classification method according to claim 4, characterized in that In S22, the parameters of the momentum encoder are updated using the momentum update formula, i.e.: (8); In Equation (8): represents the parameters of the momentum encoder; represents the parameters of the main model; is the momentum coefficient, and its value range is between 0 and 1; Construct negative sample pairs by combining the dynamic queue mechanism, specifically: Construct a dual-queue management mechanism based on field trajectories and road trajectories, and maintain separately and two independent negative sample storage channels, where is the field trajectory queue, which is used to store the field category representations generated by the momentum encoder in recent batches; is the road trajectory queue, which is used to store the road category representations generated by the momentum encoder in recent batches; In each round of training, according to the category of the current input trajectory, negative samples are selected from the feature queue corresponding to the other category to construct a cross-category contrast relationship. That is, when the current trajectory sample belongs to the field category, random samples are selected from the road trajectory queue and used as negative samples, which, together with the predicted feature representation form negative sample pairs ; when the current trajectory sample belongs to the road category, random samples are selected from the field trajectory queue and used as negative samples, which, together with the predicted feature representation form negative sample pairs .
6. The agricultural machinery trajectory data classification method according to claim 5, wherein In S23, during the feature pre-training stage, if the current trajectory sample is of the field trajectory category, negative samples are selected from the road trajectory queue. At this time, the InfoNCE loss function is: (9); In formula (9): represents the road trajectory queue; represents the i-th negative sample in the road trajectory queue; sim is the cosine similarity; represents the feature representation at the future moment predicted by the model, that is, the benchmark sample; represents the true feature representation at the future moment, that is, the positive sample; is the temperature parameter, used to control the distribution of the similarity; If the current trajectory sample is of the road trajectory category, negative samples are selected from the field trajectory queue. At this time, the InfoNCE loss function is: (10); In formula (10): represents the road trajectory queue; represents the i-th negative sample from the field trajectory queue.
7. The agricultural machinery trajectory data classification method according to claim 6, characterized in that S23 also includes that in the initial stage of the feature pre-training stage, several field trajectories and road trajectories are randomly selected from the time-series trajectory data as the pre-initialization dataset, and the pre-initialization dataset is data-augmented and then input into the momentum encoder to construct an initial negative sample queue.
8. An apparatus for implementing a method for classifying agricultural machinery trajectory data, characterized in that, The device includes: A data acquisition module for preprocessing and feature transformation operations on the original agricultural machinery GNSS trajectory data to obtain continuous and uniform time-series trajectory data; wherein, the original agricultural machinery GNSS trajectory data contains multiple discrete trajectory points, and the features of each discrete trajectory point include longitude, latitude, timestamp, speed, direction, and class label, and the classes of the trajectory points include field trajectories and road trajectories; A model construction and training module for constructing a trajectory classification model including a feature extraction module and a classification head. The feature extraction module includes an encoder network, a context network, and a momentum encoder, and uses the time-series trajectory data as training samples to train the trajectory classification model. The training of the trajectory classification model includes a feature pre-training stage and a classification fine-tuning stage, specifically: Use the encoder network to extract features from the time-series trajectory data, and use the context network to capture the long-range dependencies of the extracted features in the context information to construct positive sample pairs; Perform data augmentation operations on the time-series trajectory data, input the augmented time-series trajectory data into the momentum encoder to obtain its feature representation, and construct negative sample pairs by combining the dynamic queue mechanism; In the feature pre-training stage, based on the positive sample pairs and negative sample pairs, use the InfoNCE contrast loss function to iteratively train the feature extraction module of the trajectory classification model, and introduce an early stopping mechanism. When the loss values of consecutive training epochs tend to be stable, trigger the early stopping mechanism, use the current feature extraction module to extract the representation vectors of all time-series trajectory data, perform K-means clustering based on this representation vector, and evaluate the clustering quality by calculating the silhouette coefficient to judge the feature learning effect of the current trajectory classification model; In the classification fine-tuning stage, freeze the feature extraction module, use the supervised cross-entropy loss to train the classification head, and enable the class label for supervised learning so that the classification head outputs the class probability distribution of the trajectory; A model application module for deploying the trained trajectory classification model and using it to classify agricultural machinery trajectory data.
9. An electronic device, characterized in that, The electronic device includes: At least one processor; and A memory that stores instructions which, when executed by the at least one processor, cause the at least one processor to perform the agricultural machinery trajectory data classification method according to any one of claims 1 to 7.
10. A machine-readable storage medium, characterized in that, Executable instructions are stored on the machine-readable storage medium, and when the instructions are executed, they cause the machine to perform the agricultural machinery trajectory data classification method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Agricultural machine trajectory classification method based on trajectory similarity measurement, computer readable storage medium and computer program product
CN119046759A
Classification method and device for agricultural machine track data and storage medium
CN119128719A
Encryption event classification method and system based on prompt learning
CN116467442A
Signature handwriting identification method and system based on prompt learning, and storage medium
CN116645683A