Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Training Finished, now what? How to use model in unity?

Discussion in 'ML-Agents' started by andrewCra, Mar 18, 2023.

  1. andrewCra


    Jan 1, 2023
    Hi all,
    sorry if this is a beginner questions. I have honestly tried to find the answer, but I'm unable to find anything on how to use the trained model, once the training session finishes or is interrupted.

    I have followed the tutorials below, but neither details how to get the output file *.ONNX to work as a TF-Model in unity

    I know in the second tutorial mentioned above it mentions:
    "Saved Model message"
    However I never saw that message in the terminal. But I did find the .ONNX file in <projectFolder>/results/<trainingSessionName>/trainingSessionName.onnx

    The way I finalized the session was:
    1. hit play button again (aka stop)
    2. wait for indication it's ok to ctrl+c

    output trace:
    [INFO] RollerBall. Step: 90000. Time Elapsed: 1200.220 s. Mean Reward: 0.990. Std of Reward: 0.099. Training.
    [INFO] RollerBall. Step: 100000. Time Elapsed: 1331.158 s. Mean Reward: 0.995. Std of Reward: 0.073. Training.
    [WARNING] Restarting worker[0] after 'Communicator has exited.'
    [INFO] Listening on port 5004. Start training by pressing the Play button in the Unity Editor.
    [INFO] Learning was interrupted. Please wait while the graph is generated.
    [INFO] Exported results\RollerBall_tf\RollerBall\RollerBall-106775.onnx
    [INFO] Copied results\RollerBall_tf\RollerBall\RollerBall-106775.onnx to results\RollerBall_tf\RollerBall.onnx.

    Any idea what I'm missing?
    Is that the onnx file I need? If so, how do I get this into the "Model" Field in my "Behavior Parameters" script under the agent?

  2. al3xj3ns3n


    Sep 10, 2018
    Find that onnx file in your explorer and copy it over into the Assets folder for your unity project. Locate it within the Unity project tab and drag it onto the Model field of the Behavior Parameters of your agent prefab.
  3. smallg2023


    Sep 2, 2018
    it will only say it has finished training if you reach the max steps, otherwise you can just train it until you are happy with it and stopping it early is fine