Skip to content

metrics

Evaluation metrics for 3D detection, instance segmentation, and part segmentation.

Classes:

MeanAveragePrecision3D

MeanAveragePrecision3D(
    *,
    iou_thresholds: Sequence[float] = (0.25, 0.5),
    interpolation: Interpolation = "all",
    **kwargs: Any,
)

Bases: Metric

Packed 3D-detection mean average precision as a torchmetrics metric.

A stateful wrapper of mean_average_precision3d: each update appends one batch's packed predictions and ground truth, and compute returns {"mAP@t": ...} (averaged over the classes present in the targets) for each IoU threshold. An ignore_mask passed to update is stored as the predictions' ignore_mask entry, excluding the flagged predictions from scoring entirely (the KITTI min-height rule). The state is a per-process list of batches (not gathered across processes), so run detection validation on a single device.

Parameters:

  • iou_thresholds (Sequence[float], default: (0.25, 0.5) ) –

    IoU thresholds at which mAP@t is reported.

  • interpolation (Interpolation, default: 'all' ) –

    AP interpolation: "all" integrates the full precision-recall curve; "r11" / "r40" sample the KITTI 11- / 40-point recall grids.

  • kwargs (Any, default: {} ) –

    Forwarded to torchmetrics.Metric.

Methods:

  • update –

    Append one batch's packed predictions and ground truth.

  • compute –

    Score the accumulated batches and return one mAP@t entry per IoU threshold.

update

update(
    preds: Detection3D,
    target: Boxes3D,
    ignore_mask: OptTensor = None,
) -> None

Append one batch's packed predictions and ground truth.

Parameters:

  • preds (Detection3D) –

    Packed predictions (one decode output), {"boxes", "scores", "labels", "batch"}.

  • target (Boxes3D) –

    Packed ground truth aligned to preds, {"boxes", "labels", "batch"}.

  • ignore_mask (OptTensor, default: None ) –

    Optional per-prediction ignore mask, shape \((N,)\) bool, stored as the predictions' ignore_mask entry; flagged predictions are excluded from scoring entirely.

compute

compute() -> Dict[str, float]

Score the accumulated batches and return one mAP@t entry per IoU threshold.

AveragePrecision3D

AveragePrecision3D(
    *,
    iou_per_class: Mapping[int, float],
    class_names: Optional[Sequence[str]] = None,
    interpolation: Interpolation = "all",
    **kwargs: Any,
)

Bases: Metric

Packed 3D-detection per-class average precision as a torchmetrics metric.

A stateful wrapper of average_precision3d: each update appends one batch's packed predictions and ground truth, and compute returns one AP/<class> entry per class plus their mean as mAP, each class matched at its own IoU threshold (the KITTI / nuScenes convention, e.g. Car@0.7 and Pedestrian/Cyclist@0.5). Targets may carry an ignore_mask so predictions overlapping an ignore region are not counted as false positives. An ignore_mask passed to update is stored as the predictions' ignore_mask entry, excluding the flagged predictions from scoring entirely (the KITTI min-height rule). The state is a per-process list of batches (not gathered across processes), so run detection validation on a single device.

Parameters:

  • iou_per_class (Mapping[int, float]) –

    Mapping of class index to the IoU threshold used to match its boxes. Keys are coerced to int (YAML / OmegaConf mappings may arrive with string keys).

  • class_names (Optional[Sequence[str]], default: None ) –

    Optional class names used in the returned keys (defaults to the class index).

  • interpolation (Interpolation, default: 'all' ) –

    AP interpolation: "all" integrates the full precision-recall curve; "r11" / "r40" sample the KITTI 11- / 40-point recall grids.

  • kwargs (Any, default: {} ) –

    Forwarded to torchmetrics.Metric.

Methods:

  • update –

    Append one batch's packed predictions and ground truth.

  • compute –

    Score the accumulated batches and return one AP/<class> entry per class plus their mAP.

update

update(
    preds: Detection3D,
    target: Boxes3D,
    ignore_mask: OptTensor = None,
) -> None

