vision3d.metrics#
3D object detection evaluation metrics.
Classes
|
AP interpolation mode. |
|
3D detection mAP metric. |
Structured result returned by |
|
|
nuScenes Detection Score (NDS) metric. |
Structured result returned by |
|
Per-frame detection output. |
|
Per-frame ground-truth annotations. |
- class vision3d.metrics.APInterpolation(*values)[source]#
Bases:
EnumAP interpolation mode.
- R40 = 'r40'#
40-point interpolation (modern KITTI default).
- R11 = 'r11'#
11-point interpolation (legacy KITTI, PASCAL VOC07).
- R101 = 'r101'#
101-point interpolation (COCO).
- ALL_POINTS = 'all_points'#
VOC07 area-under-curve at every recall change.
- class vision3d.metrics.MeanAveragePrecision3D(class_ids, iou_thresholds=(0.5, 0.7), ap_interpolation=APInterpolation.R40, range_bins=None)[source]#
Bases:
object3D detection mAP metric.
Matching is greedy by descending score, one prediction to one ground truth, with precision/recall accumulated globally across frames (KITTI convention).
- Parameters:
class_ids (list[int]) – Integer class IDs to score. Predictions and GTs with labels outside this set are ignored.
iou_thresholds (tuple[float, ...]) – IoU thresholds to report AP at. Default
(0.5, 0.7).ap_interpolation (APInterpolation) – Interpolation mode. Default
APInterpolation.R40.range_bins (tuple[tuple[float, float], ...] | None) – Optional distance bins
[low, high)in meters from the sensor origin. When set, AP is also broken down per bin; boxes are bucketed by their center’s distance.
- update(preds, targets)[source]#
Accumulate one or more frames of predictions vs ground truth.
- Parameters:
preds (list[Prediction3D]) – List of per-frame
Prediction3Ddicts.targets (list[Target3D]) – List of per-frame
Target3Ddicts.
- Raises:
ValueError – If
predsandtargetsdiffer in length.- Return type:
None
- compute()[source]#
Compute the aggregated metric.
- Returns:
Populated
MeanAveragePrecision3DResult.- Return type:
- class vision3d.metrics.MeanAveragePrecision3DResult[source]#
Bases:
TypedDictStructured result returned by
MeanAveragePrecision3D.compute().Undefined slots (buckets with no ground-truth boxes accumulated) are reported as
-1.0and callers can filter them withx >= 0.- Variables:
mAP (float) – Overall mean AP, taken over every defined
(class, iou, bin)bucket.mAP_per_class (dict[int, float]) – AP per class, averaged over the other axes.
AP_per_iou (dict[float, float]) – AP per IoU threshold, averaged over the other axes.
AP_per_class_per_iou (dict[tuple[int, float], float]) – AP per
(class, iou)pair, averaged over range bins (or a single value when range bucketing is disabled).AP_per_range (dict[tuple[float, float], float]) – AP per range bin, averaged over the other axes. Only present when
range_binswas set on the metric.AP_per_class_per_range (dict[tuple[int, tuple[float, float]], float]) – AP per
(class, range_bin)pair, averaged over IoU thresholds. Only present whenrange_binswas set on the metric.
- class vision3d.metrics.NuScenesDetectionScore(class_ids, dist_thresholds=(0.5, 1.0, 2.0, 4.0), tp_threshold=2.0, min_recall=0.1, min_precision=0.1, mean_ap_weight=5.0, tp_metrics=TP_METRICS, orientation_periods=None, skip_tp_metrics=None)[source]#
Bases:
objectnuScenes Detection Score (NDS) metric.
Predictions are matched to ground truth greedily by ascending 2D center distance (within each frame, one ground truth per prediction), pooled across all frames and sorted by descending score. Average precision is integrated per distance threshold with the nuScenes recall/precision clipping, and the five TP error metrics are measured at
tp_threshold.- Parameters:
class_ids (list[int]) – Integer class IDs to score. Predictions and ground truths with labels outside this set are ignored.
dist_thresholds (tuple[float, ...]) – BEV center-distance match thresholds in meters over which AP is averaged. Default
(0.5, 1.0, 2.0, 4.0).tp_threshold (float) – The single distance threshold at which the TP error metrics are computed. Must be one of
dist_thresholds. Default2.0.min_recall (float) – Recall below which precision is discarded before integrating AP and TP errors. Default
0.1.min_precision (float) – Precision floor subtracted before integrating AP. Default
0.1.mean_ap_weight (float) – Weight of mAP relative to the TP scores in the NDS. Default
5.0.tp_metrics (tuple[str, ...]) – The TP error metrics that participate in the score, a subset of
("trans_err", "scale_err", "orient_err", "vel_err", "attr_err"). The NDS is normalized overmean_ap_weightplus the number of active TP metrics, so dropping a metric cleanly removes it rather than scoring it as a perfect (or worst-case) constant. Default: all five (the nuScenes setting). Drop"vel_err"/"attr_err"for datasets without velocity or attribute annotations."vel_err"requires per-boxvelocitiesand"attr_err"requiresattributeson every frame passed toupdate().orientation_periods (dict[int, float] | None) – Optional
{class_id: period}overriding the orientation periodicity (radians) used for the orientation error. Defaults to \(2\pi\) for every class.skip_tp_metrics (dict[int, set[str]] | None) – Optional
{class_id: set_of_metric_names}forcing the listed TP metrics tonanfor that class (and thus excluding it from those metrics’ class averages).
- Raises:
ValueError – If
class_idsordist_thresholdsis empty, iftp_thresholdis not indist_thresholds, or iftp_metricsis empty or names an unknown metric.
- classmethod from_class_names(class_names, dist_thresholds=(0.5, 1.0, 2.0, 4.0), tp_threshold=2.0, min_recall=0.1, min_precision=0.1, mean_ap_weight=5.0, tp_metrics=TP_METRICS)[source]#
Build the metric from class names using the nuScenes presets.
Class IDs are assigned by position (
class_names[i] -> i). For the official nuScenes classes this wires up thebarrierhalf-period orientation and thebarrier/traffic_coneTP-metric skips.The
orientation_periodsandskip_tp_metricsconstructor arguments are derived from the names and therefore cannot be set here; the remaining arguments are forwarded toNuScenesDetectionScoreunchanged.- Parameters:
class_names (list[str]) – Ordered class names; their indices become the integer class IDs scored by the metric.
dist_thresholds (tuple[float, ...]) – BEV center-distance match thresholds in meters over which AP is averaged.
tp_threshold (float) – The single distance threshold at which the TP error metrics are computed; must be one of
dist_thresholds.min_recall (float) – Recall below which precision is discarded before integrating AP and TP errors.
min_precision (float) – Precision floor subtracted before integrating AP.
mean_ap_weight (float) – Weight of mAP relative to the TP scores in the NDS.
tp_metrics (tuple[str, ...]) – The TP error metrics that participate in the score.
- Returns:
A configured
NuScenesDetectionScore.- Return type:
- update(preds, targets)[source]#
Accumulate one or more frames of predictions vs ground truth.
- Parameters:
preds (list[Prediction3D]) – List of per-frame
Prediction3Ddicts.targets (list[Target3D]) – List of per-frame
Target3Ddicts.
- Raises:
ValueError – If
predsandtargetsdiffer in length, or if an active TP metric needs annotations (velocitiesforvel_err,attributesforattr_err) that a frame does not provide.- Return type:
None
- compute()[source]#
Compute the aggregated NDS and its constituent metrics.
- Returns:
A populated
NuScenesDetectionScoreResult.- Return type:
- class vision3d.metrics.NuScenesDetectionScoreResult[source]#
Bases:
TypedDictStructured result returned by
NuScenesDetectionScore.compute().- Variables:
nd_score (float) – The nuScenes Detection Score, a weighted combination of
mean_apand the TP scores in[0, 1].mean_ap (float) – Mean Average Precision, averaged over distance thresholds and classes.
mean_dist_aps (dict[int, float]) – Per-class AP, averaged over distance thresholds. Keyed by class ID.
label_aps (dict[tuple[int, float], float]) – AP per
(class_id, distance_threshold)pair.tp_errors (dict[str, float]) – Mean TP error per active metric name (a subset of
trans_err,scale_err,orient_err,vel_err,attr_err), averaged over classes (ignoring skipped classes).tp_scores (dict[str, float]) – Per-metric score
max(0, 1 - error), for the active metrics only.label_tp_errors (dict[tuple[int, str], float]) – TP error per
(class_id, metric_name)pair over the active metrics;nanfor skipped class/metric combinations.
- class vision3d.metrics.Prediction3D[source]#
Bases:
TypedDictPer-frame detection output.
- Variables:
boxes (vision3d.tensors._bounding_boxes_3d.BoundingBoxes3D) –
[N, K]predicted 3D bounding boxes;Kdepends on the box format.scores (torch.Tensor) –
[N]confidence scores.labels (torch.Tensor) –
[N]integer class labels.velocities (torch.Tensor) – Optional
[N, 2]ground-plane (xy) velocities in m/s. Required byNuScenesDetectionScoreto compute the mean Average Velocity Error (AVE). Defaults to zeros when omitted.attributes (torch.Tensor) – Optional
[N]integer attribute labels. Used byNuScenesDetectionScoreto compute the mean Average Attribute Error (AAE). A negative value marks “no attribute”. Defaults to-1when omitted.
- class vision3d.metrics.Target3D[source]#
Bases:
TypedDictPer-frame ground-truth annotations.
- Variables:
boxes (vision3d.tensors._bounding_boxes_3d.BoundingBoxes3D) –
[M, K]ground-truth 3D bounding boxes.labels (torch.Tensor) –
[M]integer class labels.velocities (torch.Tensor) – Optional
[M, 2]ground-plane (xy) velocities in m/s. SeePrediction3D.attributes (torch.Tensor) – Optional
[M]integer attribute labels. A negative value marks “no attribute”, in which case the box is ignored when computing the attribute error. SeePrediction3D.