- 安装环境:Windows10 + Anaconda3(64-bit),网上很多教程,例如这个anaconda下载及安装(保姆级教程) - 知乎anaconda包管理器和环境管理器,强烈建议食用 1.下载官网下载太慢可选用镜像下载 官网下载: Anaconda | Individual Edition 镜像下载: Index of /anaconda/archive/ | 清华大学开源软件镜像站 | Tsinghua Open …https://zhuanlan.zhihu.com/p/459601766安装n卡驱动,安装cuda toolkit,注意版本号兼容,我使用的版本:Anaconda3-2023.03-Windows-x86_64,驱动版本531.14,cuda 12.1。
- 克隆仓库:https://github.com/Unity-Technologies/ml-agents https://github.com/Unity-Technologies/ml-agents版本为develop(cc1a750)
- 初始化ml环境:管理员模式打开Anaconda命令行,创建虚拟环境
,切换虚拟环境# 虚拟环境名字随便起,比如unity_ml,python 3.9.16,这个版本号一定选好,否则后果自负 conda create -n unity_ml python=3.9.16
,安装pytorch+初始化(官方文档ml-agents/Installation.md at release_18_docs · Unity-Technologies/ml-agents · GitHub)# 虚拟环境名使用刚创建好的那个 conda activate unity_ml # 退出虚拟环境 # conda deactivate
,这里被版本号坑惨了,列出我的环境版本号# 啥都不靠谱,就按照官方的文档来,https://github.com/Unity-Technologies/ml-agents/blob/release_18_docs/docs/Installation.md # 记得先 cd 到 ml-agents 目录下 pip3 install torch -f https://download.pytorch.org/whl/torch_stable.html pip3 install -e ./ml-agents-envs pip3 install -e ./ml-agents # 这里 pip 或 pip3 都能执行,各位老爷看自己环境装的啥,能用啥就用啥。但是python必须得是可执行的,有的环境下是python3,这个可能会有问题,所以才要使用Anaconda的虚拟环境管理。
,仅供参考,版本号不对太TMD折磨人了。absl-py 1.4.0 attrs 23.1.0 cachetools 5.3.0 cattrs 1.5.0 certifi 2022.12.7 charset-normalizer 3.1.0 cloudpickle 2.2.1 coloredlogs 15.0.1 filelock 3.12.0 flatbuffers 23.3.3 google-auth 2.17.3 google-auth-oauthlib 1.0.0 grpcio 1.54.0 gym 0.26.2 gym-notices 0.0.8 h5py 3.8.0 humanfriendly 10.0 idna 3.4 importlib-metadata 6.6.0 Jinja2 3.1.2 Markdown 3.4.3 MarkupSafe 2.1.2 mlagents 0.31.0.dev0 d:\project\github\ai\ml-agents\ml-agents mlagents-envs 0.31.0.dev0 d:\project\github\ai\ml-agents\ml-agents-envs mpmath 1.3.0 networkx 3.1 numpy 1.21.2 oauthlib 3.2.2 onnx 1.12.0 onnxruntime 1.12.1 onnxruntime-gpu 1.12.1 packaging 23.1 PettingZoo 1.15.0 Pillow 9.5.0 pip 23.0.1 protobuf 3.20.1 pyasn1 0.5.0 pyasn1-modules 0.3.0 pypiwin32 223 pyreadline3 3.4.1 pywin32 306 PyYAML 6.0 requests 2.28.2 requests-oauthlib 1.3.1 rsa 4.9 setuptools 66.0.0 six 1.16.0 sympy 1.11.1 tensorboard 2.12.2 tensorboard-data-server 0.7.0 tensorboard-plugin-wit 1.8.1 torch 2.0.0+cu118 typing_extensions 4.5.0 urllib3 1.26.15 Werkzeug 2.2.3 wheel 0.38.4 zipp 3.15.0
- 启动unity工程:在目录 ml-agents\Project 下,我用的unity版本是 2021.3.21f1c1
- 启动mlagents-learn:还是跟着官方文档走(ml-agents/Getting-Started.md at release_18_docs · Unity-Technologies/ml-agents · GitHubThe Unity Machine Learning Agents Toolkit (ML-Agents) is an open-source project that enables games and simulations to serve as environments for training intelligent agents using deep reinforcement learning and imitation learning. - ml-agents/Getting-Started.md at release_18_docs · Unity-Technologies/ml-agentshttps://github.com/Unity-Technologies/ml-agents/blob/release_18_docs/docs/Getting-Started.md)
,缺啥装啥,版本号不对就降级/升级。# 3DBall.yaml 是第一个例子的配置文件,对应工程Assets/ML-Agents/Examples/3DBall/Scenes/3DBall.unity,run-id随便给个名就行,主要是在results路径下生成子文件夹 mlagents-learn config/ppo/3DBall.yaml --run-id=first3DBallRun # 成功启动不报错就好
- 开始训练:unity编辑器点一下play,就看它跑就行了,命令行这边会出日志,图形化可以使用tensorboard查看,(我是看不懂),不想训练了就在命令行Ctrl + C,结果保存在result目录下 *.onnx 文件;
- 应用模型:找到 BehaviorParameters 节点,设置Model参数,BehaviorType设置为InferenceOnly,不启动命令行的 mlagents-learn 直接Play就可以了。
- 无图形界面训练:参考官方文档ml-agents/Learning-Environment-Executable.md at release_18_docs · Unity-Technologies/ml-agents · GitHubThe Unity Machine Learning Agents Toolkit (ML-Agents) is an open-source project that enables games and simulations to serve as environments for training intelligent agents using deep reinforcement learning and imitation learning. - ml-agents/Learning-Environment-Executable.md at release_18_docs · Unity-Technologies/ml-agentshttps://github.com/Unity-Technologies/ml-agents/blob/release_18_docs/docs/Learning-Environment-Executable.md,直接运行 mlagents-learn ,参数额外加上
--env=3DBall 3DBall就是构建的程序名。