AI Logic

Evaluation Metrics

F1@k (Segmental F1)

Updated:

Computing F1@k. At the top, bands along the time axis showing the ground truth (cut, add, mix, plate) and the prediction for a 30-frame cooking video; at the bottom left, for each of the 6 predicted segments, its IoU with the ground-truth segment of the same action and the TP/FP decision at thresholds 0.1, 0.25, and 0.5, plus the unused ground-truth segments (FN); at the bottom right, the resulting F1@10 80.0, F1@25 80.0, F1@50 60.0, and, for reference, a frame-wise accuracy of 80.0%

Background and overview

F1@k (segmental F1) is an evaluation metric for tasks that assign an action label to every frame of a video (temporal action segmentation): it matches predicted segments to ground-truth segments by their overlap ratio (IoU), treats those with IoU at least kk% as hits (TP), and computes an F1 score from the numbers of segments. It ranges from 0 to 100, higher is better, and kk is commonly set to 10, 25, and 50, reported together as F1@{10, 25, 50}.

F1@k=100Γ—2β‹…Precβ‹…RecPrec+Rec,Prec=TPTP+FP,Rec=TPTP+FN\mathrm{F1@}k = 100 \times \frac{2 \cdot \mathrm{Prec} \cdot \mathrm{Rec}}{\mathrm{Prec} + \mathrm{Rec}}, \quad \mathrm{Prec} = \frac{TP}{TP + FP}, \quad \mathrm{Rec} = \frac{TP}{TP + FN}

F1@k was proposed by Lea et al. in the TCN paper (2017). The paper states that the metric was designed to have the following three properties.

  • It penalizes errors that break segments into small pieces (over-segmentation)
  • It does not penalize small shifts between predicted and ground-truth boundaries (such shifts also arise from differences between annotators)
  • Its value depends on the number of action segments, not on the length of each segment

Frame-wise accuracy is dominated by long actions and barely reflects over-segmentation. On the other hand, mAP, which follows the same idea as object detection, changes greatly depending on how confidence is assigned to each segment. F1@k avoids both weaknesses by counting segment hits and misses without using confidence.

Definition and procedure

F1@k is computed with the following steps.

  1. Merge consecutive frames with the same label in the predicted and ground-truth frame-label sequences into segments (label, start, end). Many implementations exclude background segments that belong to no action.
  2. Set the threshold Ο„=k/100\tau = k / 100 (0.25 for F1@25).
  3. Go through the predicted segments one by one in temporal order and compute the IoU (overlapping frames Γ· frames covered by the two segments together) with each ground-truth segment of the same label. The IoU with segments of a different label is 0.
  4. For the ground-truth segment with the highest IoU, if the IoU is at least Ο„\tau and that ground-truth segment has not been used yet, count a TP and mark the ground-truth segment as used. Otherwise, count an FP.
  5. Let FN be the number of ground-truth segments not used by any prediction.
  6. Compute F1 from precision and recall and multiply by 100.

In the example in the figure at the top, there are 6 predicted segments and 4 ground-truth segments.

  • p1, p2, p6: They overlap their ground-truth segments heavily (IoU 0.88, 0.71, 0.57) and are TPs at every threshold.
  • p4: A one-frame "add" in the middle of "mix". It does not overlap any ground-truth segment with the same label, so it is an FP at every threshold.
  • p3, p5: Both overlap the ground-truth "mix" (14–22). At Ο„ = 0.1 and 0.25, p3 (IoU 0.30), seen first, becomes a TP, and p5 (IoU 0.42) is an FP because it is the second match to the same ground-truth segment. At Ο„ = 0.5, both lack enough IoU and are FPs, and the ground-truth "mix" becomes an FN.

As a result, F1@10 and F1@25 are 80.0 with TP 4, FP 2, FN 0, and F1@50 is 60.0 with TP 3, FP 3, FN 1.

Only one prediction can be a TP for a given ground-truth segment, so if one action is output as many pieces, all the extra segments become FPs. This is how F1@k penalizes over-segmentation. On the other hand, if the boundary is merely shifted slightly, the IoU stays high, so there is almost no penalty at a low threshold (k = 10).

What it measures and its limitations

F1@k measures how completely the ground-truth action segments are found without producing extra segments. What it looks at changes with the threshold kk.

  • k = 10: Any small overlap counts as a hit, so it mainly looks at missed segments and over-segmentation.
  • k = 50: More than half of a segment must overlap, so it also looks at the correctness of boundary positions.

