py123d_detection.core.evaluation

nuScenes-style detection metrics, for either branch and any set of class names.

The nuScenes devkit computes the metric this field reports, so this module runs the devkit’s own accumulate / calc_ap / calc_tp rather than reimplementing them. What it does not use is DetectionBox, whose constructor accepts only the ten nuScenes detection names. That single assertion is the reason a cross-dataset taxonomy such as vehicle / pedestrian / cyclist cannot be scored by the devkit at all, and the reason the thesis grew an 882-line reimplementation beside it. EvalBox carries the same fields without the whitelist, so one engine serves both branches and every taxonomy.

Ground truth and predictions arrive as EvalBox in the global frame. Each branch has its own adapter: py123d_detection.mmcv.plugin.evaluation builds them from an exported info pickle, the torch branch from 123D scenes.

Differences from the official protocol, all deliberate:

  • the ego position comes from the frame’s ego2global_translation rather than a LIDAR_TOP ego-pose record, because that is the quantity 123D actually stores;

  • there is no bike-rack filter, since there is no static_object.bicycle_rack to look up;

  • 123D carries no object attributes, so attr_err is nan per box and the devkit scores it as a flat 1.0. TP_METRIC_SETS lets you drop it instead; see evaluate().

Module Attributes

TP_METRIC_SETS

Which true-positive errors enter NDS.

UNDEFINED_TP_ERRORS

Errors that are meaningless for a class and are excluded from its average, as the devkit does.

Functions

add_center_distances(eval_boxes, ...)

Fill in each box's offset from its frame's ego position, in place.

build_detection_config(class_names[, ...])

A devkit DetectionConfig restricted to class_names.

evaluate(ground_truth, predictions, ...[, ...])

Score predictions against ground truth, following DetectionEval.evaluate.

filter_eval_boxes(eval_boxes, max_dist)

The devkit's filter_eval_boxes without the bike-rack step.

format_summary(summary)

The metrics table as the devkit's main() prints it, plus what was configured.

load_predictions(result_path, ...[, verbose])

Read a nuScenes-format result JSON into EvalBoxes of EvalBox.

to_eval_boxes(boxes_by_token)

Wrap per-frame boxes in the devkit's EvalBoxes container.

Classes

EvalBox(sample_token, translation, size, ...)

One box for the metric, in the global frame.

EvaluationInput([ground_truth, predictions, ...])

Everything the metric needs about one evaluation run.

py123d_detection.core.evaluation.TP_METRIC_SETS: Dict[str, Tuple[str, ...]] = {'no_attributes': ('trans_err', 'scale_err', 'orient_err', 'vel_err'), 'nuscenes': ('trans_err', 'scale_err', 'orient_err', 'vel_err', 'attr_err')}

Which true-positive errors enter NDS.

nuscenes is the official five. no_attributes drops attr_err, which is what you want whenever the data carries no attributes: the devkit scores a missing attribute as the worst possible value, so keeping it subtracts a flat 0.1 from NDS that says nothing about the model. NDS is then (k * mAP + sum of k scores) / 2k either way, so the two are not comparable and the choice is recorded in the summary.

py123d_detection.core.evaluation.UNDEFINED_TP_ERRORS: Dict[str, Tuple[str, ...]] = {'barrier': ('attr_err', 'vel_err'), 'traffic_cone': ('attr_err', 'vel_err', 'orient_err')}

Errors that are meaningless for a class and are excluded from its average, as the devkit does.

class py123d_detection.core.evaluation.EvalBox(sample_token, translation, size, rotation, detection_name, velocity=(0.0, 0.0), ego_translation=(0.0, 0.0, 0.0), num_pts=-1, detection_score=-1.0, attribute_name='')[source]

Bases: object

One box for the metric, in the global frame.

Field-compatible with the devkit’s DetectionBox, since the metric code reads these names, but without its assertion that detection_name is one of the ten nuScenes classes.

