Skip to main content
This guide walks you through the essential steps to run inference with ONNX Runtime. We’ll cover loading a model, preparing inputs, running inference, and processing outputs.

Prerequisites

Before you begin, make sure you have:
  • ONNX Runtime installed (Installation Guide)
  • An ONNX model file (.onnx)
  • Basic familiarity with your programming language of choice
Don’t have an ONNX model? You can export models from PyTorch, TensorFlow, scikit-learn, and other frameworks. See Model Conversion for details.

Basic Workflow

The typical ONNX Runtime inference workflow consists of these steps:
1

Create an InferenceSession

Load your ONNX model and create a session object.
2

Prepare Input Data

Format your input data as tensors matching the model’s input specifications.
3

Run Inference

Execute the model with your input data.
4

Process Outputs

Extract and use the inference results.

Python

Python is the most popular language for machine learning and provides the simplest API.

Complete Example

Using Execution Providers

Accelerate inference with GPU or other hardware:

Session Options

Customize session behavior for better performance:

IO Binding (Advanced)

For maximum performance with GPU inference:

C++

C++ provides the lowest latency and is ideal for production deployments.

Complete Example

Using CUDA Execution Provider

C#

C# provides a clean, type-safe API for .NET applications.

Complete Example

Using GPU Execution Providers

Java

Java provides a robust API for enterprise applications.

Complete Example

Using CUDA Execution Provider

JavaScript

JavaScript enables ML inference in both Node.js and web browsers.

Complete Example

Using Execution Providers

Common Patterns

Batch Inference

Process multiple inputs in a single inference call:

Dynamic Shapes

Handle models with dynamic input shapes:

Error Handling

Properly handle errors during inference:

Next Steps

Execution Providers

Learn how to leverage GPU, NPU, and other hardware accelerators

Performance Tuning

Optimize inference speed and memory usage

Model Optimization

Convert and optimize models for production

API Reference

Explore the complete API documentation