{"record":{"id":"cc602427844026f6","repo":"docling-project/docling","slug":"expected-onnx-model-to-return-at-least-3-outputs","errorCode":null,"errorMessage":"Expected ONNX model to return at least 3 outputs: [labels, boxes, scores]","messagePattern":"Expected ONNX model to return at least 3 outputs: \\[labels, boxes, scores\\]","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"docling/models/inference_engines/object_detection/onnxruntime_engine.py","lineNumber":192,"sourceCode":"        images = [item.image.convert(\"RGB\") for item in input_batch]\n        inputs = self._processor(images=images, return_tensors=\"np\")\n\n        # Get original sizes for post-processing\n        orig_sizes = np.array(\n            [[img.width, img.height] for img in images], dtype=np.int64\n        )\n\n        # Run ONNX inference\n        output_tensors = self._session.run(\n            None,\n            {\n                \"images\": inputs[\"pixel_values\"],\n                \"orig_target_sizes\": orig_sizes,\n            },\n        )\n\n        if len(output_tensors) < 3:\n            raise RuntimeError(\n                \"Expected ONNX model to return at least 3 outputs: \"\n                \"[labels, boxes, scores]\"\n            )\n\n        labels_batch, boxes_batch, scores_batch = output_tensors[:3]\n\n        batch_outputs: List[ObjectDetectionEngineOutput] = []\n        for idx, input_item in enumerate(input_batch):\n            batch_outputs.append(\n                self._build_output(\n                    input_item=input_item,\n                    labels=labels_batch[idx],\n                    scores=scores_batch[idx],\n                    boxes=boxes_batch[idx],\n                    apply_score_threshold=True,\n                )\n            )\n","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/docling-project/docling/blob/61d76f1ff3f8428065465889f7b4577da7df704c/docling/models/inference_engines/object_detection/onnxruntime_engine.py#L174-L210","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Load the .onnx file with onnx.load and inspect graph.output — confirm it exposes labels/boxes/scores (3 outputs).","Replace the file with a proper RT-DETR (or DETR-family) export matching Docling's expected contract.","Fix options.model_filename or model spec extra_config so the correct model file is loaded."],"exampleFix":"# verify the graph contract before running\nimport onnx\nmodel = onnx.load(str(model_path))\nassert len(model.graph.output) >= 3, model.graph.output","handlingStrategy":"validation","validationCode":"import onnx\nmodel = onnx.load(str(model_path))\nif len(model.graph.output) < 3:\n    raise ValueError(f\"Not a DETR-style export: outputs={[o.name for o in model.graph.output]}\")","typeGuard":null,"tryCatchPattern":"try:\n    outs = engine.predict_batch(batch)\nexcept RuntimeError as e:\n    if \"at least 3 outputs\" in str(e):\n        raise RuntimeError(\"Loaded ONNX file is not an RT-DETR detection export\") from e\n    raise","preventionTips":["Validate the ONNX graph contract (>=3 outputs) in artifact preparation scripts.","Keep model_filename/extra_config pointing at the certified RT-DETR export.","Smoke-test inference after any model file replacement."],"tags":["onnx","model-mismatch","validation","object-detection"],"backgroundTag":null,"analyzedSha":"61d76f1ff3f8428065465889f7b4577da7df704c","analyzedAt":"2026-08-14T23:53:18.727Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}