当前位置:首页 > 编程笔记 > 正文
已解决

MLAgents (0) Unity 安装及运行

来自网友在路上 137837提问 提问时间:2023-09-23 01:22:52阅读次数: 37

最佳答案 问答题库378位专家为你答疑解惑

1、下载ML-Agents

下载地址

GitHub - Unity-Technologies/ml-agents: The 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.

 在develop-Tags中,选择release_18

下载zip文件,解压

2、anaconda配置pytorch环境

conda create -n 名称 python=3.9.9

注意:Python 3.9.10 以上目前与mlagents-learn 套件不相容,会出现错误TypeError: Invalid first argument to `register()`. typing.Dict[mlagents.trainers.settings.RewardSignalType, mlagents.trainers.settings.RewardSignalSettings] is not a class.

 conda activate 名称

激活环境

在环境中安装pytorch

conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cudatoolkit=11.1 -c pytorch -c conda-forge

 安装完成后,执行python-->import torch-->torch.cuda.is_available()

如果为true,则安装成功

3、安装ml-agents-release_18所需要的库

在anaconda激活的环境中

(1)cd ml-agents-release_18的文件目录

定位到ml-agents-envs,在文件夹中创建文件setup.cfg清华源加快下载速度

[easy_install]

index_url = https://pypi.tuna.tsinghua.edu.cn/simple

执行命令 python setup.py install

安装库

安装出现 Finished processing dependencies for mlagents-envs==0.27.0

则为安装成功

(2)cd ..  --> cd ml-agents

也增加setup.cfg文件

执行命令 python setup.py install

出现错误:error: urllib3 2.0.4 is installed but urllib3<2.0 is required by {'google-auth'}

执行:pip uninstall urllib3

pip install -i https://pypi.douban.com/simple urllib3=1.26.9

重新安装urllib3

再次执行python setup.py install

当出现 Finished processing dependencies for mlagents==0.27.0

即为安装完成

4、在unity中 Window--> Package Manager

找到 com.unity.ml-agents,导入package.json

等待安装完成

之后可以搭建环境,并设置参数等

5、开启ml-agents,运行项目

在unity项目中,创建training-->xxx_config.yamlzheshi

behaviors:RB:trainer_type: ppohyperparameters:batch_size: 10buffer_size: 100learning_rate: 0.0003beta: 0.0005epsilon: 0.2lambd: 0.99num_epoch: 3learning_rate_schedule: linearnetwork_settings:normalize: falsehidden_units: 128num_layers: 2reward_signals:extrinsic:gamma: 0.99strength: 1.0max_steps: 500000time_horizon: 64summary_freq: 10000

设置完成后,在anaconda中,定位到unity项目的training

cd xx/xx/unity_project/training

执行命令: mlagents-learn.exe xxx.yaml --run-id=RB

报错:ModuleNotFoundError: No module named 'six'

执行 pip install -i https://pypi.douban.com/simple six

再次执行命令

当出现以下界面

则运行成功,端口也开启成功 

此时点击unity的运行按钮,执行运行操作

结果生成在training文件夹中

当要界面化看结果时,需要执行命令

tensorbord.exe --logdir results --port 6006

预训练后的模型保存在Assets中,要使用预训练后的模型

可将模型拖到Behavior Parameters的Model上

mlagents-learn.exe xxx.yaml --run-id=RB --resume

继续上次训练的命令

查看全文

99%的人还看了

猜你感兴趣

版权申明

本文"MLAgents (0) Unity 安装及运行":http://eshow365.cn/6-11791-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!