浏览代码

Merge pull request #1931 from Unity-Technologies/release-v0.8

Release v0.8
/hotfix-v0.9.2a
GitHub 6 年前
当前提交
2d1bda57
共有 161 个文件被更改,包括 8607 次插入7091 次删除
  1. 17
      .circleci/config.yml
  2. 3
      .gitignore
  3. 8
      Dockerfile
  4. 4
      README.md
  5. 29
      UnitySDK/Assets/ML-Agents/Editor/AgentEditor.cs
  6. 2
      UnitySDK/Assets/ML-Agents/Editor/BrainParametersDrawer.cs
  7. 1001
      UnitySDK/Assets/ML-Agents/Examples/3DBall/TFModels/3DBallHardLearning.nn
  8. 1001
      UnitySDK/Assets/ML-Agents/Examples/3DBall/TFModels/3DBallLearning.nn
  9. 6
      UnitySDK/Assets/ML-Agents/Examples/BananaCollectors/Scripts/BananaAgent.cs
  10. 622
      UnitySDK/Assets/ML-Agents/Examples/BananaCollectors/TFModels/BananaLearning.nn
  11. 22
      UnitySDK/Assets/ML-Agents/Examples/Basic/TFModels/BasicLearning.nn
  12. 272
      UnitySDK/Assets/ML-Agents/Examples/Bouncer/TFModels/BouncerLearning.nn
  13. 1001
      UnitySDK/Assets/ML-Agents/Examples/Crawler/TFModels/CrawlerDynamicLearning.nn
  14. 1001
      UnitySDK/Assets/ML-Agents/Examples/Crawler/TFModels/CrawlerStaticLearning.nn
  15. 306
      UnitySDK/Assets/ML-Agents/Examples/GridWorld/Scenes/GridWorld.unity
  16. 5
      UnitySDK/Assets/ML-Agents/Examples/GridWorld/Scenes/GridWorld.unity.meta
  17. 10
      UnitySDK/Assets/ML-Agents/Examples/GridWorld/Scripts/GridAgent.cs
  18. 997
      UnitySDK/Assets/ML-Agents/Examples/GridWorld/TFModels/GridWorldLearning.nn
  19. 999
      UnitySDK/Assets/ML-Agents/Examples/Hallway/TFModels/HallwayLearning.nn
  20. 1000
      UnitySDK/Assets/ML-Agents/Examples/PushBlock/TFModels/PushBlockLearning.nn
  21. 1000
      UnitySDK/Assets/ML-Agents/Examples/Pyramids/TFModels/PyramidsLearning.nn
  22. 1001
      UnitySDK/Assets/ML-Agents/Examples/Reacher/TFModels/ReacherLearning.nn
  23. 100
      UnitySDK/Assets/ML-Agents/Examples/SharedAssets/Scripts/RayPerception.cs
  24. 2
      UnitySDK/Assets/ML-Agents/Examples/SharedAssets/Scripts/RayPerception.cs.meta
  25. 75
      UnitySDK/Assets/ML-Agents/Examples/Soccer/Scripts/AgentSoccer.cs
  26. 4
      UnitySDK/Assets/ML-Agents/Examples/Soccer/Scripts/SoccerBallController.cs
  27. 48
      UnitySDK/Assets/ML-Agents/Examples/Soccer/Scripts/SoccerFieldArea.cs
  28. 1
      UnitySDK/Assets/ML-Agents/Examples/Tennis/Scripts/TennisArea.cs
  29. 1001
      UnitySDK/Assets/ML-Agents/Examples/Tennis/TFModels/TennisLearning.nn
  30. 1001
      UnitySDK/Assets/ML-Agents/Examples/WallJump/TFModels/BigWallJumpLearning.nn
  31. 1001
      UnitySDK/Assets/ML-Agents/Examples/WallJump/TFModels/SmallWallJumpLearning.nn
  32. 101
      UnitySDK/Assets/ML-Agents/Scripts/Academy.cs
  33. 120
      UnitySDK/Assets/ML-Agents/Scripts/Agent.cs
  34. 1
      UnitySDK/Assets/ML-Agents/Scripts/Batcher.cs
  35. 25
      UnitySDK/Assets/ML-Agents/Scripts/Brain.cs
  36. 49
      UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/AgentActionProto.cs
  37. 57
      UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/AgentInfoProto.cs
  38. 2
      UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/BrainParametersProto.cs
  39. 53
      UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/EnvironmentParametersProto.cs
  40. 16
      UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/UnityInput.cs
  41. 24
      UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/UnityMessage.cs
  42. 16
      UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/UnityOutput.cs
  43. 8
      UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/UnityRlInitializationOutput.cs
  44. 10
      UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/UnityRlInput.cs
  45. 13
      UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/UnityToExternalGrpc.cs
  46. 5
      UnitySDK/Assets/ML-Agents/Scripts/InferenceBrain/BarracudaModelParamLoader.cs
  47. 20
      UnitySDK/Assets/ML-Agents/Scripts/InferenceBrain/GeneratorImpl.cs
  48. 4
      UnitySDK/Assets/ML-Agents/Scripts/InferenceBrain/ModelParamLoader.cs
  49. 2
      UnitySDK/Assets/ML-Agents/Scripts/InferenceBrain/TFSharpInferenceEngine.cs
  50. 3
      UnitySDK/Assets/ML-Agents/Scripts/InferenceBrain/Utils/Multinomial.cs
  51. 4
      UnitySDK/Assets/ML-Agents/Scripts/LearningBrain.cs
  52. 2
      docs/Basic-Guide.md
  53. 66
      docs/Installation-Windows.md
  54. 39
      docs/Installation.md
  55. 78
      docs/Learning-Environment-Design-Agents.md
  56. 2
      docs/Learning-Environment-Examples.md
  57. 34
      docs/Migrating.md
  58. 3
      docs/Readme.md
  59. 12
      docs/Training-ML-Agents.md
  60. 213
      docs/images/agent.png
  61. 302
      docs/images/visual-observation.png
  62. 2
      gym-unity/README.md
  63. 4
      gym-unity/setup.py
  64. 7
      ml-agents/mlagents/trainers/__init__.py
  65. 3
      ml-agents/mlagents/trainers/bc/offline_trainer.py
  66. 3
      ml-agents/mlagents/trainers/bc/online_trainer.py
  67. 31
      ml-agents/mlagents/trainers/bc/trainer.py
  68. 98
      ml-agents/mlagents/trainers/learn.py
  69. 2
      ml-agents/mlagents/trainers/models.py
  70. 24
      ml-agents/mlagents/trainers/policy.py
  71. 2
      ml-agents/mlagents/trainers/ppo/models.py
  72. 63
      ml-agents/mlagents/trainers/ppo/trainer.py
  73. 95
      ml-agents/mlagents/trainers/trainer.py
  74. 116
      ml-agents/mlagents/trainers/trainer_controller.py
  75. 6
      ml-agents/setup.py
  76. 2
      protobuf-definitions/README.md
  77. 2
      protobuf-definitions/make.bat
  78. 2
      protobuf-definitions/make_for_win.bat
  79. 3
      protobuf-definitions/proto/mlagents/envs/communicator_objects/agent_action_proto.proto
  80. 3
      protobuf-definitions/proto/mlagents/envs/communicator_objects/agent_info_proto.proto
  81. 3
      protobuf-definitions/proto/mlagents/envs/communicator_objects/environment_parameters_proto.proto
  82. 4
      gym-unity/gym_unity/tests/test_gym.py
  83. 5
      ml-agents-envs/mlagents/envs/rpc_communicator.py
  84. 88
      ml-agents-envs/mlagents/envs/environment.py
  85. 25
      ml-agents-envs/mlagents/envs/communicator_objects/unity_rl_output_pb2.py
  86. 29
      ml-agents-envs/mlagents/envs/communicator_objects/unity_rl_input_pb2.py
  87. 18
      ml-agents-envs/mlagents/envs/communicator_objects/unity_rl_initialization_output_pb2.py
  88. 10
      ml-agents-envs/mlagents/envs/communicator_objects/unity_rl_initialization_input_pb2.py
  89. 12
      ml-agents-envs/mlagents/envs/communicator_objects/unity_output_pb2.py
  90. 14
      ml-agents-envs/mlagents/envs/communicator_objects/unity_message_pb2.py
  91. 12
      ml-agents-envs/mlagents/envs/communicator_objects/unity_input_pb2.py
  92. 12
      ml-agents-envs/mlagents/envs/communicator_objects/space_type_proto_pb2.py
  93. 14
      ml-agents-envs/mlagents/envs/communicator_objects/resolution_proto_pb2.py
  94. 12
      ml-agents-envs/mlagents/envs/communicator_objects/header_pb2.py
  95. 41
      ml-agents-envs/mlagents/envs/communicator_objects/environment_parameters_proto_pb2.py
  96. 20
      ml-agents-envs/mlagents/envs/communicator_objects/engine_configuration_proto_pb2.py
  97. 1
      ml-agents-envs/mlagents/envs/communicator_objects/demonstration_meta_proto_pb2.py
  98. 14
      ml-agents-envs/mlagents/envs/communicator_objects/command_proto_pb2.py
  99. 24
      ml-agents-envs/mlagents/envs/communicator_objects/brain_parameters_proto_pb2.py
  100. 48
      ml-agents-envs/mlagents/envs/communicator_objects/agent_info_proto_pb2.py

