/onnxruntime-unity-examples

Examples for ONNX Runtime Unity Plugin

Primary LanguageShaderLab

ONNX Runtime examples for Unity

npm

Examples of ONNX Runtime Unity Plugin.

2023-12-25-onnx-yolox.mp4

Tested environment

How to Run

Try all examples

Pull this repository with Git-LFS

Install pre-built ONNX Runtime via Unity Package Manager (UPM)

Add the following scopedRegistries and dependencies in Packages/manifest.json.

  "scopedRegistries": [
    {
      "name": "NPM",
      "url": "https://registry.npmjs.com",
      "scopes": [
        "com.github.asus4"
      ]
    }
  ]
  "dependencies": {
    // Core library
    "com.github.asus4.onnxruntime": "0.1.5",
    // (Optional) Utilities for Unity
    "com.github.asus4.onnxruntime.unity": "0.1.5",
    ... other dependencies
  }

How to convert Onnx to Ort format

On the mobile platform, the *.onnx model is not recommended, although it's supported on the desktop. Convert the Onnx model to Ort format.

Please refer to the ORT model format for more details.

TL;DR;

# Recommend using python virtual environment
pip install onnx
pip install onnxruntime

# In general,
# Use --optimization_style Runtime, when running on mobile GPU
# Use --optimization_style Fixed, when running on mobile CPU
python -m onnxruntime.tools.convert_onnx_models_to_ort your_onnx_file.onnx --optimization_style Runtime

Acknowledgements