Implementation:Microsoft Onnxruntime Numpy Output Extraction
Appearance
Metadata
| Field | Value |
|---|---|
| Implementation Name | Numpy_Output_Extraction |
| Repository | Microsoft_Onnxruntime |
| Source Repository | https://github.com/microsoft/onnxruntime |
| Type | Pattern Doc |
| Language | Python |
| Domain | ML_Inference, Model_Optimization |
| Last Updated | 2026-02-10 |
| Workflow | Python_Inference_Pipeline |
| Pair | 6 of 6 |
Overview
Pattern documentation for extracting and interpreting ONNX Runtime inference outputs using standard numpy array indexing on session.run() return values.
API Signature
results = session.run([output_name], {input_name: x})
predictions = results[0] # Standard list/array indexing
Import
import numpy
Code Reference
| Reference | Location |
|---|---|
| Usage example | docs/python/examples/plot_load_and_predict.py:L55 |
I/O Contract
Inputs
| Parameter | Type | Required | Description |
|---|---|---|---|
Results from session.run() |
list[numpy.ndarray] |
Yes | The list of numpy arrays returned by the inference session's run method. |
Outputs
| Output | Type | Description |
|---|---|---|
| predictions | numpy.ndarray |
Individual output tensor extracted by list index. |
| predicted_class | numpy.ndarray |
(For classification) Class labels derived via numpy.argmax().
|
| probabilities | numpy.ndarray |
(For probabilistic models) Probability distributions over classes. |
Usage Example
Basic Output Extraction
results = sess.run([output_name], {input_name: x})
predictions = results[0] # First output tensor
Classification Post-Processing
results = sess.run([output_name], {input_name: x})
predictions = results[0]
# Extract predicted class label
predicted_class = numpy.argmax(predictions, axis=-1)
Multiple Output Extraction
# Request multiple outputs
label_name = sess.get_outputs()[0].name
prob_name = sess.get_outputs()[1].name
results = sess.run([label_name, prob_name], {input_name: x})
labels = results[0] # Predicted labels
probabilities = results[1] # Probability distributions
From the source example at docs/python/examples/plot_load_and_predict.py:L54-55:
res = sess.run([output_name], {input_name: x})
print(res)
Related Pages
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment