Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Microsoft Onnxruntime InferenceSession Run

From Leeroopedia


Metadata

Field Value
Implementation Name InferenceSession_Run
Repository Microsoft_Onnxruntime
Source Repository https://github.com/microsoft/onnxruntime
Type API Doc
Language Python
Domain ML_Inference, Model_Optimization
Last Updated 2026-02-10
Workflow Python_Inference_Pipeline
Pair 5 of 6

Overview

API documentation for the session.run() method, which executes the forward pass on a loaded ONNX model and returns the requested output tensors as numpy arrays.

API Signature

session.run(output_names: list[str] | None, input_feed: dict[str, numpy.ndarray]) -> list[numpy.ndarray]

Import

No additional import is needed beyond the InferenceSession and numpy (for input preparation).

Code Reference

Reference Location
Usage example docs/python/examples/plot_load_and_predict.py:L54

I/O Contract

Inputs

Parameter Type Required Description
output_names list[str] or None Yes List of output tensor names to retrieve. Pass None to retrieve all outputs.
input_feed dict[str, numpy.ndarray] Yes Dictionary mapping input tensor names to numpy arrays containing the input data.

Outputs

Output Type Description
return value list[numpy.ndarray] A list of numpy arrays, one per requested output, in the order specified by output_names.

Usage Example

# Run with specific output
res = sess.run([output_name], {input_name: x})

# Run with all outputs
res = sess.run(None, {input_name: x})

From the source example at docs/python/examples/plot_load_and_predict.py:L54:

res = sess.run([output_name], {input_name: x})
print(res)

From the profiling example at docs/python/examples/plot_profiling.py:L42:

res = sess.run(None, {input_name: x})

Complete Inference Pipeline

import numpy
import onnxruntime as rt

# Load model
sess = rt.InferenceSession("model.onnx", providers=rt.get_available_providers())

# Inspect metadata
input_name = sess.get_inputs()[0].name
output_name = sess.get_outputs()[0].name

# Prepare input
x = numpy.random.random((3, 4, 5)).astype(numpy.float32)

# Run inference
res = sess.run([output_name], {input_name: x})
print(res[0])

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment