GithubHelp home page GithubHelp logo

unity-machine-learning-class's Introduction

Unity 機械学習講座 2021

  • Unityを使って、機械学習(特に強化学習)を肌身で感じてもらうことがゴールです
  • Unity社が公式で開発している ml-agents というオープンソースライブラリを使うので楽チンです

セットアップ

  • 初回の講座までに以下をセットアップしていただけるとスムーズです
  • 英語ですが、こちらに一通りのdocumentがありますので、こちらをみながらセットアップしていただいても良いです。

1. Unity 2020.2 のインストール

  1. こちら https://unity3d.com/get-unity/download から、Unity HubをDL & インストールします
  2. 以下の手順で、Unity 2020.2をインストールしてください unity-hub1 unity-hub2 unity-hub3 unity-hub4 ※Macの方は"Mac Build Support"にチェック

2. Unity の サンプルレポジトリをclone

  • 適当なところに、ml-agentsレポジトリをcloneする
$ cd <ml-agentsレポジトリの置き場所>
$ git clone --branch release_12 https://github.com/Unity-Technologies/ml-agents.git
# --branch release_12 が 2021/1現在の最新のリリースブランチです
  • Unity Hubに、以下の手順でサンプルProjectを追加してください add-project1 add-project2 add-project3 add-project4
こんな画面が起動すればOK

add-project5

3. Unity の ml-agentsパッケージのインストール

  • Unity の Package Manger で ml-agentsパッケージをインストールする package-manager1 package-manager2 package-manager3 package-manager4 package-manager5
ML Agents が Package Managerに表示されていればOK

package-manager6

4. サンプルシーンを開く

sample-scene1

こんな画面が表示されればOK

sample-scene2

5. python 最新版 のインストール

※ virtualenvを使用してpythonのバージョンを管理するのがオススメです

pipコマンドが叩ければOK
$ pip3 -V # 大文字Vです
pip3 19.2.3 from /Users/hoge/python/3.7.5/lib/python3.7/site-packages/pip (python 3.7)

6. Python の mlagentsパッケージのインストール

  • (Windowsのみ) pytorchのインストール
pip3 install torch==1.7.0 -f https://download.pytorch.org/whl/torch_stable.html

Note that on Windows, you may also need Microsoft's Visual C++ Redistributable if you don't have it already. See the PyTorch installation guide for more installation options and versions.

とあるので、こちらを参考にPyTorchのインストールを頑張ってください。

  • mlagentsのインストール
pip3 install mlagents
mlagents-learn コマンドが叩ければOK
mlagents-learn --help

7. 動作確認

Python mlagents-learnが起動していない状態での確認

先ほど、4.の手順で、Unity側で開いた以下の画面を表示 sample-scene2

Playボタンをおす sample-scene3

consoleを確認 sample-scene4 sample-scene5 ↑のメッセージが表示されていたら正常

かつ、青い子たちがこんな動きをします 3dball-learned

一回止めましょう sample-scene7

Python mlagents-learnの起動している状態での確認

ターミナルで

$ cd <ml-agentsレポジトリのpath>
$ mlagents-learn config/ppo/3DBall.yaml --run-id=first3DBallRun



                        ▄▄▄▓▓▓▓
                   ╓▓▓▓▓▓▓█▓▓▓▓▓
              ,▄▄▄m▀▀▀'  ,▓▓▓▀▓▓▄                           ▓▓▓  ▓▓▌
            ▄▓▓▓▀'      ▄▓▓▀  ▓▓▓      ▄▄     ▄▄ ,▄▄ ▄▄▄▄   ,▄▄ ▄▓▓▌▄ ▄▄▄    ,▄▄
          ▄▓▓▓▀        ▄▓▓▀   ▐▓▓▌     ▓▓▌   ▐▓▓ ▐▓▓▓▀▀▀▓▓▌ ▓▓▓ ▀▓▓▌▀ ^▓▓▌  ╒▓▓▌
        ▄▓▓▓▓▓▄▄▄▄▄▄▄▄▓▓▓      ▓▀      ▓▓▌   ▐▓▓ ▐▓▓    ▓▓▓ ▓▓▓  ▓▓▌   ▐▓▓▄ ▓▓▌
        ▀▓▓▓▓▀▀▀▀▀▀▀▀▀▀▓▓▄     ▓▓      ▓▓▌   ▐▓▓ ▐▓▓    ▓▓▓ ▓▓▓  ▓▓▌    ▐▓▓▐▓▓
          ^█▓▓▓        ▀▓▓▄   ▐▓▓▌     ▓▓▓▓▄▓▓▓▓ ▐▓▓    ▓▓▓ ▓▓▓  ▓▓▓▄    ▓▓▓▓`
            '▀▓▓▓▄      ^▓▓▓  ▓▓▓       └▀▀▀▀ ▀▀ ^▀▀    `▀▀ `▀▀   '▀▀    ▐▓▓▌
               ▀▀▀▀▓▄▄▄   ▓▓▓▓▓▓,                                      ▓▓▓▓▀
                   `▀█▓▓▓▓▓▓▓▓▓▌
                        ¬`▀▀▀█▓

        
 Version information:
  ml-agents: 0.23.0,
  ml-agents-envs: 0.23.0,
  Communicator API: 1.3.0,
  PyTorch: 1.7.1
2021-01-19 13:10:16 INFO [learn.py:275] run_seed set to 2906
2021-01-19 13:10:16 INFO [environment.py:205] Listening on port 5004. Start training by pressing the Play button in the Unity Editor.

※ 起動に結構時間かかるので注意

先ほど、と同様に、Unity側でPlayボタンを押す sample-scene3 sample-scene6 なにも出てなければ正常

かつ、青い子たちの動きがさっきより激しいはず 3dball-learning

止める sample-scene7

ターミナルに以下のような表示が出ていたら正常

2021-01-19 13:18:44 INFO [environment.py:111] Connected to Unity environment with package version 1.7.2-preview and communication version 1.3.0
2021-01-19 13:18:44 INFO [environment.py:271] Connected new brain:
3DBall?team=0
2021-01-19 13:18:44 INFO [stats.py:147] Hyperparameters for behavior name 3DBall: 
	trainer_type:	ppo
	hyperparameters:	
	  batch_size:	64
    (中略)
	self_play:	None
	behavioral_cloning:	None
	framework:	pytorch
2021-01-19 13:18:53 INFO [stats.py:139] 3DBall. Step: 12000. Time Elapsed: 18.819 s. Mean Reward: 1.139. Std of Reward: 0.710. Training.
2021-01-19 13:18:56 INFO [subprocess_env_manager.py:186] UnityEnvironment worker 0: environment stopping.
2021-01-19 13:18:56 INFO [trainer_controller.py:189] Learning was interrupted. Please wait while the graph is generated.
2021-01-19 13:18:56 INFO [model_serialization.py:104] Converting to results/first3DBallRun/3DBall/3DBall-12447.onnx
2021-01-19 13:18:56 INFO [model_serialization.py:116] Exported results/first3DBallRun/3DBall/3DBall-12447.onnx
2021-01-19 13:18:56 INFO [torch_model_saver.py:116] Copied results/first3DBallRun/3DBall/3DBall-12447.onnx to results/first3DBallRun/3DBall.onnx.
2021-01-19 13:18:56 INFO [trainer_controller.py:85] Saved Model
$ 

以上で動作確認は終わりです!

講義をお楽しみに!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.