py123d_detection.torch.visualize.py123d_interop

Predictions as py123d’s own detection type, so py123d’s viewer can draw them.

py123d ships a Viser viewer and the element system around it (py123d.visualization.viser). Writing a second one here would copy several thousand lines of maintained code into a package whose point is to be dependable, so this package provides the one piece that was genuinely missing: the conversion from a predictions file to the type that viewer already knows how to draw.

Two levels are offered, because they fail differently. to_box_array() is pure geometry and depends on nothing but numpy, so if a box comes out in the wrong place it is wrong here and a test can say so. to_detections() builds py123d’s object graph on top of it and needs py123d imported. That part translates labels and bookkeeping, not geometry.

Needs the viz extra for the drawing helpers; the conversion itself needs only py123d, which the base install already requires.

Module Attributes

YAW

Our box layout, [x, y, z, w, l, h, yaw, vx, vy].

BOX_ARRAY_COLUMNS

py123d's BoundingBoxSE3Index: [X, Y, Z, QW, QX, QY, QZ, LENGTH, WIDTH, HEIGHT].

Functions

add_to_viser(server, frame[, name, ...])

Draw one frame's boxes into a running viser server as wireframes.

frames_by_token(path[, dataset])

A predictions file indexed by frame token, for a viewer stepping through a scene.

label_lookup(taxonomy)

Our class names back to py123d labels, inverting the taxonomy's own map.

to_box_array(boxes)

(N, 7+) boxes in this package's layout as (N, 10) in py123d's.

to_detections(frame, taxonomy[, ...])

One frame as a BoxDetectionsSE3, ready for py123d's viewer or its matplotlib helpers.

tokens_in_order(frames)

Frame tokens sorted by their frame index, which is how a scene is walked.

unmapped_classes(taxonomy)

Classes of this taxonomy that py123d has no label for.

wireframe(boxes)

(N, 12, 2, 3) line segments for a set of boxes, via py123d's own corner maths.

py123d_detection.torch.visualize.py123d_interop.YAW = 6

Our box layout, [x, y, z, w, l, h, yaw, vx, vy].

py123d_detection.torch.visualize.py123d_interop.BOX_ARRAY_COLUMNS = 10

py123d’s BoundingBoxSE3Index: [X, Y, Z, QW, QX, QY, QZ, LENGTH, WIDTH, HEIGHT].

py123d_detection.torch.visualize.py123d_interop.to_box_array(boxes)[source]

(N, 7+) boxes in this package’s layout as (N, 10) in py123d’s.

The two differ in more than order: ours carries yaw as an angle and sizes as w, l, h, while py123d carries a quaternion and length, width, height. Getting w and l the wrong way round swaps every box’s footprint and still renders a plausible scene, so it is pinned by a test against py123d’s own corner maths.

Return type:

ndarray

py123d_detection.torch.visualize.py123d_interop.label_lookup(taxonomy)[source]

Our class names back to py123d labels, inverting the taxonomy’s own map.

A taxonomy records py123d label to class name, which is many-to-one: general_3cls sends both VEHICLE and TRAIN to vehicle. Going back therefore loses information, and the first label that maps to a class wins, which is the representative one in every taxonomy shipped here. Inverting the taxonomy rather than writing a second table means the two cannot drift apart.

Return type:

Dict[str, Any]

py123d_detection.torch.visualize.py123d_interop.unmapped_classes(taxonomy)[source]

Classes of this taxonomy that py123d has no label for.

py123d’s vocabulary is coarse on purpose, VEHICLE and TWO_WHEELER rather than car, truck, bus, trailer, bicycle and motorcycle, so a fine-grained taxonomy cannot round-trip through it. mixed_8cls loses four of its eight classes, and nuscenes_detection_10cls loses all ten because it is built from native_map rather than default_map. Those boxes still draw, as GENERIC_OBJECT; what they lose is their colour in the viewer’s legend.

Return type:

Sequence[str]

py123d_detection.torch.visualize.py123d_interop.to_detections(frame, taxonomy, ground_truth=False, score_threshold=0.0, timestamp_us=0)[source]

One frame as a BoxDetectionsSE3, ready for py123d’s viewer or its matplotlib helpers.

Parameters:
  • ground_truth (bool) – Convert the frame’s ground truth instead of its predictions.

  • score_threshold (float) – Predictions below this are left out; ignored for ground truth, which carries no score.

  • timestamp_us (int) – The frame’s time. A predictions file records none, because the metric has no use for one, so the caller supplies it when the viewer needs frames ordered.

Return type:

Any

py123d_detection.torch.visualize.py123d_interop.wireframe(boxes)[source]

(N, 12, 2, 3) line segments for a set of boxes, via py123d’s own corner maths.

This is what a viser overlay draws. Using py123d’s helpers rather than py123d_detection.torch.visualize.boxes keeps the viewer’s geometry identical to everything else py123d renders in the same scene. A test checks that the two agree, but agreeing by construction beats agreeing by coincidence.

Return type:

ndarray

py123d_detection.torch.visualize.py123d_interop.add_to_viser(server, frame, name='/predictions', score_threshold=0.3, colour=(214, 39, 40), line_width=3.0, ground_truth=False, origin=None)[source]

Draw one frame’s boxes into a running viser server as wireframes.

Wireframes rather than solid meshes so predictions read as an overlay on whatever the scene already shows, which is how the thesis distinguished them from ground truth.

Parameters:

origin (Optional[ndarray]) – Subtracted from every point. py123d’s viewer draws a scene relative to its centre, because a 123D scene sits at global coordinates large enough to cost visible precision; an overlay that skips this lands hundreds of metres from everything else. py123d_detection.torch.visualize.viewer.PredictionsElement passes the scene centre.

Return type:

Any

Returns:

the viser handle, so a caller stepping through frames can update or hide it.

py123d_detection.torch.visualize.py123d_interop.frames_by_token(path, dataset=None)[source]

A predictions file indexed by frame token, for a viewer stepping through a scene.

Return type:

Dict[str, FramePrediction]

py123d_detection.torch.visualize.py123d_interop.tokens_in_order(frames)[source]

Frame tokens sorted by their frame index, which is how a scene is walked.

A token is <scene uuid>:<frame index>, so sorting them as strings puts frame 10 before frame 2. Sorting on the parsed index is the difference between a scene that plays and one that jumps about.

Return type:

Sequence[str]