Green check
Link copied to clipboard

Using the ONNX integration​ to export Ultralytics YOLO models

Learn how to export Ultralytics YOLO models, such as Ultralytics YOLO11, using the ONNX integration for cross-platform deployment across various hardware.

When AI solutions first started gaining attention, most models were deployed on powerful servers in controlled environments. However, as technology has advanced, deployment has expanded far beyond the data center.

Today, AI models run on everything from cloud servers and desktops to smartphones and edge devices. This shift supports faster processing, offline functionality, and smarter systems that operate closer to where the data is generated.

One area where this is especially clear is computer vision - a branch of AI that enables machines to interpret visual data. It is being used to drive applications like facial recognition, autonomous driving, and real-time video analysis. As these use cases grow, so does the need for models that can run smoothly across diverse hardware and platforms.

But deploying computer vision models across a range of deployment targets isn’t always simple. Devices differ in terms of hardware, operating systems, and supported frameworks, making flexibility and compatibility essential.

That’s why having the option to export computer vision models like Ultralytics YOLO11 to different formats is key. For instance, the ONNX (Open Neural Network Exchange) integration supported by Ultralytics provides a practical way to bridge the gap between training and deployment. ONNX is an open format that makes models framework-agnostic and deployment-ready across platforms.

Fig 1. ONNX helps you take a model trained in one framework and run it in another easily.

In this article, we’ll take a closer look at the ONNX integration supported by Ultralytics and explore how you can export your YOLO11 model for flexible, cross-platform deployment.

What is ONNX and ONNX Runtime?

The Open Neural Network Exchange is an open-source project that defines a standard format for machine learning models. Originally developed by Microsoft and Facebook, it allows developers to train a model in one framework, like PyTorch, and run it in another, such as TensorFlow. This makes AI development more flexible, collaborative, and accessible, especially in fields like computer vision.

ONNX provides a common set of operators and a unified file format, making it easier to move models between different tools, frameworks, runtimes, and compilers. Normally, a model trained in one framework isn’t easily compatible with another - but with ONNX, you can export your model once and deploy it almost anywhere: on CPUs (Central Processing Units), GPUs (Graphics Processing Units), mobile devices, or edge hardware.

Also, ONNX Runtime is a high-performance inference engine developed specifically to run models in the ONNX format. It’s designed to make ONNX models run faster and more efficiently across a wide range of platforms - including servers, mobile devices, and edge hardware. ONNX Runtime is compatible with popular frameworks like PyTorch, TensorFlow, TensorFlow Lite, and scikit-learn, making it easy to integrate into different workflows and deploy models wherever they’re needed.

Fig 2. ONNX and ONNX Runtime enable flexible cross-platform model deployment.

Key features of ONNX 

Before we discuss how to export YOLO11 to ONNX format, let’s check out some key features of the ONNX model format. 

Whether you're switching between tools, deploying to different devices, or upgrading systems, ONNX helps keep everything running smoothly. Here’s what makes the ONNX model format unique:

  • One standard format: ONNX uses a common way to describe how models are built, like layers and operations (think of them as building blocks). When a model is converted to ONNX, it follows this standard so that any system that supports ONNX can understand and run it.
  • Backward compatibility: Even as ONNX continues to improve, it ensures that older models still work with newer versions. This means you don’t have to retrain or rebuild your models every time ONNX gets an update.
  • Graph-based model design: ONNX models are structured as computation graphs, where each node represents an operation (such as a layer or mathematical function), and edges indicate the flow of data. This graph-based design facilitates integration with various systems that utilize similar computational graph structures.
  • Developer-friendly tools: It comes with a wide range of tools that help you convert, validate, and optimize your models. These tools simplify the process of moving models between different frameworks and can speed up deployment - especially for computer vision applications.

An overview of the ONNX integration

Exporting Ultralytics YOLO models like Ultralytics YOLO11 in ONNX format is straightforward and it can be done in a few steps. 

To get started, install the Ultralytics Python package using a package manager like ‘pip’. This can be done by running the command “pip install ultralytics” in your command prompt or terminal to get started.

With the Ultralytics package, you can easily train, test, fine-tune, export, and deploy models for various computer vision tasks - making the whole process faster and more efficient. While installing it, if you encounter any difficulties, you can refer to the Common Issues guide for solutions and tips.

Once the Ultralytics package is installed, you can load and export the YOLO11 model to ONNX format using the code below. This example loads a pre-trained YOLO11 model (yolo11n.pt) and exports it as an ONNX file (yolo11n.onnx), making it ready for deployment across different platforms and devices.

from ultralytics import YOLO

model = YOLO("yolo11n.pt")

model.export(format="onnx") 

After converting your model to ONNX format, you can deploy it on a variety of platforms. 

The example below shows how to load the exported YOLO11 model (yolo11n.onnx) and run an inference with it. Inferencing simply means using the trained model to make predictions on new data. In this case, we’ll use the URL of an image of a bus to test the model.

onnx_model = YOLO("yolo11n.onnx")

results = onnx_model("https://ultralytics.com/images/bus.jpg",save=True)

When you run this code, the following output image will be saved in the runs/detect/predict folder.

Fig 3. Running an inference using the exported YOLO11 model on an image.

When should you choose the ONNX integration?

