Automatic ship wandering behavior identification method and system based on AIS data

By constructing a deep learning sequence labeling model and combining multidimensional feature vectors and hybrid loss functions, the problem of accurate positioning and fine-grained modeling of ship AIS trajectory wandering behavior identification in existing technologies has been solved, realizing automatic identification and efficient supervision of ship wandering behavior.

CN122020398APending Publication Date: 2026-05-12COSCO SHIPPING TECH CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
COSCO SHIPPING TECH CO LTD
Filing Date
2025-12-29
Publication Date
2026-05-12

AI Technical Summary

Technical Problem

Existing methods for identifying ship AIS trajectory loitering behavior cannot accurately pinpoint the specific time and location of loitering behavior, and lack the ability to model loitering segments with fine granularity, thus failing to achieve efficient point-by-point prediction and positioning.

Method used

A deep learning sequence labeling model incorporating a dual-branch structure, sequence attention mechanism, and channel attention mechanism is constructed. Through multi-dimensional feature vectors and a hybrid loss function, the wandering label of each trajectory point is dynamically predicted, enabling automatic identification and accurate localization of ship wandering behavior.

Benefits of technology

It enables point-by-point prediction and precise positioning of ship loitering behavior, significantly improving the interpretability and practicality of the identification results, supporting efficient processing of large-scale AIS data, reducing the need for manual intervention, and improving the level of intelligence in maritime supervision.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122020398A_ABST
    Figure CN122020398A_ABST
Patent Text Reader

Abstract

The invention provides an AIS data-based ship wandering behavior automatic identification method and system, and the method comprises the steps: carrying out the track segmentation, cleaning, resampling and space filtering of original AIS data, and obtaining a continuous navigation track segment; in combination with self-intersection detection and multi-scale sliding window analysis, candidate wandering trajectories are screened by using an isolated forest and are manually labeled, and a BIO labeled balance training set is constructed; calculating a multi-dimensional feature vector including a plane coordinate, an accumulated distance, a course periodic component, a logarithmic speed and a timestamp; a double-branch deep learning sequence labeling model is adopted for training, and a Focal Loss and Dice Loss mixed loss function is fused; inputting a to-be-recognized track into the model after same preprocessing, and outputting point-by-point labels; finally, an accurate wandering track fragment is analyzed according to the BIO rule, high-precision, fine-grained and automatic positioning of the ship wandering behavior is achieved, and the method is obviously superior to an existing coarse-grained classification or threshold value judgment method.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of maritime monitoring and intelligent shipping technology, specifically to a method and system for automatic identification of ship loitering behavior based on AIS data. Background Technology

[0002] Ship AIS trajectory sequence data refers to the dynamic and static information, including position, speed, and heading, collected by the Automatic Identification System (AIS). This data is connected sequentially in spatial coordinates to form a trajectory sequence, fully reflecting the ship's actual navigation path and motion state. Ship loitering behavior refers to a movement pattern where a ship frequently changes course within a certain geographical area during navigation, resulting in a highly redundant trajectory lacking a clear forward trend. Loitering trajectories are common on fishing boats, tugboats, and law enforcement vessels, reflecting specific activity intentions such as fishing operations, towing operations, maritime patrols, waiting to berth, or engaging in illegal activities. Timely and accurate identification of ship loitering behavior is crucial for navigation safety and anomaly warning in shipping and maritime affairs. In contrast, cargo ships and oil tankers typically follow pre-set efficient routes; any unnecessary loitering behavior leads to transportation delays, fuel waste, and increased operating costs, impacting their economic efficiency. Therefore, automatically identifying and locating ship loitering behavior based on AIS trajectory data is of great significance for improving maritime regulatory efficiency and ensuring navigation safety.

[0003] Currently, common methods for identifying ship AIS trajectory wandering behavior can be broadly categorized into two types: unsupervised and supervised methods. 1) Unsupervised methods typically rely on preset trajectory feature thresholds or segmentation rules for judgment, including typical techniques such as spatiotemporal grid analysis, trajectory refinement analysis, and sliding window analysis. Spatiotemporal grid analysis converts AIS data into grid coordinates and extracts grid features to identify ship wandering behavior. Trajectory refinement analysis uses the Douglas-Peucker algorithm to compress the trajectory, retaining key points to reduce redundant data. It calculates the curvature of key points, identifies wave points (local maxima of curvature), and finally determines ship wandering behavior through angle constraints and wave point number thresholds. Sliding window analysis traverses the trajectory through multi-scale time windows, calculates quantitative indicators based on spatiotemporal features within the window, and utilizes anomaly detection algorithms such as isolated forests to determine wandering behavior. However, while unsupervised methods do not require labeled data, they heavily rely on manually set thresholds or trajectory segmentation rules. They typically only determine whether the entire trajectory exhibits wandering characteristics, but cannot automatically and accurately pinpoint the specific time and location of wandering. 2) In supervised identification methods, several loitering patterns are first defined. Then, based on the shape of the AIS trajectory, trajectories conforming to the preset loitering patterns are labeled to form a dataset for training a classification model. For example, existing technologies propose converting detected loitering trajectory segments into standardized grayscale images and constructing a convolutional neural network (CNN) model. Through multi-layer convolution and pooling operations, the model automatically learns the morphological features of the trajectory, thereby classifying and identifying four typical loitering trajectory shapes: disordered zigzag, lasso, regular reciprocating, and random coil. While existing supervised methods can identify specific loitering patterns, their core function remains at the level of classifying the overall shape of past loitering trajectories, rather than precisely locating loitering segments point by point, which cannot adequately meet real-world needs.

[0004] In summary, existing methods for identifying loitering behavior in AIS trajectories generally suffer from two limitations. At the detection level, unsupervised methods heavily rely on manually preset thresholds or segmentation rules, and can only make coarse-grained judgments about whether loitering has occurred on the entire trajectory, failing to automatically and accurately pinpoint the specific time period in which the loitering behavior occurred, thus lacking localization accuracy. While existing supervised methods can identify specific loitering patterns, their model training depends on a large number of labeled trajectory image samples, and their core function remains static classification of the shape of the entire trajectory, similarly unable to achieve fine-grained extraction of loitering segments, lacking sequence-level fine-grained modeling capabilities and efficient segment-level localization capabilities. At the evaluation level, existing technologies lack specific evaluation criteria for the accuracy of loitering trajectory segment localization. Traditional classification metrics cannot effectively measure the spatiotemporal overlap between predicted and actual segments, making it difficult to judge the model's performance.

[0005] Therefore, there is an urgent need for an intelligent identification method that can combine trajectory spatial morphology with dynamic navigation characteristics, support point-by-point prediction, and output specific loitering time and space intervals, so as to break through the current technical bottlenecks and effectively serve the modern maritime intelligent supervision system. Summary of the Invention

[0006] To address the shortcomings of existing ship loitering behavior identification methods, such as difficulty in accurately locating the specific start and end times and spatial positions of loitering behavior, inability to support point-by-point dynamic prediction, and general neglect of the collaborative modeling of trajectory spatial morphology and navigation dynamic features, this invention provides an automatic ship loitering behavior identification method based on AIS data. By constructing a deep learning sequence labeling model incorporating a dual-branch structure, sequence attention mechanism, and channel attention mechanism, it dynamically predicts the label (including loitering start point, loitering midpoint, or normal navigation point) for each trajectory point in the AIS trajectory. This not only effectively determines whether a ship is loitering but also accurately outputs the continuous trajectory segment corresponding to each loitering behavior, achieving fine-grained identification, location, and tracking of loitering behavior. This invention also relates to an automatic ship loitering behavior identification system based on AIS data.

[0007] The technical solution of the present invention is as follows:

[0008] An automatic identification method for ship loitering behavior based on AIS data, characterized by the following steps:

[0009] Data acquisition and preprocessing steps: Acquire the ship's raw AIS data, extract multiple key fields from the raw AIS data, and sort them in chronological order to form the ship's raw AIS trajectory sequence. Then, preprocess the raw AIS trajectory sequence to divide the original AIS trajectory sequence of the same ship into multiple historical trajectory segments composed of continuous navigation points. The preprocessing includes trajectory segmentation processing, data cleaning processing, resampling and difference processing, and spatial filtering processing.

[0010] The steps for constructing the labeled training dataset are as follows: First, a self-intersection point detection method is used to identify self-intersecting regions within a ship's historical trajectory segment. Then, a multi-scale sliding window method is employed, sliding multiple windows at different time intervals along the historical trajectory segment. The course change frequency, displacement distance, and trajectory tortuosity within each window are calculated. Based on these parameters, a wandering score is calculated for each window, and the maximum wandering score among all windows is taken as the final wandering score for that historical trajectory segment. Finally, the self-intersection region information and the final wandering score are used as a filtering feature vector. Candidate wandering trajectories are automatically selected using the Isolation Forest algorithm, and these candidate trajectories are verified and filtered to obtain multiple wandering trajectory segments. The BIO labeling method is used to label each trajectory point in the wandering trajectory segment, and the label includes the starting point of the wandering trajectory segment, the middle point of the wandering trajectory segment, and the normal navigation point. Based on the K-means clustering algorithm, multiple normal trajectory segments are selected from the normal navigation trajectory of the ship, so that the ratio of the total number of trajectory points in all normal trajectory segments to the total number of trajectory points in all wandering trajectory segments is within a preset range, forming a class-balanced labeled training dataset.

[0011] Multidimensional feature vector calculation steps: Based on the labeled training dataset, calculate the multidimensional feature vector of each trajectory point in the labeled training dataset, and normalize the multidimensional feature vector; the multidimensional feature vector includes absolute plane coordinate features, heading angle periodic component features, speed change features, timestamp features, and cumulative travel distance features;

[0012] Model training steps: Input the normalized multidimensional feature vector into the deep learning sequence labeling model for training, and use a hybrid loss function that includes Focal Loss and Dice Loss as the loss function in the training of the deep learning sequence labeling model to obtain the trained deep learning sequence labeling model.

