←back to Blog

OpenCV 5.1 ONNX Support: What the 85.83% Test Score Means

Consider a photo classifier in an OpenCV application. Before it can return a label, the program must decode the image, prepare the pixels, and run the trained model. An exported model may contain some of that preparation itself. Whether the application works then depends on whether OpenCV understands every required step.

OpenCV 5.1 handles more of those steps and their variations. In the November 30, 2026 snapshot of the official ONNX backend scoreboard, it passes 1,745 of 2,033 tests, or 85.83%. An earlier OpenCV 5.0 snapshot passed 64.54%. The improvement reflects both work in OpenCV and an update to the software used to test it.

An image classifier that accepts the bytes of a JPEG file and decodes them inside the model provides a useful example. We will use it to explain what broader ONNX support can change for an application.

What You Will Learn

  • How an ONNX file describes a trained model and the calculations needed to run it.
  • What changed in OpenCV 5.1, and what the ONNX test score tells you.
  • How image decoding can become part of a model instead of separate application code.
  • How to check compatibility and speed for the model you plan to deploy.

From an ONNX file to a prediction

After training a model in a framework such as PyTorch, you can export it to ONNX for use in another program. The file stores the learned weights and describes the calculations needed to produce an answer. Running those calculations on a new image is called inference.

ONNX describes the calculations as a graph, which you can read like a flowchart. Each step, called an operator, performs a task such as multiplying arrays or resizing an image. The connections carry arrays of numbers, often called tensors, from one step to the next.

OpenCV’s deep neural network, or DNN, engine loads this graph and runs its steps. ONNX Runtime is another library that can run ONNX models. Supporting the file format is only the beginning: a library must also handle the operators, number formats, and array sizes used by a particular export.

What changed in OpenCV 5.1?

OpenCV 5.0 shipped the older DNN engine alongside a new graph engine. OpenCV 5.1 removes the older engine and uses the new one for native ONNX inference. It also removes the TensorFlow importer. The DNN team now has one native graph engine to develop and optimize. The OpenCV 5.1 release notes describe these changes and the additions below.

Some compatibility problems come from how numbers are stored. A model might use ordinary 32-bit floating-point values in one step and smaller, more compact formats in another. Recognizing the calculation is not enough if the engine cannot handle its input or output format.

OpenCV 5.1 expands Cast and CastLike, the operators that convert between number formats. The additions include FP8, FP4, INT4, UINT4, and E8M0. It also adds signed and unsigned 16-bit integer support to QuantizeLinear and DequantizeLinear. These operators convert between floating-point values and compact integer representations, a process called quantization and its reverse. Each addition supports particular operator and format combinations; it does not give every calculation support for every format.

Attention is another area of work. In a transformer model, attention lets one part of the input use information from other parts. A language model can save information about earlier text instead of calculating it again for each new piece. OpenCV 5.1 adds support for that stored history through the past and present key/value inputs and outputs of ONNX Attention. It also extends grouped-query attention with rotary embeddings, and adds LinearAttention and FlexAttention layers.

Recurrent networks process sequences while carrying information from one step to the next. OpenCV 5.1 fixes details in two such network types, LSTM and GRU. These include LSTM peephole connections, which let its stored state influence how information is retained, and batch-first layout, which places the number of sequences first in an array’s dimensions. Such details can decide whether a model runs correctly after export.

What does 85.83% test coverage mean?

The ONNX backend tests check small graphs against expected answers. Different cases exercise different inputs and settings. Passing more cases is evidence of broader compatibility, but it is not a count of complete applications or production models.

Runtime Passing tests Pass rate Operator types with passing coverage
OpenCV 5.0.0.93 1,312 / 2,033 64.54% 158 / 205
OpenCV 5.1.0.95 1,745 / 2,033 85.83% 170 / 205
ONNX Runtime 1.32.0 1,705 / 2,033 83.87% 186 / 205

