docling-project/docling · error · RuntimeError

Expected ONNX model to return at least 3 outputs: [labels, b

Error message

Expected ONNX model to return at least 3 outputs: [labels, boxes, scores]

What it means

After running the ONNX session with 'images' and 'orig_target_sizes' inputs, the engine requires at least 3 output tensors (labels, boxes, scores). Fewer outputs means the loaded .onnx file is not an RT-DETR-style detection graph, so a RuntimeError is raised instead of misparsing outputs.

Source

Thrown at docling/models/inference_engines/object_detection/onnxruntime_engine.py:192

        images = [item.image.convert("RGB") for item in input_batch]
        inputs = self._processor(images=images, return_tensors="np")

        # Get original sizes for post-processing
        orig_sizes = np.array(
            [[img.width, img.height] for img in images], dtype=np.int64
        )

        # Run ONNX inference
        output_tensors = self._session.run(
            None,
            {
                "images": inputs["pixel_values"],
                "orig_target_sizes": orig_sizes,
            },
        )

        if len(output_tensors) < 3:
            raise RuntimeError(
                "Expected ONNX model to return at least 3 outputs: "
                "[labels, boxes, scores]"
            )

        labels_batch, boxes_batch, scores_batch = output_tensors[:3]

        batch_outputs: List[ObjectDetectionEngineOutput] = []
        for idx, input_item in enumerate(input_batch):
            batch_outputs.append(
                self._build_output(
                    input_item=input_item,
                    labels=labels_batch[idx],
                    scores=scores_batch[idx],
                    boxes=boxes_batch[idx],
                    apply_score_threshold=True,
                )
            )

View on GitHub (pinned to 61d76f1ff3)

Solutions

  1. Load the .onnx file with onnx.load and inspect graph.output — confirm it exposes labels/boxes/scores (3 outputs).
  2. Replace the file with a proper RT-DETR (or DETR-family) export matching Docling's expected contract.
  3. Fix options.model_filename or model spec extra_config so the correct model file is loaded.

Example fix

# verify the graph contract before running
import onnx
model = onnx.load(str(model_path))
assert len(model.graph.output) >= 3, model.graph.output
Defensive patterns

Strategy: validation

Validate before calling

import onnx
model = onnx.load(str(model_path))
if len(model.graph.output) < 3:
    raise ValueError(f"Not a DETR-style export: outputs={[o.name for o in model.graph.output]}")

Try / catch

try:
    outs = engine.predict_batch(batch)
except RuntimeError as e:
    if "at least 3 outputs" in str(e):
        raise RuntimeError("Loaded ONNX file is not an RT-DETR detection export") from e
    raise

Prevention

When it happens

Trigger: Loading a non-detection ONNX model (classifier, embedding model) as the object detector; an RT-DETR export that fused or renamed outputs; a quantized/rewritten graph where outputs were collapsed.

Common situations: Wrong model file placed in artifacts_path under the expected name; model_filename/extra_config pointing at another model; exporting with tools that wrap outputs into a single tensor.

Related errors


AI-assisted analysis of docling-project/docling@61d76f1ff3 (2026-08-14). Data as JSON: /api/errors/cc602427844026f6. Report an issue: GitHub.