Skip to content

Cheat Sheet

Every node and field used to write a ModelSpec, at a glance.

from ml_debugger.spec import ModelSpec, LabelSchema, InputSchema, RawOutputSchema, OutputSchema
from ml_debugger.spec import NMS, InModelNMS, TopK, Decode, PostProcess, ImageShapes
from ml_debugger.spec import Invoke, LayerHook, HeadHook, NClassFrom
from ml_debugger.spec import FromCall, NMSScoreThresh, NMSIouThresh, NMSMaxDet
from ml_debugger.spec import inspect_model, infer_spec, validate_spec
from ml_debugger.spec import schema as S      # every leaf / structure node lives under S.*

Leaf nodes (S.* — terminals that carry meaning)

Leaf Example Meaning
S.Coords S.Coords("xyxy", "pixel") 2D box → formats
S.Coords3D S.Coords3D(layout="standard_7") 3D box → layouts
S.Score S.Score("raw") Detection score (one column). "raw" / "sigmoid" / "softmax"
S.LabelId S.LabelId(0) Class id (one column). 0- or 1-based
S.ClassConfs S.ClassConfs(3, "raw", "none") Per-class confidence vector. Arguments are class count, activation, background position ("none" / "index0" / "last")
S.Objectness S.Objectness("sigmoid") Objectness (one column). The default in_score=True means it multiplies into the selection score
S.ClassConfMap S.ClassConfMap() A spatial class-confidence map, read per detection at the box center
S.KeepIndex S.KeepIndex() Indices of the kept detections, as reported by the model
S.Velocity S.Velocity() Velocity block (N, 2)
S.BackgroundConf S.BackgroundConf() A standalone background-confidence column
S.ValidCount S.ValidCount() Valid row count for padded fixed-length outputs
S.Array S.Array(("C", "H", "W"), input_tensor=True) Generic array. input_tensor=True marks the input the model read
S.Ignore S.Ignore() Skipped (for recorded)

S.Coords — 2D box formats

S.Coords(box_format="xyxy", scale="pixel", size_from="input")
Argument Accepted values
box_format "xyxy" / "cxcywh" / "xywh" / "yxyx"
scale "pixel" / "normalized"
size_from "input" (default) / an (H, W) tuple / a dotted path inside the container / fn(container, i) -> (H, W)

S.Coords3D — 3D box layouts

S.Coords3D(layout="velocity_9", pc_range=None, frame=None, to_ground=None)
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
Argument Accepted values
pc_range [x_min, y_min, z_min, x_max, y_max, z_max]. Required for the normalized layouts
frame "camera" / "lidar" / "ego" / "ground".
to_ground The sensor mounting when frame="camera". A 4x4 / 3x3 matrix, or {"height":..., "pitch":..., "roll":...}

Structure and axis nodes (S.* — building the nesting)

Node Example Meaning
S.BatchAxis S.BatchAxis[S.Dict(...)] The sample (image / frame) axis
S.DetAxis S.DetAxis[S.Coords("xyxy", "pixel")] The detection (candidate) axis
S.Axis S.Axis("layer", take=-1)[S.DetAxis[...]] A named axis. take=int picks one slice; take="flatten" fuses it into the following DetAxis
S.Dict S.Dict(boxes=..., scores=...) Dict keys / object attributes
S.Obj S.Obj(MyDetections, boxes=..., scores=...) An instance of a specific class (read by attribute)
S.Seq S.Seq(boxes_node, scores_node, labels_node) Split a tuple / list by position
S.Channels S.Channels(S.Coords("xyxy","pixel"), S.Score("raw")) Split one tensor's last dimension across leaves
S.Getter S.Getter(lambda c: c.dets)[S.DetAxis[...]] Escape hatch: pull a value out with a function

Supporting arguments:

Argument Example Meaning
S.Dict(missing_ok=[...]) S.Dict(boxes=..., missing_ok=["boxes"]) Keys that may be absent entirely when there are no detections
S.Dict(key_aliases={...}) S.Dict(boxes=..., key_aliases={"boxes": ["bboxes"]}) Alternative keys, read only when the declared key is absent
S.DetAxis(valid_by=...) S.DetAxis(valid_by="score", valid_min=0.0)[...] Drop padding rows by score

ModelSpec fields

Field Type Main fields Page
labels LabelSchema n_class / ground_truth labels=
inputs InputSchema structure / resolve inputs=
invoke Invoke method / unpack_input / kwargs / container invoke=
raw_output RawOutputSchema structure / hook raw_output=
postprocess NMS / TopK / callable → postprocess= postprocess=
output OutputSchema structure / slice_with output=

Structure nodes can be passed directly

A structure node passed straight to raw_output= / output= / inputs= is wrapped in the corresponding *Schema automatically.

Post-processing fields

Class Main fields
NMS score_thresh_attr / iou_thresh_attr / max_det_attr / apply_func / custom / decode / min_box_edge_px / prenms_topk_per_class / clip_boxes_to_image / nms_mode
TopK max_num / score_thresh / topk_mode / decode
InModelNMS method / returns / kwargs / decoder / decode / activation
PostProcess fn / kwargs
Decode fn / returns / kwargs

Call-time markers

Marker Purpose
FromCall() Forwards the same-named tracer(...) kwarg to the model
NMSScoreThresh() / NMSIouThresh() / NMSMaxDet() Placeholders for NMS thresholds taken as inference arguments
ImageShapes() Passes image sizes to a post-processing function (2D detection only)

Functions and entry points

Name Purpose
inspect_model(model, sample_batch=..., ground_truth=...) Infer a ModelSpec, with questions → AutoMode
infer_spec(model, known={...}) Get a ModelSpec in one line; raises SpecInferenceError when something is missing
validate_spec(spec, model, sample_batch) Validate against the real model → Validation
spec.verify(model, sample_batch) The same checks, as a method

Pattern quick reference

Model shape Declaration
2D detector returning a list of per-image dicts output=S.BatchAxis[S.Dict(boxes=..., scores=..., labels=...)]
Returns a single-image dict output=S.Dict(...) (no BatchAxis)
Returns a tuple output=S.Seq(...)
Classification (returns logits directly) output=S.ClassConfs(activation="raw")
Classification (a .logits attribute) output=S.Dict(logits=S.ClassConfs(activation="raw"))
Query head (top K) raw_output=S.Dict(...) + postprocess=TopK(max_num=...)
NMS thresholds in model attributes postprocess=NMS(score_thresh_attr=..., iou_thresh_attr=..., max_det_attr=...)
NMS is an in-model method postprocess=NMS(custom=InModelNMS(method=..., returns=...))
Custom post-processing function raw_output=... + postprocess=<fn> + output=<its return structure>
Inference goes through another method invoke=Invoke(method="forward_test")
Input is a file path S.Array(..., input_tensor=True) inside output, or inputs=InputSchema(resolve=fn)