[0013] Behavior recognition and output steps: The ship trajectory sequence to be recognized undergoes the same preprocessing and multi-dimensional feature vector calculation as the original AIS trajectory sequence. The normalized multi-dimensional feature vector obtained is then input into a trained deep learning sequence labeling model. The trained deep learning sequence labeling model includes a parallel dual-branch structure, a sequence attention mechanism, a channel attention mechanism, and a sequence semantic encoder. The dual-branch structure includes a spatial feature processing branch and a dynamic feature processing branch. The spatial feature processing branch receives normalized absolute planar coordinate features and cumulative navigation distance features, and sequentially passes them through a one-dimensional convolutional layer and a sequence attention mechanism to generate representations of local features. The spatial feature sequence of the trajectory morphology; the dynamic feature processing branch is used to receive the normalized heading angle periodic component features, speed change features and timestamp features, and then generate a dynamic feature sequence representing dynamic navigation behavior through a feedforward neural network and a sequence attention mechanism in sequence; the spatial feature sequence and the dynamic feature sequence are then concatenated in the channel dimension to generate a fused feature sequence; the channel attention mechanism adaptively weights the fused feature sequence and inputs the weighted fused feature sequence into the sequence semantic encoder for context modeling, and outputs a predicted label for each trajectory point as belonging to the starting point of wandering behavior, the intermediate point of wandering behavior or the normal navigation point, thereby realizing the automatic identification of ship wandering behavior.

[0014] Preferably, in the model training step, during the training of the deep learning sequence labeling model, a pre-divided validation set is used for hyperparameter adjustment and model selection to obtain a trained and adjusted deep learning sequence labeling model; and a pre-divided test set is used to evaluate the performance of the trained and adjusted deep learning sequence labeling model through evaluation metrics; the evaluation metrics include average intersection-union ratio, detection rate, and error rate.

[0015] Preferably, in the data acquisition and preprocessing steps, the preprocessing specifically includes:

[0016] First, trajectory segmentation is performed: the original AIS trajectory sequence where the time interval between adjacent trajectory points of the same vessel exceeds a preset time threshold is segmented into multiple time-continuous trajectory segments; then, data cleaning is performed: each trajectory segment is cleaned point by point, removing trajectory points containing null values, outliers, coordinate jumps, or those in moored or anchored navigation states; next, resampling and interpolation are performed: a combination of spherical linear interpolation and standard linear interpolation is used to resample and interpolate the cleaned trajectory segments; finally, spatial filtering is performed: a land mask is used to filter trajectory points located in inland waterways or channels, retaining only trajectory points in open waters.

[0017] Preferably, in the step of constructing the labeled training dataset, selecting multiple normal trajectory segments from the ship's normal navigation trajectory based on the K-means clustering algorithm specifically includes:

[0018] For the normal navigation trajectory of the ship, the number of trajectory points, the minimum circumcircle diameter, and the latitude and longitude covariance are calculated to form a clustering feature vector. Based on the clustering feature vector, the K-means clustering algorithm is used to divide several normal navigation modes. Normal trajectory segments are extracted from each normal navigation mode to obtain multiple normal trajectory segments.

[0019] Preferably, in the multidimensional feature vector calculation step, the absolute planar coordinate feature includes: taking the starting point of the original AIS trajectory sequence as the coordinate origin, calculating the geographical distance between adjacent trajectory points based on the latitude and longitude coordinates of two adjacent trajectory points and using the Haversine formula; and calculating the azimuth angle between adjacent trajectory points based on the latitude and longitude coordinates of two adjacent trajectory points using the azimuth formula, then converting the geographical distance and azimuth angle into relative coordinate increments in a two-dimensional Cartesian coordinate system using the trigonometric decomposition method, and obtaining the absolute planar coordinates of each trajectory point relative to the origin by accumulating the relative coordinate increments;

[0020] The cumulative navigation distance feature includes: calculating the cumulative geographical distance from the current trajectory point to the starting point of the trajectory sequence, and using the cumulative geographical distance as the cumulative navigation distance feature;

[0021] The heading angle periodic component features include: converting the heading angle into a heading angle sine component and a heading angle cosine component, which are used as heading angle periodic component features;

[0022] The speed transformation feature includes: performing a logarithmic transformation on the speed to obtain the logarithmically transformed speed as the speed transformation feature;

[0023] The timestamp feature includes: taking the start time of the trajectory sequence as a reference, normalizing the time difference of the timestamp of each trajectory point relative to the reference to the [0,1] interval to obtain the timestamp feature.

[0024] Preferably, in the behavior recognition and output step, the sequence attention mechanism includes a parallel temporal pooling path and a local convolutional path; the temporal pooling path generates temporal attention weights through global average pooling and 1×1 convolution, and the local convolutional path extracts local contextual features through 3×1 one-dimensional convolution. After the two paths are fused with position encoding, the final temporal attention weight map is generated through a cross-space learning mechanism.

[0025] An automatic identification system for ship loitering behavior based on AIS data is characterized by comprising, in sequence, a data acquisition and preprocessing module, a labeled training dataset construction module, a multidimensional feature vector calculation module, a model training module, and a behavior recognition and output module.

[0026] The data acquisition and preprocessing module acquires the ship's raw AIS data, extracts multiple key fields from the raw AIS data, sorts them in chronological order to form the ship's raw AIS trajectory sequence, and then preprocesses the raw AIS trajectory sequence to divide the original AIS trajectory sequence of the same ship into multiple historical trajectory segments composed of continuous navigation points; the preprocessing includes trajectory segmentation processing, data cleaning processing, resampling and difference processing, and spatial filtering processing in sequence.

[0027] The labeled training dataset construction module uses a self-intersection point detection method to identify self-intersecting regions within a ship's historical trajectory segment. Then, a multi-scale sliding window method is employed, sliding multiple windows at different time intervals along the historical trajectory segment. The course change frequency, displacement distance, and trajectory tortuosity within each window are calculated. Based on these parameters, a wandering score is calculated for each window, and the maximum wandering score among all windows is taken as the final wandering score for that historical trajectory segment. The self-intersection region information and the final wandering score are used as a filtering feature vector. Candidate wandering trajectories are automatically selected using the Isolation Forest algorithm, and these trajectories are then verified and filtered to obtain multiple wandering trajectory segments. Each trajectory point in each wandering trajectory segment is labeled using the BIO labeling method, with the label including the starting point, midpoint, and normal navigation point of the wandering trajectory segment. Furthermore, multiple normal trajectory segments are selected from the ship's normal navigation trajectory based on the K-means clustering algorithm, ensuring that the ratio of the total number of trajectory points in all normal trajectory segments to the total number of trajectory points in all wandering trajectory segments is within a preset range, thus forming a class-balanced labeled training dataset.

[0028] The multidimensional feature vector calculation module calculates the multidimensional feature vector of each trajectory point in the labeled training dataset based on the labeled training dataset, and performs normalization processing on the multidimensional feature vector; the multidimensional feature vector includes absolute plane coordinate features, heading angle periodic component features, speed change features, timestamp features, and cumulative travel distance features;

[0029] The model training module inputs the normalized multidimensional feature vector into the deep learning sequence labeling model for training, and uses a hybrid loss function including Focal Loss and Dice Loss as the loss function in the training of the deep learning sequence labeling model to obtain the trained deep learning sequence labeling model.

[0030] The behavior recognition and output module performs the same preprocessing and multi-dimensional feature vector calculation on the ship trajectory sequence to be recognized as on the original AIS trajectory sequence, and inputs the normalized multi-dimensional feature vectors obtained into a trained deep learning sequence labeling model. The trained deep learning sequence labeling model includes a parallel dual-branch structure, a sequence attention mechanism, a channel attention mechanism, and a sequence semantic encoder. The dual-branch structure includes a spatial feature processing branch and a dynamic feature processing branch. The spatial feature processing branch receives the normalized absolute planar coordinate features and cumulative navigation distance features, and sequentially passes them through a one-dimensional convolutional layer and a sequence attention mechanism to generate a representation of the local area. The system generates a spatial feature sequence of the trajectory morphology. The dynamic feature processing branch receives normalized heading angle periodic component features, speed change features, and timestamp features, and sequentially generates a dynamic feature sequence representing dynamic navigation behavior through a feedforward neural network and a sequence attention mechanism. The spatial feature sequence and the dynamic feature sequence are then concatenated along the channel dimension to generate a fused feature sequence. The channel attention mechanism adaptively weights the fused feature sequence and inputs the weighted fused feature sequence into a sequence semantic encoder for context modeling, outputting a predicted label for each trajectory point as belonging to the starting point of wandering behavior, the intermediate point of wandering behavior, or the normal navigation point, thereby achieving automatic identification of ship wandering behavior.

[0031] Preferably, in the model training module, during the training of the deep learning sequence labeling model, a pre-divided validation set is used for hyperparameter adjustment and model selection to obtain a trained and adjusted deep learning sequence labeling model; and a pre-divided test set is used to evaluate the performance of the trained and adjusted deep learning sequence labeling model through evaluation metrics, including average intersection-union ratio, detection rate, and error rate.

[0032] Preferably, in the labeled training dataset construction module, selecting multiple normal trajectory segments from the ship's normal navigation trajectory based on the K-means clustering algorithm specifically includes:

[0033] For the normal navigation trajectory of the ship, the number of trajectory points, the minimum circumcircle diameter, and the latitude and longitude covariance are calculated to form a clustering feature vector. Based on the clustering feature vector, the K-means clustering algorithm is used to divide several normal navigation modes. Normal trajectory segments are extracted from each normal navigation mode to obtain multiple normal trajectory segments.

[0034] Preferably, in the multidimensional feature vector calculation module, the absolute planar coordinate feature includes: taking the starting point of the original AIS trajectory sequence as the coordinate origin, calculating the geographical distance between adjacent trajectory points based on the latitude and longitude coordinates of two adjacent trajectory points and using the Haversine formula; and calculating the azimuth angle between adjacent trajectory points based on the latitude and longitude coordinates of two adjacent trajectory points using the azimuth formula, then converting the geographical distance and azimuth angle into relative coordinate increments in a two-dimensional Cartesian coordinate system using the trigonometric decomposition method, and obtaining the absolute planar coordinates of each trajectory point relative to the origin by accumulating the relative coordinate increments;

[0035] The cumulative navigation distance feature includes: calculating the cumulative geographical distance from the current trajectory point to the starting point of the trajectory sequence, and using the cumulative geographical distance as the cumulative navigation distance feature;

