Try   HackMD

Learning Unity ML-Agent 2020 0913 (Spec GTX1060 6GB Asus GL702vm)

tags: Unity ML-Agent

佛系更新 2020 9/13要給個日期才知道這是在這幾個月能work的版本

ML-Agents工具包包含幾個組件:

  • Unity軟體包(com.unity.ml-agents)包含將集成到Unity場景中的Unity C#SDK。
  • 三個Python軟件包:
    mlagents包含機器學習算法,使您能夠訓練Unity場景中的行為。 ML-Agent的大多數用戶只需要直接安裝mlagents。
    mlagents_envs包含一個Python API,用於與Unity場景進行交互。 它是促進Unity場景與Python機器學習算法之間的數據消息傳遞的基礎層。 因此,mlagents取決於mlagents_envs。
    gym_unity為您的Unity場景提供了一個Python包裝器,該包裝器支持OpenAI Gym接口。
    Unity Project包含幾個示例環境,這些示例環境著重介紹了該工具包的各種功能以幫助您入門。

因此,要安裝和使用ML-Agents工具包,您將需要:

  • 安裝Unity(2018.4或更高版本)
  • 安裝Python(3.6.1或更高版本)
  • Clone此存儲庫(Optional)
    注意:如果您不Clone存儲庫,則將無法訪問示例環境和培訓配置。此外,《入門指南》還假設您已Clone存儲庫。
  • 安裝com.unity.ml-agents Unity 軟件包
  • 安裝mlagents Python 軟件包

如果想用你猛猛的GPU跑額外下載

  • CUDA9.0
  • Cudnn7.6.5

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Where do I start?

前面的安裝Unity 與 Python 就不多做贅述了只要記得Unity請安裝2018.4以上版本,Python請安裝3.6.1以上版本.

Step 1: Install

  • Install Tensorflow gpu (GTX1060)

  • CUDA TOOLKIT 9.0 DOWNLOAD

  • Cudnn7.6.5 series

  • Install Unity ML-Agent

假設您已經安裝完成Unity和Python,現在可以安裝上面Unity和Python軟件包。 您無需複製存儲庫即可安裝這些軟件包,但如果您想下載他們的範例環境和訓練配置以進行實驗,則可以選擇克隆存儲庫(他們的某些教程/指南假設您有權限可以訪問)。

"git clone branch release_6 https://github.com/Unity-Technologies/ml-agents.git"

當git clone完之後請記住你clone下來的儲存位置,如果不知道怎麼找尋,可以搜尋↓
(https://blog.csdn.net/u014264373/article/details/80472993)

Step 2: Unity Settings

  • Install the com.unity.ml-agents Unity package

Unity ML-Agents C#SDK是Unity軟件包。 您可以直接從“程序包管理器”註冊表中安裝com.unity.ml-agents程序包。 請確保在“高級”下拉菜單中啟用“預覽包”以找到它。

找到你剛剛git clone下來的檔案並按照以下步驟

  1. Unity UI 上方工具列的 Window -> Package Manager.
  2. 找到並點擊 "+".
  3. 選擇 Add package from disk
  4. Navigate into the com.unity.ml-agents folder.
  5. Select the package.json file.

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Step 3: 在Anaconda建置虛擬環境與Unity整合訓練模型

安裝mlagents Python軟件包涉及安裝mlagents依賴的其他Python軟件包。 因此,如果您的電腦上已安裝了任何依賴項,則可能會遇到安裝問題。因此,我們支持的安裝mlagents的途徑是利用Python虛擬環境。虛擬環境提供了一種隔離每個項目依賴性的機制,並且在Mac / Windows / Linux上受支持。 我們提供有關虛擬環境的專門指南。 (這裡我用Anaconda安裝所需要的虛擬環境)

"conda create -n mlagents python=3.6"

建立好虛擬環境之後會出現

To activate this environment, use:
activate ml-agents
To deactivate an active environment, use:
deactivate
for power-users using bash, you must source

鍵入

activate ml-agents

進入虛擬環境並從命令行安裝mlagents Python軟件包

pip3 install mlagents

這裡需要注意,因為我筆電的顯卡是GTX1060 且是 CUDA9.0 Cudnn 7.6.5
因此對應的Tensorflow-gpu==1.5.0 所以在 install mlagents完之後的
tensorflow版本為unity官方給的,因此需額外下指令

pip3 install tensorflow-gpu==1.5.0

安裝完在指令列輸入

mlagents-learn "yaml路徑" run-id=FirstTrain

即可成功使用gpu訓練模型

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

你可能會想check Observing Training Progress
但是當你在指令列輸入

tensorboard logdir results

你可能得到 "module 'tensorboard.util' has no attribute 'Retrier'"

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

我猜是因為我的版本都降到1.5.0了,因此我執行了以下步驟

pip3 uninstall tensorboard
pip3 install tensorboard==1.6.0

成功並回傳給我

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

去了指定網址後可看到以前的訓練過程

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →