{"record":{"id":"085327be1fc2d0b4","repo":"docling-project/docling","slug":"expected-onnx-model-to-return-at-least-1-output-co","errorCode":null,"errorMessage":"Expected ONNX model to return at least 1 output containing logits","messagePattern":"Expected ONNX model to return at least 1 output containing logits","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"docling/models/inference_engines/image_classification/onnxruntime_engine.py","lineNumber":180,"sourceCode":"            or self._processor is None\n            or self._input_name is None\n            or self._output_name is None\n        ):\n            raise RuntimeError(\"Engine not initialized. Call initialize() first.\")\n\n        images = [item.image.convert(\"RGB\") for item in input_batch]\n        inputs = self._processor(images=images, return_tensors=\"np\")\n        input_tensor = np.asarray(inputs[\"pixel_values\"], dtype=np.float32)\n\n        output_tensors = self._session.run(\n            [self._output_name],\n            {\n                self._input_name: input_tensor,\n            },\n        )\n\n        if len(output_tensors) < 1:\n            raise RuntimeError(\n                \"Expected ONNX model to return at least 1 output containing logits\"\n            )\n\n        logits_batch = np.asarray(output_tensors[0], dtype=np.float32)\n        if logits_batch.ndim != 2:\n            raise RuntimeError(\n                \"Expected ONNX logits output shape [batch_size, num_classes], \"\n                f\"got shape={logits_batch.shape}\"\n            )\n\n        probs_batch = self._softmax(logits_batch)\n        return self._build_batch_outputs_from_probabilities(\n            input_batch=input_batch,\n            probs_batch=probs_batch,\n        )\n","sourceCodeStart":162,"sourceCodeEnd":196,"githubUrl":"https://github.com/docling-project/docling/blob/61d76f1ff3f8428065465889f7b4577da7df704c/docling/models/inference_engines/image_classification/onnxruntime_engine.py#L162-L196","documentation":"After running the ONNX session with the requested output name, the returned list of output tensors is empty. onnxruntime normally returns one array per requested output, so an empty result means the run produced nothing usable — an abnormal state usually tied to a degraded session or mismatched output request.","triggerScenarios":"OnnxRuntimeImageClassificationEngine.predict_batch() when session.run([output_name], {...}) returns a list shorter than 1 — practically only reachable with an inconsistent session state (e.g. session invalidated after a graph/file change) or an onnxruntime edge case.","commonSituations":"Session object reused after the underlying model file was replaced/deleted; onnxruntime version regression; exotic execution providers returning empty results on failure.","solutions":["Re-create the engine (fresh session) via initialize() and retry the batch.","Update/repair the onnxruntime installation if empty run results persist across fresh sessions.","Verify the requested output name still matches the loaded graph (re-resolve via session.get_outputs())."],"exampleFix":"# before: stale session after model file swap\nengine.predict_batch(batch)  # empty output_tensors\n\n# after: rebuild session and retry\nengine = OnnxRuntimeImageClassificationEngine(...)\nengine.initialize()\nengine.predict_batch(batch)","handlingStrategy":"retry","validationCode":"outputs = session.run([output_name], {input_name: tensor})\nif len(outputs) < 1:\n    raise RuntimeError(\"onnxruntime returned no output tensors — session state suspect\")","typeGuard":null,"tryCatchPattern":"try:\n    engine.predict_batch(batch)\nexcept RuntimeError as e:\n    if \"at least 1 output\" in str(e):\n        engine.initialize()  # fresh session fixes stale-state cases\n        engine.predict_batch(batch)\n    else:\n        raise","preventionTips":["Do not replace or delete model files while a session is live.","Recreate sessions after deployment changes instead of reusing them.","Pin a known-good onnxruntime version in production images."],"tags":["onnx","onnxruntime","empty-output","session-state"],"backgroundTag":null,"analyzedSha":"61d76f1ff3f8428065465889f7b4577da7df704c","analyzedAt":"2026-08-14T23:53:18.727Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}