[0036] The heading angle periodic component features include: converting the heading angle into a heading angle sine component and a heading angle cosine component, which are used as heading angle periodic component features;

[0037] The speed transformation feature includes: performing a logarithmic transformation on the speed to obtain the logarithmically transformed speed as the speed transformation feature;

[0038] The timestamp feature includes: taking the start time of the trajectory sequence as a reference, normalizing the time difference of the timestamp of each trajectory point relative to the reference to the [0,1] interval to obtain the timestamp feature.

[0039] The beneficial effects of this invention are as follows:

[0040] This invention provides an automatic identification method for ship loitering behavior based on AIS data. First, raw AIS data is acquired and preprocessed, including trajectory segmentation, data cleaning, resampling and interpolation, and spatial filtering. This divides the raw AIS data of the same ship into multiple historical trajectory segments composed of continuous navigation points. This preprocessing effectively eliminates noise points and missing values ​​caused by equipment malfunctions or signal loss, ensuring that each trajectory segment is spatiotemporally continuous and semantically complete. Trajectory segmentation avoids semantic confusion caused by prolonged berthing or cross-task navigation. Resampling standardizes time intervals to improve the stability of subsequent modeling, while spatial filtering excludes areas prone to generating dense non-loitering trajectories, such as ports and anchorages, significantly reducing the risk of false alarms and laying a data foundation for subsequent high-precision identification. Then, a self-intersection detection method is used to identify self-intersecting regions in the historical trajectory segments. Self-intersection is a typical geometric feature of loitering behavior (such as port scheduling and patrol turnarounds). Detecting self-intersections can efficiently screen potential loitering areas, significantly reducing the scope of manual verification and improving annotation efficiency. By combining the multi-scale sliding window method, multiple windows of different time lengths (e.g., 2 hours, 4 hours, 8 hours) are slid along the trajectory to calculate the frequency of heading changes, displacement distance, and trajectory tortuosity within the window, and to comprehensively generate a wandering score that reflects the complexity of local motion. The self-intersecting region and the wandering score are input into the Isolation Forest algorithm to filter out statistically significant abnormal candidate wandering trajectories. The Isolation Forest algorithm can automatically identify trajectory segments that deviate from the normal navigation pattern in the multi-dimensional feature space, effectively filtering out a large number of obviously non-wandering samples, further focusing on suspicious segments, and reducing the cost of manual labeling. With the assistance of verification screening (e.g., manual review and confirmation), high-quality wandering trajectory segment samples are finally obtained, ensuring the accuracy of the labels, avoiding algorithm misjudgments (e.g., channel turns are mistakenly identified as wandering), and ensuring the quality of training data. Each trajectory point in these samples is then labeled using the BIO tagging method (labels include "wandering start point", "wandering midpoint", and "normal navigation point"). Simultaneously, a sufficient number of negative samples are selected from the normal navigation trajectories of the same vessel, ensuring the ratio of normal points to wandering points remains within a preset range (e.g., 0.8–1.2). This constructs a class-balanced labeled training dataset. The class balancing mechanism effectively alleviates the model's neglect of the minority class, significantly improving recall performance. Based on this, for each trajectory point in the labeled training dataset, a multi-dimensional feature vector is calculated, including absolute planar coordinates, cumulative navigation distance, course angle periodic components, speed transformation, and timestamp, and then normalized. Absolute planar coordinates preserve the spatial geometry of the trajectory; cumulative navigation distance decouples the spatial and temporal dimensions to enhance generalization ability; course angle periodic encoding solves the angle discontinuity problem; speed transformation compresses the dynamic range to suppress extreme value interference; and timestamps capture daily periodic behavior patterns. These features collectively constitute a comprehensive characterization of the ship's motion state, providing complementary inputs for spatial and dynamic dual-branch modeling.The normalized multidimensional feature vectors are then input into the deep learning sequence labeling model. End-to-end training is performed using a hybrid loss function (such as a weighted combination of Focal Loss and Dice Loss) until convergence, resulting in a well-trained deep learning sequence labeling model. During training, to address the issues of sparse data and class imbalance in loitering behavior, Focal Loss weights positive samples, allowing the model to focus more on rare segments of the loitering trajectory. Dice Loss optimizes the boundary consistency of trajectory segments, ensuring accurate localization of loitering segments. This combination of loss functions significantly improves the model's recall and enhances the spatiotemporal localization accuracy of loitering trajectory segments. Furthermore, this hybrid loss function, while optimizing overall classification accuracy, specifically strengthens the learning weights for difficult samples (such as short-term loitering or boundary points), effectively overcoming the optimization bias caused by class imbalance and giving the model stronger robustness and generalization ability. Furthermore, for the ship trajectory sequence to be identified, the same preprocessing and feature calculation process as the training data is performed to obtain normalized multidimensional feature vectors, which are then input into the aforementioned trained deep learning sequence labeling model. This model adopts a parallel dual-branch architecture—a spatial feature processing branch and a dynamic feature processing branch—capable of simultaneously capturing the local spatiotemporal patterns and dynamic navigation features of the trajectory. The spatial feature processing branch processes the absolute planar coordinates and cumulative navigation distance, extracts the local trajectory shape (local spatiotemporal features) through one-dimensional convolution, and then performs feature enhancement through a sequence attention mechanism (such as the EMSA module) to model long-range spatial dependence. The system generates a spatial feature sequence representing the geometric redundancy of the trajectory. The dynamic feature processing branch handles the periodic components of the heading angle, speed changes, and timestamps to enhance the model's understanding of navigation semantics. After encoding the single-point motion state via a feedforward neural network, it also uses a sequence attention mechanism (such as the EMSA module) for feature enhancement to integrate temporal evolution patterns, generating a dynamic feature sequence reflecting navigation anomalies. The sequence attention mechanism effectively models long-range dependencies and local contextual information through a dual-path parallel mechanism of temporal pooling and local convolutional paths, and combines position encoding to achieve cross-spatial interaction, further highlighting key time segments. The outputs of the two branches are concatenated at the channel dimension to form a fused feature, which is then adaptively weighted by a channel attention mechanism (such as the SE module) to highlight key feature channels. Finally, it is input into a sequence semantic encoder (such as a lightweight ELECTRA) for deep contextual modeling, accurately outputting a predicted label for each trajectory point belonging to "wandering start point," "wandering midpoint," or "normal navigation point." This design achieves decoupled modeling and collaborative fusion of spatial morphology and dynamic behavior, significantly improving the ability to discriminate complex wandering patterns. Finally, strictly following the BIO annotation rules, extract all continuous label segments from the predicted label sequence that begin with "wandering start point" followed by zero or more "wandering intermediate points", and determine the corresponding trajectory point sequence as the predicted wandering trajectory segment.This parsing mechanism ensures that the identified fragments are semantically valid and have clear boundaries. It can capture both short-term loitering at a single point and long-term circling operations, ultimately outputting structured loitering events with clear start and end times and spatial coordinates. This truly achieves refined identification from "whether loitering" to "when and where loitering," providing operable technical support for maritime supervision, anomaly early warning, and shipping efficiency analysis.

[0041] This invention integrates trajectory spatial morphology and navigation dynamic features to construct an end-to-end deep learning sequence labeling model, enabling point-by-point prediction, precise positioning, and dynamic tracking of ship loitering behavior. Compared to existing technologies that can only determine whether an entire trajectory has loitered or rely on preset patterns for classification, this invention can automatically identify and locate ship loitering behavior with high precision and recall. It also supports efficient processing of large-scale AIS data, significantly improving the intelligence level and decision-making efficiency of maritime monitoring, reducing the need for manual intervention, and providing a more accurate and reliable tool for ship behavior analysis. By introducing the BIO sequence labeling mechanism into the field of ship behavior recognition, this invention can automatically output the specific start and end times and spatial intervals of each loitering behavior, significantly improving the interpretability and practicality of the recognition results. This invention constructs a high-quality, class-balanced labeled dataset by combining multi-scale candidate screening with manual verification, effectively addressing the challenges of scarce wandering samples and high labeling costs in real-world scenarios. A parallel dual-branch network structure is designed to model the local trajectory geometry and the dynamic evolution of navigation status, respectively. Sequence attention and channel attention mechanisms are introduced to achieve adaptive feature fusion, significantly enhancing the model's robustness in recognizing complex and diverse wandering patterns (such as port scheduling and route adjustments). Simultaneously, a hybrid loss function and standardized feature engineering are employed to further alleviate performance bottlenecks caused by class imbalance and differences in feature scale. Practical applications demonstrate that this invention can accurately distinguish between abnormal wandering and normal turning of transport vessels, and precisely capture typical wandering segments of operating vessels. Its recognition accuracy and fine-grained positioning are significantly superior to traditional unsupervised thresholding methods and supervised methods based on image classification. This technology can be widely applied to scenarios such as intelligent maritime supervision, abnormal behavior early warning, port scheduling optimization, and ship carbon intensity (CII) assessment, providing key technical support for building an efficient, safe, and green modern shipping system.

[0042] Furthermore, the original AIS trajectory sequence where the time interval between adjacent trajectory points of the same vessel exceeds a preset time threshold is segmented into multiple time-continuous trajectory segments. This eliminates false stop points or abnormal long-distance jumps caused by data acquisition interruptions, splitting discontinuous data into multiple logically continuous and physically reasonable independent trajectory segments, laying the foundation for subsequent segment-by-segment fine processing. Each trajectory segment is then cleaned point-by-point, removing trajectory points containing null values, outliers, coordinate jumps, or those in moored or anchored navigation states. This removes low-quality and invalid data, significantly improving the reliability and consistency of the trajectory data and preventing noise points from interfering with subsequent analysis and modeling. Finally, a combination of spherical linear interpolation and standard linear interpolation is used to resample and interpolate the cleaned trajectory segments. This allows for the unified resampling of the trajectory into a standard sequence with equal time intervals while preserving the smoothness of ship motion, effectively improving data regularity. Finally, land masking is used to filter trajectory points located in inland waterways or waterways, retaining only trajectory points in open waters. Through geospatial filtering, the analysis scope is focused on the target waters (such as the open sea or high seas), eliminating interference from atypical motion patterns. This ensures that subsequent trajectory prediction, behavior analysis, or anomaly detection models operate in a consistent geographical context, improving the model's relevance and accuracy.