The Ultralytics Python package supports exporting models to several formats, including TorchScript, CoreML, TensorRT, and ONNX. So, why choose ONNX?

What makes ONNX stand out is that it’s a framework-agnostic format. While many other export formats are tied to specific tools or environments, ONNX uses a standardized format and a shared set of operators. This makes it highly portable, hardware-friendly, and ideal for cross-platform deployment - whether you're working with cloud servers, mobile apps, or edge devices. 

Here’s are some reasons why the ONNX integration could be the ideal choice for your YOLO11 projects:

  • Portable deployment: Once exported to ONNX, your YOLO11 model can be deployed on various platforms without code changes or retraining.
  • Industry-wide support: ONNX is supported by major AI companies and frameworks, making it a reliable, widely accepted format. It ensures long-term compatibility, much like how PDFs work across devices.
  • Future-proof development: Using ONNX helps protect your model investments. As tools evolve, ONNX keeps your models relevant and usable, even in new or different environments.
  • No vendor lock-in: Some tools tie you to using only their system, which can limit what your model can do. ONNX avoids that by letting you choose the platform that works best for your needs, without being stuck with a single setup.

Applications of YOLO11 and the ONNX model format

Next, let’s explore some real-world applications where YOLO11 can be deployed with the help of the ONNX integration.

Tracking inventory at warehouses using YOLO11

In busy warehouses, it’s difficult to keep an eye on every product and package at all times. Computer vision systems can help workers find products on shelves and get insights such as, the number of products, type, etc. Such systems can assist businesses automatically manage their vast inventory and save warehouse workers a lot of time.

Specifically, in smart warehouses, YOLO11 models exported to ONNX can be used to identify and count items in real time using cameras and edge devices. The exported model can help scan shelves or pallets to detect stock levels, missing items, or empty spots. Since exporting to ONNX makes the model lightweight and efficient, it can run directly on small edge devices, such as smart cameras, removing the need for expensive servers or constant cloud access.

Fig 4. An example of using YOLO11 to detect and count packages.

Hospital waste management with YOLO11

Hospitals all around the world create large amounts of waste every day, from used gloves and syringes to equipment used during surgery (like single-use or contaminated surgical tools like scissors and scalpels). In fact, research shows that hospitals produce around 5 million tones of waste every year, which is 29 pounds of waste per bed per day. 

Sorting such waste properly is essential for hygiene, safety, and following regulations. With YOLO11 models exported in ONNX format, hospitals can automate and monitor waste disposal in real time.

For instance, cameras placed near waste bins in areas like operating rooms or hallways can monitor items as they are discarded. A custom YOLO11 model, trained to recognize different types of medical waste, can analyze the footage and identify what’s being thrown away. If an item ends up in the wrong bin, like a used syringe in regular trash, the system can be set up to immediately alert staff with a light or sound, helping to prevent contamination and ensure compliance.

Fig 5. Using YOLO11 to detect medical instruments.

YOLO11-enabled crop monitoring

Knowing the right time to harvest crops can have a big impact on both the quality of the produce and the overall productivity of a farm. Traditionally, farmers rely on experience and manual inspections - but with recent advances in technology, that’s starting to change.

Now, with computer vision innovations like YOLO11, exported in ONNX format, farmers can bring automation and precision into the field. By using drones or cameras mounted on tractors or poles, farmers can capture images of their crops (such as tomatoes, apples, or wheat). YOLO11 can then be used to detect key indicators like color, size, and the distribution of crops. Based on this information, farmers can determine whether the crops are ready to harvest, still maturing, or already past their peak.

Fig 6. YOLO11 can be used to detect crops in aerial drone footage. 

ONNX limitatations to consider

While ONNX offers numerous benefits, such as portability, cross-platform compatibility, and framework interoperability, there are some limitations to keep in mind:​

  • Model size: Converting models to ONNX format can sometimes result in larger file sizes compared to their original formats. Techniques like quantization and pruning can help mitigate this issue by reducing model size without significantly impacting performance.​
  • Runtime compatibility: Although ONNX Runtime is designed for cross-platform compatibility, performance and support can vary across different hardware and operating systems. 
  • Debugging challenges: Debugging ONNX models can be more complex than in native frameworks like PyTorch or TensorFlow. Error messages may be less descriptive, making it harder to pinpoint issues. However, tools like Netron for model visualization and ONNX Runtime's logging capabilities can assist in troubleshooting.

Key takeaways

Exporting Ultralytics YOLO11 to ONNX makes it easy to take a trained computer vision model and deploy it almost anywhere - whether that’s on a laptop, mobile device, or even a compact smart camera. With the ONNX integration, you’re not tied to a single framework or platform, giving you the flexibility to run your model in the environment that suits your application best. 

This makes the transition from training to real-world deployment faster and more efficient. Whether you're tracking inventory in a warehouse or ensuring hospital waste is disposed of correctly, this setup helps systems run more smoothly, reduces errors, and saves valuable time.

Want to learn more about computer vision and AI? Explore our GitHub repository, connect with our community, and check out our licensing options to jumpstart your computer vision project. If you're exploring innovations like AI in manufacturing and computer vision in the automotive industry, visit our solutions pages to discover more. 

LinkedIn logoTwitter logoFacebook logoCopy-link symbol

Read more in this category

Let’s build the future
of AI together!

Begin your journey with the future of machine learning