Append one batch's packed predictions and ground truth.

Parameters:

  • preds (Detection3D) –

    Packed predictions (one decode output), {"boxes", "scores", "labels", "batch"}.

  • target (Boxes3D) –

    Packed ground truth aligned to preds, {"boxes", "labels", "batch"} with an optional ignore_mask.

  • ignore_mask (OptTensor, default: None ) –

    Optional per-prediction ignore mask, shape \((N,)\) bool, stored as the predictions' ignore_mask entry; flagged predictions are excluded from scoring entirely.

compute

compute() -> Dict[str, float]

Score the accumulated batches and return one AP/<class> entry per class plus their mAP.

NuScenesDetection

NuScenesDetection(
    *,
    class_names: Sequence[str],
    class_ranges: Optional[Mapping[str, float]] = None,
    dist_thresholds: Sequence[float] = (0.5, 1.0, 2.0, 4.0),
    tp_threshold: float = 2.0,
    max_boxes_per_sample: int = 500,
    min_recall: float = 0.1,
    min_precision: float = 0.1,
    **kwargs: Any,
)

Bases: Metric

The official nuScenes detection metrics as a torchmetrics metric.

A stateful wrapper of nuscenes_detection_metrics: each update appends one batch's packed predictions and ground truth together with the optional velocity, attribute and point-count extras, and compute returns the functional's flat dict (AP/<class>, mAP, the five TP errors and the NDS). The predictions' velocity entry and the velocity argument are appended to the boxes as \((v_x, v_y)\) columns, the \((M, 9)\) layout the functional scores; prediction attributes are derived from the accumulated prediction velocities in compute with the standard speed heuristic (nuscenes_velocity_attributes). Sample indices are offset per update by the number of samples seen so far (read off the batch tensors), so scenes of different updates never collide. The state is a per-process list of batches (not gathered across processes), so run detection validation on a single device.

Parameters:

  • class_names (Sequence[str]) –

    Class name per label index; barrier and traffic_cone get their official special handling by name.

  • class_ranges (Optional[Mapping[str, float]], default: None ) –

    Maximum BEV evaluation range per class name; defaults to the official ranges.

  • dist_thresholds (Sequence[float], default: (0.5, 1.0, 2.0, 4.0) ) –

    Matching thresholds in meters the AP is averaged over.

  • tp_threshold (float, default: 2.0 ) –

    Matching threshold in meters of the TP-error metrics.

  • max_boxes_per_sample (int, default: 500 ) –

    Per-sample cap on scored predictions (highest scores kept).

  • min_recall (float, default: 0.1 ) –

    Recall up to which the AP and TP-error curves are clipped.

  • min_precision (float, default: 0.1 ) –

    Precision subtracted before the AP mean.

  • kwargs (Any, default: {} ) –

    Forwarded to torchmetrics.Metric.

Methods:

  • update –

    Append one batch's packed predictions and ground truth with the optional nuScenes extras.

  • compute –

    Score the accumulated samples and return the official nuScenes metrics, NDS included.

update

update(
    preds: Detection3D,
    target: Boxes3D,
    *,
    velocity: OptTensor = None,
    num_points: OptTensor = None,
    attribute: OptTensor = None,
) -> None

Append one batch's packed predictions and ground truth with the optional nuScenes extras.

The keyword names match the dataset's ground-truth keys (velocity, num_points, attribute), so a Lightning module's metric_input_keys passthrough feeds them directly; the prediction-side velocity lives inside preds.

Parameters:

  • preds (Detection3D) –

    Packed predictions (one decode output), {"boxes", "scores", "labels", "batch"}; an optional velocity entry \((M, 2)\) is appended to the boxes as \((v_x, v_y)\) columns.

  • target (Boxes3D) –

    Packed ground truth aligned to preds, {"boxes", "labels", "batch"}.

  • velocity (OptTensor, default: None ) –

    Optional ground-truth per-box BEV velocity, shape \((K, 2)\), appended to the target boxes.

  • num_points (OptTensor, default: None ) –

    Optional ground-truth per-box point count, shape \((K,)\); boxes with exactly \(0\) points are removed (unknown counts of \(-1\) are kept).

  • attribute (OptTensor, default: None ) –

    Optional ground-truth per-box attribute id, shape \((K,)\); a negative id marks a box without an attribute.

