使用ML-Agents Toolkit(0.5)訓練遊戲ai之遊戲打包

這篇文章介紹如何訓練官方的一個例子3dball。html

確保在此以前已經安裝好訓練環境能夠參考下面的文章。git

http://www.javashuo.com/article/p-okccvquf-bx.htmlgithub

遊戲打包的官方說明文檔shell

https://github.com/Unity-Technologies/ml-agents/blob/master/docs/Learning-Environment-Executable.mdsession

https://github.com/Unity-Technologies/ml-agents/blob/master/docs/Basic-Guide.md#play-an-example-environment-using-pretrained-modelide

打開官方的實例工程ml-agents\UnitySDKui

這個工程是和插件項目在一塊兒的this

下載連接https://github.com/Unity-Technologies/ml-agents/插件

雙擊打開3dball路徑是Assets/ML-Agents/Examples/3DBall/debug

1.打包遊戲前的配置

 

  1. 打開Player Settings (菜單: Edit > Project Settings > Player).
  2. 在Resolution and Presentation下:
    • 確保 Run in Background 是勾選上的.
    • 確保  Display Resolution Dialog 設置成 Disabled.
  3. 打開 Build Settings 窗口(菜單:File > Build Settings).
  4. 選擇 target platform.
  5. If any scenes are shown in the Scenes in Build list, make sure that the 3DBall Scene is the only one checked. (If the list is empty, than only the current scene is included in the build).
  6. Click Build:
    • In the File dialog, navigate to your ML-Agents directory.
    • Assign a file name and click Save.
    • (For Windows)With Unity 2018.1, it will ask you to select a folder instead of a file name. Create a subfolder within the ML-Agents folder and select that folder to build. In the following steps you will refer to this subfolder's name as env_name.

2.開啓外部訓練

打開Anaconda Prompt

輸入

activate ml-agents
激活以前搭建好的環境

轉到ml-agents目錄下

輸入

mlagents-learn ../config/trainer_config.yaml --env=3DBall --run-id=firstRun --train
--env=指的是你的遊戲文件的路徑,遊戲程序不加後綴名
--run-id=是每次訓練後打印的分割,能夠自定義
告訴 learn.py 運行訓練session(而不是inference會話)--train

 

圖中已經開始訓練了。博主的GPU是GTX950M的,支持GPU加速。如何是n卡是不能加速的,這時候只能用cpu跑了,這樣會慢很多。

 


訓練好以後就能夠在當前目錄找到models文件夾

 

圖中的bytes就是訓練好的模型

要想在unity中使用內部模式加載這個模型須要加上一個宏

ENABLE_TENSORFLOW

在playsetting中

相關文章
相關標籤/搜索