AI Logic

Evaluation Metrics

Edit score

Updated:

Computation of the edit score. The top shows, along a time axis, the ground truth of a 30-frame cooking video (cut, add, mix, plate) and a prediction in which a single frame of "add" appears in the middle. The bottom left shows each converted into a sequence of per-segment actions (4 segments in the ground truth, 6 in the prediction) and aligned with the fewest edits (2 insertions). The bottom right shows Edit 66.7, from an edit distance of 2 divided by the larger number of segments, 6, and, for reference, a frame accuracy of 90.0%

Background and Overview

The edit score (segmental edit score) is an evaluation metric for the task of labeling each frame of a video with an action (temporal action segmentation) that condenses the prediction and ground truth into sequences of per-segment actions, divides their edit distance by the number of segments, and scales the result to 0–100. Higher is better; if the predicted actions are in the same order as the ground truth and the number of segments is the same, the score is 100.

Edit=(1−d(P,Y)max⁡(∣P∣,∣Y∣))×100\mathrm{Edit} = \left(1 - \frac{d(P, Y)}{\max(|P|, |Y|)}\right) \times 100

PP and YY are the per-segment label sequences of the prediction and ground truth, ∣P∣|P| and ∣Y∣|Y| are their numbers of segments, and dd is the edit distance between the two sequences (the minimum number of substitutions, deletions, and insertions).

This metric is needed because frame-wise accuracy barely reflects errors in which segments are broken into small pieces (over-segmentation). In the example in the figure at the top, only 3 of 30 frames are wrong, so frame accuracy is 90%, but because a single frame of "add" appears in the middle of "mix", the prediction has 6 segments instead of 4. The edit score counts these 2 extra segments as errors and comes out at 66.7.

The edit score was used in Lea et al.'s work on action segmentation, and it became one of the standard metrics in the field after the TCN paper (2017) reported it alongside the segmental F1@k and frame accuracy.

Definition and Computation

The edit score is computed for each video as follows.

  1. Merge consecutive identical labels in the frame-wise label sequences of the prediction and ground truth, turning each into a sequence of per-segment labels. In the example from Lea et al.'s 2016 paper, AAABBA becomes ABA.
  2. Many implementations remove "background" segments, which belong to no action, from the sequences. Whether to remove them follows the conventions of the dataset.
  3. Compute the edit distance dd between the two sequences with the same dynamic programming as the word error rate (WER). Substitution, deletion, and insertion all cost 1.
  4. Divide dd by the larger number of segments max⁡(∣P∣,∣Y∣)\max(|P|, |Y|), subtract from 1, and multiply by 100.
  5. The score for a whole test set is the average of the per-video edit scores.

In the example in the figure at the top, the ground truth has 4 segments, "cut → add → mix → plate", and the prediction has 6, "cut → add → mix → add → mix → plate". The prediction contains one extra "add" and one extra "mix", so the edit distance is 2 and Edit is (1−2/6)×100≈66.7(1 - 2/6) \times 100 \approx 66.7.

The edit distance never exceeds the length of the longer sequence (turning the longer sequence into the shorter one takes at most that many substitutions and deletions combined). Therefore, unlike WER, the edit score always stays within 0–100. Because it divides by the larger number of segments, the score drops in the same way whether the prediction outputs too many segments or too few.

What It Measures and Its Limitations

The edit score measures whether the prediction outputs the actions in the correct order and the correct number of times. It compares only the sequence of actions, ignoring segment lengths and positions. It therefore heavily penalizes two kinds of error.

  • Over-segmentation: a short segment of another action appears in the middle of an action. Even a one-frame error adds two segments, so the edit distance can increase by up to 2.
  • Ordering errors: the order of actions is swapped, for example outputting "add → cut" instead of "cut → add".

It has the following limitations.

  • It ignores temporal position and length: even if every segment is far off from the ground truth, the score is 100 as long as the sequence is the same. For example, a prediction that shifts every segment boundary slightly later keeps an Edit of 100 (as long as no segment disappears).
  • Scores swing widely for videos with few segments: since the denominator is the number of segments, a single edit lowers the score by 25 for a video with 4 segments, but only by about 3 for a video with 30. The test-set score is a per-video average, so short videos have relatively more influence.
  • Background handling changes the score: whether background segments are removed changes both the segment sequences and the edit distance. The authors' code (TemporalConvolutionalNetworks) and the MS-TCN evaluation code ported from it both remove background segments after merging into segments.

Because the edit score ignores segment positions, it cannot judge a model on its own. In action segmentation, the convention is to report it together with F1@k, which accounts for positional offsets, and frame-wise accuracy. Also, before comparing, match prior work on whether background is removed and on how dataset splits are defined.

Validation in the Original Paper

Lea et al.'s 2016 paper (Temporal Convolutional Networks: A Unified Approach to Action Segmentation) compares temporal models with the same input features using two measures: frame accuracy and the edit score. Part of the results on a dataset of surgical gestures (JIGSAWS, video-based setting) is shown below.

ModelEditFrame accuracy (%)
IDT (no temporal model)8.553.9
Spatial CNN (per-frame CNN)37.774.0
ST-CNN68.077.7
TCN83.181.4

The frame accuracy gap between Spatial CNN and TCN is 7.4 points, but the edit score gap is 45.4 points. Spatial CNN, which classifies each frame independently, attains high accuracy but tends to fragment segments, and this difference shows up clearly in the edit score. The paper also notes that the IDT and VGG results in the table were computed deliberately without temporal processing, which is why their edit scores are low.

The 2017 TCN paper reports the following results on the mid-level granularity (17 classes) of 50Salads.