[0043] Furthermore, for the normal navigation trajectory of the vessel, the number of trajectory points, the minimum circumcircle diameter, and the latitude and longitude covariance are calculated to form a clustering feature vector. Based on the clustering feature vector, the K-means clustering algorithm is used to divide the vessel into several normal navigation patterns. Normal trajectory segments are extracted from each normal navigation pattern, resulting in multiple normal trajectory segments. By constructing feature vectors using the number of trajectory points (density), the minimum circumcircle diameter (range of activity), and the latitude and longitude covariance (direction of motion), the vessel's navigation behavior patterns can be comprehensively and quantitatively described, providing a valid basis for clustering. The K-means algorithm can automatically discover typical navigation patterns of the vessel in different scenarios (such as direct navigation in open water, coastal navigation, and turning areas) based on the feature vectors, achieving unsupervised classification of navigation behavior. Extracting representative trajectory segments from each navigation pattern ensures that the selected "normal trajectory segments" cover all typical normal behaviors of the vessel, avoiding sample bias and providing a high-quality and diverse positive sample set for subsequent anomaly detection or trajectory prediction models.

[0044] This invention also relates to an automatic identification system for ship loitering behavior based on AIS data. This system corresponds to the aforementioned automatic identification method for ship loitering behavior based on AIS data and can be understood as a system that implements the aforementioned method. It includes a data acquisition and preprocessing module, a labeled training dataset construction module, a multi-dimensional feature vector calculation module, a model training module, and a behavior recognition and output module connected sequentially. These modules work collaboratively, overcoming the dual bottlenecks of existing technologies in positioning accuracy and automation level. Compared to traditional unsupervised methods (relying on manual thresholds and only capable of coarse overall judgment) and supervised methods (limited to overall classification of preset patterns and lacking segment-level output capabilities), this invention introduces sequence labeling into ship behavior recognition for the first time, achieving point-by-point prediction and precise spatiotemporal positioning of loitering behavior. It can automatically output the start and end times and corresponding trajectory segments of each loitering event, significantly improving the operability and regulatory value of the results. This invention designs a dual-branch feature processing architecture: the spatial branch efficiently extracts the local geometry of the trajectory (such as circling and turning) through one-dimensional convolution; the dynamic branch utilizes a feedforward network to model navigation semantic features such as the periodic component of the heading angle, speed changes, and timestamps, comprehensively depicting the ship's motion state. The outputs of the two branches are fused and enhanced via an efficient multi-scale sequence attention module (EMSA)—this module employs a parallel mechanism of temporal pooling and local convolutional paths, preserving local contextual details while modeling long-range dependencies, and combining positional encoding to achieve cross-spatial interaction, effectively highlighting key loitering periods. Addressing the issues of sparse loitering samples and severe class imbalance in real-world scenarios, this invention employs a hybrid loss function of Focal Loss and Dice Loss during the training phase: Focal Loss dynamically focuses on difficult-to-identify positive samples (i.e., true loitering points), alleviating the model's neglect of minority classes; Dice Loss directly optimizes the consistency between predicted segments and true labels at the spatiotemporal boundaries, significantly improving positioning accuracy. The synergistic effect of these two functions allows the model to significantly improve recall while maintaining high accuracy. In summary, this invention not only achieves a paradigm shift from "whether to hesitate" to "when and where to hesitate" at the technical level, but also supports end-to-end efficient processing of large-scale AIS data at the application level, significantly reducing the need for manual intervention. It provides a highly reliable and automated analysis tool for maritime intelligent monitoring, abnormal behavior early warning, port scheduling optimization, and ship energy efficiency management (such as CII compliance assessment), and has outstanding practicality and promotional value. Attached Figure Description

[0045] Figure 1 This is a flowchart of the automatic identification method for ship loitering behavior based on AIS data according to the present invention.

[0046] Figure 2 This is a schematic diagram of the structure of the deep learning sequence labeling model of the present invention.

[0047] Figure 3 This is a schematic diagram of the sequence attention mechanism of the present invention.

[0048] Figure 4 This is a schematic diagram of a typical hovering trajectory of the present invention.

[0049] Figure 5 This is a schematic diagram of the results of the invention in recognizing typical loitering trajectories. Detailed Implementation

[0050] The present invention will now be described with reference to the accompanying drawings.

[0051] This invention relates to an automatic identification method for ship loitering behavior based on AIS data. Utilizing a pre-labeled dataset, it is a supervised identification method. However, unlike existing methods that statically classify the entire trajectory, this invention constructs a deep learning sequence labeling model incorporating a bi-branch structure, sequence attention mechanism, and channel attention mechanism. This model dynamically predicts a loitering label for each trajectory point in the AIS trajectory. It not only effectively determines whether a ship is loitering but also accurately outputs the continuous trajectory segments corresponding to each loitering behavior. Combining AIS data preprocessing, trajectory feature calculation, and the deep learning sequence labeling model, it achieves automatic identification and accurate positioning of ship loitering trajectory segments, significantly improving the accuracy and efficiency of ship loitering trajectory segment detection and positioning. This provides a powerful automated tool for maritime traffic supervision and intelligent ship operation management. The flowchart of this method is as follows: Figure 1 As shown, the steps are as follows:

[0052] I. Data Acquisition and Preprocessing Steps: Acquire the original AIS data of the vessel, extract multiple key fields from the original AIS data, and sort them in chronological order to form the original AIS trajectory sequence. Then, preprocess the original AIS trajectory sequence to divide the original AIS trajectory sequence of the same vessel into multiple historical trajectory segments composed of continuous navigation points. The preprocessing includes trajectory segmentation processing, data cleaning processing, resampling and difference processing, and spatial filtering processing.

[0053] Specifically, raw AIS data for the entire year of 2021 and June to August 2022 in U.S. coastal waters were first obtained from public databases of the National Oceanic and Atmospheric Administration (NOAA) and the Bureau of Marine Energy (BOEM), and cargo ships and oil tankers were selected as target ship types. Then, several key fields were extracted from the raw AIS data, including the Maritime Mobile Service Identifier (MMSI), timestamp, longitude, latitude, speed over land (SOG), heading over land (COG), heading, status, and ship type. For a ship with the same MMSI, all key field records were arranged in ascending order by timestamp to form the ship's raw AIS trajectory sequence.

[0054] Then, preprocessing operations, including trajectory segmentation, data cleaning, resampling and interpolation, and spatial filtering, are performed on the original AIS trajectory sequence to divide the original AIS trajectory sequence of the same vessel into multiple historical trajectory segments composed of continuous navigation points. First, trajectory segmentation is performed (segmenting the trajectory of a single vessel in chronological order): the original AIS trajectory sequence where the time interval between adjacent trajectory points of the same vessel exceeds a preset time threshold (e.g., the time difference between adjacent trajectory points exceeds 3 hours) is segmented to form multiple different trajectory segments that are continuous in time. Based on this, data cleaning is performed: each trajectory segment is cleaned point-by-point, deleting points containing null values ​​or navigation statuses of moored (Status=1) or anchored (Status=5); abnormal data such as latitude, longitude, speed, and heading are removed by setting thresholds, and points with coordinate jumps (e.g., single-step displacement exceeding 100 kilometers) are identified and deleted. The trajectory was then resampled and interpolated: a combination of spherical linear interpolation and standard linear interpolation was used to resample and interpolate the cleaned trajectory segments. Specifically, the appropriate interpolation method was used according to the data type. The latitude and longitude of each trajectory point in the trajectory segment were resampled using spherical linear interpolation to maintain the authenticity of the path on the Earth's surface. The ground speed (SOG), ground heading (COG), and heading were resampled using standard linear interpolation (i.e., linear interpolation in Euclidean space) to ensure a smooth transition of dynamic parameters. Furthermore, the latitude and longitude positions, speed, and angles (ground heading (COG) and heading) were interpolated separately to uniformly adjust each trajectory point in the trajectory segment to a fixed time interval of 150 seconds. Finally, spatial filtering is performed: a land mask is used to filter trajectory points located in inland waterways or waterways, retaining only those in open waters; specifically, the Global Land Mask package is used to filter out trajectory points located on land, inland waterways, or waterways, retaining only those in open waters, thus avoiding misclassifying planned anchoring as loitering behavior, thereby completing the entire preprocessing workflow. After the above processing, several high-quality historical trajectory segments are obtained, each composed of spatiotemporally continuous and semantically consistent navigation points, serving as the basis for subsequent annotation and modeling.

[0055] II. Steps for constructing the labeled training dataset: The self-intersection point detection method is used to identify self-intersecting regions within the historical trajectory segment of a ship. Then, a multi-scale sliding window method is employed, sliding multiple windows at different time intervals along the historical trajectory segment. The course change frequency, displacement distance, and trajectory tortuosity within each window are calculated. Based on these parameters, the wandering score for each window is calculated, and the maximum wandering score among all windows is taken as the final wandering score for the historical trajectory segment. The self-intersection region information and the final wandering score are used as the filtering feature vector (or, in other words, as the input feature vector). The system automatically selects candidate wandering trajectories using the Isolation Forest algorithm and verifies and filters these trajectories (e.g., manually), resulting in multiple wandering trajectory segments. The BIO labeling method is used to label each trajectory point within a wandering trajectory segment, with the label including the starting point, midpoint, and normal navigation point of the wandering trajectory segment. Then, based on the K-means clustering algorithm, multiple normal trajectory segments are selected from the ship's normal navigation trajectory, ensuring that the ratio of the total number of trajectory points in all normal trajectory segments to the total number of trajectory points in all wandering trajectory segments is within a preset range, thus forming a class-balanced labeled training dataset.

[0056] Specifically, firstly, vessels that exhibited at least one wandering behavior are selected from historical trajectory segments. Then, a self-intersection detection method (such as ray crossing or a simplified Douglas-Peucker method) is used to identify self-intersecting regions within the historical trajectory segments of a selected vessel (i.e., finding the intersection points of trajectory lines themselves to identify potential cyclical wandering behavior areas). Next, a multi-scale sliding window analysis method is employed, sliding along the historical trajectory segment with three window sizes: 2 hours, 4 hours, and 8 hours, respectively, to calculate three indicators within each window:

[0057] 1) Heading change frequency (heading standard deviation per unit time, calculated by subtracting, standard deviation, and normalizing multiple COG values ​​within the window);

[0058] 2) Displacement distance (the straight-line distance from the start point to the end point of the window, calculated based on the latitude and longitude of the start and end points using the Haversine formula);

[0059] 3) Trajectory tortuosity (the ratio of the actual path length within the window to the displacement distance, calculated by dividing the total path length (accumulating the distances between adjacent points) by the displacement distance);

[0060] The wandering score for each window is calculated based on the frequency of course changes, displacement distance, and trajectory tortuosity. The maximum wandering score among the wandering scores of each scale window is taken as the final wandering score for that historical trajectory segment. Then, the self-intersection region information and the final wandering score are used as input features to the Isolation Forest algorithm to automatically filter out statistically significant anomalous candidate wandering trajectories. Maritime experts then manually verify and confirm the candidate trajectories, resulting in multiple confirmed wandering trajectory segments. For the confirmed wandering trajectory segments, the BIO labeling method is used to label each trajectory point in the wandering trajectory segment (labels include the starting point of wandering behavior, the intermediate point of wandering behavior, and the normal navigation point): points belonging to normal navigation are labeled "O", points belonging to the starting point of the wandering trajectory segment are labeled "BL", and points belonging to the intermediate point of the wandering trajectory segment are labeled "IL". All labeled wandering trajectory segments are used as positive samples. Next, to construct a class-balanced wandering trajectory dataset, multiple normal trajectory segments are selected from the normal navigation trajectories of the same batch of ships based on the K-means clustering algorithm. The normal navigation trajectory of a ship is analyzed, and the number of trajectory points, the minimum circumscribed circle diameter (the diameter of the smallest circumscribed circle containing all points of the entire normal navigation trajectory, also known as the spatial coverage index of the trajectory), and the latitude and longitude covariance (calculated based on the average longitude and latitude) are used to construct a clustering feature vector. Based on this clustering feature vector (number of trajectory points, circumscribed circle diameter, and latitude and longitude covariance), the K-means clustering algorithm is used to summarize and divide several typical normal navigation patterns (also known as several classes). From each normal navigation pattern (each class), a normal trajectory segment with a number of positive samples (i.e., all wandering trajectory points) is randomly selected as a negative sample, so that the ratio of the total number of normal trajectory points to the total number of wandering trajectory points is controlled within a preset range, such as within the range of [0.8, 1.2]. Finally, the data for the entire year of 2021 is divided into a training set (of which 10% is randomly selected as a validation set), and the data from June to August 2022 is used as a test set to form a high-quality labeled training dataset with class balance. Figure 4 The document showcases six typical loitering trajectory segments from the labeled training dataset. The starting and ending points of the trajectories are highlighted with green and red dots, respectively. The MMSI of the corresponding vessel for each trajectory (e.g., "309587000", "218650000") and the start and end times (e.g., "2022 / 7 / 27 3:45 - 2022 / 7 / 27 13:00") are also labeled, clearly distinguishing the affiliation and time range of each trajectory. Figure 4The dataset contains various typical hovering patterns, such as: spiral hovering (e.g., the hovering trajectory segment with MMSI 368230820): the hovering trajectory is a dense spiral, reflecting the continuous circling behavior of the ship within a fixed area; shuttle-like hovering (e.g., the hovering trajectory segment with MMSI 215386000): the hovering trajectory zigs back and forth within a short distance, reflecting the ship's small-scale back-and-forth movement; and loosely spiraling hovering (e.g., the hovering trajectory segment with MMSI 310657000): the hovering trajectory is a loose, wide-ranging circling pattern, covering a broad area but without a clear forward trend. These diverse hovering trajectory patterns ensure that the labeled training dataset can cover different types of ship hovering behavior in real-world scenarios, providing rich samples for deep learning models to learn the mapping relationship between "features" and "hovering behavior," thus improving the model's generalization and recognition capabilities.

[0061] III. Multidimensional Feature Vector Calculation Steps: Based on the labeled training dataset, calculate the multidimensional feature vector of each trajectory point in the labeled training dataset, and normalize the multidimensional feature vector; the multidimensional feature vector includes absolute plane coordinate features, heading angle periodic component features, speed change features, timestamp features, and cumulative travel distance features.

[0062] Before inputting AIS data into the model, feature calculation is performed. This involves generating more representative data features on the constructed training dataset to balance the needs of automated processing with the richness of feature information. Specifically, based on the labeled training dataset, a multi-dimensional feature vector is calculated for each trajectory point in the labeled training dataset. The multi-dimensional feature vector includes absolute planar coordinate features, cumulative flight distance features, heading angle periodic component features, speed change features, and timestamp features. Among them, 1) Absolute planar coordinate features: taking the first point of the trajectory as the origin, the geographical distance between adjacent points is calculated point by point using the Haversine formula and azimuth formula based on the latitude and longitude of adjacent points. With azimuth Among them, geographical distance Calculate according to the following formula:

[0063]

[0064] In the above formula, Indicates the geographical distance between two adjacent points. Represents the Earth's radius. and These represent the latitude and longitude of two adjacent trajectory points, respectively.

[0065] Azimuth Calculate according to the following formula:

[0066]

[0067] In the above formula, It represents the azimuth angle between two adjacent points.

[0068] Then, the two-dimensional coordinate offset of the current point relative to the previous point is obtained through triangulation. As shown in the following formula:

[0069]

[0070]

[0071] Finally, the absolute planar coordinates of each point in the local coordinate system are obtained through cumulative calculation. .

[0072] 2) Characteristics of the periodic components of the heading angle: The heading angle COG is expanded to include its sine and cosine components. Periodicity from the perspective of encoding.

[0073] 3) Speed ​​transformation characteristics: For the speed SOG, a logarithmic transformation is used to transform it into... .

[0074] 4) Timestamp feature: For timestamp, the time difference between the first point of the sequence and subsequent points is scaled to the [0,1] interval in units of 150s, based on the time of the first point of the sequence.

[0075] 5) Cumulative travel distance feature: The cumulative geographical distance D from the current trajectory point to the starting point is used as an extended feature.

[0076] Based on this, to improve the stability of model training and avoid bias caused by differences in feature scales, all multidimensional feature vectors are normalized to fall within the [0,1] interval. First, the maximum sequence length is set to... For sequences exceeding this length, truncation is performed, and the insufficient portion (shorter sequence) is padded with end points. That is, if the length of the second half after truncation is insufficient... Then use the beginning and end of the paragraph. Complete the points. Among them, the absolute planar coordinate features Divide by The coordinates are then linearly scaled to [0,1] to obtain the normalized absolute planar coordinates, as shown in the following equation:

[0077]

[0078]

[0079] The cumulative sailing distance characteristic D is also divided by The normalized cumulative sailing distance is obtained as shown in the following formula:

[0080]

[0081] Characteristics of the periodic components of the heading angle, namely the sine and cosine components of the heading angle. Originally in the interval [-1, 1], it is transformed to the interval [0, 1] through a linear transformation, as shown in the following equation:

[0082]

[0083]

[0084] Speed ​​change characteristics Then, based on the preset maximum value of 30 sections, the minimum-maximum normalization is performed as shown in the following formula:

[0085]

[0086] The timestamp feature is already within the target range after initial processing and requires no further adjustment. The final input feature vector for each trajectory point is seven-dimensional.

[0087]

[0088] IV. Model Training Steps: Input the normalized multidimensional feature vector into the deep learning sequence labeling model for training, and use a hybrid loss function that includes Focal Loss and Dice Loss as the loss function in the training of the deep learning sequence labeling model to obtain the trained deep learning sequence labeling model.

[0089] Specifically, during the model training phase, the deep learning sequence labeling model is first fully fine-tuned using a GPU-equipped server and the PyTorch framework. Then, an appropriate batch size (e.g., 32) and a reasonable training cycle (e.g., 50 training epochs) are set, and an early stopping strategy (patience=5) is introduced to prevent overfitting. Subsequently, the AdamW optimizer is used, along with a cosine annealing learning rate scheduling strategy with a linear warmup phase (warmup steps=500) to stabilize the initial training process and promote model convergence. During training, normalized multi-dimensional feature vectors are input into the model, and the label prediction probability of each trajectory point is calculated through forward propagation. Then, considering the low proportion of wandering trajectory segments and the characteristics of the sequence labeling task, a hybrid loss function combining Focal Loss and Dice Loss is designed. The training process is guided (loss value is calculated), and the model parameters are updated through backpropagation and an optimizer. Hybrid loss function. The calculation formula is:

[0090]

[0091] in, Indicates the weighting factor. This represents the Focal loss function, used to mitigate class imbalance by applying a balancing factor to positive samples. And through regulating factors The formula for reducing the loss contribution of easily classified samples is as follows:

[0092]

[0093] in, This represents the model's predicted probability for the positive class. The Dice loss function measures the similarity between the predicted and actual wandering trajectories at the segment level. Its calculation formula is as follows:

[0094]

[0095] Where A is the predicted wandering segment, and B is the actual wandering segment. It is the length of the overlap between the predicted and actual wandering segments. and These represent the predicted and actual lengths of the wandering segments, respectively. By linearly combining the Focalloss loss function, which focuses on element-level classification, and the Dice loss loss function, which focuses on segment-level matching, a more comprehensive optimization guide for the model training process is achieved.

[0096] Then, after each training cycle, the model performance is evaluated on the validation set. This involves using a pre-defined validation set for hyperparameter tuning and model selection, and saving the parameters of the best-performing model on the validation set to obtain a well-trained deep learning sequence labeling model. The entire training process shows that the model's loss on both the training and validation sets steadily decreases and eventually stabilizes, indicating that the model effectively learned the discriminative features of wandering trajectories without significant overfitting.

[0097] Finally, using the pre-defined test set, the performance of the trained and tuned deep learning sequence labeling model was evaluated using evaluation metrics, including mean intersection-over-union ratio (MIRR), detection rate, and error rate. A key evaluation dimension for wandering trajectory segment recognition is the overlap between the predicted and ground truth segments. This differs fundamentally from the calculation paradigm of discrete label accuracy in traditional classification. Therefore, a dedicated evaluation metric system for wandering trajectory segments was established. Inspired by object detection tasks in computer vision, this system introduces the following core metrics:

[0098] 1) Intersection over Union (IOU): This metric measures the degree of overlap between the predicted wandering trajectory segment and the actual segment. For each pair of predicted and actual segments, the IOU is calculated as follows:

[0099]

[0100] Here, A represents the predicted wandering trajectory segment, and B represents the actual wandering trajectory segment. A higher IOU value indicates a higher degree of overlap between the predicted and actual trajectory segments, and thus better model performance.

[0101] 2) Average Intersection over Union (IOU): This metric is the average IOU of all wandering trajectories predicted, providing a more comprehensive reflection of the model's performance in overall trajectory detection. The formula for calculating Average IOU for all wandering trajectories is:

[0102]

[0103] Where N represents the total number of wandering trajectories, This represents the IOU value of the i-th trajectory. A higher average intersection-union ratio (IU) indicates a higher overall localization accuracy of the model for the wandering segment.

[0104] 3) Detection Rate: This metric refers to the rate at which a predicted trajectory is considered successfully detected when its Intersection over Union (IOU) value exceeds a set threshold. Setting different IOU thresholds can help evaluate the model's performance at different levels of accuracy. This study used three threshold levels—0.5, 0.7, and 0.9—for evaluation, and denoted them as follows: This form.

[0105] 4) Error rate: To evaluate the model's misjudgment of normal trajectories, this metric is defined as follows: if the model predicts any point in the normal trajectory as hovering, then the normal trajectory is counted as an incorrect prediction.

[0106] Through the above multi-dimensional evaluation indicators, this evaluation indicator system can comprehensively and quantitatively evaluate the model's positioning accuracy, detection capability, and false alarm control level when identifying wandering segments.

[0107] After training, the model was applied to an independent test set to evaluate its performance in recognizing ship loitering trajectory segments. The evaluation process involved calculating the average intersection-over-union ratio (IOU), error rate, and detection rate at different thresholds (e.g., IOU > 0.5, 0.7, 0.9) based on a previously established evaluation index system for quantitative analysis. The results showed that the model achieved high overall performance on the test set, with all indicators meeting expectations, thus validating the effectiveness of the proposed method. Visual analysis was also performed to intuitively demonstrate the recognition results. Figure 5The results of identifying typical lingering trajectories in the test set are presented. Blue lines represent normal navigation trajectories, and red lines represent lingering trajectories. The start and end points of the trajectories are highlighted in green and red, respectively, and the MMSI of the vessel from which each trajectory originates and the start and end times of the lingering behavior are marked. The figure covers the identification results of various typical lingering patterns, including spiral lingering (MMSI 368230820), reciprocating shuttle lingering (MMSI 215386000), and loose swirling lingering (MMSI 310657000). All lingering segments were accurately located—the red segments closely match the spatiotemporal range of the actual lingering behavior, verifying the model's fine-grained identification capability for different types of lingering behavior. This visualization method not only verifies the rationality of the model's predictions but also provides an intuitive basis for behavioral analysis and decision-making in subsequent maritime supervision.

[0108] V. Behavior Recognition and Output Steps: The ship trajectory sequence to be recognized undergoes the same preprocessing and multi-dimensional feature vector calculation as the original AIS trajectory sequence. The normalized multi-dimensional feature vectors obtained are then input into a trained deep learning sequence labeling model. The trained deep learning sequence labeling model includes a parallel dual-branch structure, a sequence attention mechanism, a channel attention mechanism, and a sequence semantic encoder. The dual-branch structure includes a spatial feature processing branch and a dynamic feature processing branch. The spatial feature processing branch receives the normalized absolute planar coordinate features and cumulative navigation distance features, and sequentially passes them through a one-dimensional convolutional layer and a sequence attention layer. The mechanism generates a spatial feature sequence representing the local trajectory morphology. The dynamic feature processing branch receives the normalized heading angle periodic component features, speed change features, and timestamp features, and sequentially generates a dynamic feature sequence representing dynamic navigation behavior through a feedforward neural network and a sequence attention mechanism. The spatial feature sequence and the dynamic feature sequence are then concatenated along the channel dimension to generate a fused feature sequence. The channel attention mechanism adaptively weights the fused feature sequence and inputs the weighted fused feature sequence into a sequence semantic encoder for context modeling, outputting a predicted label for each trajectory point as belonging to the starting point of lingering behavior, the intermediate point of lingering behavior, or the normal navigation point.

[0109] Specifically, the preprocessing steps (including trajectory segmentation, cleaning, 150-second resampling, and spatial filtering) are exactly the same as those used for the training data (i.e., the original AIS trajectory sequence) and multi-dimensional feature vector calculations (including coordinate transformation, feature construction, and normalization) are first performed on the ship trajectory sequence to be identified, resulting in a normalized multi-dimensional (seven-dimensional) feature vector. This multi-dimensional feature vector is then input into a pre-trained deep learning sequence labeling model. The overall architecture of the pre-trained deep learning sequence labeling model is as follows: Figure 2As shown, it includes a parallel dual-branch structure, an efficient multi-scale sequence attention mechanism (also known as the sequence attention module EMSA), an SE channel attention mechanism, and a sequence semantic encoder.

[0110] The dual-branch structure includes a spatial feature processing branch and a dynamic feature processing branch, wherein, 1) the spatial feature processing branch: is used to receive the normalized absolute planar coordinates ( Characteristics and cumulative sailing distance feature The local spatiotemporal patterns are extracted by sequentially passing through a one-dimensional convolutional layer (kernel size=3) and a one-dimensional efficient multi-scale sequence attention mechanism (EMSA), generating a spatial feature sequence with dimensions (B, L, 64) representing the local trajectory morphology. 2) Dynamic feature processing branch: receives the normalized heading angle periodic component features. Speed ​​variation characteristics and timestamp features The system processes dynamic information such as heading and speed through a feedforward neural network (two-layer MLP) and a one-dimensional efficient multi-scale sequence attention mechanism (EMSA) to generate a dynamic feature sequence with dimensions (B, L, 64) representing dynamic navigation behavior.

[0111] That is, the outputs of both branches pass through a one-dimensional, efficient multi-scale sequence attention module EMSA (structure as follows). Figure 3 (As shown).

[0112] The sequence attention module adopts a grouping processing mechanism, dividing the input features into G groups according to the number of channels C, with each group having C / G channels. Within each group, dual-path feature enhancement is performed in parallel: 1) Temporal pooling path: After global average pooling (AvgPool), 1×1 one-dimensional convolution (Conv1D(1)), and sigmoid activation, the original grouped features are re-weighted to generate temporal attention weights, enhancing long-range dependencies; 2) Local convolution path: Local features are extracted through 3×1 one-dimensional convolution (Conv1D(3)). After the two paths are integrated into positional encoding, the features are interacted through a cross-space learning mechanism of average pooling (Avg Pool) → normalization (Softmax) → matrix multiplication (Matmul) to generate the final temporal attention weight map, highlighting key time segments. After the interacted features are activated by sigmoid and re-weighted, all groups are merged to obtain the final output.

[0113] Subsequently, the enhanced bi-branch features (i.e., spatial feature sequences and dynamic feature sequences) are concatenated along the channel dimension to generate a fused feature sequence of dimension (B, L, 128). The weights of each feature channel in the fused feature sequence are adaptively adjusted using the SE attention mechanism (Squeeze and Excitation). This mechanism generates channel weights sequentially through Linear(128,32) → ReLU → Linear(32,128) → Sigmoid, and performs element-wise multiplication with the fused feature sequence to achieve adaptive weighting along the channel dimension. The weighted fused feature sequence is then subjected to dimension alignment and normalization using Linear(128,128) → LayerNorm to stabilize training and accelerate convergence. Finally, the processed fused feature sequence is fed into a pre-trained sequence semantic encoder (ELECTRA-small model) for deep semantic encoding (contextual modeling). The ELECTRA-small model adopts a generative-discriminative structure and exhibits excellent performance in sequence discrimination tasks. Finally, the ELECTRA-small model outputs the predicted probability of each trajectory point in the sequence, that is, through the Linear(128,3) output layer, it outputs the predicted probability and corresponding predicted label of each trajectory point in the sequence belonging to the starting point of wandering behavior "BL", the intermediate point of wandering behavior "IL" or the normal navigation point "O", thereby realizing sequence labeling and thus realizing the automatic identification of ship wandering behavior.

[0114] This invention also relates to an automatic identification system for ship loitering behavior based on AIS data. This system corresponds to the aforementioned automatic identification method for ship loitering behavior based on AIS data and can be understood as a system that implements the above method. The system includes, in sequence, a data acquisition and preprocessing module, a labeled training dataset construction module, a multi-dimensional feature vector calculation module, a model training module, and a behavior recognition and output module. Specifically,

[0115] The data acquisition and preprocessing module acquires the ship's raw AIS data, extracts multiple key fields from the raw AIS data, sorts them in chronological order to form the ship's raw AIS trajectory sequence, and then preprocesses the raw AIS trajectory sequence to divide the original AIS trajectory sequence of the same ship into multiple historical trajectory segments composed of continuous navigation points; the preprocessing includes trajectory segmentation processing, data cleaning processing, resampling and difference processing, and spatial filtering processing in sequence.

[0116] The labeled training dataset construction module uses a self-intersection point detection method to identify self-intersecting regions within a ship's historical trajectory segment. Then, a multi-scale sliding window method is employed, sliding multiple windows at different time intervals along the historical trajectory segment. The course change frequency, displacement distance, and trajectory tortuosity within each window are calculated. Based on these parameters, a wandering score is calculated for each window, and the maximum wandering score among all windows is taken as the final wandering score for that historical trajectory segment. The self-intersection region information and the final wandering score are used as a filtering feature vector. Candidate wandering trajectories are automatically selected using the Isolation Forest algorithm, and these trajectories are then verified and filtered to obtain multiple wandering trajectory segments. Each trajectory point in each wandering trajectory segment is labeled using the BIO labeling method, with the label including the starting point, midpoint, and normal navigation point of the wandering trajectory segment. Furthermore, multiple normal trajectory segments are selected from the ship's normal navigation trajectory based on the K-means clustering algorithm, ensuring that the ratio of the total number of trajectory points in all normal trajectory segments to the total number of trajectory points in all wandering trajectory segments is within a preset range, thus forming a class-balanced labeled training dataset.