17
.circleci/config.yml


command: |
python3 -m venv venv
. venv/bin/activate
cd ml-agents && pip install -e .
cd ml-agents-envs && pip install -e .
cd ../ml-agents && pip install -e .
pip install pytest-cov==2.6.1 codacy-coverage==1.3.11
cd ../gym-unity && pip install -e .
- save_cache:
paths:

- run:
name: Run Tests
name: Run Tests for ml-agents and gym_unity
cd ml-agents/ && pytest tests/
pytest --junitxml=test-reports/junit.xml
pytest --cov=mlagents --cov-report xml --junitxml=test-reports/junit.xml -p no:warnings
python-codacy-coverage -r coverage.xml
path: ml-agents/test-reports
path: test-reports
path: ml-agents/test-reports
destination: ml-agents/test-reports
path: test-reports
destination: test-reports

3
.gitignore


/UnitySDK/Assets/ML-Agents/Plugins/System.Numerics*
/UnitySDK/Assets/ML-Agents/Plugins/System.ValueTuple*
# Plugins
/UnitySDK/Assets/ML-Agents/VideoRecorder*
# Generated doc folders
/docs/html

8
Dockerfile


# xvfb is used to do CPU based rendering of Unity
RUN apt-get install -y xvfb
# Install ml-agents-envs package locally
COPY ml-agents-envs /ml-agents-envs
WORKDIR /ml-agents-envs
RUN pip install -e .
# Install ml-agents package next
RUN pip install .
RUN pip install -e .
# port 5005 is the port used in in Editor training.
EXPOSE 5005

4
README.md


<img src="docs/images/image-banner.png" align="middle" width="3000"/>
# Unity ML-Agents Toolkit (Beta)
[![docs badge](https://img.shields.io/badge/docs-reference-blue.svg)](docs/Readme.md)
[![license badge](https://img.shields.io/badge/license-Apache--2.0-green.svg)](LICENSE)
**The Unity Machine Learning Agents Toolkit** (ML-Agents) is an open-source
Unity plugin that enables games and simulations to serve as environments for

* Visualizing network outputs within the environment
* Simplified set-up with Docker
* Wrap learning environments as a gym
* Utilizes the Unity Inference Engine
* Train using concurrent Unity environment instances
## Documentation

29
UnitySDK/Assets/ML-Agents/Editor/AgentEditor.cs


"agentParameters.onDemandDecision");
SerializedProperty cameras = serializedAgent.FindProperty(
"agentParameters.agentCameras");
SerializedProperty renderTextures = serializedAgent.FindProperty(
"agentParameters.agentRenderTextures");
if (cameras.arraySize > 0 && renderTextures.arraySize > 0)
{
EditorGUILayout.HelpBox("Brain visual observations created by first getting all cameras then all render textures.", MessageType.Info);
}
EditorGUILayout.LabelField("Agent Cameras");
for (int i = 0; i < cameras.arraySize; i++)
{

}
EditorGUILayout.EndHorizontal();
EditorGUILayout.LabelField("Agent RenderTextures");
for (int i = 0; i < renderTextures.arraySize; i++)
{
EditorGUILayout.PropertyField(
renderTextures.GetArrayElementAtIndex(i),
new GUIContent("RenderTexture " + (i + 1).ToString() + ": "));
}
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("Add RenderTextures", EditorStyles.miniButton))
{
renderTextures.arraySize++;
}
if (GUILayout.Button("Remove RenderTextures", EditorStyles.miniButton))
{
renderTextures.arraySize--;
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.PropertyField(
maxSteps,

2
UnitySDK/Assets/ML-Agents/Editor/BrainParametersDrawer.cs


property.FindPropertyRelative(NumVecObsPropName),
new GUIContent("Stacked Vectors",
"Number of states that will be stacked before " +
"beeing fed to the neural network."));
"being fed to the neural network."));
position.y += LineHeight;
EditorGUI.indentLevel--;
}

1001
UnitySDK/Assets/ML-Agents/Examples/3DBall/TFModels/3DBallHardLearning.nn
文件差异内容过多而无法显示
查看文件

1001
UnitySDK/Assets/ML-Agents/Examples/3DBall/TFModels/3DBallLearning.nn
文件差异内容过多而无法显示
查看文件

6
UnitySDK/Assets/ML-Agents/Examples/BananaCollectors/Scripts/BananaAgent.cs


public Material frozenMaterial;
public GameObject myLaser;
public bool contribute;
private RayPerception rayPer;
private RayPerception3D rayPer;
public bool useVectorObs;
public override void InitializeAgent()

Monitor.verticalOffset = 1f;
myArea = area.GetComponent<BananaArea>();
rayPer = GetComponent<RayPerception>();
rayPer = GetComponent<RayPerception3D>();
myAcademy = FindObjectOfType<BananaAcademy>();
}