It also has the following limitations.

  • It does not distinguish segment lengths: Missing a short action of a few seconds and missing a long action of several minutes are both one FN. This is by design, but it does not suit applications that want to weigh long actions more heavily.
  • The matching is greedy and not necessarily optimal: Predicted segments are examined in temporal order, and if the ground-truth segment with the highest IoU is already used, the prediction is counted as an FP without searching other ground-truth segments. As with p3 and p5 in the figure at the top, a prediction with a higher IoU that comes later does not become a TP.
  • It does not look at the order of actions directly: It only counts hits and misses per segment, so check the correctness of order with the Edit score.

How values are aggregated over the whole test set differs between implementations. The authors' code (TemporalConvolutionalNetworks) computes F1 per video and averages it, whereas the MS-TCN evaluation code sums TP, FP, and FN over all videos and computes F1 only once. Whether background segments are excluded also changes the value. When comparing with prior work, use the same evaluation code or match the aggregation method.

Validation in the original paper

The TCN paper (Lea et al., 2017) demonstrates the properties of F1@k through several experiments.

First, on synthetic data, it examines F1@10 when the input features are shifted by ss frames from the ground-truth labels (the receptive field is 16 frames).

Models = 0s = 5s = 10s = 15s = 20
ED-TCN10097.989.574.157.1
Dilated TCN10092.787.069.661.5
Bi-LSTM10072.360.254.738.5

Next are the results at the mid-level granularity (17 classes) of 50Salads.

ModelF1@10F1@25F1@50EditFrame-wise accuracy (%)
Spatial CNN32.327.118.924.854.9
Dilated TCN52.247.637.443.159.3
ST-CNN55.949.637.145.959.4
Bi-LSTM62.658.347.055.655.7
ED-TCN68.063.952.659.864.7

Dilated TCN and ST-CNN have almost the same frame-wise accuracy (59.3 and 59.4), yet Bi-LSTM, despite a lower frame-wise accuracy, has higher F1@k than both. The paper notes that F1@k and the Edit score can differ greatly even between models with similar frame-wise accuracy.

Finally, on in-store surveillance video (MERL Shopping, in a setting that looks both backward and forward in time), it compares against mAP that counts a segment as a hit if its midpoint falls within a ground-truth segment (mAP@mid).

ModelF1@10F1@25F1@50mAP@midFrame-wise accuracy (%)
MSN Det46.442.625.681.964.6
MSN Seg80.078.365.469.876.3
ED-TCN86.785.172.974.479.0

MSN Det has the highest mAP@mid, but it outputs very short segments, and its F1@k is the lowest even at low thresholds. The paper states that mAP judged only by midpoints is not suited to applications that need start and end times. It also reports that, for the same predictions, merely changing segment confidence from the mean within the segment to the maximum changed mAP@mid from 50.9 to 69.8, and gives this as a reason for proposing F1@k, which needs no confidence.

Where it is used

F1@k is mainly used in the following situations.

  • Benchmarks for temporal action segmentation: On 50Salads, GTEA, Breakfast, and others, the standard is to report F1@{10, 25, 50}, Edit, and frame-wise accuracy side by side. The MS-TCN paper also compares with prior work using these five numbers.
Model (50Salads)F1@{10, 25, 50}EditFrame-wise accuracy (%)
ED-TCN68.0, 63.9, 52.659.864.7
MS-TCN76.3, 74.0, 64.567.980.7
  • Evaluating action detection without confidence scores: Models that build segments from frame-wise labels do not naturally have per-segment confidence. F1@k makes it possible to evaluate them with the same idea as detection tasks, without creating confidence scores.
  • Evaluating techniques that reduce over-segmentation: When checking the effect of losses that smooth predictions or of multi-stage models, F1@k changes clearly even when frame-wise accuracy does not.

Comparison with similar metrics

The following table compares F1@k with metrics that evaluate temporal segments, from the same perspectives.

MetricUnit comparedMatching to ground truthBoundary shiftsOver-segmentationConfidenceRange
F1@kSegmentSame label and IoU β‰₯ k%Tolerated when k is smallExtra segments become FPsNot needed0–100
Edit scoreSequence of segment labelsAligned by edit distanceIgnoredStrongly penalizedNot needed0–100
Frame-wise accuracyFrameFrame-by-frame agreementPenalized by the number of shifted framesBarely penalizedNot needed0–100
mAP@k (segment IoU)SegmentSame label and IoU β‰₯ k%Tolerated when k is smallExtra segments become FPsNeeded0–1
F1 score (classification)Example (sample)Label agreement――Not needed0–1

Like mAP for object detection and action detection, F1@k decides hits by an IoU threshold, but instead of sorting by confidence and drawing a curve, it counts every segment once and turns the result into an F1. The idea of the overlap ratio of regions (IoU) is the same as in mIoU for segmentation.

Rough guidelines for choosing among them:

  • To compare with prior work in temporal action segmentation: Report F1@{10, 25, 50}, the Edit score, and frame-wise accuracy together.
  • To emphasize boundary accuracy: Look at F1@50 or a stricter threshold.
  • To emphasize the order of actions: Look at the Edit score.
  • For tasks where the model outputs per-segment confidence and ranking matters, as in retrieval: Use mAP.

