Video and Temporal Reasoning › Event localization
Language AI HandbookAll chapters Temporal localization answers an event query with a time interval. A different task can ask for a spatial region as well. Here the predicted and reference intervals are measured in seconds on the same clip timeline.
An interval prediction supports a precise timing check. Ordering can also be correct from relative signals when exact start and end times are unavailable.
Temporal intersection over union (tIoU) compares a predicted interval and a reference interval . Use finite, nonnegative times and require positive duration for both. Define the overlap length first, then divide by the length of the union:
The symbols are:
- : the start and end times of the predicted interval
- : the start and end times of the ground-truth interval
- : the overlap length, truncated at zero for disjoint or touching intervals.
- : the union length. Adding both lengths counts shared time twice, so subtract it once.
The union is positive under these duration assumptions. A threshold turns the continuous score into a hit when tIoU is at least . Report the threshold and how invalid predictions affect the denominator. In this example protocol, an invalid prediction counts as a miss and stays in the denominator. Validate reference intervals before running the evaluation.
Moving or widening a predicted interval changes its overlap and union. A containing prediction larger than the reference keeps the full reference overlap and increases the union.
For positive-duration intervals, tIoU ranges from 0 for no overlap to 1 for identical intervals. The reported hit rate depends on the chosen threshold.
Disjoint intervals all score zero, even if the prediction misses by only one frame. A containing interval scores the reference duration divided by its own duration. Widening a misplaced interval can recover a hit at a low threshold, while widening an already perfect interval lowers its score. A separate endpoint-error metric can describe the size of near-misses.
The main approaches to temporal localization differ in whether they treat candidate intervals explicitly.
- Proposal-and-select scores candidate windows. The highest attainable overlap depends on the candidates available to score.
- Boundary regression estimates start and end offsets or probabilities over candidate boundary times.
- Timestamp generation asks a text model to emit numeric boundaries. Parse the times as numbers and check that both endpoints fall inside the clip before calculating overlap.
A matching interval only establishes the overlap score. A broad guess can overlap by chance. For a 0.4-second reference, a containing 0.8-second prediction scores 0.50; the same prediction misses at a 0.70 threshold.
PythonIn [14]Expand
from math import isfinite
def temporal_iou(predicted, reference):
p_start, p_end = predicted
r_start, r_end = reference
if any(not isfinite(t) or t < 0 for t in (p_start, p_end, r_start, r_end)):
raise ValueError("Endpoints must be finite, nonnegative clip times.")
p_length = p_end - p_start
r_length = r_end - r_start
if p_length <= 0 or r_length <= 0:
raise ValueError("Both intervals must have positive duration.")
overlap = max(0, min(p_end, r_end) - max(p_start, r_start))
longer = max(p_length, r_length)
shorter = min(p_length, r_length)
# Scale both lengths by the longer interval before forming their ratio.
return (overlap / longer) / (1 + (shorter - overlap) / longer)
reference = (3.1, 3.5)
print(f"Containing prediction: {temporal_iou((2.9, 3.7), reference):.2f}")
print(f"Touching prediction: {temporal_iou((3.5, 3.9), reference):.2f}")ConsoleOut [14]Expand
Containing prediction: 0.50 Touching prediction: 0.00
The function divides the overlap and the union by the longer interval length. This gives the same ratio without adding two potentially large durations. Pass it parsed times after checking the clip duration.
Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!