2.1. Overview
We propose TPDNet, a topology-aware lane detection framework that integrates inter-lane relational reasoning and structural consistency constraints into an iterative lane refinement pipeline. The overall architecture is illustrated in
Figure 2.
Section 2.2 introduces the lane representation and refinement pipeline,
Section 2.3 describes the topology-aware reasoning module,
Section 2.4 explains the decoupled prediction head,
Section 2.5 presents the structural loss, and
Section 2.6 summarizes training and inference. Given an input road image, a ResNet backbone [
20] equipped with a Feature Pyramid Network [
21] extracts multi-scale visual features. Built on CLRHead [
9], TPDNet uses these features to generate initial lane priors, which are then progressively refined through
T stages.
At each refinement stage, ROI features are first aggregated by the ROIGather module, which enhances each lane proposal with image-level contextual information. The resulting lane-query features are then fed into the TPR, where relational dependencies among candidate lanes are explicitly modeled to capture global road topology. In this way, each lane representation is updated not only according to local visual evidence, but also according to the structural configuration of other lanes.
After the final refinement stage, the topology-enhanced lane features are passed to the TDH. TDH separates geometric regression from lane classification into two independent branches, thereby alleviating task interference and improving prediction stability. During training, the TCL further imposes smoothness and ordering constraints on the predicted lanes, encouraging structurally coherent outputs. Through this design, TPDNet jointly exploits visual appearance, inter-lane topology, and structural supervision for robust lane detection in complex road scenarios.
2.2. Lane Representation and Iterative Refinement
Lane markings are thin, elongated, and continuous curvilinear structures. Instead of using bounding-box representations, which are not well suited for describing fine-grained lane geometry, we represent each lane as a structured sequence of
N equidistantly sampled 2D points along the image height [
8,
9,
22]:
The vertical coordinates are fixed and uniformly sampled along the image height
H:
The network predicts the corresponding horizontal coordinates through lateral offsets. Specifically, each lane is initialized from a
Lane Prior , and the refined horizontal coordinate is obtained as:
Following the CLRHead formulation [
9], each Lane Prior is further parameterized by
, where
denotes the foreground probability,
l the lane length, and
the starting position and initial orientation angle relative to the horizontal axis. This point-based representation provides a compact yet flexible description of lane geometry and is compatible with subsequent iterative refinement.
Given the initial lane priors, TPDNet progressively refines lane geometry through multiple stages. At each stage, ROI features are extracted according to the current lane geometry and used to predict residual updates for the lane parameters. Let
denote the hierarchical feature maps used across the
T refinement stages, where
corresponds to the coarsest semantic features and
corresponds to the finest spatial details. Starting from the initial lane priors
, the lane parameters are iteratively updated as
where
denotes the stage-specific refinement function that extracts ROI features according to the previous-stage lane geometry
and predicts residual coordinate updates through fully connected layers [
9,
23]. This iterative refinement strategy enables coarse lane hypotheses to be gradually adjusted toward accurate lane positions.
To integrate multi-scale visual information, TPDNet adopts a cross-layer refinement strategy. High-level feature maps provide semantic context for identifying lane structures, while low-level feature maps preserve fine-grained spatial details for accurate localization. By progressively aggregating features across different FPN levels, the model can balance global structural integrity and local geometric precision.
At each refinement stage, the extracted ROI features are further enhanced by ROIGather. Specifically, ROIGather aggregates contextual information from the global image feature map and combines it with local lane proposal features through a residual connection. This step enriches each lane proposal with image-level context, which is particularly useful under weak visual cues such as occlusion, shadows, or illumination changes. Let
denote the local ROI features of a lane proposal at stage
t, and let
denote the flattened global feature map from the FPN. Following the attention mechanism [
12], the cross-attention weight matrix
is computed as
The aggregated global context feature
is then obtained by
The context-enhanced lane feature is computed through a residual connection with a learnable scalar scaling factor
:
The enhanced lane-query features are then passed to TPR for topology-aware relational reasoning among candidate lanes.
2.3. Topology-Aware Perception Reasoner
After ROIGather enriches each lane proposal with image-level contextual information, the resulting lane-query features still need to interact with each other to capture the structural organization of the road. If lane candidates are processed independently, the model may fail to preserve inter-lane relationships such as relative ordering, spatial proximity, parallelism, and geometric continuity. To address this issue, we introduce the TPR, which is applied after ROIGather at each refinement stage to perform topology-aware relational reasoning among all lane candidates.
The key idea of TPR is to treat lane candidates as nodes in a geometry-aware relational graph. Each node represents one lane candidate, and each edge describes the structural dependency between a pair of lanes. Different from standard self-attention, which mainly relies on feature similarity, TPR incorporates both lane-level visual features and pairwise relative geometry to construct topology-aware lane affinities. In this way, each lane representation is updated according to not only its own visual evidence, but also the structural configuration of surrounding lanes.
Compared with previous graph-based lane detectors and generic relational reasoning modules, TPR is distinguished in three aspects. First, the graph nodes are not pixels, anchors, or manually grouped lane segments, but iteratively refined lane candidates whose geometry is updated at each refinement stage. The relational graph is therefore dynamic and evolves with the predicted lane layout. Second, the edge representation is not derived only from feature similarity or Euclidean proximity. It explicitly encodes lane-specific topology cues, including relative start position, orientation, length, shared valid support, mean lateral displacement, and top/bottom separation. Third, the relative geometry affects both the attention logits and the aggregated messages: the bias term changes which lanes communicate, whereas the relation message changes what geometric information is propagated. This dual use is intended to make the reasoning process sensitive to lane ordering, parallelism, convergence, and crossing tendency, rather than merely adding a generic positional encoding to self-attention.
For clarity, the following formulation is written for a single image in a mini-batch, and the batch dimension is omitted. Let M denote the number of candidate lanes, N denote the number of sampled lateral coordinates for each lane, and D denote the dimension of the lane-level feature. TPR uses attention heads, and the feature dimension of each head is . The superscript denotes the refinement stage. When no ambiguity arises, the stage superscript is omitted in the attention formulation for compactness.
Lane-level Feature Preparation: At refinement stage
t, ROIGather aggregates sampled lane features and image-level contextual information for each candidate lane. The output feature of the
i-th candidate lane is denoted as
, where
. The lane-level features of all candidates are stacked row-wise as
These compact lane-level features serve as node representations for subsequent topology-aware relational reasoning.
Each lane candidate is also associated with its current geometric prediction. Following the CLRNet-style lane representation, the geometry of the
i-th candidate lane is written as
where
and
are the background and foreground classification scores,
denotes the starting position,
denotes the normalized orientation angle,
denotes the predicted lane length, and
are the normalized lateral coordinates sampled along predefined vertical positions. Only the geometric terms are used to construct the relative geometry vector.
Relative Geometric Encoding: To make the relation modeling sensitive to lane topology, TPR explicitly encodes the pairwise geometric configuration between lane candidates. For each ordered lane pair
, we construct a relative geometry vector describing lane
j with respect to lane
i:
Specifically, the relative start-point, orientation, and length terms are defined as
Here, is computed in the normalized angle space, and therefore and are used to provide a periodic encoding of the relative orientation.
Since not all sampled lateral coordinates are valid for every candidate lane, we define the common valid sampled-point set of lanes
i and
j as
Let
denote the valid count used for normalization. The mean signed and absolute lateral displacements are then computed as
The overlap ratio is defined as the proportion of commonly valid sampled points:
In the adopted lane representation, the sampled coordinates are ordered from bottom to top. Therefore, the bottom and top lateral displacements are defined as
The relative geometry vector is projected by a lightweight relation encoder:
where
is implemented by a multi-layer perceptron, and
denotes the dimension of the relation embedding.
The relation embedding is further projected into two complementary geometry-aware terms:
where
and
are learnable linear projection matrices. The vector
provides head-specific relative geometry biases for attention computation, and its
h-th element is denoted as
. The vector
provides a geometry-aware relation message and is reshaped into
, where
.
Topology-aware Lane Affinity Construction. Given the lane-level feature matrix
, TPR first computes query, key, and value projections:
where
are learnable projection matrices. The projected features are reshaped into
attention heads, yielding
for the
h-th head.
The attention logit from lane
i to lane
j in the
h-th head is computed by combining feature similarity with the relative geometry bias:
The normalized topology-aware lane affinity is obtained by applying softmax over all source lanes:
The resulting affinity matrix indicates how much information lane i aggregates from lane j under both visual feature similarity and relative geometric constraints.
Relational Aggregation. Based on the learned topology-aware affinity matrix, TPR aggregates both visual content messages and geometry-aware relation messages for each lane candidate:
where
denotes the visual content message from lane
j, and
denotes the geometry-aware message that describes lane
j relative to lane
i.
Messages from all attention heads are concatenated and projected back to the original feature space:
where
is a learnable output projection matrix, and
.
Finally, the topology-enhanced lane feature is obtained through residual updates, layer normalization, and a feed-forward network:
The output features are topology-enhanced lane representations. Compared with the original lane features, they preserve local appearance cues while incorporating relational information from other candidate lanes. At each refinement stage, these features are fed into the subsequent prediction head to generate classification scores and geometric residuals. Since TPR is applied at every refinement stage, inter-lane relationships are progressively updated as lane geometry becomes more accurate.
2.4. Topology-Decoupled Head
In lane detection, classification and geometric regression emphasize different optimization objectives. Classification focuses on distinguishing foreground lane candidates from background proposals, whereas geometric regression requires accurate localization of lane start positions, orientations, lengths, and sampled lateral coordinates. Optimizing these objectives through a shared prediction pathway may introduce task interference, especially when visually ambiguous lane candidates require different discriminative and localization cues.
To alleviate this issue, we introduce a TDH to separate lane classification and geometric regression at the prediction level. Instead of applying the decoupled prediction only after the final refinement stage, TDH is used at each refinement stage. Let
denote the topology-enhanced feature of the
i-th lane candidate at refinement stage
t, where
D is the feature dimension. TDH first initializes two branch-specific feature transformations from the same topology-enhanced lane feature:
where
and
are the intermediate features of the geometry and classification branches, respectively. Each branch consists of stacked fully connected layers with nonlinear activations, allowing the two tasks to learn task-specific representations while still sharing the topology-aware lane feature as input.
The geometry branch predicts a regression vector
:
Specifically, the regression vector is written as
where
,
, and
are residual updates for the start position and orientation of the current lane prior,
denotes the predicted lane length, and
are the point-wise lateral offsets for the
N sampled positions.
Given the lane prior from the previous stage, the start position and orientation are updated as
The updated prior parameters define a coarse lane hypothesis
at each sampled vertical position
. The final lateral coordinate is then obtained by adding the predicted point-wise offset:
In this way, TDH preserves the iterative refinement mechanism of the baseline lane representation while assigning geometry-specific parameters to an independent regression pathway.
The classification branch predicts a two-dimensional logit vector:
where the two logits correspond to the background and foreground lane classes. During inference, the foreground confidence of the
i-th lane candidate is obtained by applying a softmax operation:
Low-confidence candidates are filtered according to this foreground probability before non-maximum suppression.
To further encourage feature-level disentanglement between the two prediction tasks, we introduce an orthogonality regularization term on the branch-specific intermediate features. Let
and
denote the final-stage geometry and classification branch features, respectively, where
B is the batch size,
M is the number of lane candidates, and
d is the hidden dimension of each branch. For the
b-th image in a mini-batch, the cross-branch correlation matrix is computed as
The orthogonality loss is defined as a normalized squared correlation penalty:
where
denotes the Frobenius norm and
Z is a normalization factor used to stabilize the loss scale. In implementation,
Z is set according to the number of lane candidates and the hidden dimension. This regularization suppresses excessive correlation between the geometry and classification feature subspaces, thereby reducing task interference without changing the inference pipeline.
Overall, TDH provides a lightweight prediction-level decoupling mechanism. The geometry branch focuses on lane shape refinement and coordinate localization, while the classification branch focuses on foreground confidence estimation. Combined with the topology-enhanced features provided by TPR, the decoupled design improves optimization stability and helps produce more reliable lane predictions.
2.5. Topology Consistency Loss
Standard geometric losses supervise lane candidates mainly through point-wise regression or lane-level overlap, but they do not explicitly penalize structurally implausible predictions such as local oscillations, lane crossings, or inconsistent relative ordering. To improve the structural coherence of predicted lanes, we introduce a TCL, which imposes both intra-lane smoothness and inter-lane ordering constraints.
During training, TCL is applied only to matched positive lane candidates after dynamic label assignment. This avoids imposing structural constraints on background proposals. The predicted lateral coordinates are first decoded into the image coordinate system. Therefore, unless otherwise specified, the coordinates used in this section are measured in pixels rather than in normalized coordinates.
Let
denote the
i-th matched positive predicted lane, where
is the decoded lateral coordinate at the sampled vertical position
, and
N is the number of sampled points. Since not all sampled points are valid for every predicted lane, we define a validity mask
where
W is the image width and
is the indicator function.
2.5.1. Smoothness Loss
Lane markings are continuous curvilinear structures, and their lateral coordinates should vary smoothly along the vertical direction. To suppress high-frequency oscillations, we penalize the second-order finite difference of the predicted lateral coordinates. For a valid triplet of consecutive sampled points, the second-order difference is computed as
The corresponding valid-triplet mask is defined as
The smoothness loss is then formulated as
where
is a small constant for numerical stability. This loss is computed only over valid triplets whose three lateral coordinates fall inside the image boundary.
2.5.2. Order Loss
In real road scenes, adjacent lane markings usually preserve a consistent left-to-right spatial order. However, predicted lane candidates are not inherently ordered. Therefore, before applying the ordering constraint, we first sort valid predicted lanes according to their mean lateral positions. For the
i-th matched positive lane, its mean lateral coordinate is computed as
Let denote the permutation that sorts the valid lanes in ascending order of , from left to right. The ordering constraint is imposed only on adjacent lanes in this sorted sequence.
For two adjacent sorted lanes
and
, the common valid mask at the
n-th sampled position is defined as
The lateral separation between the two adjacent lanes is
The order loss penalizes violations of a minimum lateral separation margin:
where
is a pixel-level margin. This formulation prevents unnatural lane crossings and overly close adjacent predictions, while avoiding constraints on invalid or non-overlapping sampled positions.
The proposed topology consistency loss is defined as
where
balances the contribution of the ordering constraint.
2.5.3. Line IoU Loss
In addition to TCL, we retain the Line IoU (LIoU) loss as a complementary lane-level geometric supervision term. Unlike point-wise regression losses, LIoU treats each lane as a holistic geometric entity and measures the overlap between the predicted lane and its matched ground-truth lane.
Given a predicted lane
and its matched ground-truth lane
, each sampled point is extended to a horizontal line segment with half-width
e. The per-point intersection and union are defined as
and
The LIoU loss is then computed as
In our implementation, the half-width parameter is set to pixels, which provides a stable tolerance for lane-level geometric matching.
Compared with LIoU, which focuses on the global overlap between predicted and ground-truth lanes, TCL explicitly regularizes the internal smoothness of each predicted lane and the spatial ordering among adjacent lanes. Therefore, the two losses are complementary: LIoU improves lane-level geometric alignment, while TCL encourages structurally coherent lane predictions.
2.6. Training and Inference
2.6.1. Dynamic Label Assignment
During training, each ground-truth lane is assigned to a set of positive lane candidates through a dynamic label assignment strategy. The assignment is performed independently at each refinement stage, so that intermediate lane predictions can also receive direct supervision.
For each predicted lane candidate and ground-truth lane pair, we compute an assignment cost that combines classification confidence and geometric similarity. Let denote the focal-loss-based classification cost. To measure geometric consistency, we consider three complementary terms: the average lateral distance between sampled lane points, the start-point distance, and the orientation difference.
Given a predicted lane
and a ground-truth lane
, let
denote the average lateral point distance computed over valid ground-truth sampled positions. Let
denote the Euclidean distance between their start points, and let
denote the orientation difference. These distance terms are normalized and converted into similarity scores:
and
where
is a small constant for numerical stability. The overall geometric similarity is then defined as
The final assignment cost is formulated as
where
and
balance the classification cost and geometric similarity. A lower assignment cost indicates that the predicted candidate is more suitable for the corresponding ground-truth lane.
Instead of assigning a fixed number of positive candidates to each ground-truth lane, we adopt a dynamic-
k strategy. We first compute the pairwise LIoU between predicted lanes and ground-truth lanes. For the
j-th ground-truth lane, the number of positive candidates is determined by the sum of the top-
q LIoU values:
where
in our implementation. For each ground-truth lane, the
predicted candidates with the lowest assignment costs are selected as positive samples. If one predicted candidate is assigned to multiple ground-truth lanes, only the assignment with the lowest cost is retained.
2.6.2. Overall Training Objective
The proposed network is supervised by classification, prior-parameter regression, lane-level geometric alignment, auxiliary segmentation, topology consistency, and branch orthogonality losses. Since TPDNet follows an iterative refinement pipeline, the classification, prior-parameter regression, LIoU, and topology consistency losses are computed at each refinement stage and averaged over all stages.
At refinement stage
t, the stage-wise detection loss is written as
Here, is the focal classification loss for foreground/background prediction, and is the smooth- loss applied to the lane prior parameters, including start position, orientation, and length. measures lane-level geometric overlap, while imposes smoothness and ordering constraints on matched positive lanes.
The stage-wise losses are averaged across all
T refinement stages:
In addition, an auxiliary segmentation loss is applied to the segmentation branch to strengthen dense visual supervision. The orthogonality regularization is computed using the final-stage geometry and classification branch features, encouraging feature-level disentanglement between the two prediction tasks.
The complete training objective is therefore
Equivalently, expanding the stage-wise detection terms gives
All balancing weights are treated as hyperparameters and are set according to the validation performance.
2.6.3. Inference
During inference, only the predictions from the final refinement stage are used. For each lane candidate, the classification branch outputs a two-dimensional logit vector corresponding to the background and foreground classes. The foreground confidence is obtained by applying a softmax operation:
Candidates with foreground confidence lower than a predefined threshold are discarded.
After confidence filtering, Line-IoU-based non-maximum suppression is applied to remove redundant lane predictions. The remaining candidates are decoded into lane point sequences according to their predicted start position, length, and sampled lateral coordinates. Since the final lane geometry is decoded from the regression branch, the decoupled prediction design reduces direct interference from the classification branch during lane localization.
The final output is a set of lane instances:
where
is the confidence threshold and
denotes the set of lane candidates retained after non-maximum suppression.