output= — Final Output Structure
output= declares the shape of what the model call returns. Mirror the return value as it is.
(If you passed your own function to postprocess=, declare that function's return
structure here instead.)
OutputSchema fields
| Field | Type | Contents |
|---|---|---|
structure |
structure node | The final-output container structure |
slice_with |
callable | For containers whose rows are sliced unusually: slice_with(container, keep_indices) -> container |
A structure node passed straight to output= becomes OutputSchema(structure=...).
from ml_debugger.spec import OutputSchema
output=OutputSchema(structure=S.BatchAxis[...], slice_with=my_slice_fn)
Assembling the structure
| What the model returns | How to write it |
|---|---|
| A list / object per image | S.BatchAxis[...] at the top |
A batched dict ({boxes: (B, N, 4), ...}) |
S.BatchAxis on each branch |
| A tuple or list | S.Seq(...) to split by position |
| One tensor packing several meanings | S.Channels(leaf, ...) to split the last dimension |
| Somewhere the above cannot express | S.Getter(fn) to pull it out |
| A branch missing entirely when there are no detections | missing_ok=["key"] on that S.Dict (default is a zero-length S.DetAxis) |
| Padded fixed length, with the valid row count on another branch | An S.ValidCount() leaf on that branch |
S.BatchAxis[...] is the sample (image) axis; S.DetAxis[...] is the detection axis.
The common 2D detection shape (list-of-dicts)
Models following the torchvision convention — a list of per-image
{"boxes","scores","labels", ...} dicts.
spec = ModelSpec(
labels=LabelSchema(n_class=3, ground_truth=gt),
output=S.BatchAxis[ # per-image list
S.Dict(
boxes=S.DetAxis[S.Coords("xyxy", "pixel")], # boxes: pixel xyxy
scores=S.DetAxis[S.Score("raw")], # confidence
labels=S.DetAxis[S.LabelId(0)], # class id (0-based)
cls_logits=S.DetAxis[S.ClassConfs(3, "raw", "none")], # per-class confidence
)
],
)
| Leaf | Arguments | Meaning |
|---|---|---|
S.Coords(box_format, scale) |
box_format: "xyxy" / "cxcywh" / "xywh" / "yxyx"scale: "pixel" / "normalized" |
2D box |
S.Score(activation) |
"raw" / "sigmoid" / "softmax" |
Detection score (one column) |
S.LabelId(base) |
0 / 1 |
Class-id base |
S.ClassConfs(n_class, activation, background) |
background: "none" / "index0" / "last" |
Per-class confidence vector (one column per class) |
For models whose output has no S.ClassConfs column, see raw_output=.
S.Score vs S.ClassConfs
S.Score is the score of one detection (a single column); S.ClassConfs is the confidence
vector across classes (one column per class). A model that emits both can declare both.
When candidates carry objectness separately from the class distribution, declare the objectness
with S.Objectness().
Common variations
Normalized coordinates / cxcywh
Declared as leaf attributes. If the model returns a single-image dict (no image axis),
omit S.BatchAxis.
output=S.Dict( # no image axis (one image)
bbox=S.DetAxis[S.Coords("cxcywh", "normalized")],
conf=S.DetAxis[S.Score("raw")],
cls=S.DetAxis[S.LabelId(0)],
)
The reference size for normalized coordinates
By default the reference size is the input image size (size_from="input").
If the output uses its own target size, declare it with size_from=.
S.Coords("cxcywh", "normalized", size_from=(640, 640)) # a fixed (H, W) tuple
S.Coords("cxcywh", "normalized", size_from="meta.image_size") # a dotted path inside the container
S.Coords("cxcywh", "normalized", size_from=lambda c, i: (h, w)) # fn(container, i) -> (H, W)
When no image size is available from the input
Setups where the model is called with file paths cannot yield an input tensor, so normalized
coordinates cannot be restored. Declare size_from= explicitly, or declare inputs=.
Custom object outputs
If the model returns instances of your own class rather than dicts, use S.Obj.
Pass the class as the first argument and declare locations by attribute name.
output=S.BatchAxis[
S.Obj(
MyDetections, # a class with boxes / scores / labels attributes
boxes=S.DetAxis[S.Coords("xyxy", "pixel")],
scores=S.DetAxis[S.Score("raw")],
labels=S.DetAxis[S.LabelId(0)],
)
]
HuggingFace-style outputs
Models returning values on object attributes such as .logits can also be read with S.Dict
(it reads dict keys and object attributes alike).
When the key name varies between models
S.Dict(key_aliases=...) names the alternative keys to read when the declared key is absent, e.g.
S.Dict(boxes=..., key_aliases={"boxes": ["bboxes"]}).
3D detection
The common 3D shape is a query head (returning (B, Q, C) scores and (B, Q, D) boxes), written as
raw_output= + TopK. Box layouts are declared with S.Coords3D(layout=...).
layout |
Width | Columns | pc_range |
|---|---|---|---|
"standard_7" (default) |
7 | [x, y, z, w, l, h, yaw] (meters) |
Not needed |
"velocity_9" |
9 | [x, y, z, w, l, h, yaw, vx, vy] (mmdet3d-style) |
Not needed |
"velocity_9_yaw_last" |
9 | [x, y, z, w, l, h, vx, vy, yaw] (det3d-style) |
Not needed |
"normalized_8" |
8 | Normalized coordinates | Required |
"normalized_10" |
10 | Normalized coordinates (BEVFormer-style) | Required |
"mmdet3d_logdim" |
10 | Metric centers, log-encoded dimensions | Not needed |
"camera_7_lhw" |
7 | [x, y, z, l, h, w, rot_y] (monocular camera heads) |
Not needed |
There are two nine-column velocity layouts
The order of yaw and velocity differs between implementation families.
mmdet3d-style ([..., yaw, vx, vy]) is "velocity_9"; det3d-style ([..., vx, vy, yaw]) is
"velocity_9_yaw_last". Mixing them up records yaw and velocity swapped, so check the column
order of the implementation you use.
S.Coords3D also takes two coordinate-frame arguments:
| Argument | Contents |
|---|---|
frame |
The frame the boxes live in: "camera" / "lidar" / "ego" / "ground". |
to_ground |
The sensor mounting used by that conversion (frame="camera" only). A 4x4 / 3x3 matrix, or a mapping of height / pitch / roll. |
spec = ModelSpec(
labels=LabelSchema(
n_class=3,
ground_truth=S.BatchAxis[
S.Dict(
gt_boxes=S.DetAxis[S.Coords3D(layout="standard_7")],
gt_labels=S.DetAxis[S.LabelId(0)],
)
],
),
raw_output=S.Dict(
cls_scores=S.DetAxis[S.ClassConfs(3, "sigmoid", "none")],
bbox_preds=S.DetAxis[S.Coords3D(layout="velocity_9")],
),
postprocess=TopK(max_num=300), # the top K become the final detections
)
3D models that return detections directly as a list of per-frame dicts can be written like 2D, with
S.Coords3D leaves in output= and no postprocess.
Classification
For classification you declare just two things: where the prediction is and which activation it
carries. There is no candidate pruning, so postprocess= is unused, and the final layer need not be
an nn.Linear.
If the model returns a (batch, n_class) tensor, the return value itself is the prediction.
spec = ModelSpec(
labels=LabelSchema(n_class=5),
output=S.ClassConfs(activation="raw"), # "raw" = unactivated logits
)
Models returning them on a HuggingFace-style .logits attribute name the location by key.
spec = ModelSpec(
labels=LabelSchema(n_class=5),
output=S.Dict(logits=S.ClassConfs(activation="raw")),
)
activation |
Meaning |
|---|---|
"raw" |
Unactivated logits |
"softmax" |
Softmaxed probabilities |
"sigmoid" |
Sigmoided probabilities |
Related pages
- labels= — GT uses the same leaves
- postprocess= — when the return value is not the final detections
- Cheat Sheet — every leaf and structure node, with examples