PyTorch example

Show code
python
import torch


def segments(frames, bg_class=None):
  """Convert frame-wise labels (a 1D tensor) into a list of segments (label, start, end (exclusive))."""
  labels, counts = torch.unique_consecutive(frames, return_counts=True)
  ends = torch.cumsum(counts, 0)
  starts = ends - counts
  segs = list(zip(labels.tolist(), starts.tolist(), ends.tolist()))
  if bg_class is not None:
    segs = [s for s in segs if s[0] != bg_class]
  return segs


def f1_counts(pred, target, tau, bg_class=None):
  """TP, FP, FN for one video (same decision rule as the authors' code).
  Go through predicted segments in temporal order; if the ground-truth segment with the same label and the highest IoU
  is unused and IoU >= tau, it is a TP, otherwise an FP. Unused ground-truth segments are FNs."""
  P, Y = segments(pred, bg_class), segments(target, bg_class)
  used = [False] * len(Y)
  tp = fp = 0
  for lp, sp, ep in P:
    ious = [(min(ep, ey) - max(sp, sy)) / (max(ep, ey) - min(sp, sy)) if lp == ly else 0.0
            for ly, sy, ey in Y]
    idx = max(range(len(Y)), key=lambda i: ious[i]) if Y else None
    if idx is not None and ious[idx] >= tau and not used[idx]:
      tp += 1
      used[idx] = True
    else:
      fp += 1
  fn = len(Y) - sum(used)
  return tp, fp, fn


def f1_at_k(videos, k, bg_class=None):
  """F1@k over the whole test set. As in the MS-TCN evaluation code, TP, FP, FN are summed over all videos before computing it.
  (The authors' code averages per-video F1, so the value differs slightly)"""
  tp = fp = fn = 0
  for pred, target in videos:
    a, b, c = f1_counts(pred, target, k / 100, bg_class)
    tp, fp, fn = tp + a, fp + b, fn + c
  prec = tp / (tp + fp) if tp + fp else 0.0
  rec = tp / (tp + fn) if tp + fn else 0.0
  return 100 * 2 * prec * rec / (prec + rec) if prec + rec else 0.0


# Example from the figure at the top (0: cut, 1: add, 2: mix, 3: plate). 30 frames
target = torch.tensor([0] * 8 + [1] * 6 + [2] * 9 + [3] * 7)
pred = torch.tensor([0] * 7 + [1] * 6 + [2] * 4 + [1] * 1 + [2] * 8 + [3] * 4)
for k in (10, 25, 50):
  print(f"F1@{k}", round(f1_at_k([(pred, target)], k), 1))  # 80.0, 80.0, 60.0

FAQ

Q. What value of k should be used for F1@k?
A.

In temporal action segmentation, the convention is to report the three values 10, 25, and 50 side by side. The smaller k is, the more lenient the criterion, looking only at misses and over-segmentation; the larger k is, the stricter it becomes, also requiring correct boundary positions. Looking at how the three values drop shows whether boundary shifts are frequent or the number of segments is off.

Q. How do F1@k and mAP differ?
A.

Both decide segment hits and misses with an IoU threshold, but mAP ranks segments by confidence and computes the area under the precision–recall curve. F1@k uses no confidence and counts every segment once to compute F1. The TCN paper cites the fact that merely changing how confidence is computed changes mAP greatly as a reason for using F1@k.

Q. Why does the F1@k of the same model differ slightly between papers?
A.

Because aggregation and the treatment of background differ between implementations. The value changes depending on whether per-video F1 is averaged or TP, FP, and FN are summed over all videos before computing it. It also changes with whether background segments are excluded and how the data splits are defined. When comparing, use values computed with the same evaluation code.

References

  1. Lea, C., Flynn, M. D., Vidal, R., Reiter, A., & Hager, G. D. (2017). Temporal Convolutional Networks for Action Segmentation and Detection. CVPR 2017. arXiv:1611.05267.
  2. Lea, C., Vidal, R., Reiter, A., & Hager, G. D. (2016). Temporal Convolutional Networks: A Unified Approach to Action Segmentation. Version submitted to the ECCV 2016 Workshop (Brave New Ideas for Motion Representations in Videos). arXiv:1608.08242.
  3. Abu Farha, Y., & Gall, J. (2019). MS-TCN: Multi-Stage Temporal Convolutional Network for Action Segmentation. CVPR 2019. arXiv:1903.01945.
  4. colincsl/TemporalConvolutionalNetworks (the authors' public code, overlap_f1 in code/metrics.py).
  5. yabufarha/ms-tcn (public code for MS-TCN, f_score in eval.py).