Importing a trained model | Barracuda | 0.8.0-preview
docs.unity3d.com
    Show / Hide Table of Contents

    Importing a trained model

    Before you import a trained model, you must have exported your model to the ONNX format.

    Resource loading

    When you have a valid ONNX model, import it into your project; to do this, add the .onnx file to your project's Assets folder. Unity imports the model as an NNModel asset:

    Assets

    Assets

    You can then reference this asset directly in your script as follows:

    public NNModel modelAsset;
    

    A model is an asset wrapper and is stored in binary format. You must compile it into a run-time model (of type Model) like this:

    public NNModel modelAsset;
    private Model m_RuntimeModel;
    
    void Start()
    {   
        m_RuntimeModel = ModelLoader.Load(modelAsset);
    }    
    

    Runtime loading

    You can also use the ModelLoader to directly load the asset from a specified path:

    Model model = ModelLoader.Load(modelPath);
    

    For more information see Loading resources at runtime.

    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023