如何使ML代理在Unity中运行? [英] How to get ML Agents to run in Unity?

查看:114
本文介绍了如何使ML代理在Unity中运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试遍历文档,但是其中提到的步骤还不够清楚.有没有很好的循序渐进视频教程,可以对您有所帮助?我在YouTube上看到的版本已经很老了,无法与GitHub https:上的最新更新一起使用://github.com/Unity-Technologies/ml-agents

I've tried going through the documentation but the steps mentioned there aren't quite clear enough. Is there a good step by step video tutorial that can be helpful? The ones I saw on YouTube are pretty old and don't work with the latest updates on GitHub https://github.com/Unity-Technologies/ml-agents

推荐答案

这将帮助您设置ml代理版本14.

This will help you to setup ml agent version 14.

https://github.com/Unity -Technologies/ml-agents/blob/master/docs/Installation.md

我当前正在使用此版本. 我建议您仅出于此目的创建一个新的python环境. 不要在python环境终端中使用pip install mlagents.当我安装它时,它没有更新为14,因此请使用上面的链接查看完整的指南,但这是重要的内容.

I am currently using this version. I suggest you create a new python environment for only this purpose. Don't use pip install mlagents in your python environment terminal. This is not updated to 14 when i installed it , so use the link above to see complete guide but here's the important stuff.

下载zip文件 ML代理主控 解压缩此Zip时,应打开此解压缩的文件夹. 然后在该位置打开cmd.激活您的python环境并执行以下步骤:
您应该从克隆的存储库而不是从PyPi安装软件包.为此,您需要分别安装 ml-agents ml-agents-envs .在ml-agents = master文件夹中打开cmd并激活python环境,在仓库的根目录中,运行:
cd ml-agents-envs pip3 install -e ./ cd .. cd ml-agents pip3 install -e ./ 这两个软件包都从同一ml代理文件夹安装非常重要,如果版本不兼容,则这将不起作用.如果从同一文件夹安​​装,则两个软件包的版本相同,即14.

Download zip file Ml Agents master When you extract this Zip, you should open this extracted folder . Then open cmd at that location. Activate your python environment and follow these steps:
You should install the packages from the cloned repo rather than from PyPi. To do this, you will need to install ml-agents and ml-agents-envs separately.Open cmd inside ml-agents=master folder and activate your python environment then, From the repo's root directory, run:
cd ml-agents-envs pip3 install -e ./ cd .. cd ml-agents pip3 install -e ./ It is very important that both packages are installed from same ml agent folder , this will not work if the version are not compatible. if installed from same folder both packages will have same version i.e. 14 in this case.

这两个软件包将帮助您使用预定义的 PPo SAC 算法.
我想您已经安装了2018或2019 Unity.打开它并转到文件->打开项目

These two packages will help you to use predefined PPo and SAC algo.
I suppose you have installed 2018 or 2019 Unity. Open it and Goto File -> Open project

现在在打开的对话框中,选择已下载的 ml-agents-master 文件夹中的文件夹 Project .

Now in open dialog box select folder Project inside ml-agents-master folder that you have downloaded.

对不起,大多数东西都被命名为project,但不要混淆,早期的项目是 ml-agents-master 中的文件夹,但是打开它后,您会看到一个 Project 工具栏.遵循资产\ ML-Agents \示例\ 3DBall \ Scenes ,现在双击3Dball. 如您所见,这将打开一个场景.您还可以分别看到 TFModels Scirpts ,它们分别是预定义的神经网络和代码.

Sorry that most of the things are named project but don't be confused , Earlier project was a folder inside ml-agents-master but after opening it you will see a Project toolbar. Follow Assets\ML-Agents\Examples\3DBall\Scenes now double click on 3Dball. This will open a scene as you can see here. You can also see TFModels and Scirpts they are predefined neural network and code ,respectively.

在左侧的层次结构工具栏中选择 Agent (,这只会对3Dball的实例进行更改,最好使用预制件,然后双击3Dball,将仅打开一个3Dball,其设置将应用到现在的所有实例层次结构中,您将仅看到一个3Dball,现在选择它的Agent rest相同,但是现在更改将影响3Dball的所有副本,预制件用于控制所有副本,这有助于以同时训练多个特工),然后在右侧的检查器视图中打开,在行为参数内部,您可以看到模型和在其框中输入.保持选中代理,否则此检查器视图将消失. 现在转到 TFModels 文件夹,您将看到一个看起来像神经网络的3DBall文件.将其拖到该代理的行为"参数模型中. 完成所有这些步骤后,单击顶部的播放"选项.现在,预定义的模型将开始播放,您将看到它可以很好地平衡球.

Select Agent in Hierarchy toolbar in left side (this will make change for only that instance of 3Dball it will be better to go to prefabs then double click on 3Dball this will open only one 3Dball whose settings will be applied on all instances now in hierarchy you will see only one 3Dball , now select it's Agent rest is same but now changes will affect all copies of 3Dball, prefabs are used to control all the copies this helps to train multiple agents at same time) then in right side Inspector view will open ,inside Behaviors parameters you can see Model and a input in its box. Keep the agent selected otherwise this inspector view will disappear . Now Goto TFModels folder , you will see a 3DBall file that looks like Neural network. Drag this to that Agent's Behavior parameters Model. After Following all these steps Click on play option on top . Now the predefined model will start playing and you will see that it can balance the ball pretty well.

现在,您可以看到经过训练的模型如何工作,并希望使用预定义的 PPO和SAC 再次进行训练,请遵循

Now that you are able to see how trained model work and want to train again using predefined PPO and SAC , follow this

goto: ml-agents-master \ config ,在这里您将找到文件 trainer_config.yaml ,现在打开cmd然后激活您的环境并输入代码
mlagents-learn trainer_config.yaml --run-id=firstRun --train
当屏幕上显示消息通过在Unity编辑器中按播放按钮开始训练"时,您可以在Unity中按▶️按钮在编辑器中开始训练.您可以按Ctrl + C停止训练,并且训练后的模型将位于模型run-identifier-> behavior_name.nn中,其中 behavior_name 是与该模型相对应的代理的行为名称.
将模型文件移动到Project/Assets/ML-Agents/Examples/3DBall/TFModels/. 打开Unity编辑器,然后如上所述选择3DBall场景. 选择3DBall预制代理对象. 将.nn文件从编辑器的项目"窗口拖到Ball3DAgent检查器窗口中的模型"占位符. 按下编辑器顶部的▶️按钮.

goto : ml-agents-master\config, here you will find a file trainer_config.yaml , Now open cmd then activate your environment and enter code
mlagents-learn trainer_config.yaml --run-id=firstRun --train
When the message "Start training by pressing the Play button in the Unity Editor" is displayed on the screen, you can press the ▶️ button in Unity to start training in the Editor. You can press Ctrl+C to stop the training, and your trained model will be at models run-identifier -> behavior_name.nn where behavior_name is the name of the Behavior Name of the agents corresponding to the model.
Move your model file into Project/Assets/ML-Agents/Examples/3DBall/TFModels/. Open the Unity Editor, and select the 3DBall scene as described above. Select the 3DBall prefab Agent object. Drag the .nn file from the Project window of the Editor to the Model placeholder in the Ball3DAgent inspector window. Press the ▶️ button at the top of the Editor.

现在,对于您自己的python中的RL算法:
看到它显示的这个
jupyter笔记本我们如何激活团结健身房并获得观察,奖励和重置环境.为此,还可以创建Unity可执行文件,它只是使用某些设置创建exe文件,您可以在其中找到

Now , For your own RL algorithm in python :
see this jupyter notebook it shows how we activate unity gym and get observations ,rewards and reset environment. For this use can also create Unity executable , it's just creating exe files with some settings which you will find here


希望这一切正常,祝你好运.


Hope this works without any issues.And Good Luck with this.

这篇关于如何使ML代理在Unity中运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