浏览代码

Merge pull request #1495 from Unity-Technologies/release-v0.6

release-v0.6 --> develop
/develop-generalizationTraining-TrainerController
GitHub 6 年前
当前提交
c8cc5a29
共有 151 个文件被更改,包括 3972 次插入4211 次删除
  1. 18
      README.md
  2. 53
      UnitySDK/Assets/Gizmos/HeuristicBrain Icon.png
  3. 52
      UnitySDK/Assets/Gizmos/HeuristicBrain Icon.png.meta
  4. 74
      UnitySDK/Assets/Gizmos/LearningBrain Icon.png
  5. 52
      UnitySDK/Assets/Gizmos/LearningBrain Icon.png.meta
  6. 75
      UnitySDK/Assets/Gizmos/PlayerBrain Icon.png
  7. 52
      UnitySDK/Assets/Gizmos/PlayerBrain Icon.png.meta
  8. 2
      UnitySDK/Assets/ML-Agents/Editor/Tests/EditModeTestInternalBrainTensorApplier.cs
  9. 2
      UnitySDK/Assets/ML-Agents/Editor/Tests/EditModeTestInternalBrainTensorGenerator.cs
  10. 2
      UnitySDK/Assets/ML-Agents/Examples/3DBall/Brains/3DBallHardLearning.asset
  11. 2
      UnitySDK/Assets/ML-Agents/Examples/3DBall/Brains/3DBallLearning.asset
  12. 10
      UnitySDK/Assets/ML-Agents/Examples/BananaCollectors/Brains/BananaLearning.asset
  13. 2
      UnitySDK/Assets/ML-Agents/Examples/BananaCollectors/Prefabs/RLArea.prefab
  14. 2
      UnitySDK/Assets/ML-Agents/Examples/Basic/Brains/BasicLearning.asset
  15. 10
      UnitySDK/Assets/ML-Agents/Examples/Bouncer/Brains/BouncerLearning.asset
  16. 2
      UnitySDK/Assets/ML-Agents/Examples/Crawler/Brains/CrawlerDynamicLearning.asset
  17. 2
      UnitySDK/Assets/ML-Agents/Examples/Crawler/Brains/CrawlerStaticLearning.asset
  18. 2
      UnitySDK/Assets/ML-Agents/Examples/GridWorld/Brains/GridWorldLearning.asset
  19. 2
      UnitySDK/Assets/ML-Agents/Examples/Hallway/Brains/HallwayLearning.asset
  20. 2
      UnitySDK/Assets/ML-Agents/Examples/PushBlock/Brains/PushBlockLearning.asset
  21. 2
      UnitySDK/Assets/ML-Agents/Examples/Pyramids/Brains/PyramidsLearning.asset
  22. 2
      UnitySDK/Assets/ML-Agents/Examples/Reacher/Brains/ReacherLearning.asset
  23. 2
      UnitySDK/Assets/ML-Agents/Examples/Soccer/Brains/GoalieLearning.asset
  24. 2
      UnitySDK/Assets/ML-Agents/Examples/Soccer/Brains/StrikerLearning.asset
  25. 2
      UnitySDK/Assets/ML-Agents/Examples/Tennis/Brains/TennisLearning.asset
  26. 10
      UnitySDK/Assets/ML-Agents/Examples/Walker/Brains/WalkerLearning.asset
  27. 2
      UnitySDK/Assets/ML-Agents/Examples/WallJump/Brains/BigWallJumpLearning.asset
  28. 2
      UnitySDK/Assets/ML-Agents/Examples/WallJump/Brains/SmallWallJumpLearning.asset
  29. 2
      UnitySDK/Assets/ML-Agents/Scripts/Academy.cs
  30. 6
      UnitySDK/Assets/ML-Agents/Scripts/InferenceBrain/ApplierImpl.cs
  31. 5
      UnitySDK/Assets/ML-Agents/Scripts/InferenceBrain/GeneratorImpl.cs
  32. 12
      UnitySDK/Assets/ML-Agents/Scripts/InferenceBrain/ModelParamLoader.cs
  33. 5
      UnitySDK/Assets/ML-Agents/Scripts/InferenceBrain/TensorApplier.cs
  34. 6
      UnitySDK/Assets/ML-Agents/Scripts/InferenceBrain/TensorGenerator.cs
  35. 36
      UnitySDK/Assets/ML-Agents/Scripts/LearningBrain.cs
  36. 2
      config/offline_bc_config.yaml
  37. 19
      docs/Background-TensorFlow.md
  38. 2
      docs/Background-Unity.md
  39. 101
      docs/Basic-Guide.md
  40. 16
      docs/FAQ.md
  41. 58
      docs/Getting-Started-with-Balance-Ball.md
  42. 2
      docs/Glossary.md
  43. 329
      docs/Learning-Environment-Create-New.md
  44. 10
      docs/Learning-Environment-Design-Learning-Brains.md
  45. 2
      docs/Learning-Environment-Design-Player-Brains.md
  46. 3
      docs/Learning-Environment-Examples.md
  47. 13
      docs/Learning-Environment-Executable.md
  48. 4
      docs/ML-Agents-Overview.md
  49. 15
      docs/Migrating.md
  50. 2
      docs/Readme.md
  51. 6
      docs/Training-Imitation-Learning.md
  52. 2
      docs/Training-ML-Agents.md
  53. 999
      docs/images/mlagents-3DBallHierarchy.png
  54. 277
      docs/images/mlagents-NewProject.png
  55. 360
      docs/images/mlagents-NewTutAcademy.png
  56. 999
      docs/images/mlagents-NewTutAssignBrain.png
  57. 502
      docs/images/mlagents-NewTutBlock.png
  58. 536
      docs/images/mlagents-NewTutFloor.png
  59. 132
      docs/images/mlagents-NewTutHierarchy.png
  60. 507
      docs/images/mlagents-NewTutSphere.png
  61. 819
      docs/images/mlagents-NewTutSplash.png
  62. 999
      docs/images/mlagents-Open3DBall.png
  63. 75
      gym-unity/README.md
  64. 20
      ml-agents/mlagents/envs/environment.py
  65. 16
      ml-agents/mlagents/envs/exception.py
  66. 44
      ml-agents/mlagents/envs/rpc_communicator.py
  67. 9
      ml-agents/mlagents/trainers/bc/offline_trainer.py
  68. 2
      ml-agents/mlagents/trainers/demo_loader.py
  69. 19
      ml-agents/mlagents/trainers/learn.py
  70. 8
      ml-agents/mlagents/trainers/models.py
  71. 2
      ml-agents/mlagents/trainers/policy.py
  72. 2
      ml-agents/setup.py
  73. 4
      ml-agents/tests/envs/test_envs.py
  74. 2
      ml-agents/tests/mock_communicator.py
  75. 4
      ml-agents/tests/trainers/test_demo_loader.py
  76. 4
      ml-agents/tests/trainers/test_trainer_controller.py
  77. 5
      SURVEY.md
  78. 224
      UnitySDK/Assets/ML-Agents/Editor/Tests/MultinomialTest.cs
  79. 122
      UnitySDK/Assets/ML-Agents/Editor/Tests/RandomNormalTest.cs
  80. 7
      UnitySDK/Assets/ML-Agents/Examples/3DBall/TFModels/3DBallHardLearning.bytes.meta
  81. 7
      UnitySDK/Assets/ML-Agents/Examples/3DBall/TFModels/3DBallLearning.bytes.meta
  82. 7
      UnitySDK/Assets/ML-Agents/Examples/BananaCollectors/TFModels/BananaLearning.bytes.meta
  83. 7
      UnitySDK/Assets/ML-Agents/Examples/Basic/TFModels/BasicLearning.bytes.meta
  84. 7
      UnitySDK/Assets/ML-Agents/Examples/Bouncer/TFModels/BouncerLearning.bytes.meta
  85. 7
      UnitySDK/Assets/ML-Agents/Examples/Crawler/TFModels/CrawlerDynamicLearning.bytes.meta
  86. 7
      UnitySDK/Assets/ML-Agents/Examples/Crawler/TFModels/CrawlerStaticLearning.bytes.meta
  87. 7
      UnitySDK/Assets/ML-Agents/Examples/GridWorld/TFModels/GridWorldLearning.bytes.meta
  88. 7
      UnitySDK/Assets/ML-Agents/Examples/Hallway/TFModels/HallwayLearning.bytes.meta
  89. 7
      UnitySDK/Assets/ML-Agents/Examples/PushBlock/TFModels/PushBlockLearning.bytes.meta
  90. 7
      UnitySDK/Assets/ML-Agents/Examples/Pyramids/TFModels/PyramidsLearning.bytes.meta
  91. 7
      UnitySDK/Assets/ML-Agents/Examples/Reacher/TFModels/ReacherLearning.bytes.meta
  92. 7
      UnitySDK/Assets/ML-Agents/Examples/Soccer/TFModels/GoalieLearning.bytes.meta
  93. 7
      UnitySDK/Assets/ML-Agents/Examples/Soccer/TFModels/StrikerLearning.bytes.meta
  94. 7
      UnitySDK/Assets/ML-Agents/Examples/Tennis/TFModels/TennisLearning.bytes.meta
  95. 7
      UnitySDK/Assets/ML-Agents/Examples/Walker/TFModels/WalkerLearning.bytes.meta
  96. 7
      UnitySDK/Assets/ML-Agents/Examples/WallJump/TFModels/BigWallJumpLearning.bytes.meta
  97. 7
      UnitySDK/Assets/ML-Agents/Examples/WallJump/TFModels/SmallWallJumpLearning.bytes.meta
  98. 213
      UnitySDK/Assets/ML-Agents/Scripts/InferenceBrain/TFSharpInferenceEngine.cs
  99. 12
      UnitySDK/Assets/ML-Agents/Scripts/InferenceBrain/TFSharpInferenceEngine.cs.meta
  100. 40
      UnitySDK/Assets/ML-Agents/Scripts/InferenceBrain/Tensor.cs

18
README.md


[contribution guidelines](CONTRIBUTING.md) and
[code of conduct](CODE_OF_CONDUCT.md).
You can connect with us and the broader community
through Unity Connect and GitHub:
If you run into any problems using the ML-Agents toolkit,
[submit an issue](https://github.com/Unity-Technologies/ml-agents/issues) and
make sure to include as much detail as possible.
* Join our
[Unity Machine Learning Channel](https://connect.unity.com/messages/c/035fba4f88400000)
to connect with others using the ML-Agents toolkit and Unity developers
enthusiastic about machine learning. We use that channel to surface updates
regarding the ML-Agents toolkit (and, more broadly, machine learning in
games).
* If you run into any problems using the ML-Agents toolkit,
[submit an issue](https://github.com/Unity-Technologies/ml-agents/issues) and
make sure to include as much detail as possible.
Your opinion matters a great deal to us. Only by hearing your thoughts on the Unity ML-Agents Toolkit can we continue to improve and grow. Please take a few minutes to [let us know about it](https://github.com/Unity-Technologies/ml-agents/issues/1454).
team at ml-agents@unity3d.com.
team at ml-agents@unity3d.com.
## Translations

53
UnitySDK/Assets/Gizmos/HeuristicBrain Icon.png

之前 之后
宽度: 64  |  高度: 64  |  大小: 4.9 KiB

52
UnitySDK/Assets/Gizmos/HeuristicBrain Icon.png.meta


fileFormatVersion: 2
guid: b9fe19b47e0744881b9f4afc17dcd926
guid: fbee1fddc738f410ea0b37fe6301d7c0
TextureImporter:
fileIDToRecycleName: {}
externalObjects: {}

enableMipMap: 0
sRGBTexture: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0

maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 0
aniso: 1
filterMode: -1
aniso: -1
wrapU: 1
wrapV: 1
wrapU: -1
wrapV: -1
nPOTScale: 0
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0

spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
alphaIsTransparency: 0
textureType: 2
textureType: 0
textureShape: 1
maxTextureSizeSet: 0
compressionQualitySet: 0

maxTextureSize: 128
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
- buildTarget: Standalone
maxTextureSize: 128
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
- buildTarget: iPhone
maxTextureSize: 128
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
- buildTarget: Android
maxTextureSize: 128
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1

74
UnitySDK/Assets/Gizmos/LearningBrain Icon.png

之前 之后
宽度: 64  |  高度: 64  |  大小: 4.8 KiB

52
UnitySDK/Assets/Gizmos/LearningBrain Icon.png.meta


fileFormatVersion: 2
guid: e7372058b17fb432794fe9b7e395fed5
guid: aff60a06d6c704801a2d09a8e72cbefc
TextureImporter:
fileIDToRecycleName: {}
externalObjects: {}

enableMipMap: 0
sRGBTexture: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0

maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 0
aniso: 1
filterMode: -1
aniso: -1
wrapU: 1
wrapV: 1
wrapU: -1
wrapV: -1
nPOTScale: 0
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0

spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
alphaIsTransparency: 0
textureType: 2
textureType: 0
textureShape: 1
maxTextureSizeSet: 0
compressionQualitySet: 0

maxTextureSize: 128
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
- buildTarget: Standalone
maxTextureSize: 128
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
- buildTarget: iPhone
maxTextureSize: 128
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
- buildTarget: Android
maxTextureSize: 128
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1

75
UnitySDK/Assets/Gizmos/PlayerBrain Icon.png

之前 之后
宽度: 64  |  高度: 64  |  大小: 5.1 KiB

52
UnitySDK/Assets/Gizmos/PlayerBrain Icon.png.meta


fileFormatVersion: 2
guid: 176f3272b939d48de9b37abe13b2b8c3
guid: 224cd0666bb7b4477b0806fd29cf5966
TextureImporter:
fileIDToRecycleName: {}
externalObjects: {}

enableMipMap: 0
sRGBTexture: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0

maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 0
aniso: 1
filterMode: -1
aniso: -1
wrapU: 1
wrapV: 1
wrapU: -1
wrapV: -1
nPOTScale: 0
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0

spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
alphaIsTransparency: 0
textureType: 2
textureType: 0
textureShape: 1
maxTextureSizeSet: 0
compressionQualitySet: 0

maxTextureSize: 128
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
- buildTarget: Standalone
maxTextureSize: 128
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
- buildTarget: iPhone
maxTextureSize: 128
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
- buildTarget: Android
maxTextureSize: 128
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1

2
UnitySDK/Assets/ML-Agents/Editor/Tests/EditModeTestInternalBrainTensorApplier.cs


using System.Linq;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.MachineLearning.InferenceEngine;
using UnityEngine.MachineLearning.InferenceEngine.Util;
using System.Reflection;
using MLAgents.InferenceBrain;

2
UnitySDK/Assets/ML-Agents/Editor/Tests/EditModeTestInternalBrainTensorGenerator.cs


using System.Linq;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.MachineLearning.InferenceEngine;
using UnityEngine.MachineLearning.InferenceEngine.Util;
using MLAgents.InferenceBrain;
namespace MLAgents.Tests

2
UnitySDK/Assets/ML-Agents/Examples/3DBall/Brains/3DBallHardLearning.asset


-
-
vectorActionSpaceType: 1
model: {fileID: 11400000, guid: c2381a94783b14d5fa1c56dc947a9578, type: 3}
model: {fileID: 4900000, guid: 8a2da2218425f46e9921caefda4b7813, type: 3}

2
UnitySDK/Assets/ML-Agents/Examples/3DBall/Brains/3DBallLearning.asset


-
-
vectorActionSpaceType: 1
model: {fileID: 0}
model: {fileID: 4900000, guid: 9f58800fa9d54477aa01ee258842f6b3, type: 3}

10
UnitySDK/Assets/ML-Agents/Examples/BananaCollectors/Brains/BananaLearning.asset


-
-
vectorActionSpaceType: 0
graphModel: {fileID: 0}
graphPlaceholders: []
BatchSizePlaceholderName: batch_size
VectorObservationPlacholderName: vector_observation
RecurrentInPlaceholderName: recurrent_in
RecurrentOutPlaceholderName: recurrent_out
VisualObservationPlaceholderName: []
ActionPlaceholderName: action
PreviousActionPlaceholderName: prev_action
model: {fileID: 4900000, guid: 69bd818d72b944849916d2fda9fe471b, type: 3}

2
UnitySDK/Assets/ML-Agents/Examples/BananaCollectors/Prefabs/RLArea.prefab


m_Script: {fileID: 11500000, guid: 700720465a0104fa586fa4a412b044f8, type: 3}
m_Name:
m_EditorClassIdentifier:
brain: {fileID: 11400000, guid: 9e7865ec29c894c2d8c1617b0fa392f9, type: 2}
brain: {fileID: 11400000, guid: dff7429d656234fed84c4fac2a7a683c, type: 2}
agentParameters:
agentCameras: []
maxStep: 5000

2
UnitySDK/Assets/ML-Agents/Examples/Basic/Brains/BasicLearning.asset


vectorActionDescriptions:
-
vectorActionSpaceType: 0
model: {fileID: 0}
model: {fileID: 4900000, guid: 503ce1e8257904bd0b5be8f7fb4b5d28, type: 3}

10
UnitySDK/Assets/ML-Agents/Examples/Bouncer/Brains/BouncerLearning.asset


-
-
vectorActionSpaceType: 1
graphModel: {fileID: 4900000, guid: f6197a66bd242464e8b654ef1ac01faf, type: 3}
graphPlaceholders: []
BatchSizePlaceholderName: batch_size
VectorObservationPlacholderName: vector_observation
RecurrentInPlaceholderName: recurrent_in
RecurrentOutPlaceholderName: recurrent_out
VisualObservationPlaceholderName: []
ActionPlaceholderName: action
PreviousActionPlaceholderName: prev_action
model: {fileID: 4900000, guid: 760d2b8347b4b46e3a44d9b989e1304e, type: 3}

2
UnitySDK/Assets/ML-Agents/Examples/Crawler/Brains/CrawlerDynamicLearning.asset


-
-
vectorActionSpaceType: 1
model: {fileID: 0}
model: {fileID: 4900000, guid: 9482a8782450a4d87b20942c4523176b, type: 3}

2
UnitySDK/Assets/ML-Agents/Examples/Crawler/Brains/CrawlerStaticLearning.asset


-
-
vectorActionSpaceType: 1
model: {fileID: 0}
model: {fileID: 4900000, guid: e256bd37f98f246e5be72618766d0a93, type: 3}

2
UnitySDK/Assets/ML-Agents/Examples/GridWorld/Brains/GridWorldLearning.asset


vectorActionDescriptions:
-
vectorActionSpaceType: 0
model: {fileID: 0}
model: {fileID: 4900000, guid: 0fd168a0ea1d04ef9a68c80cf452ce3d, type: 3}

2
UnitySDK/Assets/ML-Agents/Examples/Hallway/Brains/HallwayLearning.asset


vectorActionDescriptions:
-
vectorActionSpaceType: 0
model: {fileID: 0}
model: {fileID: 4900000, guid: 84588668e6ea948d3ab55bb813cc769b, type: 3}

2
UnitySDK/Assets/ML-Agents/Examples/PushBlock/Brains/PushBlockLearning.asset


vectorActionDescriptions:
-
vectorActionSpaceType: 0
model: {fileID: 0}
model: {fileID: 4900000, guid: e22850d2072904a0ab06069cda2599e5, type: 3}

2
UnitySDK/Assets/ML-Agents/Examples/Pyramids/Brains/PyramidsLearning.asset


vectorActionDescriptions:
-
vectorActionSpaceType: 0
model: {fileID: 0}
model: {fileID: 4900000, guid: 7d1c7f27447234c3a81169de00dcaa8a, type: 3}

2
UnitySDK/Assets/ML-Agents/Examples/Reacher/Brains/ReacherLearning.asset


-
-
vectorActionSpaceType: 1
model: {fileID: 0}
model: {fileID: 4900000, guid: 5fb4a3624e9ca4e1c81b51b5117cb31e, type: 3}

2
UnitySDK/Assets/ML-Agents/Examples/Soccer/Brains/GoalieLearning.asset


vectorActionDescriptions:
-
vectorActionSpaceType: 0
model: {fileID: 0}
model: {fileID: 4900000, guid: 890ab8f03425c4a80a52ba674ddec3f3, type: 3}

2
UnitySDK/Assets/ML-Agents/Examples/Soccer/Brains/StrikerLearning.asset


vectorActionDescriptions:
-
vectorActionSpaceType: 0
model: {fileID: 0}
model: {fileID: 4900000, guid: 23410257d39d44616bfefdff59c7fbc9, type: 3}

2
UnitySDK/Assets/ML-Agents/Examples/Tennis/Brains/TennisLearning.asset


-
-
vectorActionSpaceType: 1
model: {fileID: 0}
model: {fileID: 4900000, guid: 6d4281b70d41f48cb83d663b84f78c9a, type: 3}

10
UnitySDK/Assets/ML-Agents/Examples/Walker/Brains/WalkerLearning.asset


-
-
vectorActionSpaceType: 1
graphModel: {fileID: 0}
graphPlaceholders: []
BatchSizePlaceholderName: batch_size
VectorObservationPlacholderName: vector_observation
RecurrentInPlaceholderName: recurrent_in
RecurrentOutPlaceholderName: recurrent_out
VisualObservationPlaceholderName: []
ActionPlaceholderName: action
PreviousActionPlaceholderName: prev_action
model: {fileID: 4900000, guid: 48ab33cf9fbee4883948187618027835, type: 3}

2
UnitySDK/Assets/ML-Agents/Examples/WallJump/Brains/BigWallJumpLearning.asset


-
-
vectorActionSpaceType: 0
model: {fileID: 0}
model: {fileID: 4900000, guid: c118879bb5db84f269e4da23ba8c4f61, type: 3}

2
UnitySDK/Assets/ML-Agents/Examples/WallJump/Brains/SmallWallJumpLearning.asset


-
-
vectorActionSpaceType: 0
model: {fileID: 0}
model: {fileID: 4900000, guid: 92cd96b2c34334db692e93af25b64d2a, type: 3}

2
UnitySDK/Assets/ML-Agents/Scripts/Academy.cs


[SerializeField]
public BroadcastHub broadcastHub = new BroadcastHub();
private const string kApiVersion = "API-5";
private const string kApiVersion = "API-6";
// Fields provided in the Inspector

6
UnitySDK/Assets/ML-Agents/Scripts/InferenceBrain/ApplierImpl.cs


using UnityEngine.MachineLearning.InferenceEngine;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.MachineLearning.InferenceEngine.Util;
using System.Collections.Generic;
using MLAgents.InferenceBrain.Utils;
namespace MLAgents.InferenceBrain
{

5
UnitySDK/Assets/ML-Agents/Scripts/InferenceBrain/GeneratorImpl.cs


using UnityEngine.MachineLearning.InferenceEngine;
using System.Collections.Generic;
using System.Collections.Generic;
using UnityEngine.MachineLearning.InferenceEngine.Util;
using MLAgents.InferenceBrain.Utils;
namespace MLAgents.InferenceBrain
{

12
UnitySDK/Assets/ML-Agents/Scripts/InferenceBrain/ModelParamLoader.cs


using UnityEngine.MachineLearning.InferenceEngine;
using UnityEngine;
#if ENABLE_TENSORFLOW
using System;
using System.Collections.Generic;
using System.Linq;

Continuous
}
private const long ApiVersion = 1;
private InferenceEngine _engine;
private TFSharpInferenceEngine _engine;
private BrainParameters _brainParameters;
private List<string> _failedModelChecks = new List<string>();

/// <param name="brainParameters"> The BrainParamters that are used verify the
/// compatibility with the InferenceEngine</param>
/// <returns></returns>
public static ModelParamLoader GetLoaderAndCheck(InferenceEngine engine,
public static ModelParamLoader GetLoaderAndCheck(TFSharpInferenceEngine engine,
BrainParameters brainParameters)
{
ModelParamLoader modelParamLoader = new ModelParamLoader(engine, brainParameters);

private ModelParamLoader(InferenceEngine engine, BrainParameters brainParameters)
private ModelParamLoader(TFSharpInferenceEngine engine, BrainParameters brainParameters)
{
_engine = engine;
_brainParameters = brainParameters;

{
_engine.ExecuteGraph(new Tensor[0], outputs);
}
catch (Exception e)
catch
{
return -1;
}

}
}
}
#endif

5
UnitySDK/Assets/ML-Agents/Scripts/InferenceBrain/TensorApplier.cs


using UnityEngine.MachineLearning.InferenceEngine;
using System.Collections.Generic;
using UnityEngine.MachineLearning.InferenceEngine.Util;
using System;
using System.Collections.Generic;
namespace MLAgents.InferenceBrain
{

6
UnitySDK/Assets/ML-Agents/Scripts/InferenceBrain/TensorGenerator.cs


using UnityEngine.MachineLearning.InferenceEngine;
using System.Collections.Generic;
using UnityEngine.MachineLearning.InferenceEngine.Util;
using System.Linq;
using System;
using System.Collections.Generic;
namespace MLAgents.InferenceBrain
{

36
UnitySDK/Assets/ML-Agents/Scripts/LearningBrain.cs


using UnityEngine;
using System.Linq;
using MLAgents.InferenceBrain;
using UnityEngine.MachineLearning.InferenceEngine;
using UnityEngine.Profiling;
namespace MLAgents

{
private TensorGenerator _tensorGenerator;
private TensorApplier _tensorApplier;
#if ENABLE_TENSORFLOW
public Model model;
#endif
public TextAsset model;
private InferenceEngine _engine;
#if ENABLE_TENSORFLOW
private TFSharpInferenceEngine _engine;
#endif
private IEnumerable<Tensor> _inferenceInputs;
private IEnumerable<Tensor> _inferenceOutputs;

/// </exception>
public void ReloadModel(int seed = 0)
{
#if ENABLE_TENSORFLOW
var config = new InferenceEngineConfig
{
Device = InferenceEngineConfig.DeviceType.CPU
};
_engine = InferenceAPI.LoadModel(model, config);
_engine = new TFSharpInferenceEngine();
_engine.PrepareModel(model.bytes);
}
else
{

_inferenceOutputs = _modelParamLoader.GetOutputTensors();
_tensorGenerator = new TensorGenerator(brainParameters, seed);
_tensorApplier = new TensorApplier(brainParameters, seed);
#endif
}
/// <summary>

/// Brain Parameters</returns>
public IEnumerable<string> GetModelFailedChecks()
{
#if ENABLE_TENSORFLOW
#else
return new List<string>(){
"You need to install the TensorflowSharp plugin and add the ENABLE_TENSORFLOW " +
"flag in your Player Settings in order to use inference. "};
#endif
}
/// <inheritdoc />

{
return;
}
#if ENABLE_TENSORFLOW
if (_engine == null)
{
Debug.LogError($"No model was present for the Brain {name}.");

// Update the outputs
_tensorApplier.ApplyTensors(_inferenceOutputs, agentInfos);
#else
if (agentInfos.Count > 0)
{
Debug.LogError(string.Format(
"The brain {0} was set to inference mode but the Tensorflow library is not " +
"present in the Unity project.",
name));
}
#endif
agentInfos.Clear();
}
}

2
config/offline_bc_config.yaml


num_layers: 2
sequence_length: 32
memory_size: 256
demo_path: ./UnitySDK/Assets/Demonstrations/<Your_Demon_File>.demo
demo_path: ./UnitySDK/Assets/Demonstrations/<Your_Demo_File>.demo
HallwayLearning:
trainer: offline_bc

19
docs/Background-TensorFlow.md


performing computations using data flow graphs, the underlying representation of
deep learning models. It facilitates training and inference on CPUs and GPUs in
a desktop, server, or mobile device. Within the ML-Agents toolkit, when you
train the behavior of an agent, the output is a TensorFlow model (.tf) file
train the behavior of an agent, the output is a TensorFlow model (.bytes) file
that you can then embed within a Learning Brain. Unless you implement a new
algorithm, the use of TensorFlow is mostly abstracted away and behind the
scenes.

recommend our guide on [using Tensorboard with ML-Agents](Using-Tensorboard.md) or
this [tutorial](https://github.com/dandelionmane/tf-dev-summit-tensorboard-tutorial).
## Tensorflow Model Inference
## TensorflowSharp
We have are using the [Unity Machine Learning Inference SDK](Inference-Engine.md) to
run the models inside of Unity. In order to use it, you will need to have an
appropriate backend downloaded.
This means that the Learning Brain is not natively supported since Unity scripts
are written in C#. Consequently, to enable the Learning Brain, we leverage a
third-party library
[TensorFlowSharp](https://github.com/migueldeicaza/TensorFlowSharp) which
provides .NET bindings to TensorFlow. Thus, when a Unity environment that
contains a Learning Brain is built, inference is performed via TensorFlowSharp.
We provide an additional in-depth overview of how to leverage
[TensorFlowSharp within Unity](Using-TensorFlow-Sharp-in-Unity.md)
which will become more
relevant once you install and start training behaviors within the ML-Agents
toolkit. Given the reliance on TensorFlowSharp, the Learning Brain is currently
marked as experimental.

2
docs/Background-Unity.md


* [Physics](https://docs.unity3d.com/Manual/PhysicsSection.html)
* [Ordering of event functions](https://docs.unity3d.com/Manual/ExecutionOrder.html)
(e.g. FixedUpdate, Update)
* [Prefabs](https://docs.unity3d.com/Manual/Prefabs.html)

101
docs/Basic-Guide.md


# Basic Guide
This guide will show you how to use a pre-trained model in an example Unity
environment, and show you how to train the model yourself.
environment (3D Ball) and show you how to train the model yourself.
If you are not familiar with the [Unity Engine](https://unity3d.com/unity), we
highly recommend the [Roll-a-ball

Equivalent or .NET 4.x Equivalent)**
6. Go to **File** > **Save Project**
## Setting up the Inference Engine
## Setting up TensorFlowSharp
We provide pre-trained models for all the agents in all our demo environments.
To be able to run those models, you'll first need to set-up the Inference
Engine. The Inference Engine is a general API to
run neural network models in Unity that leverages existing inference libraries such
as TensorFlowSharp and Apple's Core ML. Since the ML-Agents Toolkit uses TensorFlow
for training neural network models, the output model format is TensorFlow and
the model files include a `.tf` extension. Consequently, you need to install
the TensorFlowSharp backend to be able to run these models within the Unity
Editor. You can find instructions
on how to install the TensorFlowSharp backend [here](Inference-Engine.md).
Once the backend is installed, you will need to reimport the models : Right click
on the `.tf` model and select `Reimport`.
We provide pre-trained models (`.bytes` files) for all the agents
in all our demo environments. To be able to run those models, you'll
first need to set-up TensorFlowSharp support. Consequently, you need to install
the TensorFlowSharp plugin to be able to run these models within the Unity
Editor.
1. Download the [TensorFlowSharp Plugin](https://s3.amazonaws.com/unity-ml-agents/0.5/TFSharpPlugin.unitypackage)
2. Import it into Unity by double clicking the downloaded file. You can check
if it was successfully imported by checking the
TensorFlow files in the Project window under **Assets** > **ML-Agents** >
**Plugins** > **Computer**.
3. Go to **Edit** > **Project Settings** > **Player** and add `ENABLE_TENSORFLOW`
to the `Scripting Define Symbols` for each type of device you want to use
(**`PC, Mac and Linux Standalone`**, **`iOS`** or **`Android`**).
![Project Settings](images/project-settings.png)
**Note**: If you don't see anything under **Assets**, drag the
`UnitySDK/Assets/ML-Agents` folder under **Assets** within Project window.
![Imported TensorFlowsharp](images/imported-tensorflowsharp.png)
We've included pre-trained models for the 3D Ball example.
1. In the **Project** window, go to `Assets/ML-Agents/Examples/3DBall/Scenes` folder
1. In the **Project** window, go to the `Assets/ML-Agents/Examples/3DBall/Scenes` folder
2. In the **Project** window, go to `Assets/ML-Agents/Examples/3DBall/Prefabs` folder
and select the `Game/Platform` prefab.
3. In the `Ball 3D Agent` Component: Drag the **3DBallLearning** Brain located in
`Assets/ML-Agents/Examples/3DBall/Brains` into the `Brain` property of
the `Ball 3D Agent`.
4. Make sure that all of the Agents in the Scene now have **3DBallLearning** as `Brain`.
__Note__ : You can modify multiple game objects in a scene by selecting them all at
2. In the **Project** window, go to the `Assets/ML-Agents/Examples/3DBall/Prefabs` folder.
Expand `Game` and click on the `Platform` prefab. You should see the `Platform` prefab in the **Inspector** window.
**Note**: The platforms in the `3DBall` scene were created using the `Platform` prefab. Instead of updating all 12 platforms individually, you can update the `Platform` prefab instead.
![Platform Prefab](images/platform_prefab.png)
3. In the **Project** window, drag the **3DBallLearning** Brain located in
`Assets/ML-Agents/Examples/3DBall/Brains` into the `Brain` property under `Ball 3D Agent (Script)` component in the **Inspector** window.
![3dball learning brain](images/3dball_learning_brain.png)
4. You should notice that each `Platform` under each `Game` in the **Hierarchy** windows now contains **3DBallLearning** as `Brain`. __Note__ : You can modify multiple game objects in a scene by selecting them all at
5. In the **Project** window, locate the `Assets/ML-Agents/Examples/3DBall/TFModels`
5. In the **Project** window, click on the **3DBallLearning** Brain located in
`Assets/ML-Agents/Examples/3DBall/Brains`. You should see the properties in the **Inspector** window.
6. In the **Project** window, open the `Assets/ML-Agents/Examples/3DBall/TFModels`
6. Drag the `3DBallLearning` model file from the `Assets/ML-Agents/Examples/3DBall/TFModels`
folder to the **Model** field of the **3DBallLearning** Brain.
7. Click the **Play** button and you will see the platforms balance the balls
7. Drag the `3DBallLearning` model file from the `Assets/ML-Agents/Examples/3DBall/TFModels`
folder to the **Model** field of the **3DBallLearning** Brain in the **Inspector** window. __Note__ : All of the brains should now have `3DBallLearning` as the TensorFlow model in the `Model` property
8. Click the **Play** button and you will see the platforms balance the balls
![Running a pretrained model](images/running-a-pretrained-model.gif)
![Running a pretrained model](images/running-a-pretrained-model.gif)
## Using the Basics Jupyter Notebook

## Training the Brain with Reinforcement Learning
### Adding a Brain to the training session
### Setting up the enviornment for training
1. Assign the **3DBallLearning** Brain to the agents you would like to train.
__Note:__ You can assign the same Brain to multiple agents at once : To do so, you can
use the prefab system. When an agent is created from a prefab, modifying the prefab
will modify the agent as well. If the agent does not synchronize with the prefab, you
can hit the Revert button on top of the Inspector.
Alternatively, you can select multiple agents in the scene and modify their `Brain`
property all at once.
2. Select the **Ball3DAcademy** GameObject and make sure the **3DBallLearning** Brain
is in the Broadcast Hub. In order to train, you need to toggle the
`Control` checkbox.
__Note:__ Assigning a Brain to an agent (dragging a Brain into the `Brain` property of
1. Each platform agent needs an assigned `Learning Brain`. In this example, each platform agent was created using a prefab. To update all of the brains in each platform agent at once, you only need to update the platform agent prefab. In the **Project** window, go to the `Assets/ML-Agents/Examples/3DBall/Prefabs` folder. Expand `Game` and click on the `Platform` prefab. You should see the `Platform` prefab in the **Inspector** window. In the **Project** window, drag the **3DBallLearning** Brain located in `Assets/ML-Agents/Examples/3DBall/Brains` into the `Brain` property under `Ball 3D Agent (Script)` component in the **Inspector** window.
**Note**: The Unity prefab system will modify all instances of the agent properties in your scene. If the agent does not synchronize automatically with the prefab, you can hit the Revert button in the top of the **Inspector** window.
2. In the **Hierarchy** window, select `Ball3DAcademy`.
3. In the **Project** window, go to `Assets/ML-Agents/Examples/3DBall/Brains` folder and drag the **3DBallLearning** Brain to the `Brains` property under `Braodcast Hub` in the `Ball3DAcademy` object in the **Inspector** window. In order to train, make sure the `Control` checkbox is selected.
**Note:** Assigning a Brain to an agent (dragging a Brain into the `Brain` property of
![Set Brain to External](images/mlagents-SetBrainToTrain.png)
![Set Brain to External](images/mlagents-SetBrainToTrain.png)
### Training the environment

Editor"_ is displayed on the screen, you can press the :arrow_forward: button
in Unity to start training in the Editor.
**Note**: Alternatively, you can use an executable rather than the Editor to
**Note**: Alternatively, you can use an executable rather than the Editor to
perform training. Please refer to [this
page](Learning-Environment-Executable.md) for instructions on how to build and
use an executable.

### After training
You can press Ctrl+C to stop the training, and your trained model will be at
`models/<run-identifier>/<brain_name>.tf` where
`models/<run-identifier>/<brain_name>.bytes` where
`<brain_name>` is the name of the Brain corresponding to the model.
(**Note:** There is a known bug on Windows that causes the saving of the model to
fail when you early terminate the training, it's recommended to wait until Step

`UnitySDK/Assets/ML-Agents/Examples/3DBall/TFModels/`.
2. Open the Unity Editor, and select the **3DBall** scene as described above.
3. Select the **3DBallLearning** Learning Brain from the Scene hierarchy.
5. Drag the `<brain_name>.tf` file from the Project window of
5. Drag the `<brain_name>.bytes` file from the Project window of
the Editor to the **Model** placeholder in the **3DBallLearning**
inspector window.
6. Press the :arrow_forward: button at the top of the Editor.

16
docs/FAQ.md


to [Setting Up The ML-Agents Toolkit Within
Unity](Installation.md#setting-up-ml-agent-within-unity) for solution.
## Cannot drag Model into Learning Brain
## TensorFlowSharp flag not turned on
You might not have the appropriate backend required to import the model. Refer to the
[Inference Engine](Inference-Engine.md) for more information on how to import backends
and reimport the asset.
If you have already imported the TensorFlowSharp plugin, but haven't set
ENABLE_TENSORFLOW flag for your scripting define symbols, you will see the
following error message:
```console
UnityAgentsException: The brain 3DBallLearning was set to inference mode but the Tensorflow library is not present in the Unity project.
```
This error message occurs because the TensorFlowSharp plugin won't be used
without the ENABLE_TENSORFLOW flag, refer to [Setting Up The ML-Agents Toolkit
Within Unity](Installation.md#setting-up-ml-agent-within-unity) for solution.
## Environment Permission Error

_Solution_: Look into the [log
files](https://docs.unity3d.com/Manual/LogFiles.html) generated by the Unity
Environment to figure what error happened.
# _Cause_: You have assigned HTTP_PROXY and HTTPS_PROXY values in your
* _Cause_: You have assigned HTTP_PROXY and HTTPS_PROXY values in your
environment variables. _Solution_: Remove these values and try again.
## Communication port {} still in use

58
docs/Getting-Started-with-Balance-Ball.md


In order to install and set up the ML-Agents toolkit, the Python dependencies
and Unity, see the [installation instructions](Installation.md).
## Understanding a Unity Environment (3D Balance Ball)
## Understanding the Unity Environment (3D Balance Ball)
An agent is an autonomous actor that observes and interacts with an
_environment_. In the context of Unity, an environment is a scene containing an

The Academy object for the scene is placed on the Ball3DAcademy GameObject. When
you look at an Academy component in the inspector, you can see several
properties that control how the environment works.
The **Broadcast Hub** keeps track of which Brains will send data during training,
If a Brain is added to the hub, his data will be sent to the external training
The **Broadcast Hub** keeps track of which Brains will send data during training.
If a Brain is added to the hub, the data from this Brain will be sent to the external training
control the agents linked to the Brain to train them.
The **Training** and **Inference Configuration** properties
control and train the agents linked to the Brain.
The **Training Configuration** and **Inference Configuration** properties
Typically, you set low graphics quality and a high time scale for the **Training
configuration** and a high graphics quality and the timescale to `1.0` for the
Typically, you would set a low graphics quality and timescale to greater `1.0` for the **Training
Configuration** and a high graphics quality and timescale to `1.0` for the
**Inference Configuration** .
**Note:** if you want to observe the environment during training, you can adjust

Another aspect of an environment to look at is the Academy implementation. Since
Another aspect of an environment is the Academy implementation. Since
the base Academy class is abstract, you must always define a subclass. There are
three functions you can implement, though they are all optional:

### Brain
Brains are assets that exist in your project folder. The Ball3DAgents are connected
to a Brain, for example : the **3DBallLearning**.
A Brain doesn't store any information about an Agent, it just
As of v0.6, a Brain is a Unity asset and exists within the `UnitySDK` folder. These brains (ex. **3DBallLearning.asset**) are loaded into each Agent object (ex. **Ball3DAgents**). A Brain doesn't store any information about an Agent, it just
returns the chosen action to the Agent. Thus, all Agents can share the same
Brain, but act independently. The Brain settings tell you quite a bit about how
returns the chosen action to the Agent. All Agents can share the same
Brain, but would act independently. The Brain settings tell you quite a bit about how
You can create Brain objects by selecting `Assets ->
Create -> ML-Agents -> Brain`. There are 3 kinds of Brains :
The **Learning Brain** is a Brain that uses a Neural Network to take decisions.
When the Brain is checked as `Control` in the Academy **Broadcast Hub**, the
external process will be taking decisions for the agents
and generate a neural network when the training is over. You can also use the
You can create new Brain assets by selecting `Assets ->
Create -> ML-Agents -> Brain`. There are 3 types of Brains.
The **Learning Brain** is a Brain that uses a trained neural network to make decisions.
When the `Control` box is checked in the Brains property under the **Broadcast Hub** in the Academy, the external process that is training the neural network will take over decision making for the agents
and ultimately generate a trained neural network. You can also use the
The **Heuristic** Brain allows you to hand-code the Agent's logic by extending
The **Heuristic** Brain allows you to hand-code the Agent logic by extending
can be useful when testing your agents and environment. If none of these types
of Brains do what you need, you can implement your own Brain.
can be useful when testing your agents and environment. You can also implement your own type of Brain.
In this tutorial, you will use a **Learning Brain** for training.
In this tutorial, you will use the **Learning Brain** for training.
#### Vector Observation Space

explaining it.
To train the agents within the Ball Balance environment, we will be using the
Python package. We have provided a convenient script called `mlagents-learn`
Python package. We have provided a convenient command called `mlagents-learn`
which accepts arguments used to configure both training and inference phases.
We can use `run_id` to identify the experiment and create a folder where the

use it with Agents having a **Learning Brain**.
__Note:__ Do not just close the Unity Window once the `Saved Model` message appears.
Either wait for the training process to close the window or press Ctrl+C at the
command-line prompt. If you simply close the window manually, the `.tf` file
command-line prompt. If you close the window manually, the `.bytes` file
### Setting up Inference Support
### Setting up TensorFlowSharp
In order to run neural network models inside of Unity, you will need to setup the
Inference Engine with an appropriate backend. See [here](Inference-Engine.md) for more
information.
Because TensorFlowSharp support is still experimental, it is disabled by
default. Please note that the `Learning` Brain inference can only be used with
TensorFlowSharp.
To set up the TensorFlowSharp Support, follow [Setting up ML-Agents Toolkit
within Unity](Basic-Guide.md#setting-up-ml-agents-within-unity) section. of the
Basic Guide page.
### Embedding the trained model into Unity

2
docs/Glossary.md


* **Agent** - Unity Component which produces observations and takes actions in
the environment. Agents actions are determined by decisions produced by a
linked Brain.
* **Brain** - Unity Component which makes decisions for the agents linked to it.
* **Brain** - Unity Asset which makes decisions for the agents linked to it.
* **Decision** - The specification produced by a Brain for an action to be
carried out given an observation.
* **Editor** - The Unity Editor, which may include any pane (e.g. Hierarchy,

329
docs/Learning-Environment-Create-New.md


steps:
1. Create an environment for your agents to live in. An environment can range
from a simple physical simulation containing a few objects to an entire game
or ecosystem.
from a simple physical simulation containing a few objects to an entire game
or ecosystem.
containing the environment. Your Academy class can implement a few optional
methods to update the scene independently of any agents. For example, you can
add, move, or delete agents and other entities in the environment.
3. Create one or more Brain assets by clicking `Assets -> Create -> ML-Agents
-> Bain`. And name them appropriately.
containing the environment. Your Academy class can implement a few optional
methods to update the scene independently of any agents. For example, you can
add, move, or delete agents and other entities in the environment.
3. Create one or more Brain assets by clicking **Assets** > **Create** >
**ML-Agents** > **Brain**, and naming them appropriately.
uses to observe its environment, to carry out assigned actions, and to
calculate the rewards used for reinforcement training. You can also implement
optional methods to reset the Agent when it has finished or failed its task.
uses to observe its environment, to carry out assigned actions, and to
calculate the rewards used for reinforcement training. You can also implement
optional methods to reset the Agent when it has finished or failed its task.
in the scene that represents the Agent in the simulation. Each Agent object
must be assigned a Brain object.
in the scene that represents the Agent in the simulation. Each Agent object
must be assigned a Brain object.
[run the training process](Training-ML-Agents.md).
[run the training process](Training-ML-Agents.md).
**Note:** If you are unfamiliar with Unity, refer to
[Learning the interface](https://docs.unity3d.com/Manual/LearningtheInterface.html)

importing the ML-Agents assets into it:
1. Launch the Unity Editor and create a new project named "RollerBall".
2. In a file system window, navigate to the folder containing your cloned
ML-Agents repository.
3. Drag the `ML-Agents` folder from `UnitySDK/Assets` to the Unity Editor
Project window.
4. Setup the ML-Agents toolkit by following the instructions [here](https://github.com/Unity-Technologies/ml-agents/blob/master/docs/Basic-Guide.md#setting-up-the-ml-agents-toolkit-within-unity).
2. Make sure that the Scripting Runtime Version for the project is set to use
**.NET 4.x Equivalent** (This is an experimental option in Unity 2017,
but is the default as of 2018.3.)
3. In a file system window, navigate to the folder containing your cloned
ML-Agents repository.
4. Drag the `ML-Agents` and `Gizmos` folders from `UnitySDK/Assets` to the Unity
Editor Project window.
Your Unity **Project** window should contain the following assets:

for the Agent to move around on, a Cube to act as the goal or target for the
agent to seek, and a Sphere to represent the Agent itself.
### Create the floor plane
### Create the Floor Plane
3. Select Plane to view its properties in the Inspector window.
4. Set Transform to Position = (0,0,0), Rotation = (0,0,0), Scale = (1,1,1).
3. Select the Floor Plane to view its properties in the Inspector window.
4. Set Transform to Position = (0, 0, 0), Rotation = (0, 0, 0), Scale = (1, 1, 1).
default-material to *floor*.
default-material to *LightGridFloorSquare* (or any suitable material of your choice).
name. This opens the **Object Picker** dialog so that you can choose the a
name. This opens the **Object Picker** dialog so that you can choose a
different material from the list of all materials currently in the project.)
![The Floor in the Inspector window](images/mlagents-NewTutFloor.png)

1. Right click in Hierarchy window, select 3D Object > Cube.
2. Name the GameObject "Target"
3. Select Target to view its properties in the Inspector window.
4. Set Transform to Position = (3,0.5,3), Rotation = (0,0,0), Scale = (1,1,1).
3. Select the Target Cube to view its properties in the Inspector window.
4. Set Transform to Position = (3, 0.5, 3), Rotation = (0, 0, 0), Scale = (1, 1, 1).
default-material to *Block*.
default-material to *Block*.
![The Target Cube in the Inspector window](images/mlagents-NewTutBlock.png)

2. Name the GameObject "RollerAgent"
3. Select Target to view its properties in the Inspector window.
4. Set Transform to Position = (0,0.5,0), Rotation = (0,0,0), Scale = (1,1,1).
3. Select the RollerAgent Sphere to view its properties in the Inspector window.
4. Set Transform to Position = (0, 0.5, 0), Rotation = (0, 0, 0), Scale = (1, 1, 1).
default-material to *checker 1*.
default-material to *CheckerSquare*.
7. Add the Physics/Rigidbody component to the Sphere. (Adding a Rigidbody)
7. Add the Physics/Rigidbody component to the Sphere.
![The Agent GameObject in the Inspector window](images/mlagents-NewTutSphere.png)

Next, edit the new `RollerAcademy` script:
1. In the Unity Project window, double-click the `RollerAcademy` script to open
it in your code editor. (By default new scripts are placed directly in the
**Assets** folder.)
2. In the editor, change the base class from `MonoBehaviour` to `Academy`.
3. Delete the `Start()` and `Update()` methods that were added by default.
it in your code editor. (By default new scripts are placed directly in the
**Assets** folder.)
2. In the code editor, add the statement, `using MLAgents;`.
3. Change the base class from `MonoBehaviour` to `Academy`.
4. Delete the `Start()` and `Update()` methods that were added by default.
In such a basic scene, we don't need the Academy to initialize, reset, or
otherwise control any objects in the environment so we have the simplest

![The Academy properties](images/mlagents-NewTutAcademy.png)
## Add Brains
## Add Brain Assets
(Learning, Heuristic or player) determines how the Brain makes decisions.
(Learning, Heuristic or Player) determines how the Brain makes decisions.
1. Go to `Assets -> Create -> ML-Agents` and select the type of Brain you want to
create. In this tutorial, we will create a **Learning Brain** and
a **Player Brain**.
1. Go to **Assets** > **Create** > **ML-Agents** and select the type of Brain asset
you want to create. For this tutorial, create a **Learning Brain** and
a **Player Brain**.
![Creating a Brain Asset](images/mlagents-NewTutBrain.png)
![The Brain default properties](images/mlagents-NewTutBrain.png)
## Implement an Agent
To create the Agent:

1. In the Unity Project window, double-click the `RollerAgent` script to open it
in your code editor.
2. In the editor, change the base class from `MonoBehaviour` to `Agent`.
2. In the editor, add the `using MLAgents;` statement and then change the base
class from `MonoBehaviour` to `Agent`.
leave it alone for now.
leave it alone for now.
So far, these are the basic steps that you would use to add ML-Agents to any
Unity project. Next, we will add the logic that will let our Agent learn to roll

this reference, add a public field of type `Transform` to the RollerAgent class.
Public fields of a component in Unity get displayed in the Inspector window,
allowing you to choose which GameObject to use as the target in the Unity
Editor. To reset the Agent's velocity (and later to apply force to move the
Editor.
To reset the Agent's velocity (and later to apply force to move the
agent) we need a reference to the Rigidbody component. A
[Rigidbody](https://docs.unity3d.com/ScriptReference/Rigidbody.html) is Unity's
primary element for physics simulation. (See

{
if (this.transform.position.y < 0)
{
// The Agent fell
this.transform.position = new Vector3(0, 0.5f, 0);
// If the Agent fell, zero its momentum
this.transform.position = new Vector3( 0, 0.5f, 0);
else
{
// Move the target to a new spot
Target.position = new Vector3(Random.value * 8 - 4,
0.5f,
Random.value * 8 - 4);
}
// Move the target to a new spot
Target.position = new Vector3(Random.value * 8 - 4,
0.5f,
Random.value * 8 - 4);
Next, let's implement the Agent.CollectObservations() function.
Next, let's implement the `Agent.CollectObservations()` method.
### Observing the Environment

In our case, the information our Agent collects includes:
* Position of the target. In general, it is better to use the relative position
of other objects rather than the absolute position for more generalizable
training. Note that the Agent only collects the x and z coordinates since the
floor is aligned with the x-z plane and the y component of the target's
position never changes.
* Position of the target.
// Calculate position relative to the target
Vector3 relativePosition = Target.position - this.transform.position;
// Position relative to the target
AddVectorObs(relativePosition.x / 5);
AddVectorObs(relativePosition.z / 5);
AddVectorObs(Target.position);
* Position of the Agent itself relative to the size of the floor (which is 10)
* Position of the Agent itself.
// Relative position
AddVectorObs(this.transform.position.x / 5);
AddVectorObs(this.transform.position.z / 5);
AddVectorObs(this.transform.position);
it doesn't overshoot the target and roll off the platform.
it doesn't overshoot the target and roll off the platform.
AddVectorObs(rBody.velocity.x / 5);
AddVectorObs(rBody.velocity.z / 5);
AddVectorObs(rBody.velocity.x);
AddVectorObs(rBody.velocity.z);
All the values are divided to normalize the inputs to the neural network to
the range [-1,1]. (The platform is a square which reaches from positions -5 to +5
thereby having an edge length of 10 units.)
In total, the state observation contains 6 values and we need to use the
In total, the state observation contains 8 values and we need to use the
// Calculate position relative to the target
Vector3 relativePosition = Target.position - this.transform.position;
// Position relative to the target
AddVectorObs(relativePosition.x / 5);
AddVectorObs(relativePosition.z / 5);
// Relative position
AddVectorObs(this.transform.position.x / 10);
AddVectorObs(this.transform.position.x / 10);
// Target and Agent positions
AddVectorObs(Target.position);
AddVectorObs(this.transform.position);
AddVectorObs(rBody.velocity.x/5);
AddVectorObs(rBody.velocity.z/5);
AddVectorObs(rBody.velocity.x);
AddVectorObs(rBody.velocity.z);
The final part of the Agent code is the Agent.AgentAction() function, which
receives the decision from the Brain.
The final part of the Agent code is the `Agent.AgentAction()` method, which
receives the decision from the Brain and assigns the reward.
the `Vector Action Space Type` and `Vector Action Space Size` settings of the
the `Vector Action` `Space Type` and `Space Size` settings of the
`Vector Action Size` to 2. The first element,`action[0]` determines the force
`Space Size` to 2. The first element,`action[0]` determines the force
to set `Vector Action Size` to 3. Each of these values returned by the network
are between `-1` and `1.` Note the Brain really has no idea what the values in
to set `Vector Action Size` to 3.) Note that the Brain really has no idea what the values in
The RollerAgent applies the values from the action[] array to its Rigidbody
The RollerAgent applies the values from the `action[]` array to its Rigidbody
component, `rBody`, using the `Rigidbody.AddForce` function:
```csharp

### Rewards
Reinforcement learning requires rewards. Assign rewards in the `AgentAction()`
function. The learning algorithm uses the rewards assigned to the Agent at each
step in the simulation and learning process to determine whether it is giving
function. The learning algorithm uses the rewards assigned to the Agent during
the simulation and learning process to determine whether it is giving
assigned task (reaching the Target cube, in this case) and punish the Agent if
it irrevocably fails (falls off the platform). You can sometimes speed up
training with sub-rewards that encourage behavior that helps the Agent complete
the task. For example, the RollerAgent reward system provides a small reward if
the Agent moves closer to the target in a step and a small negative reward at
each step which encourages the Agent to complete its task quickly.
assigned task. In this case, the Agent is given a reward of 1.0 for reaching the
Target cube.
When it does, the code increments the Agent.reward variable by 1.0 and marks the
agent as finished by setting the Agent to done.
When it does, the code calls the `Agent.SetReward()` method to assign a
reward of 1.0 and marks the agent as finished by calling the `Done()` method
on the Agent.
```csharp
float distanceToTarget = Vector3.Distance(this.transform.position,

{
AddReward(1.0f);
SetReward(1.0f);
Done();
}
```

`ResetOnDone` mechanism and doesn't set a `Max Steps` limit for the Academy (so
it never resets the environment).
It can also encourage an Agent to finish a task more quickly by assigning a
negative reward at each step:
```csharp
// Time penalty
AddReward(-0.05f);
```
Finally, to punish the Agent for falling off the platform, assign a large
negative reward and, of course, set the Agent to done so that it resets itself
in the next step:
Finally, if the Agent falls off the platform, set the Agent to done so that it can reset itself:
AddReward(-1.0f);
Done();
}
```

```csharp
public float speed = 10;
private float previousDistance = float.MaxValue;
// Actions, size = 2
Vector3 controlSignal = Vector3.zero;
controlSignal.x = vectorAction[0];
controlSignal.z = vectorAction[1];
rBody.AddForce(controlSignal * speed);
// Rewards
float distanceToTarget = Vector3.Distance(this.transform.position,
Target.position);

{
AddReward(1.0f);
SetReward(1.0f);
// Time penalty
AddReward(-0.05f);
AddReward(-1.0f);
// Actions, size = 2
Vector3 controlSignal = Vector3.zero;
controlSignal.x = vectorAction[0];
controlSignal.z = vectorAction[1];
rBody.AddForce(controlSignal * speed);
}
}
Note the `speed` and `previousDistance` class variables defined before the
Note the `speed` class variable defined before the
function. Since `speed` is public, you can set the value from the Inspector
window.

to connect everything together in the Unity Editor. This involves assigning the
Brain asset to the Agent, changing some of the Agent Components properties, and
Brain asset to the Agent, changing some of the Agent Component's properties, and
Brains to the **Broadcast Hub**.
2. Select the RollerAgent GameObject to show its properties in the Inspector
window.
3. Drag the Brain `RollerBallPlayer` from the Project window to the
RollerAgent `Brain` field.
4. Change `Decision Frequency` from `1` to `5`.
Brains to the **Broadcast Hub**.
2. Select the **RollerAgent** GameObject to show its properties in the Inspector
window.
3. Drag the Brain **RollerBallPlayer** from the Project window to the
RollerAgent **Brain** field.
4. Change **Decision Frequency** from `1` to `10`.
5. Drag the Target GameObject from the Hierarchy window to the RollerAgent
Target field.
Also, drag the Target GameObject from the Hierarchy window to the RollerAgent
Target field.
Finally, select the **RollerBallBrain** Asset in the **Project** window so that you can
see its properties in the Inspector window. Set the following properties:
Finally, select the the `RollerBallBrain` and `RollerBallPlayer` Brain assets
so that you can edit their properties in the Inspector window. Set the following
properties on both of them:
* `Vector Observation` `Space Size` = 8
* `Vector Action` `Space Type` = **Continuous**
* `Vector Action` `Space Size` = 2
* `Vector Observation Space Size` = 6
* `Vector Action Space Type` = **Continuous**
* `Vector Action Space Size` = 2
Select the **RollerBallPlayer** Asset in the **Project** window and set the same
property values.
Now you are ready to test the environment before training.

positive values and one to specify negative values for each action, for a total
of four keys.
1. Select the `RollerBallPlayer` Brain to view its properties in the Inspector.
2. Expand the **Continuous Player Actions** dictionary (only visible when using
a **PlayerBrain**).
1. Select the `RollerBallPlayer` Aset to view its properties in the Inspector.
2. Expand the **Key Continuous Player Actions** dictionary (only visible when using
a **PlayerBrain**).
3. Set **Size** to 4.
4. Set the following mappings:

`env_name` to the name of the environment file you specify when building this
environment.
## Training the Environment
Then drag the `RollerBallBrain` into the Academy's `Broadcast Hub` and check
to `Control` checkbox for that brain. From there, the process is
Then, select the Academy GameObject and check the `Control` checkbox for
the RollerBallBrain item in the **Broadcast Hub** list. From there, the process is
The hyperparameters for training are specified in the configuration file that you ls
pass to the `mlagents-learn` program. Using the default settings specified
in the `config/trainer_config.yaml` file (in your ml-agents folder), the
RollerAgent takes about 300,000 steps to train. However, you can change the
following hyperparameters to speed up training considerably (to under 20,000 steps):
batch_size: 10
buffer_size: 100
Since this example creates a very simple training environment with only a few inputs
and outputs, using small batch and buffer sizes speeds up the training considerably.
However, if you add more complexity to the environment or change the reward or
observation functions, you might also find that training performs better with different
hyperparameter values.
**Note:** In addition to setting these hyperparameter values, the Agent
**DecisionFrequency** parameter has a large effect on training time and success.
A larger value reduces the number of decisions the training algorithm has to consider and,
in this simple environment, speeds up training.
To train in the editor, run the following Python command from a Terminal or Console
window before pressing play:
mlagents-learn config/config.yaml --run-id=RollerBall-1 --train
(where `config.yaml` is a copy of `trainer_config.yaml` that you have edited
to change the `batch_size` and `buffer_size` hyperparameters for your brain.)
**Note:** If you get a `command not found` error when running this command, make sure
that you have followed the *Install Python and mlagents Package* section of the
ML-Agents [Installation](Installation.md) instructions.
To monitor the statistics of Agent performance during training, use
[TensorBoard](Using-Tensorboard.md).
![TensorBoard statistics display](images/mlagents-RollerAgentStats.png)
In particular, the *cumulative_reward* and *value_estimate* statistics show how
well the Agent is achieving the task. In this example, the maximum reward an
Agent can earn is 1.0, so these statistics approach that value when the Agent
has successfully *solved* the problem.
**Note:** If you use TensorBoard, always increment or change the `run-id`
you pass to the `mlagents-learn` command for each training run. If you use
the same id value, the statistics for multiple runs are combined and become
difficult to interpret.
## Review: Scene Layout
This section briefly reviews how to organize your scene when using Agents in

to use Unity ML-Agents:
* Academy
* Agents
You also need to have brain assets linked appropriately to Agents and to Academy
to use Unity ML-Agents: an Academy and one or more Agents. You also need to
have brain assets linked appropriately to your Agents and to the Academy.
* You can only train Learning Brains that have been included into the Academy's
Broadcast Hub.
* You can only train Learning Brains that have been added to the Academy's Broadcast Hub list.

10
docs/Learning-Environment-Design-Learning-Brains.md


To use a graph model:
1. Select the **Learning Brain** asset in the **Project** window of the Unity Editor.
**Note:** In order to use the **Learning** Brain, you have appropriate backend for the
Inference Engine. See [here](Inference-Engine.md).
**Note:** In order to use the **Learning** Brain with inference, you need to have
TensorFlowSharp enabled. Refer to [this section](Basic-Guide.md#setting-up-ml-agents-within-unity) for more information.
2. Import the `model_name` file produced by the PPO training
program. (Where `model_name` is the name of the model file, which is
constructed from the name of your Unity environment executable and the run-id

[import assets into Unity](https://docs.unity3d.com/Manual/ImportingAssets.html)
in various ways. The easiest way is to simply drag the file into the
**Project** window and drop it into an appropriate folder.
3. Once the `model_name.tf` file is imported, drag it from the **Project**
3. Once the `model_name.bytes` file is imported, drag it from the **Project**
window to the **Model** field of the Brain component.
If you are using a model produced by the ML-Agents `mlagents-learn` command, use

The default values of the TensorFlow graph parameters work with the model
produced by the PPO and BC training code in the ML-Agents SDK. To use a default
ML-Agents model, the only parameter that you need to set is the `Model`,
which must be set to the `.tf` file containing the trained model itself.
which must be set to the `.bytes` file containing the trained model itself.
* `Model` : This must be the `.tf` file corresponding to the pre-trained
* `Model` : This must be the `.bytes` file corresponding to the pre-trained