[0117] The multidimensional feature vector calculation module calculates the multidimensional feature vector of each trajectory point in the labeled training dataset based on the labeled training dataset, and performs normalization processing on the multidimensional feature vector; the multidimensional feature vector includes absolute plane coordinate features, heading angle periodic component features, speed change features, timestamp features, and cumulative travel distance features;

[0118] The model training module inputs the normalized multidimensional feature vector into the deep learning sequence labeling model for training, and uses a hybrid loss function including Focal Loss and Dice Loss as the loss function in the training of the deep learning sequence labeling model to obtain the trained deep learning sequence labeling model.

[0119] The behavior recognition and output module performs the same preprocessing and multi-dimensional feature vector calculation on the ship trajectory sequence to be recognized as on the original AIS trajectory sequence, and inputs the normalized multi-dimensional feature vectors obtained into a trained deep learning sequence labeling model. The trained deep learning sequence labeling model includes a parallel dual-branch structure, a sequence attention mechanism, a channel attention mechanism, and a sequence semantic encoder. The dual-branch structure includes a spatial feature processing branch and a dynamic feature processing branch. The spatial feature processing branch receives the normalized absolute planar coordinate features and cumulative navigation distance features, and sequentially passes them through a one-dimensional convolutional layer and a sequence attention mechanism to generate a representation of the local area. The system generates a spatial feature sequence of the trajectory morphology. The dynamic feature processing branch receives normalized heading angle periodic component features, speed change features, and timestamp features, and sequentially generates a dynamic feature sequence representing dynamic navigation behavior through a feedforward neural network and a sequence attention mechanism. The spatial feature sequence and the dynamic feature sequence are then concatenated along the channel dimension to generate a fused feature sequence. The channel attention mechanism adaptively weights the fused feature sequence and inputs the weighted fused feature sequence into a sequence semantic encoder for context modeling, outputting a predicted label for each trajectory point as belonging to the starting point of wandering behavior, the intermediate point of wandering behavior, or the normal navigation point, thereby achieving automatic identification of ship wandering behavior.

[0120] Preferably, in the model training module, during the training of the deep learning sequence labeling model, a pre-defined validation set is used for hyperparameter adjustment and model selection to obtain a trained and adjusted deep learning sequence labeling model; and a pre-defined test set is used to evaluate the performance of the trained and adjusted deep learning sequence labeling model through evaluation metrics, including average intersection-union ratio, detection rate, and error rate.

[0121] Preferably, in the labeled training dataset construction module, selecting multiple normal trajectory segments from the ship's normal navigation trajectory based on the K-means clustering algorithm specifically includes:

[0122] For the normal navigation trajectory of the ship, the number of trajectory points, the minimum circumcircle diameter, and the latitude and longitude covariance are calculated to form a clustering feature vector. Based on the clustering feature vector, the K-means clustering algorithm is used to divide several normal navigation modes. Normal trajectory segments are extracted from each normal navigation mode to obtain multiple normal trajectory segments.

[0123] Preferably, in the multidimensional feature vector calculation module, the absolute planar coordinate feature includes: taking the starting point of the original AIS trajectory sequence as the coordinate origin, calculating the geographical distance between adjacent trajectory points based on the latitude and longitude coordinates of two adjacent trajectory points and using the Haversine formula; and calculating the azimuth angle between adjacent trajectory points based on the latitude and longitude coordinates of two adjacent trajectory points using the azimuth formula, then converting the geographical distance and azimuth angle into relative coordinate increments in a two-dimensional Cartesian coordinate system using the trigonometric decomposition method, and obtaining the absolute planar coordinates of each trajectory point relative to the origin by accumulating the relative coordinate increments;

[0124] The cumulative navigation distance feature includes: calculating the cumulative geographical distance from the current trajectory point to the starting point of the trajectory sequence, and using the cumulative geographical distance as the cumulative navigation distance feature;

[0125] The heading angle periodic component features include: converting the heading angle into a heading angle sine component and a heading angle cosine component, which are used as heading angle periodic component features;

[0126] The speed transformation feature includes: performing a logarithmic transformation on the speed to obtain the logarithmically transformed speed as the speed transformation feature;

[0127] The timestamp feature includes: taking the start time of the trajectory sequence as a reference, normalizing the time difference of the timestamp of each trajectory point relative to the reference to the [0,1] interval to obtain the timestamp feature.

[0128] Preferably, the sequence attention mechanism includes a parallel temporal pooling path and a local convolutional path; the temporal pooling path generates temporal attention weights through global average pooling and 1×1 convolution, and the local convolutional path extracts local contextual features through 3×1 one-dimensional convolution. After the two paths are fused with positional encoding, the final temporal attention weight map is generated through a cross-space learning mechanism.

[0129] This invention provides an objective and scientific method and system for automatically identifying ship loitering behavior based on AIS data. By introducing sequence labeling concepts into ship behavior recognition, a dual-branch feature processing architecture is designed: the spatial branch efficiently extracts the local geometry of the trajectory (such as circling and turning) through one-dimensional convolution; the dynamic branch utilizes a feedforward network to model navigation semantic features such as the periodic component of the heading angle, speed changes, and timestamps, comprehensively characterizing the ship's motion state. The outputs of the two branches are fused and enhanced via an efficient multi-scale sequence attention module (EMSA)—this module employs a parallel mechanism of temporal pooling and local convolutional paths, preserving local contextual details while modeling long-range dependencies, and combining positional encoding to achieve cross-spatial interaction, effectively highlighting key loitering periods. During the training phase, a hybrid loss function combining Focal Loss and Dice Loss is employed to address the issues of sparse loitering samples and severe class imbalance in real-world scenarios. This not only represents a paradigm shift from "whether to loiter" to "when and where to loiter" at the technical level, but also supports efficient end-to-end processing of large-scale AIS data at the application level, significantly reducing the need for manual intervention. It provides a highly reliable and automated analysis tool for maritime intelligent monitoring, abnormal behavior early warning, port scheduling optimization, and ship energy efficiency management (such as CII compliance assessment), demonstrating outstanding practicality and promotional value.

[0130] It should be noted that the specific embodiments described above enable those skilled in the art to more fully understand the present invention, but do not limit the present invention in any way. Therefore, although the present invention has been described in detail with reference to the accompanying drawings and embodiments, those skilled in the art should understand that modifications or equivalent substitutions can still be made to the present invention. In short, all technical solutions and improvements that do not depart from the spirit and scope of the present invention should be covered within the protection scope of the present invention patent.

Claims

1. A method for automatically identifying ship loitering behavior based on AIS data, characterized in that, Includes the following steps: Data acquisition and preprocessing steps: Acquire the ship's raw AIS data, extract multiple key fields from the raw AIS data, and sort them in chronological order to form the ship's raw AIS trajectory sequence. Then, preprocess the raw AIS trajectory sequence to divide the original AIS trajectory sequence of the same ship into multiple historical trajectory segments composed of continuous navigation points. The preprocessing includes trajectory segmentation processing, data cleaning processing, resampling and difference processing, and spatial filtering processing. The steps for constructing the labeled training dataset are as follows: First, a self-intersection point detection method is used to identify self-intersecting regions within a ship's historical trajectory segment. Then, a multi-scale sliding window method is employed, sliding multiple windows at different time intervals along the historical trajectory segment. The course change frequency, displacement distance, and trajectory tortuosity within each window are calculated. Based on these parameters, a wandering score is calculated for each window, and the maximum wandering score among all windows is taken as the final wandering score for that historical trajectory segment. Finally, the self-intersection region information and the final wandering score are used as a filtering feature vector. Candidate wandering trajectories are automatically selected using the Isolation Forest algorithm, and these candidate trajectories are verified and filtered to obtain multiple wandering trajectory segments. The BIO labeling method is used to label each trajectory point in the wandering trajectory segment, and the label includes the starting point of the wandering trajectory segment, the middle point of the wandering trajectory segment, and the normal navigation point. Based on the K-means clustering algorithm, multiple normal trajectory segments are selected from the normal navigation trajectory of the ship, so that the ratio of the total number of trajectory points in all normal trajectory segments to the total number of trajectory points in all wandering trajectory segments is within a preset range, forming a class-balanced labeled training dataset. Multidimensional feature vector calculation steps: Based on the labeled training dataset, calculate the multidimensional feature vector of each trajectory point in the labeled training dataset, and normalize the multidimensional feature vector; the multidimensional feature vector includes absolute plane coordinate features, heading angle periodic component features, speed change features, timestamp features, and cumulative travel distance features; Model training steps: Input the normalized multidimensional feature vector into the deep learning sequence labeling model for training, and use a hybrid loss function that includes Focal Loss and Dice Loss as the loss function in the training of the deep learning sequence labeling model to obtain the trained deep learning sequence labeling model. Behavior recognition and output steps: The ship trajectory sequence to be recognized undergoes the same preprocessing and multi-dimensional feature vector calculation as the original AIS trajectory sequence. The normalized multi-dimensional feature vector obtained is then input into a trained deep learning sequence labeling model. The trained deep learning sequence labeling model includes a parallel dual-branch structure, a sequence attention mechanism, a channel attention mechanism, and a sequence semantic encoder. The dual-branch structure includes a spatial feature processing branch and a dynamic feature processing branch. The spatial feature processing branch receives normalized absolute planar coordinate features and cumulative navigation distance features, and sequentially passes them through a one-dimensional convolutional layer and a sequence attention mechanism to generate representations of local features. The spatial feature sequence of the trajectory morphology; the dynamic feature processing branch is used to receive the normalized heading angle periodic component features, speed change features and timestamp features, and then generate a dynamic feature sequence representing dynamic navigation behavior through a feedforward neural network and a sequence attention mechanism in sequence; the spatial feature sequence and the dynamic feature sequence are then concatenated in the channel dimension to generate a fused feature sequence; the channel attention mechanism adaptively weights the fused feature sequence and inputs the weighted fused feature sequence into the sequence semantic encoder for context modeling, and outputs a predicted label for each trajectory point as belonging to the starting point of wandering behavior, the intermediate point of wandering behavior or the normal navigation point, thereby realizing the automatic identification of ship wandering behavior.