ModelF1@{10, 25, 50}EditFrame accuracy (%)
Dilated TCN52.2, 47.6, 37.443.159.3
ST-CNN55.9, 49.6, 37.145.959.4
Bi-LSTM62.6, 58.3, 47.055.655.7
ED-TCN68.0, 63.9, 52.659.864.7

Bi-LSTM has the lowest frame accuracy of the four but ranks second in edit score and F1@k. The paper notes that models with similar frame accuracy can differ greatly in F1@k and edit score, and that ED-TCN over-segments far less.

Where It Is Used

The edit score is mainly used in the following settings.

  • Action segmentation benchmarks: on 50Salads, GTEA, Breakfast, and others, the standard practice is to report five numbers side by side: F1@{10, 25, 50}, Edit, and frame accuracy. It is used to compare models such as TCN and MS-TCN.
  • Evaluating techniques that reduce over-segmentation: the MS-TCN paper shows the effect of increasing the number of stages on 50Salads. Frame accuracy stays almost the same, while the edit score changes greatly.
Model (50Salads)F1@{10, 25, 50}EditFrame accuracy (%)
SS-TCN (1 stage)27.0, 25.3, 21.520.578.2
MS-TCN (2 stages)55.5, 52.9, 47.347.979.8
MS-TCN (4 stages)76.3, 74.0, 64.567.980.7
  • Recognizing robot and surgical motions: in robots that collaborate with people and in surgical skill assessment, the order of motions itself matters. Lea et al. also report the edit score on surgical gestures (JIGSAWS).

Comparison with Similar Metrics

The table compares the edit score with other metrics that evaluate time segments from the same perspectives.

MetricUnit comparedConsiders positional offsets?Penalizes over-segmentation?Needs confidence scores?Range
Edit scoreSequence of segment labelsNoHeavilyNo0–100
F1@kSegments (matched by IoU)Yes (threshold k)Yes (extra segments are FPs)No0–100
Frame accuracyFramesYes (only by the number of shifted frames)BarelyNo0–100
mAP@k (segment IoU)SegmentsYes (threshold k)YesYes0–1
WERWord sequence――No0 and up (no upper bound)

WER works almost the same way as the edit score, but its denominator is only the number of reference words, so it can exceed 100%. The edit score uses the length of the longer sequence as the denominator, so it stays within 0–100.

Guidelines for choosing:

  • Comparing with prior work on action segmentation: do not use the edit score alone; report it together with F1@{10, 25, 50} and frame accuracy.
  • Emphasizing whether the order of actions is correct (checking work procedures, recognizing surgical phases, and so on): the edit score is a good fit.
  • Checking whether segment start and end positions are correct: look at F1@k with a strict threshold (such as k = 50).
  • Detection tasks that output a confidence score per segment: use mAP.

PyTorch example

Show code
python
import torch


def segment_labels(frames, bg_class=None):
  """Turn per-frame labels (a 1-D tensor) into a sequence of per-segment labels (AAABBA -> ABA).
  If bg_class is given, background segments are removed after merging (same order as the authors' code)."""
  labels = torch.unique_consecutive(frames).tolist()
  if bg_class is not None:
    labels = [c for c in labels if c != bg_class]
  return labels


def levenshtein(p, y):
  """Edit distance between sequences of segment labels (substitution, deletion, and insertion all cost 1)."""
  m, n = len(p), len(y)
  d = [[0] * (n + 1) for _ in range(m + 1)]
  for i in range(m + 1):
    d[i][0] = i
  for j in range(n + 1):
    d[0][j] = j
  for i in range(1, m + 1):
    for j in range(1, n + 1):
      d[i][j] = min(d[i - 1][j - 1] + (p[i - 1] != y[j - 1]),  # match / substitution
                    d[i - 1][j] + 1,                           # deletion
                    d[i][j - 1] + 1)                           # insertion
  return d[m][n]


def edit_score(pred, target, bg_class=None):
  """Edit score of one video: (1 - d / max(|P|, |Y|)) x 100."""
  p = segment_labels(pred, bg_class)
  y = segment_labels(target, bg_class)
  if max(len(p), len(y)) == 0:
    return 100.0
  return (1 - levenshtein(p, y) / max(len(p), len(y))) * 100


# 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] * 7 + [2] * 4 + [1] * 1 + [2] * 5 + [3] * 6)
print(edit_score(pred, target))  # 66.66...
print((pred == target).float().mean().item() * 100)  # frame accuracy 90.0

# The test-set score is the average of the per-video edit scores
videos = [(pred, target)]
print(sum(edit_score(p, y) for p, y in videos) / len(videos))

FAQ

Q. If the edit score is 100, is the prediction completely correct?
A.

No. The edit score looks only at the sequence of segment labels, so even if segment boundaries are far off, the score is 100 as long as the order and number of actions match the ground truth. Check positional correctness with F1@k or frame accuracy.

Q. Why is the edit score low even though frame accuracy is high?
A.

Because over-segmentation is occurring: short erroneous segments appear in several places in the middle of actions. Even if only a few frames are wrong, fragmenting segments lengthens the segment sequence and increases the edit distance. Models that use temporal context (TCN, MS-TCN, and others) or techniques that smooth predictions often help.

Q. How does the edit score differ from WER?
A.

Both use the edit distance between sequences, but they compare different things and divide by different numbers. WER divides the edit distance between word sequences by the number of reference words NN, so it can exceed 100%. The edit score divides the edit distance dd between segment label sequences by the length of the longer sequence and flips it so that higher is better, (1−d/max⁡(∣P∣,∣Y∣))×100(1 - d/\max(|P|,|Y|)) \times 100, so it stays within 0–100.

References

  1. 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.
  2. 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.
  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, code/metrics.py).
  5. yabufarha/ms-tcn (public code for MS-TCN, eval.py).