Wiki › Project

ONNX models in Unity

Project · study · 2024

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

In the knowledge graph

ONNX models in Unity and the 12 things it is linked to. Open any dot for its page, or explore it in the full graph.

When
2023202420252026
May 2024 · 11 commits

As data

Everything on this page is read from triples in the knowledge graph. These are the 25 it states about ONNX models in Unity, and 3 more its ontology implies; the console runs SPARQL over the whole graph, here in your browser.

Download
@prefix id: <https://ask.chaipat.cc/id/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix cj: <https://ask.chaipat.cc/ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

id:UnityONNX
    a cj:Project ;
    rdfs:label "ONNX models in Unity" ;
    cj:description "Converting a Keras model to ONNX and running it inside Unity." ;
    cj:context id:OpenSource ;
    cj:repository "https://github.com/AppleBoiy/UnityONNX"^^xsd:anyURI ;
    cj:firstCommit "2024-05-18"^^xsd:date ;
    cj:lastCommit "2024-05-18"^^xsd:date ;
    cj:commitCount 11 ;
    cj:kind "study" ;
    cj:license "MIT" ;
    cj:theme id:ThemeUnity , id:ThemeML ;
    cj:uses id:Unity ,
            id:CSharp ,
            id:ONNX ,
            id:TensorFlow ,
            id:Tf2onnx ,
            id:Barracuda ,
            id:Python ;
    cj:tier 3 ;
    cj:runsOn id:macOS ;
    cj:handles id:ONNXFormat ;
    cj:article "https://ask.chaipat.cc/wiki/UnityONNX"^^xsd:anyURI ;
    cj:activeIn id:Y2024 ;
    cj:activity _:b173 .