metrics
Evaluation metrics for 3D detection, instance segmentation, and part segmentation.
Classes:
-
BoxMeanAveragePrecisionβPacked 3D-detection mean average precision as a
torchmetricsmetric. -
BoxAveragePrecisionβPacked 3D-detection per-class average precision as a
torchmetricsmetric. -
NuScenesDetectionβThe official nuScenes detection metrics as a
torchmetricsmetric. -
InstanceAveragePrecisionβPoint-mask instance-segmentation AP as a
torchmetricsmetric. -
InstancePartMeanIntersectionOverUnionβShapeNetPart instance / class mean IoU as a
torchmetricsmetric.
BoxMeanAveragePrecision [source] ΒΆ
BoxMeanAveragePrecision(
*,
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 box_average_precision: each update reduces one batch's packed predictions and ground truth to its compact box_matches record, and compute returns {"mAP@t": ...} (averaged over the classes present in the targets) for each IoU threshold. An ignore_mask passed to update is used 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 records (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@tis 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βReduce one batch's packed predictions and ground truth to its
box_matchesrecord and append it. -
computeβScore the accumulated batches and return one
mAP@tentry per IoU threshold.
update [source] ΒΆ
update(
preds: Detection3D,
target: Boxes3D,
ignore_mask: OptTensor = None,
) -> None
Reduce one batch's packed predictions and ground truth to its box_matches record and append it.
Parameters:
-
preds(Detection3D) βPacked predictions (one
decodeoutput),{"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, used as the predictions'
ignore_maskentry; flagged predictions are excluded from scoring entirely.
BoxAveragePrecision [source] ΒΆ
BoxAveragePrecision(
*,
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 box_average_precision: each update reduces one batch's packed predictions and ground truth to its compact box_matches record, 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 used 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 records (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βReduce one batch's packed predictions and ground truth to its
box_matchesrecord and append it. -
computeβScore the accumulated batches and return one
AP/<class>entry per class plus theirmAP.
update [source] ΒΆ
update(
preds: Detection3D,
target: Boxes3D,
ignore_mask: OptTensor = None,
) -> None
Reduce one batch's packed predictions and ground truth to its box_matches record and append it.
Parameters:
-
preds(Detection3D) βPacked predictions (one
decodeoutput),{"boxes", "scores", "labels", "batch"}. -
target(Boxes3D) βPacked ground truth aligned to
preds,{"boxes", "labels", "batch"}with an optionalignore_mask. -
ignore_mask(OptTensor, default:None) βOptional per-prediction ignore mask, shape \((N,)\) bool, used as the predictions'
ignore_maskentry; flagged predictions are excluded from scoring entirely.
NuScenesDetection [source] ΒΆ
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;
barrierandtraffic_coneget 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,
NDSincluded.
update [source] ΒΆ
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
decodeoutput),{"boxes", "scores", "labels", "batch"}; an optionalvelocityentry \((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.
InstanceAveragePrecision [source] ΒΆ
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_matchesrecord. -
computeβScore the accumulated scene records and return the per-class average precisions and their mean.
update [source] ΒΆ
update(match: InstanceMatches) -> None
Append one scene's instance_matches record.
Parameters:
-
match(InstanceMatches) βThe per-scene record returned by
instance_matches(per-instance counts, labels, scores and same-class pairwise intersections).
InstancePartMeanIntersectionOverUnion [source] ΒΆ
InstancePartMeanIntersectionOverUnion(
*,
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_intersection_over_union: 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-Dpredsis 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: