Ordinal Depth Ranking Loss
Compute the ordinal (ranking) depth loss.
Ordinal depth loss enforces that the relative ordering of depths is preserved, even if absolute depths are wrong. For each pair of pixels with :
where:
- is ground truth depth
- is predicted depth
- is a margin
- returns -1, 0, or 1
Pairs with equal ground-truth depth () are skipped and contribute no loss. The total loss is the sum of over all remaining pairs, rounded to 4 decimal places.
The loss penalizes predictions that violate the ground truth ordering, or respect it by less than the margin τ.
Ordinal loss is useful when absolute depth is hard to obtain but relative depth (which object is closer) is known.
Example
ordinal_loss([1, 2, 3], [1, 2, 3], 0.1)
0.0
predandgthold one depth per pixel, andmarginis . Every unordered pair of pixels is compared once: , , .- Pair : ground truth gives , so the sign is (pixel 0 is closer). The predicted gap agrees, so .
- Pair : sign , predicted gap , so . Pair : sign , gap , so .
- The total is , printed as
0.0: every predicted gap points the right way and exceeds the margin . - Notice a pair only costs something when its predicted gap points the wrong way or is right by less than . Reversing the prediction to makes every pair violate: .
- Pairs whose ground-truth depths are equal carry no ordering and add no loss.
Constraints
- pred: list of predicted depths
- gt: list of ground truth depths
- margin: ranking margin (τ)
- Return total ordinal loss rounded to 4 decimal places