These are CPU results using ONNX 1.23.2. The OpenCV 5.0 row comes from November 17, 2026; the other two rows come from November 30. OpenCV’s passing count rose from 1,312 to 1,745: 433 more cases and about 21.3 percentage points. Every percentage includes all 2,033 cases, including failures and skipped tests. The OpenCV results and ONNX Runtime results contain the detailed histories.

ONNX 1.23.2 backend test results. OpenCV 5.0: November 17, 2026; OpenCV 5.1 and ONNX Runtime: November 30. These snapshots include an OpenCV scoreboard adapter update; they are not a controlled comparison that changes only the runtime version.

The testing software changed between these snapshots too. A test adapter connects the ONNX tests to OpenCV’s Python interface. A November adapter update preserved FP16, FP8, and other output formats instead of converting them to ordinary floating-point values. The same OpenCV 5.1 package scored 83.67% before that update. The current score therefore captures the release’s capabilities more accurately; the full increase cannot be attributed to changing the OpenCV version alone.

The last column counts operator types that appear in passing tests. OpenCV passes more individual cases in this snapshot, while ONNX Runtime covers more operator types: 186 versus 170. Passing a test for an operator does not establish support for every version, shape, format, or setting of that operator. An 85.83% test score does not mean that 85.83% of all models will run.

A model that accepts JPEG bytes

Applications usually decode a JPEG into pixels before giving those pixels to a classifier. The ONNX ImageDecoder operator lets that first step sit inside the graph. It was introduced in opset 20. An opset identifies the versions of ONNX operator definitions that a model uses.

OpenCV 5.1 includes an ImageDecoder implementation based on its own image codecs. The graph can therefore contain decoding, resizing, adjusting pixel values, and the classifier itself. Preparing pixels for a model is called preprocessing.

The SqueezeNet example includes image decoding and preprocessing in the ONNX graph. This diagram explains the workflow; it is not an execution trace or a benchmark result.

In the SqueezeNet example, the model accepts raw JPEG bytes and performs decoding and preprocessing inside the graph. OpenCV 5.1 runs the complete graph. ONNX Runtime 1.32’s CPU path fails to load its ImageDecoder node with a NOT_IMPLEMENTED error. Moving decoding into application code lets ONNX Runtime run the remaining graph.

Keeping these preparation steps with the model means each application does not have to recreate them separately. The demonstration concerns this graph and these runtime versions. Another model may need different operators or image codecs, so its support still needs checking.

Does broader support also mean faster inference?

Compatibility and speed need separate measurements. A model can run correctly and still take longer than another implementation. The published OpenCV 5.1 DNN benchmarks compare its CPU engine with ONNX Runtime 1.31 on several systems.

On the AMD Ryzen 9 9950X, OpenCV has lower median inference time on 45 of the 65 models that both libraries completed. ONNX Runtime has lower times on 18; two are tied at the table’s reported precision. The median is the middle value in a sorted set of measurements.

Both libraries received the same inputs and used 32 threads, without core pinning, on this 16-core Linux system. The table reports medians from repeated runs. OpenCV was built without CUDA, OpenCL, or the ONNX Runtime backend, so these timings measure its CPU engine. This benchmark uses ONNX Runtime 1.31; the test-coverage comparison uses 1.32. They are separate experiments.

Checking your own model

If an earlier OpenCV release could not run your export, 5.1 is worth another test. Use the OpenCV 5.1 release with the exact ONNX file you intend to deploy. Check its opset, input dimensions, number formats, and preprocessing requirements. A model exported with different settings can take a different path through the engine.

Compare the outputs with a reference implementation before measuring speed. Then time the model on the hardware and thread settings your application will use. Include image preparation and result handling when measuring the complete application. For supported graphs, OpenCV can keep decoding, preprocessing, inference, and post-processing in one library. The JPEG example shows one way to move more of that work into the model itself.

Thanks to the OpenCV DNN contributors and ONNX scoreboard maintainers.

The post OpenCV 5.1 ONNX Support: What the 85.83% Test Score Means appeared first on OpenCV.