Wiki › Project

ONNX models in Unity

Article
From Chaipat's knowledge graph

ONNX models in Unity is a step-by-step guide, with a working Unity project, for running a deep-learning model trained in Keras inside a Unity game. It was tested on macOS with Unity 2023.2 and Python 3.11.

Steps

  1. Save the trained Keras model and export it in TensorFlow's SavedModel format.
  2. Convert it to ONNX, the open model-exchange format, with tf2onnx.
  3. Import the .onnx file into Unity and run it from C# with Unity's Barracuda inference library.

The README pins the exact library versions that worked (TensorFlow 2.16.1, Keras 3.3.3 and tf2onnx 1.16.1), because conversion is sensitive to versions.

See also