Unity ML Agents Training Commands

Basic Training Method (through Unity Editor)

This method is good for quickly checking to see if everything is working. For serious training it is recommended that you use the faster method below.

  1. Go to your terminal and run the following command:
    • mlagents-learn config/agent_config.yaml --run-id=RunIdExample
  2. Wait until you get the printout that tells you to go hit the play button
  3. Go back to unity and press the play button to see the training happen

Stopping and resuming training

    • To stop training, hit “ctrl/cmd + c” on your keyboard
    • To resume training, you can use the argument resume
    • To overwrite training, use the argument force
mlagents-learn config/agent_config.yaml --run-id=RunIdExample --resume

Faster Training Method (via Project Build)

Running mlagents as an executable rather than in the editor allows you to run multiple copies of the agent at the same time. It can be done by building the project and then running using that build.

  1. Build the Unity file
    1. File -> Build Settings
    2. In the window that pops up, make sure you have “PC, Mac & Linux Standalone” selected as the platform
    3. Hit build (bottom right)
    4. Navigate to the build folder in the unity project
      • For Windows: Create a new folder and name it something, and click on the created folder
      • For Mac: type in a name for the build
    5. Click Select and wait as until your project finished building
  2. Run the following command:
    • For Windows:
      • mlagents-learn config/agent_config.yaml --run-id=RunIdExample --env="Build/<exampleFolder>/Final Project Testing V2" --num-envs=2
    • For Mac:
      • mlagents-learn config/agent_config.yaml --run-id=RunIdExample --env="BuildName" --num-envs=2
    • Number of copies running can be modified by changing the  num-envs
    • Can be run with no graphics at all by adding in the argument no-graphics at the end
      • For Windows:
        • mlagents-learn config/agent_config.yaml --run-id=RunIdExample --env="Build/<exampleFolder>/Final Project Testing V2" --num-envs=2 --no-graphics
      • For Mac:
        • mlagents-learn config/agent_config.yaml --run-id=RunIdExample --env="BuildName" --num-envs=2 --no-graphics
  3. Look in the terminal, which will print updates on how your agent is performing

Viewing the results

You can see a graph of your results by typing in the command and going to http://localhost:6006/

  • tensorboard --logdir results --port 6006