Multiple Object Tracking Metrics (motmetrics)

1.4.0 · active · verified Fri Apr 17

motmetrics is a Python library providing a comprehensive suite of metrics for benchmarking multiple object trackers (MOT). It simplifies the evaluation of tracker performance by handling associations between ground truth and hypothesis data, and calculating standard metrics like MOTA, MOTP, and more. The current version is 1.4.0, with an active but infrequent release cadence focused on maintenance and bug fixes.

Common errors

Warnings

Install

Imports

Quickstart

Initialize a `MOTAccumulator`, then iterate frame by frame. For each frame, compute a distance matrix (e.g., IoU) between ground truth and tracker hypotheses bounding boxes, and update the accumulator. Finally, use `motmetrics.metrics.create()` to compute and display standard MOT metrics.

import motmetrics as mm
import numpy as np

# Dummy data: Ground truth and tracker hypotheses for two frames
# Format: [id, x, y, width, height] for bounding box coordinates
gt_frame1 = np.array([[1, 10, 10, 5, 5], [2, 20, 20, 5, 5]])
ts_frame1 = np.array([[1, 10, 10, 5, 5], [2, 20, 20, 5, 5]])

gt_frame2 = np.array([[1, 11, 11, 5, 5], [2, 21, 21, 5, 5]])
ts_frame2 = np.array([[1, 11, 11, 5, 5], [2, 21, 21, 5, 5]])

# Create an accumulator to store tracking results
acc = mm.MOTAccumulator(auto_id=True)

# Process Frame 1:
# Calculate Intersection over Union (IoU) distances between ground truth and hypotheses
# Bounding boxes are expected as [x, y, width, height]
C1 = mm.distances.iou_matrix(gt_frame1[:, 1:], ts_frame1[:, 1:], max_iou=0.5)
acc.update(gt_frame1[:, 0], ts_frame1[:, 0], C1)

# Process Frame 2:
C2 = mm.distances.iou_matrix(gt_frame2[:, 1:], ts_frame2[:, 1:], max_iou=0.5)
acc.update(gt_frame2[:, 0], ts_frame2[:, 0], C2)

# Compute and display metrics
mh = mm.metrics.create()
summary = mh.compute(acc, metrics=['mota', 'motp', 'num_frames'], name='dummy_tracking')
print(summary)

view raw JSON →