compute

compute() -> Dict[str, float]

Score the accumulated samples and return the official nuScenes metrics, NDS included.

InstanceAveragePrecision

InstanceAveragePrecision(
    *,
    num_classes: int,
    class_names: Optional[Sequence[str]] = None,
    min_points: int = 100,
    **kwargs: Any,
)

Bases: Metric

Point-mask instance-segmentation AP as a torchmetrics metric.

A stateful wrapper of instance_average_precision: each update appends one scene's instance_matches record (the compact per-scene reduction of predicted masks against ground-truth instances), and compute returns {"AP/<class>": ..., "mAP": ..., "mAP@0.5": ..., "mAP@0.25": ...} following the standard indoor instance-segmentation protocol. The state is a per-process list of records (not gathered across processes), so run instance validation on a single device.

Parameters:

  • num_classes (int) –

    Number of instance classes.

  • class_names (Optional[Sequence[str]], default: None ) –

    Optional names for the AP/<class> keys; falls back to the class index.

  • min_points (int, default: 100 ) –

    Minimum point count for a prediction or ground-truth instance to be scored; smaller ground-truth instances count as ignore regions.

  • kwargs (Any, default: {} ) –

    Forwarded to torchmetrics.Metric.

Methods:

  • update –

    Append one scene's instance_matches record.

  • compute –

    Score the accumulated scene records and return the per-class average precisions and their mean.

update

update(match: Mapping[str, Tensor]) -> None

Append one scene's instance_matches record.

Parameters:

  • match (Mapping[str, Tensor]) –

    The per-scene record returned by instance_matches (per-instance counts, labels, scores and same-class pairwise intersections).

compute

compute() -> Dict[str, float]

Score the accumulated scene records and return the per-class average precisions and their mean.

InstancePartMeanIoU

InstancePartMeanIoU(
    *,
    part_ids: Optional[Sequence[Sequence[int]]] = None,
    restrict_to_category: bool = False,
    **kwargs: Any,
)

Bases: Metric

ShapeNetPart instance / class mean IoU as a torchmetrics metric.

A stateful wrapper of part_iou: each shape is scored only over the part labels its category owns (a part absent from both the prediction and the target counts as IoU \(1\)), per-category IoU sums and shape counts accumulate across update calls (summed across processes), and compute returns the protocol's two numbers: ins_mIoU (mean over shapes) and cls_mIoU (mean per category, then over the categories seen). The category of each shape is read off its target labels, since every category owns a disjoint part range.

Parameters:

  • part_ids (Optional[Sequence[Sequence[int]]], default: None ) –

    Part labels owned by each category; defaults to the 16-category / 50-part ShapeNetPart table (ShapeNetPart.seg_ids).

  • restrict_to_category (bool, default: False ) –

    If True, the argmax of 2-D preds is taken over the shape's own category parts only (logits of the other parts are masked out), the protocol of PointNet, Point-MAE and Point-M2AE. The default is the global argmax over all parts (DGCNN, PointNeXt).

  • kwargs (Any, default: {} ) –

    Forwarded to torchmetrics.Metric.

Methods:

  • update –

    Score one packed batch of shapes.

  • compute –

    Reduce the accumulated per-category IoU sums into ins_mIoU and cls_mIoU.

update

update(
    preds: Tensor, target: Tensor, batch: Tensor
) -> None

Score one packed batch of shapes.

Parameters:

  • preds (Tensor) –

    Predicted part indices \((N,)\), or logits / probabilities \((N, \text{num\_classes})\).

  • target (Tensor) –

    Ground truth part indices, shape \((N,)\).

  • batch (Tensor) –

    Per-point shape index, shape \((N,)\).

compute

compute() -> Dict[str, Tensor]

Reduce the accumulated per-category IoU sums into ins_mIoU and cls_mIoU.