if (shoot)
{
myLaser.transform.localScale = new Vector3(1f, 1f, 1f);
Vector3 position = transform.TransformDirection(RayPerception.PolarToCartesian(25f, 90f));
Vector3 position = transform.TransformDirection(RayPerception3D.PolarToCartesian(25f, 90f));
Debug.DrawRay(transform.position, position, Color.red, 0f, true);
RaycastHit hit;
if (Physics.SphereCast(transform.position, 2f, position, out hit, 25f))

622
UnitySDK/Assets/ML-Agents/Examples/BananaCollectors/TFModels/BananaLearning.nn
文件差异内容过多而无法显示
查看文件

22
UnitySDK/Assets/ML-Agents/Examples/Basic/TFModels/BasicLearning.nn


vector_observation���� action_masks���� action_probsconcat_1actionvalue_estimatestrided_slice_1/stack_2������?strided_slice_1/stack_2strided_slice_1/stack_1������?strided_slice_1/stack_1strided_slice_1/stack������?strided_slice_1/stackstrided_slice/stack_2������?strided_slice/stack_2strided_slice/stack_1������?strided_slice/stack_1strided_slice/stack������?strided_slice/stack
action_output_shape������?action_output_shape  memory_size������? memory_size version_number������?version_numberis_continuous_control������?is_continuous_controlSum/reduction_indices������?Sum/reduction_indicesadd_1/y������?add_1/yadd/y������?add/ymain_graph_0/hidden_0/BiasAdd�����?vector_observationmain_graph_0/hidden_0/kernel�main_graph_0/hidden_0/bias�main_graph_0/hidden_0/Mul2 �����?main_graph_0/hidden_0/BiasAdd dense/MatMul�����?main_graph_0/hidden_0/Mul dense/kernel�<dense/MatMul/patch:0� action_probs2�����? dense/MatMulSoftmax2�����? action_probsaddd�����?Softmaxadd/yMulf�����?add action_masksSum������?MulSum/reduction_indicestruedivg�����?MulSumadd_1d�����?truedivadd_1/yLog_12r�����?add_1concat_12�����?Log_1action2�����?Log_1dense_1/BiasAdd�����?main_graph_0/hidden_0/Muldense_1/kernel� dense_1/bias
value_estimate2�����?dense_1/BiasAdd�?�?@@�?�?@@@@@�?���.���. �>>)L=(�V��j���Q�� �>�G߽1�p���Ѽ��/�H:%�Ţt�o�轏�ۆ�>�| �Os"�RiQ�Aɾ~m�=��������)�=A�]>�����_��씅�7�>S��<G����9>z|�=�J>>�i8>Dy�=��>��(�����k�,>V��>��������>򖿾�Ej>��8�� �=*ˈ���=W�J<d���n��>��_�f8=:wZ�A.����<��%����=�ī��n>Ћ��tz>��E>K�����s>�����襾���=M'�=���7UU�yq��P!��uj�>���3��>]E��K�>�� >������>��޾�ֽ�>�<n�8=`{�媫�gM���8� ��<ȁ������W(>���!$#>�R>(\u��EȽ>C��/��� �0��>c�k;�я���F>羒�Ѽ�Y�����=H�A=A��<>m���m>�>"��p����<�X�p�b�J��>r >u��>����[ 6>�2>>B#���Y����<>X�q��=dJ��|�=�����Y>���yŶ<=���i7�t��>��Ⱦ���>�͚>%����1�<��<f��=Pl>��$=�}�n = H�v\&��!�>�L���`>X���|�>+�����>��b=M�\>B|������1�;[��=I� ����99]�>\��>e��> ������Fy���G�2��> ]��5A������n ?�/n�V�����=�v�>S��>�Y���4u>zo�����>�>Yf >|�J>�f�� qk��}����R���=�(�>X���9�U�٧�����>?km >��X���Z���=�:V�-f�>a�I>��>�=}>��q>��Ͼ�!��pW�>�%?a"�>#B$=_�ȼ ���6�W��b�>�{#?�M?l<v�27u�+p?�l?q��>8t�>o��>� ?��+��H���O ?M2?� ?���=�3��#�1���N>��A?r?rƁ>yj���+a>�x"?H�>�wn>�=~O[>h��C�� �߾o� ?�Z�>U�>�\�>�`��&�¾��Ⱦ�^(?J&0>
��>ܢ�K�=:L�=Ui?M�=A�>%��>�1\>o�J�{(��i8�=ȟ+?&'�>0u>쐷��$1�p�>a� ?��?
�>�W,�\�?���>ʉ?&�X��2>�2+>6��=�Xr�g��YX>�.�>�i�>�"?q�R����������#?��>�7?A ž���>�?�� ?���> DZ>aM�>m��>����Ğe=T��=��>a@%>��3?F���fy��� G��
> ��>���>����\�=6B?�S4>���>~<?�?��+��Pؾ�P��J�>�?@p�><��>ar�����u�>����< I�����Q�a>h|����;\���gJ���d=y�\>{߾���>�ң�c4J�;�پ�U�~�=#�%�+�Խ�KȾ�+��������>��V�+#辘Y�>iV����=W�a>�ѽ� �������=���>�ɶ>�3s<�9 >߄w=L�*>y_���H��G
�>/S�>�8>�V�=ná>��=&�[>��)>\nQ���>U���ꈾ��H>F��>m�>=̛��� ۾Z�+?��*?{�?��}�?�?��?8c?�?�P?��?�(�|��3#?�
(?�*/?[&?����� �mw~>��)>�֤��mϾ������?����ǽ���!&?�S޾l���� ? �>s��>+�����þ��¾jF?��¾]g㾻l?r����LܾB�?�)��������>+�ʾ��ѾH�?�P׾����n"?�⌾
N����>D��>��>ò ����>*��>�����xȾg/ھ �?����gN��^?��޾��پE+?�þ�
ؾ��
?�E�>���>�e� 3�>8r�>��
9S��.�I>D�!�!�������9W���>�>�>3�л����>���>�˩��}���a�y�ؾJd=��K�?�ɾ=�=F*�=
action_output_shape������?action_output_shape  memory_size������? memory_size version_number������?version_numberis_continuous_control������?is_continuous_controladd_1/y������?add_1/ySum/reduction_indices������?Sum/reduction_indicesadd/y������?add/ymain_graph_0/hidden_0/BiasAdd�����?vector_observationmain_graph_0/hidden_0/kernel�main_graph_0/hidden_0/bias�main_graph_0/hidden_0/Mul2 �����?main_graph_0/hidden_0/BiasAdd dense/MatMul�����?main_graph_0/hidden_0/Mul dense/kernel�<dense/MatMul/patch:0� action_probs2�����? dense/MatMulSoftmax2�����? action_probsaddd�����?Softmaxadd/yMulf�����?add action_masksSum������?MulSum/reduction_indicestruedivg�����?MulSumadd_1d�����?truedivadd_1/yLog_12r�����?add_1concat_12�����?Log_1action2�����?Log_1dense_1/BiasAdd�����?main_graph_0/hidden_0/Muldense_1/kernel� dense_1/bias
value_estimate2�����?dense_1/BiasAdd�?�?@@�?�?@@@@@���.�?���.�)= �=��X����>��>���d?)>PXx>.���Ӿ�Q��d?>�8�>Y�&=:[:>ۙa>��>��f>A
=95����>��>d�����D���=���>^��sN����,=�=ܴ�>B��Q�>�Kξԙ��۹[>ۺ�����>0��K�>�0�қ�=���;T���>���>�>ʚ`>f�>>bS�>ɴJ>��>�Ƣ�$�j���@���6�P���>L�+Y$��Ԫ�p��>��Ǽ!�ž�jf>k����G�����>��=�T���ث���iܾQy�>��k>[�>lN8�<'=0�R��#��1�
J>��پ���>x��;�NN>�I^>��8=Ԣ��7�~= ʋ>�B�;+��>:�&>�CR��v�����>�0c��h>w��>2Ѿ�F����>�1��@ȶ>y�\=]�"=���Tn�=�)�>K�>3��>ѩ��� ��u|M>�B��xj��>�c�>�k����>NO�>8�����j<�>����W���<�>�Zþח�>��>�>L�e�Y��>��=�J�=�x+��[!�-1�>3�q=�z���?(����mί>x�5����>�ߴ���ؼo���Z7��8O>�m����=F�5>������C�zcݾ@��JqL>DP�B�o������D?�h=r�? ����������쩾"���������?������q"���Ɇ�͂>>�:eH���i�ΰ�>;���˕>ZG >��R<o����->X������Z��> nA<�v����> �H������F=SR0>У�=�hC���Ⱦ�~s��}>pj潦/����4��5#���>��O=C8�>�Y��[�>8@,>!�>��=>�Y����>����"�>S�m>�z�>l�<��>H��^0+�-�V�~ؾ�j�=� ���>}�=��?r=i��;Z?c�>��%���I>M ��k>U��>�樺%����p�>�����s���S�Kp)�5�?!��)��>�!?^��>4��T�=�Q�>��L�"u�>�Ͼ-��>buo>0�?����q��<�_��z���h����cD? � ��C?���>3z�>�|~���5?���>ۗ��|�&��G�s��=��$?�4?o��5�'?�D�@h��,�������C&?������>���>��?� ���c
?�q?j�_=�膾y���>�H>���>� ˾��>��f����?0���\���'?�br���>p�7?8?�?��<�>�d�>}���H������9?Ϛ�>�1�>�짾�x?����]���b��1��VA�>�ޞ��c�>��7?�;)?Sϟ�j=c>gǸ>�)��z���Hʾ����>�M ?p� ?�hT��"Ͼ�S=��f>�%=� O���Q���=��>�!Ѽ [�>�x��{>O�j>q嶾̇>i�=�i¼��>E�a���4>��4>�ۅ��W<>U����_,>��>�Ѧ;
J���4>C��>i�>����.���|�=�݃��H:>H�����˼�ܽ��=fG2� �w� +�=y9�=�F>^��=�� �&>�����l>�޲�[�<[��>A�>vf���P��8�s�4�;1F1>m�<ƨ7?������C& ���ݾh�&?ˎ���4?33?��!?��J5.?�b6?s��5���J ���"?^�&?��-?
�� ����
��$?a��>H��>(� ����>�s�>Yb�� �>e��>�2 ��5�>�7�>eF��7ھ�Q
���?W ?T.�>g���$���m�;?��ᾚ0߾H�?G��_���љ?C�>-ɽ>�� ������Hm/?�������a=?�A�>*w�>x) ��^z>�a >%���3��>h?M����kv����?=���
��xV?�/쾷����?
�>�S?�����$>��r����>JI��F�5?r6e�� 0�3�->D�G�u�f�܂�9S��0�=�C�>�T����o�6�>y �>׹2>2����^=

272
UnitySDK/Assets/ML-Agents/Examples/Bouncer/TFModels/BouncerLearning.nn
文件差异内容过多而无法显示
查看文件

1001
UnitySDK/Assets/ML-Agents/Examples/Crawler/TFModels/CrawlerDynamicLearning.nn
文件差异内容过多而无法显示
查看文件

1001
UnitySDK/Assets/ML-Agents/Examples/Crawler/TFModels/CrawlerStaticLearning.nn
文件差异内容过多而无法显示
查看文件

306
UnitySDK/Assets/ML-Agents/Examples/GridWorld/Scenes/GridWorld.unity


m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.43667555, g: 0.4842717, b: 0.56452394, a: 1}
m_IndirectSpecularColor: {r: 0.43668893, g: 0.4842832, b: 0.56452656, a: 1}
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0

value: 1
actorObjs: []
players:
trueAgent: {fileID: 2008405822}
trueAgent: {fileID: 858783320}
camObject: {fileID: 231883441}
camObject: {fileID: 99095112}
agentPref: {fileID: 1657514749044530, guid: 628960e910f094ad1909ecc88cc8016d, type: 2}
goalPref: {fileID: 1508142483324970, guid: 1ec4e4e96e7514d45b7ebc3ba5a9a481, type: 2}
pitPref: {fileID: 1811317785436014, guid: d13ee2db77b3a4dcc8664d2fe2a0f219, type: 2}

m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0}
--- !u!1 &231883441
--- !u!1 &99095112
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}

- component: {fileID: 231883447}
- component: {fileID: 231883446}
- component: {fileID: 231883445}
- component: {fileID: 231883444}
- component: {fileID: 99095116}
- component: {fileID: 99095115}
- component: {fileID: 99095114}
- component: {fileID: 99095113}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera

m_IsActive: 1
--- !u!124 &231883444
--- !u!124 &99095113
m_GameObject: {fileID: 231883441}
m_GameObject: {fileID: 99095112}
--- !u!92 &231883445
--- !u!92 &99095114
m_GameObject: {fileID: 231883441}
m_GameObject: {fileID: 99095112}
--- !u!20 &231883446
--- !u!20 &99095115
m_GameObject: {fileID: 231883441}
m_GameObject: {fileID: 99095112}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 2

m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: 0.022
--- !u!4 &231883447
--- !u!4 &99095116
m_GameObject: {fileID: 231883441}
m_GameObject: {fileID: 99095112}
m_LocalRotation: {x: 0.35355338, y: 0.35355338, z: -0.1464466, w: 0.8535535}
m_LocalPosition: {x: -5, y: 8.2, z: -5}
m_LocalScale: {x: 1, y: 1, z: 1}

m_LocalScale: {x: 0, y: 0, z: 0}
m_Children:
- {fileID: 1553342943}
- {fileID: 918893359}
- {fileID: 1305247360}
m_Father: {fileID: 0}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

serializedVersion: 2
m_Bits: 4294967295
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_TargetTexture: {fileID: 8400000, guid: 114608d5384404f89bff4b6f88432958, type: 2}
m_TargetDisplay: 0
m_TargetEye: 3
m_HDR: 0

m_Father: {fileID: 0}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &858783320 stripped
GameObject:
m_PrefabParentObject: {fileID: 1657514749044530, guid: 628960e910f094ad1909ecc88cc8016d,
type: 2}
m_PrefabInternal: {fileID: 1477921759}
--- !u!1 &918893358
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 918893359}
- component: {fileID: 918893361}
- component: {fileID: 918893360}
m_Layer: 5
m_Name: Text
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &918893359
RectTransform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 918893358}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 363761400}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -369.5, y: -62.2}
m_SizeDelta: {x: 160, y: 55.6}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &918893360
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 918893358}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 708705254, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 20
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 2
m_MaxSize: 40
m_Alignment: 7
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: 'Agent View
(RenderTexture)'
--- !u!222 &918893361
CanvasRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 918893358}
--- !u!1 &959566328
GameObject:
m_ObjectHideFlags: 0

m_Father: {fileID: 486401524}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1305247359
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 1305247360}
- component: {fileID: 1305247362}
- component: {fileID: 1305247361}
m_Layer: 5
m_Name: RawImage
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1305247360
RectTransform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1305247359}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 363761400}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -369.5, y: -197}
m_SizeDelta: {x: 200, y: 200}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1305247361
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1305247359}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: -98529514, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_Texture: {fileID: 8400000, guid: 114608d5384404f89bff4b6f88432958, type: 2}
m_UVRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
--- !u!222 &1305247362
CanvasRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1305247359}
--- !u!1001 &1477921759
Prefab:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 114143683117020968, guid: 628960e910f094ad1909ecc88cc8016d,
type: 2}
propertyPath: agentParameters.agentCameras.Array.size
value: 0
objectReference: {fileID: 0}
- target: {fileID: 114143683117020968, guid: 628960e910f094ad1909ecc88cc8016d,
type: 2}
propertyPath: agentParameters.agentRenderTextures.Array.size
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4587181662868872, guid: 628960e910f094ad1909ecc88cc8016d, type: 2}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4587181662868872, guid: 628960e910f094ad1909ecc88cc8016d, type: 2}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4587181662868872, guid: 628960e910f094ad1909ecc88cc8016d, type: 2}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4587181662868872, guid: 628960e910f094ad1909ecc88cc8016d, type: 2}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4587181662868872, guid: 628960e910f094ad1909ecc88cc8016d, type: 2}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4587181662868872, guid: 628960e910f094ad1909ecc88cc8016d, type: 2}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4587181662868872, guid: 628960e910f094ad1909ecc88cc8016d, type: 2}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4587181662868872, guid: 628960e910f094ad1909ecc88cc8016d, type: 2}
propertyPath: m_RootOrder
value: 7
objectReference: {fileID: 0}
- target: {fileID: 1657514749044530, guid: 628960e910f094ad1909ecc88cc8016d, type: 2}
propertyPath: m_Name
value: trueAgent
objectReference: {fileID: 0}
- target: {fileID: 114143683117020968, guid: 628960e910f094ad1909ecc88cc8016d,
type: 2}
propertyPath: agentParameters.agentRenderTextures.Array.data[0]
value:
objectReference: {fileID: 8400000, guid: 114608d5384404f89bff4b6f88432958, type: 2}
- target: {fileID: 114143683117020968, guid: 628960e910f094ad1909ecc88cc8016d,
type: 2}
propertyPath: renderCamera
value:
objectReference: {fileID: 489340228}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 628960e910f094ad1909ecc88cc8016d, type: 2}
m_IsPrefabParent: 0
--- !u!1 &1553342942
GameObject:
m_ObjectHideFlags: 0

m_Father: {fileID: 486401524}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 90, z: 0}
--- !u!1001 &2008405821
Prefab:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 4587181662868872, guid: 628960e910f094ad1909ecc88cc8016d, type: 2}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4587181662868872, guid: 628960e910f094ad1909ecc88cc8016d, type: 2}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4587181662868872, guid: 628960e910f094ad1909ecc88cc8016d, type: 2}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4587181662868872, guid: 628960e910f094ad1909ecc88cc8016d, type: 2}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4587181662868872, guid: 628960e910f094ad1909ecc88cc8016d, type: 2}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4587181662868872, guid: 628960e910f094ad1909ecc88cc8016d, type: 2}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4587181662868872, guid: 628960e910f094ad1909ecc88cc8016d, type: 2}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4587181662868872, guid: 628960e910f094ad1909ecc88cc8016d, type: 2}
propertyPath: m_RootOrder
value: 7
objectReference: {fileID: 0}
- target: {fileID: 1657514749044530, guid: 628960e910f094ad1909ecc88cc8016d, type: 2}
propertyPath: m_Name
value: trueAgent
objectReference: {fileID: 0}
- target: {fileID: 114143683117020968, guid: 628960e910f094ad1909ecc88cc8016d,
type: 2}
propertyPath: agentParameters.agentCameras.Array.data[0]
value:
objectReference: {fileID: 489340228}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 628960e910f094ad1909ecc88cc8016d, type: 2}
m_IsPrefabParent: 0
--- !u!1 &2008405822 stripped
GameObject:
m_PrefabParentObject: {fileID: 1657514749044530, guid: 628960e910f094ad1909ecc88cc8016d,
type: 2}
m_PrefabInternal: {fileID: 2008405821}

5
UnitySDK/Assets/ML-Agents/Examples/GridWorld/Scenes/GridWorld.unity.meta


fileFormatVersion: 2
guid: 7c777442467e245108558a5155153927
timeCreated: 1502222754
licenseType: Free
guid: c6fdbb551d80c435abe6fc911b1ea11f
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

10
UnitySDK/Assets/ML-Agents/Examples/GridWorld/Scripts/GridAgent.cs


public float timeBetweenDecisionsAtInference;
private float timeSinceDecision;
[Tooltip("Because we want an observation right before making a decision, we can force " +
"a camera to render before making a decision. Place the agentCam here if using " +
"RenderTexture as observations.")]
public Camera renderCamera;
[Tooltip("Selecting will turn on action masking. Note that a model trained with action " +
"masking turned on may not behave optimally when action masking is turned off.")]
public bool maskActions = true;

private void WaitTimeInference()
{
if(renderCamera != null)
{
renderCamera.Render();
}
if (!academy.GetIsInference())
{
RequestDecision();

997
UnitySDK/Assets/ML-Agents/Examples/GridWorld/TFModels/GridWorldLearning.nn
文件差异内容过多而无法显示
查看文件

999
UnitySDK/Assets/ML-Agents/Examples/Hallway/TFModels/HallwayLearning.nn
文件差异内容过多而无法显示
查看文件

1000
UnitySDK/Assets/ML-Agents/Examples/PushBlock/TFModels/PushBlockLearning.nn
文件差异内容过多而无法显示
查看文件

1000
UnitySDK/Assets/ML-Agents/Examples/Pyramids/TFModels/PyramidsLearning.nn
文件差异内容过多而无法显示
查看文件

1001
UnitySDK/Assets/ML-Agents/Examples/Reacher/TFModels/ReacherLearning.nn
文件差异内容过多而无法显示
查看文件

100
UnitySDK/Assets/ML-Agents/Examples/SharedAssets/Scripts/RayPerception.cs


using System.Collections.Generic;
using System.Collections;
using System.Collections.Generic;
namespace MLAgents
{
/// <summary>
/// Ray perception component. Attach this to agents to enable "local perception"
/// via the use of ray casts directed outward from the agent.
/// </summary>
public class RayPerception : MonoBehaviour
{
List<float> perceptionBuffer = new List<float>();
Vector3 endPosition;
RaycastHit hit;
/// <summary>
/// Creates perception vector to be used as part of an observation of an agent.
/// </summary>
/// <returns>The partial vector observation corresponding to the set of rays</returns>
/// <param name="rayDistance">Radius of rays</param>
/// <param name="rayAngles">Anlges of rays (starting from (1,0) on unit circle).</param>
/// <param name="detectableObjects">List of tags which correspond to object types agent can see</param>
/// <param name="startOffset">Starting heigh offset of ray from center of agent.</param>
/// <param name="endOffset">Ending height offset of ray from center of agent.</param>
public List<float> Perceive(float rayDistance,
float[] rayAngles, string[] detectableObjects,
float startOffset, float endOffset)
{
perceptionBuffer.Clear();
// For each ray sublist stores categorial information on detected object
// along with object distance.
foreach (float angle in rayAngles)
{
endPosition = transform.TransformDirection(
PolarToCartesian(rayDistance, angle));
endPosition.y = endOffset;
if (Application.isEditor)
{
Debug.DrawRay(transform.position + new Vector3(0f, startOffset, 0f),
endPosition, Color.black, 0.01f, true);
}
float[] subList = new float[detectableObjects.Length + 2];
if (Physics.SphereCast(transform.position +
new Vector3(0f, startOffset, 0f), 0.5f,
endPosition, out hit, rayDistance))
{
for (int i = 0; i < detectableObjects.Length; i++)
{
if (hit.collider.gameObject.CompareTag(detectableObjects[i]))
{
subList[i] = 1;
subList[detectableObjects.Length + 1] = hit.distance / rayDistance;
break;
}
}
}
else
{
subList[detectableObjects.Length] = 1f;
}
public abstract class RayPerception : MonoBehaviour {
perceptionBuffer.AddRange(subList);
}
return perceptionBuffer;
}
protected List<float> perceptionBuffer = new List<float>();
/// <summary>
/// Converts polar coordinate to cartesian coordinate.
/// </summary>
public static Vector3 PolarToCartesian(float radius, float angle)
{
float x = radius * Mathf.Cos(DegreeToRadian(angle));
float z = radius * Mathf.Sin(DegreeToRadian(angle));
return new Vector3(x, 0f, z);
}
public virtual List<float> Perceive(float rayDistance,
float[] rayAngles, string[] detectableObjects,
float startOffset, float endOffset)
{
return perceptionBuffer;
}
/// <summary>
/// Converts degrees to radians.
/// </summary>
public static float DegreeToRadian(float degree)
{
return degree * Mathf.PI / 180f;
}
}
/// <summary>
/// Converts degrees to radians.
/// </summary>
public static float DegreeToRadian(float degree)
{
return degree * Mathf.PI / 180f;
}
}

2
UnitySDK/Assets/ML-Agents/Examples/SharedAssets/Scripts/RayPerception.cs.meta


fileFormatVersion: 2
guid: bb172294dbbcc408286b156a2c4b553c
guid: a14e2e238ae844231bc2c88e17bae5a5
MonoImporter:
externalObjects: {}
serializedVersion: 2

75
UnitySDK/Assets/ML-Agents/Examples/Soccer/Scripts/AgentSoccer.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine;
using MLAgents;
public class AgentSoccer : Agent

{
red, blue
Red,
Blue
striker, goalie
Striker,
Goalie
public Rigidbody agentRB;
public Rigidbody agentRb;
SoccerAcademy academy;
Renderer agentRenderer;
RayPerception rayPer;

team = (Team)Random.Range(0, 2);
agentRenderer.material = team == Team.red ? academy.redMaterial : academy.blueMaterial;
if (team == Team.Red)
{
JoinRedTeam(agentRole);
}
else
{
JoinBlueTeam(agentRole);
}
team = Team.red;
team = Team.Red;
tag = "redAgent";
team = Team.blue;
team = Team.Blue;
tag = "blueAgent";
}
public override void InitializeAgent()

rayPer = GetComponent<RayPerception>();
academy = FindObjectOfType<SoccerAcademy>();
PlayerState playerState = new PlayerState();
playerState.agentRB = GetComponent<Rigidbody>();
agentRB = GetComponent<Rigidbody>();
agentRB.maxAngularVelocity = 500;
playerState.startingPos = transform.position;
playerState.agentScript = this;
agentRb = GetComponent<Rigidbody>();
agentRb.maxAngularVelocity = 500;
var playerState = new PlayerState
{
agentRB = agentRb,
startingPos = transform.position,
agentScript = this,
};
area.playerStates.Add(playerState);
playerIndex = area.playerStates.IndexOf(playerState);
playerState.playerIndex = playerIndex;

float rayDistance = 20f;
float[] rayAngles = { 0f, 45f, 90f, 135f, 180f, 110f, 70f };
string[] detectableObjects;
if (team == Team.red)
if (team == Team.Red)
detectableObjects = new string[] { "ball", "redGoal", "blueGoal",
detectableObjects = new[] { "ball", "redGoal", "blueGoal",
detectableObjects = new string[] { "ball", "blueGoal", "redGoal",
detectableObjects = new[] { "ball", "blueGoal", "redGoal",
"wall", "blueAgent", "redAgent" };
}
AddVectorObs(rayPer.Perceive(rayDistance, rayAngles, detectableObjects, 0f, 0f));

int action = Mathf.FloorToInt(act[0]);
// Goalies and Strikers have slightly different action spaces.
if (agentRole == AgentRole.goalie)
if (agentRole == AgentRole.Goalie)
{
kickPower = 0f;
switch (action)

}
}
transform.Rotate(rotateDir, Time.deltaTime * 100f);
agentRB.AddForce(dirToGo * academy.agentRunSpeed,
agentRb.AddForce(dirToGo * academy.agentRunSpeed,
ForceMode.VelocityChange);
}

{
// Existential penalty for strikers.
if (agentRole == AgentRole.striker)
if (agentRole == AgentRole.Striker)
if (agentRole == AgentRole.goalie)
if (agentRole == AgentRole.Goalie)
{
AddReward(1f / 3000f);
}

void OnCollisionEnter(Collision c)
{
float force = 2000f * kickPower;
if (c.gameObject.tag == "ball")
if (c.gameObject.CompareTag("ball"))
{
Vector3 dir = c.contacts[0].point - transform.position;
dir = dir.normalized;

public override void AgentReset()
{
if (academy.randomizePlayersTeamForTraining)

if (team == Team.red)
if (team == Team.Red)
{
JoinRedTeam(agentRole);
transform.rotation = Quaternion.Euler(0f, -90f, 0f);

JoinBlueTeam(agentRole);
transform.rotation = Quaternion.Euler(0f, 90f, 0f);
}
transform.position = area.GetRandomSpawnPos(team.ToString(),
agentRole.ToString());
agentRB.velocity = Vector3.zero;
agentRB.angularVelocity = Vector3.zero;
transform.position = area.GetRandomSpawnPos(agentRole, team);
agentRb.velocity = Vector3.zero;
agentRb.angularVelocity = Vector3.zero;
}
public override void AgentOnDone()
{
}
}

4
UnitySDK/Assets/ML-Agents/Examples/Soccer/Scripts/SoccerBallController.cs


{
if (col.gameObject.CompareTag(redGoalTag)) //ball touched red goal
{
area.GoalTouched(AgentSoccer.Team.blue);
area.GoalTouched(AgentSoccer.Team.Blue);
area.GoalTouched(AgentSoccer.Team.red);
area.GoalTouched(AgentSoccer.Team.Red);
}
}
}

48
UnitySDK/Assets/ML-Agents/Examples/Soccer/Scripts/SoccerFieldArea.cs


ps.agentScript.ChooseRandomTeam();
}
if (scoredTeam == AgentSoccer.Team.red)
if (scoredTeam == AgentSoccer.Team.Red)
{
StartCoroutine(GoalScoredSwapGroundMaterial(academy.redMaterial, 1));
}

public void RewardOrPunishPlayer(PlayerState ps, float striker, float goalie)
{
if (ps.agentScript.agentRole == AgentSoccer.AgentRole.striker)
if (ps.agentScript.agentRole == AgentSoccer.AgentRole.Striker)
if (ps.agentScript.agentRole == AgentSoccer.AgentRole.goalie)
if (ps.agentScript.agentRole == AgentSoccer.AgentRole.Goalie)
{
ps.agentScript.AddReward(goalie);
}

public Vector3 GetRandomSpawnPos(string type, string position)
public Vector3 GetRandomSpawnPos(AgentSoccer.AgentRole role, AgentSoccer.Team team)
Vector3 randomSpawnPos = Vector3.zero;
if (type == "red")
if (role == AgentSoccer.AgentRole.Goalie)
if (position == "goalie")
{
xOffset = 13f;
}
if (position == "striker")
{
xOffset = 7f;
}
xOffset = 13f;
if (type == "blue")
if (role == AgentSoccer.AgentRole.Striker)
if (position == "goalie")
{
xOffset = -13f;
}
if (position == "striker")
{
xOffset = -7f;
}
xOffset = 7f;
randomSpawnPos = ground.transform.position +
if (team == AgentSoccer.Team.Blue)
{
xOffset = xOffset * -1f;
}
var randomSpawnPos = ground.transform.position +
new Vector3(xOffset, 0f, 0f)
+ (Random.insideUnitSphere * 2);
randomSpawnPos.y = ground.transform.position.y + 2;

public Vector3 GetBallSpawnPosition()
{
var randomSpawnPos = ground.transform.position +
new Vector3(0f, 0f, 0f)
+ (Random.insideUnitSphere * 2);
randomSpawnPos.y = ground.transform.position.y + 2;
return randomSpawnPos;
}
void SpawnObjAtPos(GameObject obj, Vector3 pos)
{
obj.transform.position = pos;

{
ball.transform.position = GetRandomSpawnPos("ball", "ball");
ball.transform.position = GetBallSpawnPosition();
ballRB.velocity = Vector3.zero;
ballRB.angularVelocity = Vector3.zero;
}

1
UnitySDK/Assets/ML-Agents/Examples/Tennis/Scripts/TennisArea.cs


using System.Collections;
using System.Collections.Generic;
using System.Security.AccessControl;
using UnityEngine;
public class TennisArea : MonoBehaviour {

1001
UnitySDK/Assets/ML-Agents/Examples/Tennis/TFModels/TennisLearning.nn
文件差异内容过多而无法显示
查看文件

1001
UnitySDK/Assets/ML-Agents/Examples/WallJump/TFModels/BigWallJumpLearning.nn
文件差异内容过多而无法显示
查看文件

1001
UnitySDK/Assets/ML-Agents/Examples/WallJump/TFModels/SmallWallJumpLearning.nn
文件差异内容过多而无法显示
查看文件

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


/**
* Welcome to Unity Machine Learning Agents (ML-Agents).
*
*
* The ML-Agents toolkit contains five entities: Academy, Brain, Agent, Communicator and
* Python API. The academy, and all its brains and connected agents live within
* a learning environment (herin called Environment), while the communicator

[Tooltip("Frames per second (FPS) engine attempts to maintain.")]
public int targetFrameRate;
/// Initializes a new instance of the
/// Initializes a new instance of the
/// <see cref="EnvironmentConfiguration"/> class.
/// <param name="width">Width of environment window (pixels).</param>
/// <param name="height">Height of environment window (pixels).</param>

}
/// <summary>
/// An Academy is where Agent objects go to train their behaviors. More
/// An Academy is where Agent objects go to train their behaviors. More
/// in a scene is attached to one brain (a single brain may be attached to
/// in a scene is attached to one brain (a single brain may be attached to
/// multiple agents). Currently, this class is expected to be extended to
/// implement the desired academy behavior.
/// </summary>

"docs/Learning-Environment-Design-Academy.md")]
public abstract class Academy : MonoBehaviour
{
[SerializeField]
[SerializeField]
private const string kApiVersion = "API-7";
private const string kApiVersion = "API-8";
/// Used to restore oringal value when deriving Academy modifies it
/// Used to restore oringal value when deriving Academy modifies it
/// Used to restore oringal value when deriving Academy modifies it
/// Used to restore oringal value when deriving Academy modifies it
/// Used to restore oringal value when deriving Academy modifies it
/// Used to restore oringal value when deriving Academy modifies it
private float originalMaximumDeltaTime;
// Fields provided in the Inspector

/// <summary/>
/// <remarks>
/// Default reset parameters are specified in the academy Editor, and can
/// be modified when training with an external Brain by passinga config
/// dictionary at reset.
/// be modified when training with an external Brain by passinga config
/// dictionary at reset.
public CommunicatorObjects.CustomResetParameters customResetParameters;
// Fields not provided in the Inspector.

/// the same message is not used multiple times.
private ulong lastCommunicatorMessageNumber;
/// If true, the Academy will use inference settings. This field is
/// If true, the Academy will use inference settings. This field is
/// initialized in <see cref="Awake"/> depending on the presence
/// or absence of a communicator. Furthermore, it can be modified by an
/// external Brain during reset via <see cref="SetIsInference"/>.

/// current episode.
bool maxStepReached;
/// The number of episodes completed by the environment. Incremented
/// The number of episodes completed by the environment. Incremented
/// each time a step is taken in the environment. Is reset to 0 during
/// each time a step is taken in the environment. Is reset to 0 during
/// The number of total number of steps completed during the whole simulation. Incremented
/// each time a step is taken in the environment.
int totalStepCount;
/// Flag that indicates whether the inference/training mode of the
/// environment was switched by the external Brain. This impacts the
/// engine settings at the next environment step.

// The Academy uses a series of events to communicate with agents and
// brains to facilitate synchronization. More specifically, it ensure
// that all the agents performs their steps in a consistent order (i.e. no
// agent can act based on a decision before another agent has had a chance
// agent can act based on a decision before another agent has had a chance
// Signals to all the Brains at each environment step so they can decide
// Signals to all the Brains at each environment step so they can decide
// Signals to all the agents at each environment step along with the
// Signals to all the listeners that the academy is being destroyed
public event System.Action DestroyAction;
// Signals to all the agents at each environment step along with the
// Academy's maxStepReached, done and stepCount values. The agents rely
// on this event to update their own values of max step reached and done
// in addition to aligning on the step count of the global episode.

// if their flag has been set to done (assuming the agent has requested a
// if their flag has been set to done (assuming the agent has requested a
// decision).
public event System.Action AgentResetIfDone;

originalGravity = Physics.gravity;
originalFixedDeltaTime = Time.fixedDeltaTime;
originalMaximumDeltaTime = Time.maximumDeltaTime;
InitializeAcademy();
Communicator communicator = null;

{
brain.SetToControlledExternally();
}
// Try to launch the communicator by usig the arguments passed at launch
try
{

Random.InitState(pythonParameters.Seed);
Application.logMessageReceived += HandleLog;
logPath = Path.GetFullPath(".") + "/UnitySDK.log";
logWriter = new StreamWriter(logPath, false);
logWriter.WriteLine(System.DateTime.Now.ToString());
logWriter.WriteLine(" ");
logWriter.Close();
using (var fs = File.Open(logPath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite))
{
logWriter = new StreamWriter(fs);
logWriter.WriteLine(System.DateTime.Now.ToString());
logWriter.WriteLine(" ");
logWriter.Close();
}
}
// If a communicator is enabled/provided, then we assume we are in

BrainDecideAction += () => { };
DestroyAction += () => { };
AgentSetStatus += (m, d, i) => { };
AgentResetIfDone += () => { };
AgentSendState += () => { };

{
resetParameters[kv.Key] = kv.Value;
}
customResetParameters = newResetParameters.CustomResetParameters;
logWriter = new StreamWriter(logPath, true);
logWriter.WriteLine(type.ToString());
logWriter.WriteLine(logString);
logWriter.WriteLine(stackTrace);
logWriter.Close();
using (var fs = File.Open(logPath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite))
{
logWriter = new StreamWriter(fs);
logWriter.WriteLine(type.ToString());
logWriter.WriteLine(logString);
logWriter.WriteLine(stackTrace);
logWriter.Close();
}
}
/// <summary>

}
/// <summary>
/// Returns the current step counter (within the current epside).
/// Returns the current step counter (within the current episode).
/// Current episode number.
/// Current step count.
/// </returns>
public int GetStepCount()
{

/// <summary>
/// Returns the total step counter.
/// </summary>
/// <returns>
/// Total step count.
/// </returns>
public int GetTotalStepCount()
{
return totalStepCount;
}
/// <summary>
/// Sets the done flag to true.
/// </summary>
public void Done()

}
/// <summary>
/// Forces the full reset. The done flags are not affected. Is either
/// Forces the full reset. The done flags are not affected. Is either
/// called the first reset at inference and every external reset
/// at training.
/// </summary>

AgentAct();
stepCount += 1;
totalStepCount += 1;
}
/// <summary>

Physics.gravity = originalGravity;
Time.fixedDeltaTime = originalFixedDeltaTime;
Time.maximumDeltaTime = originalMaximumDeltaTime;
// Signal to listeners that the academy is being destroyed now
DestroyAction();
}
}

120
UnitySDK/Assets/ML-Agents/Scripts/Agent.cs


public int id;
/// <summary>
/// User-customizable object for sending structured output from Unity to Python in response
/// to an action in addition to a scalar reward.
/// </summary>
public CustomObservation customObservation;
/// <summary>
/// Converts a AgentInfo to a protobuffer generated AgentInfoProto
/// </summary>
/// <returns>The protobuf verison of the AgentInfo.</returns>

MaxStepReached = maxStepReached,
Done = done,
Id = id,
CustomObservation = customObservation
};
if (memories != null)
{

public string textActions;
public List<float> memories;
public float value;
public CommunicatorObjects.CustomAction customAction;
}
/// <summary>

/// observations.
/// </summary>
public List<Camera> agentCameras = new List<Camera>();
/// <summary>
/// The list of the RenderTextures the agent uses for visual
/// observations.
/// </summary>
public List<RenderTexture> agentRenderTextures = new List<RenderTexture>();
/// <summary>
/// The maximum number of steps the agent takes before being done.

/// becomes enabled or active.
void OnEnable()
{
textureArray = new Texture2D[agentParameters.agentCameras.Count];
for (int i = 0; i < agentParameters.agentCameras.Count; i++)
var textureCount = agentParameters.agentCameras.Count+agentParameters.agentRenderTextures.Count;
textureArray = new Texture2D[textureCount];
for (int i = 0; i < textureCount; i++)
{
textureArray[i] = new Texture2D(1, 1, TextureFormat.RGB24, false);
}

* param.numStackedVectorObservations]);
info.visualObservations = new List<Texture2D>();
info.customObservation = null;
}
/// <summary>

info.stackedVectorObservation.AddRange(info.vectorObservation);
info.visualObservations.Clear();
if (param.cameraResolutions.Length > agentParameters.agentCameras.Count)
var visualObservationCount = agentParameters.agentCameras.Count+agentParameters.agentRenderTextures.Count;
if (param.cameraResolutions.Length > visualObservationCount)
"Not enough cameras for agent {0} : Bain {1} expecting at " +
"least {2} cameras but only {3} were present.",
"Not enough cameras/renderTextures for agent {0} : Brain {1} expecting at " +
"least {2} cameras/renderTextures but only {3} were present.",
agentParameters.agentCameras.Count));
visualObservationCount));
for (int i = 0; i < brain.brainParameters.cameraResolutions.Length; i++)
//First add all cameras
for (int i = 0; i < agentParameters.agentCameras.Count; i++)
ref textureArray[i]);
info.visualObservations.Add(textureArray[i]);
}
//Then add all renderTextures
var camCount = agentParameters.agentCameras.Count;
for (int i = 0; i < agentParameters.agentRenderTextures.Count; i++)
{
ObservationToTexture(
agentParameters.agentRenderTextures[i],
param.cameraResolutions[camCount+i].width,
param.cameraResolutions[camCount+i].height,
ref textureArray[i]);
info.visualObservations.Add(textureArray[i]);
}

/// <param name="actionIndex">The index of the masked action on branch 0</param>
protected void SetActionMask(int actionIndex)
{
actionMasker.SetActionMask(0, new int[1] {actionIndex});
actionMasker.SetActionMask(0, new int[1] { actionIndex });
}
/// <summary>

/// <param name="actionIndex">The index of the masked action</param>
protected void SetActionMask(int branch, int actionIndex)
{
actionMasker.SetActionMask(branch, new int[1] {actionIndex});
actionMasker.SetActionMask(branch, new int[1] { actionIndex });
}
/// <summary>

}
/// <summary>
/// Specifies the agent behavior at every step based on the provided
/// action.
/// </summary>
/// <param name="vectorAction">
/// Vector action. Note that for discrete actions, the provided array
/// will be of length 1.
/// </param>
/// <param name="textAction">Text action.</param>
/// <param name="customAction">
/// A custom action, defined by the user as custom protobuffer message. Useful if the action is hard to encode
/// as either a flat vector or a single string.
/// </param>
public virtual void AgentAction(float[] vectorAction, string textAction, CommunicatorObjects.CustomAction customAction)
{
// We fall back to not using the custom action if the subclassed Agent doesn't override this method.
AgentAction(vectorAction, textAction);
}
/// <summary>
/// Specifies the agent behavior when done and
/// <see cref="AgentParameters.resetOnDone"/> is false. This method can be
/// used to remove the agent from the scene.

}
/// <summary>
/// Updates the custom action.
/// </summary>
/// <param name="customAction">Custom action.</param>
public void UpdateCustomAction(CommunicatorObjects.CustomAction customAction)
{
action.customAction = customAction;
}
/// <summary>
/// Updates the value of the agent.
/// </summary>
/// <param name="textActions">Text actions.</param>

if ((requestAction) && (brain != null))
{
requestAction = false;
AgentAction(action.vectorActions, action.textActions);
AgentAction(action.vectorActions, action.textActions, action.customAction);
}
if ((stepCount >= agentParameters.maxStep)

RenderTexture.active = prevActiveRT;
RenderTexture.ReleaseTemporary(tempRT);
}
}
/// <summary>
/// Converts a RenderTexture and correspinding resolution to a 2D texture.
/// </summary>
/// <returns>The 2D texture.</returns>
/// <param name="obsTexture">RenderTexture.</param>
/// <param name="width">Width of resulting 2D texture.</param>
/// <param name="height">Height of resulting 2D texture.</param>
/// <param name="texture2D">Texture2D to render to.</param>
public static void ObservationToTexture(RenderTexture obsTexture, int width, int height, ref Texture2D texture2D)
{
if (width != texture2D.width || height != texture2D.height)
{
texture2D.Resize(width, height);
}
if(width != obsTexture.width || height != obsTexture.height)
{
throw new UnityAgentsException(string.Format(
"RenderTexture {0} : width/height is {1}/{2} brain is expecting {3}/{4}.",
obsTexture.name, obsTexture.width, obsTexture.height, width, height));
}
var prevActiveRT = RenderTexture.active;
RenderTexture.active = obsTexture;
texture2D.ReadPixels(new Rect(0, 0, texture2D.width, texture2D.height), 0, 0);
texture2D.Apply();
RenderTexture.active = prevActiveRT;
}
/// <summary>
/// Sets the custom observation for the agent for this episode.
/// </summary>
/// <param name="customObservation">New value of the agent's custom observation.</param>
public void SetCustomObservation(CustomObservation customObservation)
{
info.customObservation = customObservation;
}
}