sample_token: str
translation: Tuple[float, float, float]
size: Tuple[float, float, float]

(width, length, height), the devkit’s wlh order.

rotation: Tuple[float, float, float, float]

Quaternion (w, x, y, z).

detection_name: str
velocity: Tuple[float, float] = (0.0, 0.0)
ego_translation: Tuple[float, float, float] = (0.0, 0.0, 0.0)

Box centre relative to the ego position. add_center_distances() fills it in.

num_pts: int = -1
detection_score: float = -1.0
attribute_name: str = ''
property ego_dist: float
serialize()[source]
Return type:

Dict[str, Any]

classmethod deserialize(content)[source]

Read one box of a nuScenes-format result JSON.

Return type:

EvalBox

class py123d_detection.core.evaluation.EvaluationInput(ground_truth=<factory>, predictions=<factory>, ego_translations=<factory>)[source]

Bases: object

Everything the metric needs about one evaluation run.

ground_truth: Dict[str, list]

Ground-truth boxes per frame token. Every evaluated frame needs an entry, empty or not: a frame left out is a frame the model is not penalised for missing.

predictions: Dict[str, list]
ego_translations: Dict[str, ndarray]

Ego position per frame token, used to compute each box’s distance from the ego vehicle.

py123d_detection.core.evaluation.build_detection_config(class_names, class_range=None, base='detection_cvpr_2019')[source]

A devkit DetectionConfig restricted to class_names.

DetectionConfig.__init__ insists on the ten nuScenes classes, so the named base config is created first and its plain attributes are narrowed afterwards.

Parameters:

class_range (Optional[Mapping[str, float]]) – Radius in metres per class, on top of the base config’s radii.

Raises:

ValueError – if a class has no radius. Guessing one silently decides how much of the scene counts, so it has to be stated.

py123d_detection.core.evaluation.to_eval_boxes(boxes_by_token)[source]

Wrap per-frame boxes in the devkit’s EvalBoxes container.

py123d_detection.core.evaluation.load_predictions(result_path, max_boxes_per_sample, verbose=False)[source]

Read a nuScenes-format result JSON into EvalBoxes of EvalBox.

py123d_detection.core.evaluation.add_center_distances(eval_boxes, ego_translations)[source]

Fill in each box’s offset from its frame’s ego position, in place.

The devkit’s add_center_dist reads the ego pose from a nuScenes database; here it comes from the frame itself.

Return type:

None

py123d_detection.core.evaluation.filter_eval_boxes(eval_boxes, max_dist)[source]

The devkit’s filter_eval_boxes without the bike-rack step.

Drops boxes beyond their class radius, and boxes explicitly recorded as having zero lidar points. A count of -1 means the dataset does not record one, and is kept.

Return type:

Tuple[int, int]

Returns:

box counts before and after.

py123d_detection.core.evaluation.evaluate(ground_truth, predictions, class_names, ego_translations, output_dir=None, class_range=None, eval_version='detection_cvpr_2019', tp_metrics='nuscenes', verbose=True)[source]

Score predictions against ground truth, following DetectionEval.evaluate.

Parameters:
  • ground_truth (Mapping[str, Iterable[EvalBox]]) – Boxes per frame token, in the global frame. Every evaluated frame needs an entry even when it has no box, or the frames a model failed on vanish from recall.

  • predictions – Either the same mapping shape, or an EvalBoxes from load_predictions().

  • ego_translations (Mapping[str, ndarray]) – Ego position per frame token.

  • tp_metrics (str) – A key of TP_METRIC_SETS.

Raises:

AssertionError – if the prediction and ground-truth frames differ. Scoring a subset silently inflates recall, which is the one mistake this metric cannot show you.

Return type:

Dict[str, Any]

Returns:

The devkit’s serialized metrics plus evaluation describing how they were made.

py123d_detection.core.evaluation.format_summary(summary)[source]

The metrics table as the devkit’s main() prints it, plus what was configured.

Return type:

str