1
0
forked from HQU-gxy/CVTH3PE

refactor: Improve timestamp handling in camera affinity matrix calculation

- Replaced direct access to tracking and detection timestamps with a more efficient use of `itertools.chain` to gather timestamps, enhancing readability and performance in `calculate_camera_affinity_matrix_jax`.
- Maintained precision in timestamp calculations to ensure accurate results in affinity computations.
This commit is contained in:
2025-04-29 13:05:52 +08:00
parent 29c8ef3990
commit ce1d5f3cf7

View File

@ -20,6 +20,7 @@ from copy import deepcopy as deep_copy
from dataclasses import dataclass from dataclasses import dataclass
from datetime import datetime, timedelta from datetime import datetime, timedelta
from functools import partial, reduce from functools import partial, reduce
from itertools import chain
from pathlib import Path from pathlib import Path
from typing import ( from typing import (
Any, Any,
@ -1055,10 +1056,11 @@ def calculate_camera_affinity_matrix_jax(
# subsecond detail (resolution ≈ 200ms). Keep them in float64 until # subsecond detail (resolution ≈ 200ms). Keep them in float64 until
# after subtraction so we preserve Δtontheorderofmilliseconds. # after subtraction so we preserve Δtontheorderofmilliseconds.
# --- timestamps ---------- # --- timestamps ----------
tracking0 = next(iter(trackings))
detection0 = next(iter(camera_detections))
t0 = min( t0 = min(
tracking0.last_active_timestamp, detection0.timestamp chain(
(trk.last_active_timestamp for trk in trackings),
(det.timestamp for det in camera_detections),
)
).timestamp() # common origin (float) ).timestamp() # common origin (float)
ts_trk = jnp.array( ts_trk = jnp.array(
[trk.last_active_timestamp.timestamp() - t0 for trk in trackings], [trk.last_active_timestamp.timestamp() - t0 for trk in trackings],