Unity’s ML-Agents and Effective ways of training (3/3)

we.R.play
4 min readJun 25, 2021

By Sajjad Saleem Game Developer at WRP Studios

This is the third part of my blog where we discuss the solutions to the time consumption issue while training the ML-Agents.

I’ve distributed the blog into three parts. (You may skip accordingly)
Part 1 Introduction to ML-Agents
Part 2 Resolutions to Time Problem
Part 3 ML-Agent’s Environment Executable to the Rescue

ML-Agent’s Environment Executable to the Rescue

ML-Agent allows you to create an executable file and use that file to create multiple instances of application environments that will work in the same way as creating the duplicates of the environment prefab in the same scenes. It’s as easy as it gets, just follow the steps mentioned below:

1. Create an Executable file

This is a simple step, inside Unity editor click on Files → Build Settings and select “PC,MAC and Linux standalone” platform with only the training scene selected as a scene on build just like the screenshot attached below, so that when multiple instances of applications are being loaded they all are in the same environment.

2. Load application environments

After creating the build you will need to launch the terminal and navigate to the folder where the Ml-Agents toolkit is installed and run the following command:

mlagents-learn <trainer-config-file> — num-envs=<number_of_environments> — env=<env_name> — run-id=<run-identifier>

WHERE:

<trainer-config-file> is the file path of trainer configuration yaml<env_name> is the name and path to the executable file you exported from unity<number_of_environments> is count of environment instances<run-identifier> is a string used to differentiate the results of different training runs

In my case, ML-Agent toolkit was installed inside my project folder and this is how I was able to run it:

Press enter and voilà you will see multiple windows of the application running in parallel. If you did everything right then you should see something like this on your terminal:

Benefits of ML-Agent’s Environment Executable

1. Freedom To Use Editor

The feature uses an executable file generated from unity to be used as a source for ML-Agent training, meaning you will have an editor available during the whole training process and you can continue your work while the agent is being trained in the background application.

2. Sharing is easy

You will no longer need to share your entire repository for training and instead just need to share executable files with your colleagues.

3. Remote Training

You can put your executable file on a remote machine for faster training.

However, there isn’t all good news without a pinch of bad. The major limitation is that you cannot create numerous instances of the application environments as you can create while using the environment as a prefab. We would recommend initially start with 3 environments. As the more instances of application you initiate, the more processing power will be required.

Conclusion:

I have mentioned two ways through which you can achieve faster and better results in a training process and both have trade-offs. But in case you don’t have a dedicated machine, or you can’t make a prefab of an environment, then ML-Agent’s Environment Executable is your go-to option. In the end, it’s going to be your decision to choose between these options or any other approach that I missed out on.

I hope this blog has been helpful. Let us know if you have any queries regarding this and if you have any feedback for us.

About Us
WRP Studios is a game development and animation studio making our own games and providing game development services around the world. Our latest ego boost is when Explottens got published by Apple Arcade. It was one of the launch titles to go LIVE in 2019.

Website: https://werplay.com/
Discord: https://discord.gg/jaWhzuy
Jobs: careers@werplay.com
Try our latest game “Explottens”: https://apps.apple.com/us/app/explottens/id965816162

Sign up as Beta Player for current puzzle games and get a chance to play the Alpha Beta version
https://mailchi.mp/ff413de04360/lost-twins-2

--

--