
The Unity Machine Learning Agents SDK (ML-Agents), is an open-source Unity plugin that enables games and simulations to serve as environments for training intelligent agents. Agents can be trained using reinforcement learning, imitation learning, neuroevolution, or other machine learning methods through a simple-to-use Python API.
In this tutorial, you’ll learn how to set up Unity ML-Agents. Topics covered include:
- How to download ML-Agents from GitHub
- How to install ML-Agents via the Package Manager
- How to import ML-Agents Example Projects
Anaconda is a distribution of the Python and R programming languages for scientific computing (data science, machine learning applications, large-scale data processing, predictive analytics, etc.), that aims to simplify package management and deployment.
To download Anaconda, go to the Anaconda download site and install it on your machine.
For Ubuntu users, follow these installation steps. For mac and windows users, use the graphical installation file for easy installation.
To create a Conda environment, use the following commends
conda create -n <environment name>
unity ML Agent requires Python 3.6 or 3.7. If you are using Windows, please install the x86–64 version and not x86. If your Python environment doesn’t include pip3, see these instructions on installing it.
Activate conda environment using
conda activate <environment name>
and install the following important libraries
- TensorFlow
- Scipy
- Sklearn
- NumPy & pandas
- Matplotlib
Download and install Unity. Ml agent recommends that you install Unity through the Unity Hub as it will enable you to manage multiple Unity versions.
For Ubuntu user, follow this StackOverflow thread to install
Go to the Releases page on the Unity ML-Agents GitHub and find the latest release in the list and finally ownload the Source code (.zip) file
Installing the mlagents
Python package involves installing other Python packages that mlagents
depends on.
(Windows) Installing PyTorch
On Windows, you’ll have to install the PyTorch package separately prior to installing ML-Agents. Activate your virtual environment and run from the command line:
pip3 install torch==1.7.0 -f https://download.pytorch.org/whl/torch_stable.html
Installing mlagents
To install the mlagents
Python package, activate your virtual environment and run from the command line:
pip3 install mlagents
ML-Agents is installed via the Unity Package Manager.
- In Unity, click Window > Package Manager to open the Package Manager.
Within the Package Manager window:
- Click on Advanced and enable Show preview packages
- Make sure the Unity Registry option is selected above the list of packages
- Search for “ML-Agents” and click on it
- Click See all versions
- Choose the version that matches the release you downloaded from GitHub
- Click the Install button and allow the package to install