depth_fm.objectives.metrics¶
metrics ¶
DTM evaluation metrics for Mars DepthFM.
Implements all standard monocular depth estimation metrics used in the literature (DepthFM, Marigold, MiDaS), plus Mars-DTM–specific metrics.
All metrics operate on affine-aligned predictions: since flow matching produces affine-invariant depth, we first solve for optimal scale and shift via least-squares before computing error metrics (following DepthFM §4).
Metrics
AbsRel — mean |d - d| / d SqRel — mean (d - d)² / d RMSE — root mean squared error (metres) RMSElog — RMSE on log-depth δ₁ — % pixels with max(d/d, d/d) < 1.25 δ₂ — same with threshold 1.25² δ₃ — same with threshold 1.25³ NormAng — mean angular error between surface normals (degrees) Slope RMSE — RMSE of slope magnitude (degrees)
DTMMetrics
dataclass
¶
DTMMetrics(abs_rel: float = 0.0, sq_rel: float = 0.0, rmse: float = 0.0, rmse_log: float = 0.0, si_log: float = 0.0, delta_1: float = 0.0, delta_2: float = 0.0, delta_3: float = 0.0, normal_angular_error: float = 0.0, slope_rmse: float = 0.0, dbf_score: float = 0.0, curvature_rmse: float = 0.0, ms_ssim_topo: float = 0.0, photo_consistency: float = 0.0, psd_ratio: float = 0.0, scale: float = 1.0, shift: float = 0.0, patch_swd: float = 0.0)
Container for a single evaluation result.
Metrics follow the state-of-the-art depth estimation evaluation protocol
- SILog (Eigen et al., 2014; KITTI benchmark primary metric)
- AbsRel, SqRel, RMSE, RMSElog (standard depth metrics)
- δ₁, δ₂, δ₃ (threshold accuracy)
- NormAng, SlopeRMSE (terrain-specific)
- PhotoConsistency (SSIM of rendered shading vs orthoimage — resolution- independent quality signal for Mars DTM, not limited by GT resolution)
- PSD ratio (power spectral density slope ratio — ensures predicted terrain has correct frequency content; Kirk et al. 2003)
MetricsAggregator
dataclass
¶
Accumulates per-sample metrics and computes summary statistics.
summary ¶
Return mean ± std for each metric.
Uses ddof=0 (population std) when n < 2 to avoid NaN.
Source code in src/depth_fm/objectives/metrics.py
worst_k ¶
Return the k worst-performing tile_ids by the given metric.
Source code in src/depth_fm/objectives/metrics.py
affine_align ¶
affine_align(pred: ndarray, gt: ndarray, valid_mask: ndarray | None = None) -> tuple[np.ndarray, float, float]
Solve for optimal scale s and shift t: aligned = s * pred + t.
Uses least-squares to minimise || s * pred + t - gt ||² over valid pixels. This is the standard affine-invariant alignment used by DepthFM and Marigold.
Source code in src/depth_fm/objectives/metrics.py
compute_depth_metrics ¶
compute_depth_metrics(pred: ndarray, gt: ndarray, valid_mask: ndarray | None = None, align: bool = True) -> DTMMetrics
Compute all depth metrics between predicted and ground-truth DTMs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pred
|
ndarray
|
predicted depth (H, W), arbitrary scale |
required |
gt
|
ndarray
|
ground-truth depth (H, W), in metres |
required |
valid_mask
|
ndarray | None
|
boolean mask of valid pixels (H, W) |
None
|
align
|
bool
|
if True, affine-align prediction to GT first |
True
|
Returns:
| Type | Description |
|---|---|
DTMMetrics
|
DTMMetrics dataclass |
Source code in src/depth_fm/objectives/metrics.py
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 | |
compute_photo_consistency ¶
compute_photo_consistency(pred_elevation: ndarray, ortho_gray: ndarray, sun_vector: ndarray, intensity: float = 1.0, ambient: float = 0.0, lunar_lambert_weight: float = 0.5, valid_mask: ndarray | None = None) -> float
SSIM between Lunar-Lambert render of predicted DTM and real orthoimage.
This is the key resolution-independent quality metric for Mars DTM: even if the GT DTM is low-resolution, a good prediction should produce shading that matches the high-resolution orthoimage.
Returns:
| Type | Description |
|---|---|
float
|
SSIM value in [0, 1] (higher = better photometric consistency). |