2023-03-05

What is ONNX

What is ONNX

The Open Neural Network Exchange (ONNX) is an open-source project that aims to provide a standard format for representing deep learning models. Developed by Microsoft, Facebook, and other industry partners, ONNX enables developers to share and deploy models across different deep learning frameworks like PyTorch and TensorFlow, and hardware platforms seamlessly.

The main goals of the ONNX project are to:

  • Improve interoperability between deep learning frameworks, making it easier for developers to train and deploy models using their preferred tools.
  • Enable hardware vendors to optimize their platforms for ONNX models, ensuring maximum performance and efficiency.
  • Encourage the development of an ecosystem of tools and libraries that support the ONNX format, fostering innovation and collaboration in the deep learning community.

Key Features of ONNX

ONNX offers several features that make it an attractive choice for representing deep learning models:

  • Standardized format
    ONNX provides a well-defined schema for representing neural networks, including their architecture, weights, and metadata. This schema is designed to be both human-readable and machine-interpretable, making it easy to work with ONNX models.

  • Extensible operator set
    ONNX includes a comprehensive set of predefined operators (operations) that cover most common neural network layers and functions. Additionally, ONNX allows developers to define custom operators for specialized use cases, ensuring flexibility and extensibility.

  • Wide framework support
    Many popular deep learning frameworks, such as TensorFlow, PyTorch, and Caffe2, offer native support for ONNX, enabling developers to import and export models between these frameworks with minimal effort.

  • Efficient runtime
    ONNX Runtime is a high-performance, cross-platform library for running ONNX models on various hardware platforms, including CPUs, GPUs, and edge devices. ONNX Runtime provides optimizations for specific hardware, ensuring the best possible performance.

  • Growing ecosystem
    The ONNX project has attracted a vibrant community of developers and organizations, resulting in a growing ecosystem of tools, libraries, and pre-trained models that support the ONNX format.

Supported Frameworks and Tools

The ONNX ecosystem encompasses a wide range of deep learning frameworks and tools that offer support for the ONNX format. Some of the most popular frameworks with ONNX support include:

  • TensorFlow
    An open-source machine learning library developed by Google, widely used for training and deploying neural networks.

  • PyTorch
    A popular deep learning framework developed by Facebook, known for its dynamic computation graph and user-friendly interface.

  • Caffe2
    A lightweight, modular, and scalable deep learning framework developed by Facebook, designed for high-performance deployment on various platforms.

  • Apache MXNet
    A flexible and efficient deep learning library, with support for various programming languages and a focus on distributed computing.

  • Keras
    A high-level neural networks API, capable of running on top of TensorFlow, Microsoft Cognitive Toolkit, and others.

These frameworks provide tools and utilities to convert models to and from the ONNX format, enabling seamless model sharing and interoperability.

https://onnx.ai/supported-tools.html

ONNX Runtime

ONNX Runtime is a high-performance, cross-platform library for running ONNX models. Developed by Microsoft, it provides an efficient and straightforward way to perform inference on ONNX models across various hardware platforms, including CPUs, GPUs, and edge devices. ONNX Runtime offers support for a wide range of ONNX operators and optimizations for specific hardware, ensuring maximum performance.

Key features of ONNX Runtime include:

  • High performance
    ONNX Runtime is optimized for speed and can efficiently execute complex models on various hardware platforms.

  • Cross-platform
    It supports Windows, Linux, and macOS, as well as popular cloud platforms like GCP and AWS.

  • Hardware acceleration
    ONNX Runtime can take advantage of the latest hardware accelerators, such as NVIDIA GPUs and Intel FPGAs, to accelerate model inference.

  • Language bindings
    It offers APIs for popular programming languages, including Python, C++, and C#.

  • Model optimization
    ONNX Runtime provides tools to optimize models for better performance and reduced memory footprint.

https://onnxruntime.ai/docs/

ONNX File Format

The ONNX file format is designed to be both human-readable and machine-interpretable, making it easier to understand and work with. An ONNX model file contains a serialized representation of a neural network, including its architecture, weights, and metadata. The main components of an ONNX file are:

  • ModelProto
    The top-level structure containing all the information about the model, such as its graph, metadata, and model version.

  • GraphProto
    A substructure within ModelProto that represents the neural network's computation graph, including nodes (operations), inputs, outputs, and initializers (weights and biases).

  • NodeProto
    Each node in the graph represents an operation (such as convolution or matrix multiplication) with input and output tensors.

  • TensorProto
    A multidimensional array of data used for representing inputs, outputs, and weights in the model. TensorProto includes information about data type, dimensions, and the actual data in raw or specialized formats.

  • OperatorSet
    A collection of operators (operations) supported by the model. Each OperatorSet is associated with a version and a domain to ensure backward compatibility.

ONNX Model Zoo

The ONNX Model Zoo is a collection of pre-trained models available in ONNX format, contributed by the community and various organizations. These models cover a wide range of tasks and domains, including image classification, object detection, natural language processing, and more. The ONNX Model Zoo provides an excellent starting point for developers looking to incorporate pre-trained models into their applications or use them as a basis for transfer learning.

Some popular models available in the ONNX Model Zoo include:

  • ResNet
    A family of deep residual networks for image classification, known for their excellent performance and efficiency.

  • MobileNet
    A set of efficient models for mobile and embedded vision applications, designed for low-latency and low-power consumption.

  • BERT
    A transformer-based model for natural language processing tasks, such as question answering and sentiment analysis.

  • YOLO
    A state-of-the-art object detection model known for its speed and accuracy.

https://github.com/ankkhedia/model-zoo

References

https://github.com/onnx/onnx
https://onnxruntime.ai/docs/
https://github.com/onnx/models
https://github.com/ankkhedia/model-zoo

Ryusei Kakujo

researchgatelinkedingithub

Focusing on data science for mobility

Bench Press 100kg!