Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
Dismiss Notice
Join us now in the Performance Profiling Dev Blitz Day 2023 - Q&A forum where you can connect with our teams behind the Memory and CPU Profilers and the Frame Debugger.

"the external ONNX file data" to NNModel Instance

Discussion in 'ML-Agents' started by gichan_unity, Sep 7, 2021.

  1. gichan_unity

    gichan_unity

    Joined:
    Sep 7, 2021
    Posts:
    4
    I would like to read the external ONNX file of ML-Agent and import it during runtime.

    The code I wrote is as follows.

    upload_2021-9-7_12-0-12.png

    save me.

    Please....
     
    Last edited: Sep 10, 2021
  2. gichan_unity

    gichan_unity

    Joined:
    Sep 7, 2021
    Posts:
    4
    upload_2021-9-8_15-48-4.png
    this is error text
     
  3. gft-ai

    gft-ai

    Joined:
    Jan 12, 2021
    Posts:
    44
  4. gichan_unity

    gichan_unity

    Joined:
    Sep 7, 2021
    Posts:
    4
    I'll check. Thank you for your interest.
     
  5. gichan_unity

    gichan_unity

    Joined:
    Sep 7, 2021
    Posts:
    4
  6. gft-ai

    gft-ai

    Joined:
    Jan 12, 2021
    Posts:
    44
    I don’t quite understand what you mean?
    Maybe it might help if you explained what you have done and what you want to achieve?

    Where is this .onnx model from? Did you train a model using mlagents or did you train a model somewhere else and converted into onnx and you want to load it to unity? Need more context! :)
     
  7. unity_72548131E1D9F001A288

    unity_72548131E1D9F001A288

    Joined:
    Oct 30, 2021
    Posts:
    1
    Having the same issue with a build. The model is trained using ML-Agents but it is not in the Projects Asset directory. It's being loaded from a completely different directory. Not sure why but unless the NNModel is in the asset database, which isn't an option for a build, it will throw the error 244.
     
  8. IkigaiMonkey

    IkigaiMonkey

    Joined:
    Sep 22, 2012
    Posts:
    18
    Hey guys, did anyone solve this?

    We need to load models that we download in runtime from a webserver, and we execute it in a build (not in Editor), is it possible?
    All the examples and code I find only work within Editor using the Resources Folder.
     
  9. maxgrafqmul

    maxgrafqmul

    Joined:
    Oct 5, 2020
    Posts:
    3
    Any updates on this?
     
  10. maxgrafqmul

    maxgrafqmul

    Joined:
    Oct 5, 2020
    Posts:
    3
    Edit: figured it out. For future people wanting to dynamically load ONNX model files from disk without relying on Resources or Assets:

    Code (CSharp):
    1. var ONNXPath = "/my/onnx/path/file.onnx";
    2. var converter = new ONNXModelConverter(optimizeModel: true); // requires the Unity.Barracuda.ONNX assembly
    3.  
    4. // Read file at path and convert to byte array
    5. byte[] modelData = File.ReadAllBytes(ONNXPath);
    6. var model = converter.Convert(modelData); // type is Unity.Barracuda.Model
    7. // profit...
     
    jdmcgraw likes this.