2. The automatic identification method for ship loitering behavior based on AIS data according to claim 1, characterized in that, In the model training step, during the training of the deep learning sequence labeling model, a pre-defined validation set is used to adjust hyperparameters and select the model, resulting in a trained and adjusted deep learning sequence labeling model. The performance of the trained and adjusted deep learning sequence labeling model is evaluated using a pre-defined test set and evaluation metrics, including mean intersection-over-union ratio, detection rate, and error rate.

3. The automatic identification method for ship loitering behavior based on AIS data according to claim 1, characterized in that, The data acquisition and preprocessing steps include, in particular, the preprocessing process: First, trajectory segmentation is performed: the original AIS trajectory sequence where the time interval between adjacent trajectory points of the same vessel exceeds a preset time threshold is segmented into multiple time-continuous trajectory segments; then, data cleaning is performed: each trajectory segment is cleaned point by point, removing trajectory points containing null values, outliers, coordinate jumps, or those in moored or anchored navigation states; next, resampling and interpolation are performed: a combination of spherical linear interpolation and standard linear interpolation is used to resample and interpolate the cleaned trajectory segments; finally, spatial filtering is performed: a land mask is used to filter trajectory points located in inland waterways or channels, retaining only trajectory points in open waters.

4. The automatic identification method for ship loitering behavior based on AIS data according to claim 1, characterized in that, In the step of constructing the labeled training dataset, the selection of multiple normal trajectory segments from the ship's normal navigation trajectory based on the K-means clustering algorithm specifically includes: For the normal navigation trajectory of the ship, the number of trajectory points, the minimum circumcircle diameter, and the latitude and longitude covariance are calculated to form a clustering feature vector. Based on the clustering feature vector, the K-means clustering algorithm is used to divide several normal navigation modes. Normal trajectory segments are extracted from each normal navigation mode to obtain multiple normal trajectory segments.

5. The automatic identification method for ship loitering behavior based on AIS data according to claim 1, characterized in that, In the multidimensional feature vector calculation step, the absolute planar coordinate feature includes: taking the starting point of the original AIS trajectory sequence as the coordinate origin, calculating the geographical distance between adjacent trajectory points based on the latitude and longitude coordinates of two adjacent trajectory points and using the Haversine formula; and calculating the azimuth angle between adjacent trajectory points based on the latitude and longitude coordinates of two adjacent trajectory points using the azimuth formula, then converting the geographical distance and azimuth angle into relative coordinate increments in a two-dimensional Cartesian coordinate system using the trigonometric decomposition method, and obtaining the absolute planar coordinates of each trajectory point relative to the origin by accumulating the relative coordinate increments; The cumulative navigation distance feature includes: calculating the cumulative geographical distance from the current trajectory point to the starting point of the trajectory sequence, and using the cumulative geographical distance as the cumulative navigation distance feature; The heading angle periodic component features include: converting the heading angle into a heading angle sine component and a heading angle cosine component, which are used as heading angle periodic component features; The speed transformation feature includes: performing a logarithmic transformation on the speed to obtain the logarithmically transformed speed as the speed transformation feature; The timestamp feature includes: taking the start time of the trajectory sequence as a reference, normalizing the time difference of the timestamp of each trajectory point relative to the reference to the [0,1] interval to obtain the timestamp feature.

6. The automatic identification method for ship loitering behavior based on AIS data according to claim 1, characterized in that, In the behavior recognition and output step, the sequence attention mechanism includes a parallel temporal pooling path and a local convolution path. The temporal pooling path generates temporal attention weights through global average pooling and 1×1 convolution, and the local convolution path extracts local contextual features through 3×1 one-dimensional convolution. After the two paths are fused with position encoding, the final temporal attention weight map is generated through a cross-space learning mechanism.

7. An automatic identification system for ship loitering behavior based on AIS data, characterized in that, It includes, in sequence, a data acquisition and preprocessing module, a labeled training dataset construction module, a multi-dimensional feature vector calculation module, a model training module, and an action recognition and output module. The data acquisition and preprocessing module acquires the ship's raw AIS data, extracts multiple key fields from the raw AIS data, sorts them in chronological order to form the ship's raw AIS trajectory sequence, and then preprocesses the raw AIS trajectory sequence to divide the original AIS trajectory sequence of the same ship into multiple historical trajectory segments composed of continuous navigation points; the preprocessing includes trajectory segmentation processing, data cleaning processing, resampling and difference processing, and spatial filtering processing in sequence. The labeled training dataset construction module uses a self-intersection point detection method to identify self-intersecting regions within a ship's historical trajectory segment. Then, a multi-scale sliding window method is employed, sliding multiple windows at different time intervals along the historical trajectory segment. The course change frequency, displacement distance, and trajectory tortuosity within each window are calculated. Based on these parameters, a wandering score is calculated for each window, and the maximum wandering score among all windows is taken as the final wandering score for that historical trajectory segment. The self-intersection region information and the final wandering score are used as a filtering feature vector. Candidate wandering trajectories are automatically selected using the Isolation Forest algorithm, and these trajectories are then verified and filtered to obtain multiple wandering trajectory segments. Each trajectory point in each wandering trajectory segment is labeled using the BIO labeling method, with the label including the starting point, midpoint, and normal navigation point of the wandering trajectory segment. Furthermore, multiple normal trajectory segments are selected from the ship's normal navigation trajectory based on the K-means clustering algorithm, ensuring that the ratio of the total number of trajectory points in all normal trajectory segments to the total number of trajectory points in all wandering trajectory segments is within a preset range, thus forming a class-balanced labeled training dataset. The multidimensional feature vector calculation module calculates the multidimensional feature vector of each trajectory point in the labeled training dataset based on the labeled training dataset, and performs normalization processing on the multidimensional feature vector; the multidimensional feature vector includes absolute plane coordinate features, heading angle periodic component features, speed change features, timestamp features, and cumulative travel distance features; The model training module inputs the normalized multidimensional feature vector into the deep learning sequence labeling model for training, and uses a hybrid loss function including Focal Loss and Dice Loss as the loss function in the training of the deep learning sequence labeling model to obtain the trained deep learning sequence labeling model. The behavior recognition and output module performs the same preprocessing and multi-dimensional feature vector calculation on the ship trajectory sequence to be recognized as on the original AIS trajectory sequence, and inputs the normalized multi-dimensional feature vectors obtained into a trained deep learning sequence labeling model. The trained deep learning sequence labeling model includes a parallel dual-branch structure, a sequence attention mechanism, a channel attention mechanism, and a sequence semantic encoder. The dual-branch structure includes a spatial feature processing branch and a dynamic feature processing branch. The spatial feature processing branch receives the normalized absolute planar coordinate features and cumulative navigation distance features, and sequentially passes them through a one-dimensional convolutional layer and a sequence attention mechanism to generate a representation of the local area. The system generates a spatial feature sequence of the trajectory morphology. The dynamic feature processing branch receives normalized heading angle periodic component features, speed change features, and timestamp features, and sequentially generates a dynamic feature sequence representing dynamic navigation behavior through a feedforward neural network and a sequence attention mechanism. The spatial feature sequence and the dynamic feature sequence are then concatenated along the channel dimension to generate a fused feature sequence. The channel attention mechanism adaptively weights the fused feature sequence and inputs the weighted fused feature sequence into a sequence semantic encoder for context modeling, outputting a predicted label for each trajectory point as belonging to the starting point of wandering behavior, the intermediate point of wandering behavior, or the normal navigation point, thereby achieving automatic identification of ship wandering behavior.

8. The automatic identification system for ship loitering behavior based on AIS data according to claim 7, characterized in that, In the model training module, during the training of the deep learning sequence labeling model, a pre-defined validation set is used to adjust hyperparameters and select the model, resulting in a well-trained deep learning sequence labeling model. The performance of the well-trained deep learning sequence labeling model is evaluated using a pre-defined test set and evaluation metrics, including mean intersection-over-union ratio, detection rate, and error rate.

9. The automatic identification system for ship loitering behavior based on AIS data according to claim 7, characterized in that, In the labeled training dataset construction module, the selection of multiple normal trajectory segments from the ship's normal navigation trajectory based on the K-means clustering algorithm specifically includes: For the normal navigation trajectory of the ship, the number of trajectory points, the minimum circumcircle diameter, and the latitude and longitude covariance are calculated to form a clustering feature vector. Based on the clustering feature vector, the K-means clustering algorithm is used to divide several normal navigation modes. Normal trajectory segments are extracted from each normal navigation mode to obtain multiple normal trajectory segments.

10. The automatic identification system for ship loitering behavior based on AIS data according to claim 7, characterized in that, In the multidimensional feature vector calculation module, the absolute planar coordinate features include: taking the starting point of the original AIS trajectory sequence as the origin, calculating the geographical distance between adjacent trajectory points based on the latitude and longitude coordinates of two adjacent trajectory points and using the Haversine formula; calculating the azimuth angle between adjacent trajectory points based on the latitude and longitude coordinates of two adjacent trajectory points using the azimuth formula; then converting the geographical distance and azimuth angle into relative coordinate increments in a two-dimensional Cartesian coordinate system using the trigonometric decomposition method; and obtaining the absolute planar coordinates of each trajectory point relative to the origin by accumulating the relative coordinate increments. The cumulative navigation distance feature includes: calculating the cumulative geographical distance from the current trajectory point to the starting point of the trajectory sequence, and using the cumulative geographical distance as the cumulative navigation distance feature; The heading angle periodic component features include: converting the heading angle into a heading angle sine component and a heading angle cosine component, which are used as heading angle periodic component features; The speed transformation feature includes: performing a logarithmic transformation on the speed to obtain the logarithmically transformed speed as the speed transformation feature; The timestamp feature includes: taking the start time of the trajectory sequence as a reference, normalizing the time difference of the timestamp of each trajectory point relative to the reference to the [0,1] interval to obtain the timestamp feature.