Unity AI project notes

1. Create a virtual environment

Before starting a Unity AI project, you first need to set up an appropriate virtual environment. The following steps will guide you on how to create:

  1. Download Python 3.7.
  2. Download Anaconda 2020.11. Mirror resources can be found at the Tsinghua University open source software mirror station: https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/
  3. Use Anaconda to create a new environment named ml-agents. If you are using the command line, you can use the following command to create:
    conda create --name ml-agents python=3.8
  4. Enter in Anaconda Prompt
    activate ml-agents
    to activate the environment you just created.
  5. Install tensorflow 2.2.0, command:
    python -m pip install tensorflow==2.2.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
  6. Install torch 1.7.1, command:
    pip install torch==1.7.1 -i https://pypi.tuna.tsinghua.edu.cn/simple
  7. Install ml-agents, command:
    pip install mlagents -i https://pypi.tuna.tsinghua.edu.cn/simple
    (Note: Please ensure that the VPN is not enabled during the installation process, otherwise the installation may fail)
  8. If an error is reported during training, you may need to downgrade the protobuf version. Command:
    pip install protobuf==3.20.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

2. Training

After setting up the environment, you can start training your Unity AI project:

  1. Enter in Anaconda Prompt
    activate ml-agents
    to activate your environment.
  2. enter
    E:
    Switch to drive E. (Steps 2 and 3 need to be determined according to your own project)
  3. pass
    cd E:\UnityProjects\TestAI\Assets\Train
    Go to the training directory in your project.
  4. enter
    mlagents-learn config.yaml
    Start training.
  5. If you need to resume previous training, you can enter
    mlagents-learn config.yaml --resume

3. Ensure version correspondence

Make sure your Unity version matches the version installed on pip. You can view the corresponding relationship in the Releases section of https://github.com/Unity-Technologies/ml-agents/releases/tag/release_20 . For example, the ML-Agents Release 4 version I use is paired as follows:

  • com.unity.ml-agents (C#):v1.2.0
  • mlagents (Python):v0.18.0
  • mlagents-envs (Python):v0.18.0
  • gym-unity (Python):v0.18.0
  • Communicator (C#/Python):v1.0.0

To check the version, follow these steps:

  1. Check the ML-Agents version of your Unity project: In the Unity Editor, open Window > Package Manager. In the window that opens, find the ML-Agents package and view its version number.
  2. Check the ML-Agents version of the training environment: In the command line terminal, run the following command:
    pip show mlagents
  3. Update the command line tools MLAgents and mlagents-envs to the corresponding versions. The commands are as follows:
    • pip install --upgrade mlagents==0.18.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
    • pip install --upgrade mlagents-envs==0.18.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

Reference: https://zhuanlan.zhihu.com/p/82617680

Guess you like

Origin blog.csdn.net/qq_42608732/article/details/132040197