py123d_detection.torch.predictions¶
Predictions on disk, written one frame at a time and read back the same way.
Evaluation used to hold every frame’s boxes in memory until the whole run was scored, which on a three-dataset validation pass meant tens of millions of box objects and, in one case, an OOM kill at 67 GB. Writing each frame out as it is predicted keeps the peak at one frame, and makes the far more useful thing possible: scoring a checkpoint again, with a different class range, true-positive set or box cap, without running the model again.
The format is JSON Lines, one object per frame, with the boxes as arrays rather than one object per box:
{"token": "<scene uuid>:<frame>", "dataset": "nuscenes", "ego_translation": [x, y, z],
"boxes": [[x, y, z, w, l, h, yaw, vx, vy], ...], "scores": [...], "labels": [...],
"gt_boxes": [...], "gt_labels": [...]}
Arrays rather than per-box objects because a frame carries up to 900 predictions and the nuScenes result format spends about ten keys on each of them. Ground truth travels with the predictions so a file is enough to re-score on its own; it is a few boxes a frame against hundreds of predictions, so it costs almost nothing.
Boxes are in the global frame, already converted, because that is what the metric measures in and converting once is what keeps predictions and ground truth honest with each other.
This is not the nuScenes submission format. py123d_detection.core.evaluation.load_predictions()
still reads that, for a file produced elsewhere.
Module Attributes
Columns of a box: |
Functions
|
Which datasets a predictions file covers, in the order they first appear. |
|
Frames of one dataset, or all of them when |
|
Concatenate per-rank prediction files into one, keeping each frame once. |
|
Per-rank prediction files in a stable order, so a merge is reproducible. |
|
Stream a predictions file back, one frame at a time. |
Classes
|
One frame's predictions and ground truth, in the global frame. |
|
Append frames to a JSON Lines file, one line at a time. |
- py123d_detection.torch.predictions.BOX_COLUMNS = 9¶
Columns of a box:
[x, y, z, w, l, h, yaw, vx, vy].
- class py123d_detection.torch.predictions.FramePrediction(token, dataset, ego_translation, boxes, scores, labels, gt_boxes, gt_labels, ego_pose=None)[source]¶
Bases:
objectOne frame’s predictions and ground truth, in the global frame.
- ego_translation: ndarray¶
(3,)ego position, which the metric turns into each box’s distance from the vehicle.
- ego_pose: ndarray | None = None¶
(4, 4)ego-to-global pose, when the writer had it.The metric needs only the translation, to measure each box’s distance from the vehicle. A bird’s-eye view wants the rotation too, so it can draw the scene the way the vehicle was facing rather than aligned to global north. Optional so a file written before this field still reads.
- as_json()[source]¶
A plain dict, with full float precision so a re-score reproduces the first one exactly.
- class py123d_detection.torch.predictions.PredictionWriter(path)[source]¶
Bases:
objectAppend frames to a JSON Lines file, one line at a time.
Used as a context manager so a crashed run still leaves a readable file of everything predicted up to that point, which is what makes a failed evaluation diagnosable instead of just lost.
- py123d_detection.torch.predictions.read_predictions(path)[source]¶
Stream a predictions file back, one frame at a time.
- Return type:
- py123d_detection.torch.predictions.dataset_names(path)[source]¶
Which datasets a predictions file covers, in the order they first appear.
- py123d_detection.torch.predictions.frames_for(path, dataset=None)[source]¶
Frames of one dataset, or all of them when
datasetis None.- Return type:
- py123d_detection.torch.predictions.rank_files(directory)[source]¶
Per-rank prediction files in a stable order, so a merge is reproducible.
- py123d_detection.torch.predictions.merge_rank_files(paths, out)[source]¶
Concatenate per-rank prediction files into one, keeping each frame once.
Deduplication is not tidiness, it is correctness.
DistributedSamplerpads the last batch so every rank sees the same number of samples, which means the first few frames of a split are handed to two ranks and would otherwise be scored twice. The dataset can repeat a token on its own account too: when a frame is rejected by the box filters it walks forward to the next usable one, so two indices can return the same frame.Scoring a frame twice inflates both its hits and its misses, and scoring a subset inflates recall. Neither shows up as an error, so the counts are returned for the caller to log.