浏览代码

Merge branch 'master' into develop-hybrid-actions-singleton

/develop/actionmodel-csharp
Andrew Cohen 4 年前
当前提交
e5f14400
共有 216 个文件被更改,包括 1771 次插入848 次删除
  1. 12
      .circleci/config.yml
  2. 4
      .github/workflows/pre-commit.yml
  3. 47
      .yamato/com.unity.ml-agents-promotion.yml
  4. 14
      .yamato/com.unity.ml-agents-test.yml
  5. 3
      .yamato/gym-interface-test.yml
  6. 3
      .yamato/python-ll-api-test.yml
  7. 9
      .yamato/standalone-build-test.yml
  8. 8
      .yamato/training-int-tests.yml
  9. 5
      DevProject/ProjectSettings/EditorBuildSettings.asset
  10. 159
      Dockerfile
  11. 26
      Project/Assets/ML-Agents/Examples/3DBall/Prefabs/3DBall.prefab
  12. 19
      Project/Assets/ML-Agents/Examples/3DBall/Scenes/3DBall.unity
  13. 14
      Project/Assets/ML-Agents/Examples/3DBall/Scripts/Ball3DAgent.cs
  14. 23
      Project/Assets/ML-Agents/Examples/Crawler/Scenes/CrawlerStaticVariableSpeed.unity
  15. 154
      Project/Assets/ML-Agents/Examples/FoodCollector/Prefabs/VisualFoodCollectorArea.prefab
  16. 73
      Project/Assets/ML-Agents/Examples/FoodCollector/Scenes/VisualFoodCollector.unity
  17. 8
      Project/Assets/ML-Agents/Examples/FoodCollector/Scripts/FoodCollectorAgent.cs
  18. 125
      Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/ModelOverrider.cs
  19. 10
      README.md
  20. 1
      com.unity.ml-agents.extensions/Documentation~/Grid-Sensor.md
  21. 31
      com.unity.ml-agents.extensions/Documentation~/com.unity.ml-agents.extensions.md
  22. 4
      com.unity.ml-agents.extensions/README.md
  23. 4
      com.unity.ml-agents.extensions/Runtime/Sensors/GridSensor.cs
  24. 2
      com.unity.ml-agents.extensions/package.json
  25. 38
      com.unity.ml-agents/CHANGELOG.md
  26. 2
      com.unity.ml-agents/Documentation~/com.unity.ml-agents.md
  27. 1
      com.unity.ml-agents/Editor/CameraSensorComponentEditor.cs
  28. 1
      com.unity.ml-agents/Editor/RenderTextureSensorComponentEditor.cs
  29. 49
      com.unity.ml-agents/Runtime/Academy.cs
  30. 2
      com.unity.ml-agents/Runtime/Actuators/IActionReceiver.cs
  31. 2
      com.unity.ml-agents/Runtime/Actuators/IDiscreteActionMask.cs
  32. 26
      com.unity.ml-agents/Runtime/Agent.cs
  33. 62
      com.unity.ml-agents/Runtime/Communicator/GrpcExtensions.cs
  34. 4
      com.unity.ml-agents/Runtime/Communicator/UnityRLCapabilities.cs
  35. 2
      com.unity.ml-agents/Runtime/Demonstrations/DemonstrationRecorder.cs
  36. 2
      com.unity.ml-agents/Runtime/DiscreteActionMasker.cs
  37. 40
      com.unity.ml-agents/Runtime/Grpc/CommunicatorObjects/Capabilities.cs
  38. 34
      com.unity.ml-agents/Runtime/Grpc/CommunicatorObjects/Observation.cs
  39. 64
      com.unity.ml-agents/Runtime/SensorHelper.cs
  40. 2
      com.unity.ml-agents/Runtime/Sensors/CameraSensor.cs
  41. 28
      com.unity.ml-agents/Runtime/Sensors/CameraSensorComponent.cs
  42. 52
      com.unity.ml-agents/Runtime/Sensors/ObservationWriter.cs
  43. 2
      com.unity.ml-agents/Runtime/Sensors/RenderTextureSensor.cs
  44. 28
      com.unity.ml-agents/Runtime/Sensors/RenderTextureSensorComponent.cs
  45. 198
      com.unity.ml-agents/Runtime/Sensors/StackingSensor.cs
  46. 47
      com.unity.ml-agents/Runtime/Utilities.cs
  47. 31
      com.unity.ml-agents/Tests/Editor/Communicator/GrpcExtensionsTests.cs
  48. 156
      com.unity.ml-agents/Tests/Editor/Sensor/StackingSensorTests.cs
  49. 10
      com.unity.ml-agents/Tests/Editor/Sensor/VectorSensorTests.cs
  50. 4
      com.unity.ml-agents/Tests/Runtime/RuntimeAPITest.cs
  51. 2
      com.unity.ml-agents/package.json
  52. 4
      docs/Installation-Anaconda-Windows.md
  53. 6
      docs/Installation.md
  54. 4
      docs/Learning-Environment-Create-New.md
  55. 2
      docs/Learning-Environment-Design-Agents.md
  56. 10
      docs/Learning-Environment-Examples.md
  57. 24
      docs/ML-Agents-Overview.md
  58. 16
      docs/Migrating.md
  59. 13
      docs/Training-Configuration-File.md
  60. 2
      docs/Training-on-Amazon-Web-Service.md
  61. 4
      docs/Unity-Inference-Engine.md
  62. 2
      gym-unity/gym_unity/__init__.py
  63. 4
      gym-unity/setup.py
  64. 2
      ml-agents-envs/mlagents_envs/__init__.py
  65. 11
      ml-agents-envs/mlagents_envs/communicator_objects/capabilities_pb2.py
  66. 6
      ml-agents-envs/mlagents_envs/communicator_objects/capabilities_pb2.pyi
  67. 19
      ml-agents-envs/mlagents_envs/communicator_objects/observation_pb2.py
  68. 6
      ml-agents-envs/mlagents_envs/communicator_objects/observation_pb2.pyi
  69. 4
      ml-agents-envs/mlagents_envs/environment.py
  70. 81
      ml-agents-envs/mlagents_envs/rpc_utils.py
  71. 76
      ml-agents-envs/mlagents_envs/tests/test_rpc_utils.py
  72. 4
      ml-agents-envs/setup.py
  73. 7
      ml-agents/mlagents/torch_utils/cpu_utils.py
  74. 2
      ml-agents/mlagents/trainers/__init__.py
  75. 9
      ml-agents/mlagents/trainers/buffer.py
  76. 12
      ml-agents/mlagents/trainers/environment_parameter_manager.py
  77. 5
      ml-agents/mlagents/trainers/learn.py
  78. 3
      ml-agents/mlagents/trainers/model_saver/tf_model_saver.py
  79. 4
      ml-agents/mlagents/trainers/optimizer/tf_optimizer.py
  80. 10
      ml-agents/mlagents/trainers/policy/checkpoint_manager.py
  81. 7
      ml-agents/mlagents/trainers/policy/torch_policy.py
  82. 2
      ml-agents/mlagents/trainers/ppo/trainer.py
  83. 151
      ml-agents/mlagents/trainers/sac/optimizer_torch.py
  84. 6
      ml-agents/mlagents/trainers/sac/trainer.py
  85. 38
      ml-agents/mlagents/trainers/settings.py
  86. 2
      ml-agents/mlagents/trainers/tests/test_learn.py
  87. 8
      ml-agents/mlagents/trainers/tests/test_rl_trainer.py
  88. 16
      ml-agents/mlagents/trainers/tests/test_settings.py
  89. 10
      ml-agents/mlagents/trainers/tests/test_subprocess_env_manager.py
  90. 1
      ml-agents/mlagents/trainers/tests/test_trainer_controller.py
  91. 27
      ml-agents/mlagents/trainers/tests/test_trainer_util.py
  92. 24
      ml-agents/mlagents/trainers/tests/test_training_status.py
  93. 4
      ml-agents/mlagents/trainers/tests/torch/saver/test_saver.py
  94. 20
      ml-agents/mlagents/trainers/tests/torch/saver/test_saver_reward_providers.py
  95. 10
      ml-agents/mlagents/trainers/tests/torch/test_policy.py
  96. 12
      ml-agents/mlagents/trainers/tests/torch/test_ppo.py
  97. 10
      ml-agents/mlagents/trainers/tests/torch/test_sac.py
  98. 253
      ml-agents/mlagents/trainers/tests/torch/test_simple_rl.py
  99. 17
      ml-agents/mlagents/trainers/tests/torch/test_utils.py
  100. 2
      ml-agents/mlagents/trainers/torch/components/bc/module.py

12
.circleci/config.yml


filters:
tags:
# Matches e.g. "release_123"
only: /^release_[0-9]+$/
only: /^DEPRECATED_release_[0-9]+$/
branches:
ignore: /.*/
- deploy:

tags:
# Matches e.g. "release_123"
only: /^release_[0-9]+$/
only: /^DEPRECATED_release_[0-9]+$/
branches:
ignore: /.*/
- deploy:

tags:
# Matches e.g. "release_123"
only: /^release_[0-9]+$/
only: /^DEPRECATED_release_[0-9]+$/
branches:
ignore: /.*/
# These deploy jobs upload to the pypi test repo. They have different tag triggers than the real ones.

filters:
tags:
# Matches e.g. "release_123_test456
only: /^release_[0-9]+_test[0-9]+$/
only: /^DEPRECATED_release_[0-9]+_test[0-9]+$/
branches:
ignore: /.*/
- deploy:

filters:
tags:
# Matches e.g. "release_123_test456
only: /^release_[0-9]+_test[0-9]+$/
only: /^DEPRECATED_release_[0-9]+_test[0-9]+$/
branches:
ignore: /.*/
- deploy:

filters:
tags:
# Matches e.g. "release_123_test456
only: /^release_[0-9]+_test[0-9]+$/
only: /^DEPRECATED_release_[0-9]+_test[0-9]+$/
branches:
ignore: /.*/

4
.github/workflows/pre-commit.yml


runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
- uses: actions/setup-python@v2
with:
python-version: 3.7.x
- uses: actions/setup-ruby@v1
with:
ruby-version: '2.6'

47
.yamato/com.unity.ml-agents-promotion.yml


test_editors:
- version: 2019.3
test_platforms:
- name: win
type: Unity::VM
image: package-ci/win10:stable
flavor: b1.large
---
{% for editor in test_editors %}
{% for platform in test_platforms %}
promotion_test_{{ platform.name }}_{{ editor.version }}:
name : Promotion Test {{ editor.version }} on {{ platform.name }}
agent:
type: {{ platform.type }}
image: {{ platform.image }}
flavor: {{ platform.flavor}}
variables:
UPMCI_PROMOTION: 1
commands:
- npm install upm-ci-utils@stable -g --registry https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-npm
- upm-ci package test --unity-version {{ editor.version }} --package-path com.unity.ml-agents
artifacts:
logs:
paths:
- "upm-ci~/test-results/**/*"
dependencies:
- .yamato/com.unity.ml-agents-pack.yml#pack
{% endfor %}
{% endfor %}
promotion_test_trigger:
name: Promotion Tests Trigger
dependencies:
{% for editor in test_editors %}
{% for platform in test_platforms %}
- .yamato/com.unity.ml-agents-promotion.yml#promotion_test_{{platform.name}}_{{editor.version}}
{% endfor %}
{% endfor %}
promote:
name: Promote to Production
agent:

- "upm-ci~/packages/*.tgz"
dependencies:
- .yamato/com.unity.ml-agents-pack.yml#pack
- .yamato/com.unity.ml-agents-test.yml#all_package_tests
{% for editor in test_editors %}
{% for platform in test_platforms %}
- .yamato/com.unity.ml-agents-promotion.yml#promotion_test_{{ platform.name }}_{{ editor.version }}
{% endfor %}
{% endfor %}

14
.yamato/com.unity.ml-agents-test.yml


- version: 2018.4
# 2018.4 doesn't support code-coverage
enableCodeCoverage: !!bool false
# We want some scene tests to run in the DevProject, but packages there only support 2019+
testProject: Project
testProject: DevProject
testProject: DevProject
testProject: DevProject
testProject: DevProject
test_platforms:
- name: win
type: Unity::VM

type: Unity::VM
image: package-ci/ubuntu:stable
flavor: b1.medium
packages:
- name: com.unity.ml-agents
assembly: Unity.ML-Agents

flavor: {{ platform.flavor}}
commands:
- npm install upm-ci-utils@stable -g --registry https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-npm
- upm-ci project test -u {{ editor.version }} --project-path Project --package-filter {{ package.name }} {{ coverageOptions }} --extra-utr-arg "reruncount=2"
- upm-ci project test -u {{ editor.version }} --project-path {{ editor.testProject }} --package-filter {{ package.name }} {{ coverageOptions }} --extra-utr-arg "reruncount=2"
{% if editor.enableCodeCoverage %}
- python3 ml-agents/tests/yamato/check_coverage_percent.py upm-ci~/test-results/ {{ package.minCoveragePct }}
{% endif %}

pull_request.target match "release.+") AND
NOT pull_request.draft AND
(pull_request.changes.any match "com.unity.ml-agents/**" OR
pull_request.changes.any match " {{ editor.testProject }}/**" OR
{% if package.name == "com.unity.ml-agents.extensions" %}
pull_request.changes.any match "com.unity.ml-agents.extensions/**" OR
{% endif %}

- python -m pip install unity-downloader-cli --index-url https://artifactory.prd.it.unity3d.com/artifactory/api/pypi/pypi/simple --upgrade
- unity-downloader-cli -u trunk -c editor --wait --fast
- npm install upm-ci-utils@stable -g --registry https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-npm
- upm-ci project test -u {{ editor.version }} --project-path Project --package-filter {{ package.name }} {{ coverageOptions }} --extra-utr-arg "reruncount=2"
- upm-ci project test -u {{ editor.version }} --project-path {{ editor.testProject }} --package-filter {{ package.name }} {{ coverageOptions }} --extra-utr-arg "reruncount=2"
{% if editor.enableCodeCoverage %}
- python3 ml-agents/tests/yamato/check_coverage_percent.py upm-ci~/test-results/ {{ package.minCoveragePct }}
{% endif %}

3
.yamato/gym-interface-test.yml


test_editors:
- version: 2019.4
{% metadata_file .yamato/test_versions.metafile %}
---
{% for editor in test_editors %}
test_gym_interface_{{ editor.version }}:

3
.yamato/python-ll-api-test.yml


test_editors:
- version: 2019.4
{% metadata_file .yamato/test_versions.metafile %}
---
{% for editor in test_editors %}
test_mac_ll_api_{{ editor.version }}:

9
.yamato/standalone-build-test.yml


test_editors:
- version: 2018.4
- version: 2019.3
{% metadata_file .yamato/test_versions.metafile %}
---
{% for editor in test_editors %}
test_mac_standalone_{{ editor.version }}:

UNITY_VERSION: {{ editor.version }}
commands:
- pip install pyyaml --index-url https://artifactory.prd.it.unity3d.com/artifactory/api/pypi/pypi/simple
# TODO remove the "--user" command and the path prefix when we can migrate away from the custom bokken image
- python -m pip install unity-downloader-cli --index-url https://artifactory.prd.it.unity3d.com/artifactory/api/pypi/pypi/simple --upgrade --user
- /Users/bokken/Library/Python/3.7/bin/unity-downloader-cli -u {{ editor.version }} -c editor --wait --fast
- python -u -m ml-agents.tests.yamato.standalone_build_tests --scene=Assets/ML-Agents/TestScenes/TestCompressedGrid/TestGridCompressed.unity
- python -u -m ml-agents.tests.yamato.standalone_build_tests --scene=Assets/ML-Agents/TestScenes/TestCompressedTexture/TestTextureCompressed.unity
triggers:
cancel_old_ci: true
expression: |

8
.yamato/training-int-tests.yml


test_editors:
- version: 2018.4
- version: 2019.4
- version: 2020.1
{% metadata_file .yamato/test_versions.metafile %}
---
{% for editor in test_editors %}
test_mac_training_int_{{ editor.version }}:

UNITY_VERSION: {{ editor.version }}
commands:
- pip install pyyaml --index-url https://artifactory.prd.it.unity3d.com/artifactory/api/pypi/pypi/simple
# TODO remove the "--user" command and the path prefix when we can migrate away from the custom bokken image
- python -m pip install unity-downloader-cli --index-url https://artifactory.prd.it.unity3d.com/artifactory/api/pypi/pypi/simple --upgrade --user
- /Users/bokken/Library/Python/3.7/bin/unity-downloader-cli -u {{ editor.version }} -c editor --wait --fast
- python -u -m ml-agents.tests.yamato.training_int_tests
# Backwards-compatibility tests.
# If we make a breaking change to the communication protocol, these will need

5
DevProject/ProjectSettings/EditorBuildSettings.asset


EditorBuildSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Scenes: []
m_Scenes:
- enabled: 1
path: Assets/ML-Agents/Scripts/Tests/Runtime/AcademyTest/AcademyStepperTestScene.unity
guid: 9bafc50b1e55b43b2b1ae9620f1f8311
m_configObjects: {}

159
Dockerfile


# Based off of python:3.6-slim, except that we are using ubuntu instead of debian.
FROM ubuntu:16.04
# ensure local python is preferred over distribution python
ENV PATH /usr/local/bin:$PATH
FROM nvidia/cuda:10.0-cudnn7-devel-ubuntu18.04
# http://bugs.python.org/issue19846
# > At the moment, setting "LANG=C" on a Linux system *fundamentally breaks Python 3*, and that's not OK.
ENV LANG C.UTF-8
RUN yes | unminimize
# runtime dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
libexpat1 \
libffi6 \
libgdbm3 \
libreadline6 \
libsqlite3-0 \
libssl1.0.0 \
&& rm -rf /var/lib/apt/lists/*
RUN echo "deb http://packages.cloud.google.com/apt cloud-sdk-xenial main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
RUN wget https://packages.cloud.google.com/apt/doc/apt-key.gpg && apt-key add apt-key.gpg
RUN apt-get update && \
apt-get install -y --no-install-recommends wget curl tmux vim git gdebi-core \
build-essential python3-pip unzip google-cloud-sdk htop mesa-utils xorg-dev xorg \
libglvnd-dev libgl1-mesa-dev libegl1-mesa-dev libgles2-mesa-dev && \
wget http://security.ubuntu.com/ubuntu/pool/main/libx/libxfont/libxfont1_1.5.1-1ubuntu0.16.04.4_amd64.deb && \
wget http://security.ubuntu.com/ubuntu/pool/universe/x/xorg-server/xvfb_1.18.4-0ubuntu0.10_amd64.deb && \
yes | gdebi libxfont1_1.5.1-1ubuntu0.16.04.4_amd64.deb && \
yes | gdebi xvfb_1.18.4-0ubuntu0.10_amd64.deb
RUN python3 -m pip install --upgrade pip
RUN pip install setuptools==41.0.0
ENV GPG_KEY 0D96DF4D4110E5C43FBFB17F2D347EA6AA65421D
ENV PYTHON_VERSION 3.6.4
ENV LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH
RUN set -ex \
&& buildDeps=" \
dpkg-dev \
gcc \
libbz2-dev \
libc6-dev \
libexpat1-dev \
libffi-dev \
libgdbm-dev \
liblzma-dev \
libncursesw5-dev \
libreadline-dev \
libsqlite3-dev \
libssl-dev \
make \
tcl-dev \
tk-dev \
wget \
xz-utils \
zlib1g-dev \
# as of Stretch, "gpg" is no longer included by default
$(command -v gpg > /dev/null || echo 'gnupg dirmngr') \
" \
&& apt-get update && apt-get install -y $buildDeps --no-install-recommends && rm -rf /var/lib/apt/lists/* \
\
&& wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \
&& wget -O python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \
&& export GNUPGHOME="$(mktemp -d)" \
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPG_KEY" \
&& gpg --batch --verify python.tar.xz.asc python.tar.xz \
&& rm -rf "$GNUPGHOME" python.tar.xz.asc \
&& mkdir -p /usr/src/python \
&& tar -xJC /usr/src/python --strip-components=1 -f python.tar.xz \
&& rm python.tar.xz \
\
&& cd /usr/src/python \
&& gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" \
&& ./configure \
--build="$gnuArch" \
--enable-loadable-sqlite-extensions \
--enable-shared \
--with-system-expat \
--with-system-ffi \
--without-ensurepip \
&& make -j "$(nproc)" \
&& make install \
&& ldconfig \
\
&& apt-get purge -y --auto-remove $buildDeps \
\
&& find /usr/local -depth \
\( \
\( -type d -a \( -name test -o -name tests \) \) \
-o \
\( -type f -a \( -name '*.pyc' -o -name '*.pyo' \) \) \
\) -exec rm -rf '{}' + \
&& rm -rf /usr/src/python
# make some useful symlinks that are expected to exist
RUN cd /usr/local/bin \
&& ln -s idle3 idle \
&& ln -s pydoc3 pydoc \
&& ln -s python3 python \
&& ln -s python3-config python-config
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
ENV PYTHON_PIP_VERSION 9.0.3
RUN set -ex; \
\
apt-get update; \
apt-get install -y --no-install-recommends wget; \
rm -rf /var/lib/apt/lists/*; \
\
wget -O get-pip.py 'https://bootstrap.pypa.io/get-pip.py'; \
\
apt-get purge -y --auto-remove wget; \
\
python get-pip.py \
--disable-pip-version-check \
--no-cache-dir \
"pip==$PYTHON_PIP_VERSION" \
; \
pip --version; \
\
find /usr/local -depth \
\( \
\( -type d -a \( -name test -o -name tests \) \) \
-o \
\( -type f -a \( -name '*.pyc' -o -name '*.pyo' \) \) \
\) -exec rm -rf '{}' +; \
rm -f get-pip.py
RUN apt-get update && apt-get -y upgrade
# 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
COPY ml-agents /ml-agents
#checkout ml-agents for SHA
RUN mkdir /ml-agents
RUN pip install -e .
# Port 5004 is the port used in Editor training.
# Environments will start from port 5005,
# so allow enough ports for several environments.
EXPOSE 5004-5050
ENTRYPOINT ["xvfb-run", "--auto-servernum", "--server-args='-screen 0 640x480x24'", "mlagents-learn"]
ARG SHA
RUN git init
RUN git remote add origin https://github.com/Unity-Technologies/ml-agents.git
RUN git fetch --depth 1 origin $SHA
RUN git checkout FETCH_HEAD
RUN pip install -e /ml-agents/ml-agents-envs
RUN pip install -e /ml-agents/ml-agents

26
Project/Assets/ML-Agents/Examples/3DBall/Prefabs/3DBall.prefab


m_Name:
m_EditorClassIdentifier:
m_BrainParameters:
vectorObservationSize: 8
numStackedVectorObservations: 1
vectorActionSize: 02000000
vectorActionDescriptions: []
vectorActionSpaceType: 1
VectorObservationSize: 8
NumStackedVectorObservations: 1
VectorActionSize: 02000000
VectorActionDescriptions: []
VectorActionSpaceType: 1
m_TeamID: 0
m_useChildSensors: 1
TeamId: 0
m_UseChildSensors: 1
m_UseChildActuators: 1
m_ObservableAttributeHandling: 0
--- !u!114 &114715123104194396
MonoBehaviour:
m_ObjectHideFlags: 0

m_Script: {fileID: 11500000, guid: aaba48bf82bee4751aa7b89569e57f73, type: 3}
m_Name:
m_EditorClassIdentifier:
maxStep: 5000
agentParameters:
maxStep: 0
hasUpgradedFromAgentParameters: 1
MaxStep: 5000
useVecObs: 1
--- !u!114 &1306725529891448089
MonoBehaviour:
m_ObjectHideFlags: 0

m_Name:
m_EditorClassIdentifier:
DecisionPeriod: 5
RepeatAction: 1
offsetStep: 0
TakeActionsBetweenDecisions: 1
--- !u!114 &1758424554059689351
MonoBehaviour:
m_ObjectHideFlags: 0

m_Script: {fileID: 11500000, guid: 3a6da8f78a394c6ab027688eab81e04d, type: 3}
m_Name:
m_EditorClassIdentifier:
debugCommandLineOverride:
--- !u!1 &1533320402322554
GameObject:
m_ObjectHideFlags: 0

19
Project/Assets/ML-Agents/Examples/3DBall/Scenes/3DBall.unity


m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.44971162, g: 0.49977726, b: 0.5756362, a: 1}
m_IndirectSpecularColor: {r: 0.44971168, g: 0.4997775, b: 0.57563686, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:

m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 1321468028730240, guid: cfa81c019162c4e3caf6e2999c6fdf48, type: 3}
propertyPath: m_Name
value: 3DBall
objectReference: {fileID: 0}
- target: {fileID: 4679453577574622, guid: cfa81c019162c4e3caf6e2999c6fdf48, type: 3}
propertyPath: m_LocalPosition.x
value: 0

- target: {fileID: 4679453577574622, guid: cfa81c019162c4e3caf6e2999c6fdf48, type: 3}
propertyPath: m_RootOrder
value: 5
objectReference: {fileID: 0}
- target: {fileID: 4679453577574622, guid: cfa81c019162c4e3caf6e2999c6fdf48, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4679453577574622, guid: cfa81c019162c4e3caf6e2999c6fdf48, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4679453577574622, guid: cfa81c019162c4e3caf6e2999c6fdf48, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: cfa81c019162c4e3caf6e2999c6fdf48, type: 3}

maximumDeltaTime: 0.33333334
solverIterations: 6
solverVelocityIterations: 1
reuseCollisionCallbacks: 1
--- !u!1 &1746325439
GameObject:
m_ObjectHideFlags: 0

14
Project/Assets/ML-Agents/Examples/3DBall/Scripts/Ball3DAgent.cs


{
[Header("Specific to Ball3D")]
public GameObject ball;
[Tooltip("Whether to use vector observation. This option should be checked " +
"in 3DBall scene, and unchecked in Visual3DBall scene. ")]
public bool useVecObs;
Rigidbody m_BallRb;
EnvironmentParameters m_ResetParams;

public override void CollectObservations(VectorSensor sensor)
{
sensor.AddObservation(gameObject.transform.rotation.z);
sensor.AddObservation(gameObject.transform.rotation.x);
sensor.AddObservation(ball.transform.position - gameObject.transform.position);
sensor.AddObservation(m_BallRb.velocity);
if (useVecObs)
{
sensor.AddObservation(gameObject.transform.rotation.z);
sensor.AddObservation(gameObject.transform.rotation.x);
sensor.AddObservation(ball.transform.position - gameObject.transform.position);
sensor.AddObservation(m_BallRb.velocity);
}
}
public override void OnActionReceived(ActionBuffers actionBuffers)

23
Project/Assets/ML-Agents/Examples/Crawler/Scenes/CrawlerStaticVariableSpeed.unity


objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 0456c89e8c9c243d595b039fe7aa0bf9, type: 3}
--- !u!1 &441460235 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 4845971001715176661, guid: 0456c89e8c9c243d595b039fe7aa0bf9,
type: 3}
m_PrefabInstance: {fileID: 71447557}
m_PrefabAsset: {fileID: 0}
--- !u!114 &441460236
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 441460235}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f2902496c0120472b90269f94a0aec7e, type: 3}
m_Name:
m_EditorClassIdentifier:
Record: 1
NumStepsToRecord: 10000
DemonstrationName: ExpCrawlerStaVS
DemonstrationDirectory:
--- !u!1001 &455366880
PrefabInstance:
m_ObjectHideFlags: 0

m_Name:
m_EditorClassIdentifier:
target: {fileID: 1053322438}
smoothingTime: 0
--- !u!81 &914210116
AudioListener:
m_ObjectHideFlags: 0

154
Project/Assets/ML-Agents/Examples/FoodCollector/Prefabs/VisualFoodCollectorArea.prefab


m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1145096862361766}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
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_Name:
m_EditorClassIdentifier:
m_BrainParameters:
vectorObservationSize: 0
numStackedVectorObservations: 1
vectorActionSize: 03000000030000000300000002000000
vectorActionDescriptions: []
vectorActionSpaceType: 0
m_Model: {fileID: 0}
VectorObservationSize: 1
NumStackedVectorObservations: 1
VectorActionSize: 03000000030000000300000002000000
VectorActionDescriptions: []
VectorActionSpaceType: 0
m_Model: {fileID: 11400000, guid: c3b1eb0bcf06b4c0488599c7ab806de7, type: 3}
m_TeamID: 0
TeamId: 0
m_UseChildActuators: 1
m_ObservableAttributeHandling: 0
--- !u!114 &114380897261200276
MonoBehaviour:
m_ObjectHideFlags: 0

m_Script: {fileID: 11500000, guid: c66e6845309d241c78a6d77ee2567928, type: 3}
m_Name:
m_EditorClassIdentifier:
maxStep: 5000
agentParameters:
maxStep: 0
hasUpgradedFromAgentParameters: 1
MaxStep: 5000
area: {fileID: 1145096862361766}
turnSpeed: 300
moveSpeed: 2

myLaser: {fileID: 1900094563283840}
contribute: 0
useVectorObs: 0
useVectorFrozenFlag: 1
--- !u!114 &114326390494230518
MonoBehaviour:
m_ObjectHideFlags: 0

m_Script: {fileID: 11500000, guid: 282f342c2ab144bf38be65d4d0c4e07d, type: 3}
m_Name:
m_EditorClassIdentifier:
camera: {fileID: 20380145723616022}
sensorName: CameraSensor
width: 84
height: 84
grayscale: 0
compression: 1
m_Camera: {fileID: 20380145723616022}
m_SensorName: CameraSensor
m_Width: 84
m_Height: 84
m_Grayscale: 0
m_ObservationStacks: 1
m_Compression: 1
--- !u!114 &4034342608499629224
MonoBehaviour:
m_ObjectHideFlags: 0

m_Name:
m_EditorClassIdentifier:
DecisionPeriod: 5
RepeatAction: 1
offsetStep: 0
TakeActionsBetweenDecisions: 1
--- !u!1 &1179319070824364
GameObject:
m_ObjectHideFlags: 0

m_Name:
m_EditorClassIdentifier:
m_BrainParameters:
vectorObservationSize: 0
numStackedVectorObservations: 1
vectorActionSize: 03000000030000000300000002000000
vectorActionDescriptions: []
vectorActionSpaceType: 0
m_Model: {fileID: 0}
VectorObservationSize: 1
NumStackedVectorObservations: 1
VectorActionSize: 03000000030000000300000002000000
VectorActionDescriptions: []
VectorActionSpaceType: 0
m_Model: {fileID: 11400000, guid: c3b1eb0bcf06b4c0488599c7ab806de7, type: 3}
m_TeamID: 0
TeamId: 0
m_UseChildActuators: 1
m_ObservableAttributeHandling: 0
--- !u!114 &114869844339180154
MonoBehaviour:
m_ObjectHideFlags: 0

m_Script: {fileID: 11500000, guid: c66e6845309d241c78a6d77ee2567928, type: 3}
m_Name:
m_EditorClassIdentifier:
maxStep: 5000
agentParameters:
maxStep: 0
hasUpgradedFromAgentParameters: 1
MaxStep: 5000
area: {fileID: 1145096862361766}
turnSpeed: 300
moveSpeed: 2

myLaser: {fileID: 1307818939507544}
contribute: 0
useVectorObs: 0
useVectorFrozenFlag: 1
--- !u!114 &114429222608880102
MonoBehaviour:
m_ObjectHideFlags: 0

m_Script: {fileID: 11500000, guid: 282f342c2ab144bf38be65d4d0c4e07d, type: 3}
m_Name:
m_EditorClassIdentifier:
camera: {fileID: 20863703825242712}
sensorName: CameraSensor
width: 84
height: 84
grayscale: 0
compression: 1
m_Camera: {fileID: 20863703825242712}
m_SensorName: CameraSensor
m_Width: 84
m_Height: 84
m_Grayscale: 0
m_ObservationStacks: 1
m_Compression: 1
--- !u!114 &7234640249101665162
MonoBehaviour:
m_ObjectHideFlags: 0

m_Name:
m_EditorClassIdentifier:
DecisionPeriod: 5
RepeatAction: 1
offsetStep: 0
TakeActionsBetweenDecisions: 1
--- !u!1 &1353209702154624
GameObject:
m_ObjectHideFlags: 0

m_Name:
m_EditorClassIdentifier:
m_BrainParameters:
vectorObservationSize: 0
numStackedVectorObservations: 1
vectorActionSize: 03000000030000000300000002000000
vectorActionDescriptions: []
vectorActionSpaceType: 0
m_Model: {fileID: 0}
VectorObservationSize: 1
NumStackedVectorObservations: 1
VectorActionSize: 03000000030000000300000002000000
VectorActionDescriptions: []
VectorActionSpaceType: 0
m_Model: {fileID: 11400000, guid: c3b1eb0bcf06b4c0488599c7ab806de7, type: 3}
m_TeamID: 0
TeamId: 0
m_UseChildActuators: 1
m_ObservableAttributeHandling: 0
--- !u!114 &114484596947519388
MonoBehaviour:
m_ObjectHideFlags: 0

m_Script: {fileID: 11500000, guid: c66e6845309d241c78a6d77ee2567928, type: 3}
m_Name:
m_EditorClassIdentifier:
maxStep: 5000
agentParameters:
maxStep: 0
hasUpgradedFromAgentParameters: 1
MaxStep: 5000
area: {fileID: 1145096862361766}
turnSpeed: 300
moveSpeed: 2

myLaser: {fileID: 1898252046043334}
contribute: 0
useVectorObs: 0
useVectorFrozenFlag: 1
--- !u!114 &114036270357198286
MonoBehaviour:
m_ObjectHideFlags: 0

m_Script: {fileID: 11500000, guid: 282f342c2ab144bf38be65d4d0c4e07d, type: 3}
m_Name:
m_EditorClassIdentifier:
camera: {fileID: 20696931947702132}
sensorName: CameraSensor
width: 84
height: 84
grayscale: 0
compression: 1
m_Camera: {fileID: 20696931947702132}
m_SensorName: CameraSensor
m_Width: 84
m_Height: 84
m_Grayscale: 0
m_ObservationStacks: 1
m_Compression: 1
--- !u!114 &3164735207755090463
MonoBehaviour:
m_ObjectHideFlags: 0

m_Name:
m_EditorClassIdentifier:
DecisionPeriod: 5
RepeatAction: 1
offsetStep: 0
TakeActionsBetweenDecisions: 1
--- !u!1 &1399553220224106
GameObject:
m_ObjectHideFlags: 0

m_Name:
m_EditorClassIdentifier:
m_BrainParameters:
vectorObservationSize: 0
numStackedVectorObservations: 1
vectorActionSize: 03000000030000000300000002000000
vectorActionDescriptions: []
vectorActionSpaceType: 0
m_Model: {fileID: 0}
VectorObservationSize: 1
NumStackedVectorObservations: 1
VectorActionSize: 03000000030000000300000002000000
VectorActionDescriptions: []
VectorActionSpaceType: 0
m_Model: {fileID: 11400000, guid: c3b1eb0bcf06b4c0488599c7ab806de7, type: 3}
m_TeamID: 0
TeamId: 0
m_UseChildActuators: 1
m_ObservableAttributeHandling: 0
--- !u!114 &114729119221978826
MonoBehaviour:
m_ObjectHideFlags: 0

m_Script: {fileID: 11500000, guid: c66e6845309d241c78a6d77ee2567928, type: 3}
m_Name:
m_EditorClassIdentifier:
maxStep: 5000
agentParameters:
maxStep: 0
hasUpgradedFromAgentParameters: 1
MaxStep: 5000
area: {fileID: 1145096862361766}
turnSpeed: 300
moveSpeed: 2

myLaser: {fileID: 1779831409734062}
contribute: 0
useVectorObs: 0
useVectorFrozenFlag: 1
--- !u!114 &114322691115031348
MonoBehaviour:
m_ObjectHideFlags: 0

m_Script: {fileID: 11500000, guid: 282f342c2ab144bf38be65d4d0c4e07d, type: 3}
m_Name:
m_EditorClassIdentifier:
camera: {fileID: 20363738094913048}
sensorName: CameraSensor
width: 84
height: 84
grayscale: 0
compression: 1
m_Camera: {fileID: 20363738094913048}
m_SensorName: CameraSensor
m_Width: 84
m_Height: 84
m_Grayscale: 0
m_ObservationStacks: 1
m_Compression: 1
--- !u!114 &5903164052970896384
MonoBehaviour:
m_ObjectHideFlags: 0

m_Name:
m_EditorClassIdentifier:
DecisionPeriod: 5
RepeatAction: 1
offsetStep: 0
TakeActionsBetweenDecisions: 1
--- !u!1 &1971119195936814
GameObject:
m_ObjectHideFlags: 0

73
Project/Assets/ML-Agents/Examples/FoodCollector/Scenes/VisualFoodCollector.unity


m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 1145096862361766, guid: c85b585836e104587b4efdc4d8b9d62b, type: 3}
propertyPath: m_Name
value: VisualFoodCollectorArea
objectReference: {fileID: 0}
- target: {fileID: 4307641258646068, guid: c85b585836e104587b4efdc4d8b9d62b, type: 3}
propertyPath: m_LocalPosition.x
value: 0

- target: {fileID: 4307641258646068, guid: c85b585836e104587b4efdc4d8b9d62b, type: 3}
propertyPath: m_RootOrder
value: 5
objectReference: {fileID: 0}
- target: {fileID: 4307641258646068, guid: c85b585836e104587b4efdc4d8b9d62b, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4307641258646068, guid: c85b585836e104587b4efdc4d8b9d62b, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4307641258646068, guid: c85b585836e104587b4efdc4d8b9d62b, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: c85b585836e104587b4efdc4d8b9d62b, type: 3}

m_AnchoredPosition: {x: -1000, y: -239.57645}
m_SizeDelta: {x: 160, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!1001 &1094805673
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 1145096862361766, guid: c85b585836e104587b4efdc4d8b9d62b, type: 3}
propertyPath: m_Name
value: VisualFoodCollectorArea (1)
objectReference: {fileID: 0}
- target: {fileID: 4307641258646068, guid: c85b585836e104587b4efdc4d8b9d62b, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4307641258646068, guid: c85b585836e104587b4efdc4d8b9d62b, type: 3}
propertyPath: m_LocalPosition.y
value: 60
objectReference: {fileID: 0}
- target: {fileID: 4307641258646068, guid: c85b585836e104587b4efdc4d8b9d62b, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4307641258646068, guid: c85b585836e104587b4efdc4d8b9d62b, type: 3}
propertyPath: m_LocalRotation.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: 4307641258646068, guid: c85b585836e104587b4efdc4d8b9d62b, type: 3}
propertyPath: m_LocalRotation.y
value: -0
objectReference: {fileID: 0}
- target: {fileID: 4307641258646068, guid: c85b585836e104587b4efdc4d8b9d62b, type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 4307641258646068, guid: c85b585836e104587b4efdc4d8b9d62b, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4307641258646068, guid: c85b585836e104587b4efdc4d8b9d62b, type: 3}
propertyPath: m_RootOrder
value: 6
objectReference: {fileID: 0}
- target: {fileID: 4307641258646068, guid: c85b585836e104587b4efdc4d8b9d62b, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4307641258646068, guid: c85b585836e104587b4efdc4d8b9d62b, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4307641258646068, guid: c85b585836e104587b4efdc4d8b9d62b, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: c85b585836e104587b4efdc4d8b9d62b, type: 3}
--- !u!1001 &1232021009
PrefabInstance:
m_ObjectHideFlags: 0

8
Project/Assets/ML-Agents/Examples/FoodCollector/Scripts/FoodCollectorAgent.cs


public GameObject myLaser;
public bool contribute;
public bool useVectorObs;
[Tooltip("Use only the frozen flag in vector observations. If \"Use Vector Obs\" " +
"is checked, this option has no effect. This option is necessary for the " +
"VisualFoodCollector scene.")]
public bool useVectorFrozenFlag;
EnvironmentParameters m_ResetParams;

sensor.AddObservation(localVelocity.z);
sensor.AddObservation(m_Frozen);
sensor.AddObservation(m_Shoot);
}
else if (useVectorFrozenFlag)
{
sensor.AddObservation(m_Frozen);
}
}

125
Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/ModelOverrider.cs


public class ModelOverrider : MonoBehaviour
{
HashSet<string> k_SupportedExtensions = new HashSet<string> { "nn", "onnx" };
const string k_CommandLineModelOverrideFlag = "--mlagents-override-model";
const string k_CommandLineModelOverrideDirectoryFlag = "--mlagents-override-model-directory";
const string k_CommandLineModelOverrideExtensionFlag = "--mlagents-override-model-extension";
const string k_CommandLineQuitAfterEpisodesFlag = "--mlagents-quit-after-episodes";

Agent m_Agent;
// Assets paths to use, with the behavior name as the key.
Dictionary<string, string> m_BehaviorNameOverrides = new Dictionary<string, string>();
string m_OverrideExtension = "nn";
private List<string> m_OverrideExtensions = new List<string>();
// Cached loaded NNModels, with the behavior name as the key.
Dictionary<string, NNModel> m_CachedModels = new Dictionary<string, NNModel>();

public bool HasOverrides
{
get { return m_BehaviorNameOverrides.Count > 0 || !string.IsNullOrEmpty(m_BehaviorNameOverrideDirectory); }
get
{
GetAssetPathFromCommandLine();
return !string.IsNullOrEmpty(m_BehaviorNameOverrideDirectory);
}
}
public static string GetOverrideBehaviorName(string originalBehaviorName)

/// <returns></returns>
void GetAssetPathFromCommandLine()
{
m_BehaviorNameOverrides.Clear();
var maxEpisodes = 0;
string[] commandLineArgsOverride = null;
if (!string.IsNullOrEmpty(debugCommandLineOverride) && Application.isEditor)

var args = commandLineArgsOverride ?? Environment.GetCommandLineArgs();
for (var i = 0; i < args.Length; i++)
{
if (args[i] == k_CommandLineModelOverrideFlag && i < args.Length - 2)
{
var key = args[i + 1].Trim();
var value = args[i + 2].Trim();
m_BehaviorNameOverrides[key] = value;
}
else if (args[i] == k_CommandLineModelOverrideDirectoryFlag && i < args.Length - 1)
if (args[i] == k_CommandLineModelOverrideDirectoryFlag && i < args.Length - 1)
m_OverrideExtension = args[i + 1].Trim().ToLower();
var isKnownExtension = k_SupportedExtensions.Contains(m_OverrideExtension);
var overrideExtension = args[i + 1].Trim().ToLower();
var isKnownExtension = k_SupportedExtensions.Contains(overrideExtension);
Debug.LogError($"loading unsupported format: {m_OverrideExtension}");
Debug.LogError($"loading unsupported format: {overrideExtension}");
m_OverrideExtensions.Add(overrideExtension);
}
else if (args[i] == k_CommandLineQuitAfterEpisodesFlag && i < args.Length - 1)
{

}
}
if (HasOverrides)
if (!string.IsNullOrEmpty(m_BehaviorNameOverrideDirectory))
{
// If overriding models, set maxEpisodes to 1 or the command line value
m_MaxEpisodes = maxEpisodes > 0 ? maxEpisodes : 1;

return m_CachedModels[behaviorName];
}
string assetPath = null;
if (m_BehaviorNameOverrides.ContainsKey(behaviorName))
if (string.IsNullOrEmpty(m_BehaviorNameOverrideDirectory))
assetPath = m_BehaviorNameOverrides[behaviorName];
}
else if (!string.IsNullOrEmpty(m_BehaviorNameOverrideDirectory))
{
assetPath = Path.Combine(m_BehaviorNameOverrideDirectory, $"{behaviorName}.{m_OverrideExtension}");
Debug.Log($"No override directory set.");
return null;
if (string.IsNullOrEmpty(assetPath))
{
Debug.Log($"No override for BehaviorName {behaviorName}, and no directory set.");
return null;
}
// Try the override extensions in order. If they weren't set, try .nn first, then .onnx.
var overrideExtensions = (m_OverrideExtensions.Count > 0)
? m_OverrideExtensions.ToArray()
: new[] { "nn", "onnx" };
try
bool isOnnx = false;
string assetName = null;
foreach (var overrideExtension in overrideExtensions)
rawModel = File.ReadAllBytes(assetPath);
var assetPath = Path.Combine(m_BehaviorNameOverrideDirectory, $"{behaviorName}.{overrideExtension}");
try
{
rawModel = File.ReadAllBytes(assetPath);
isOnnx = overrideExtension.Equals("onnx");
assetName = "Override - " + Path.GetFileName(assetPath);
break;
}
catch (IOException)
{
// Do nothing - try the next extension, or we'll exit if nothing loaded.
}
catch (IOException)
if (rawModel == null)
Debug.Log($"Couldn't load file {assetPath} at full path {Path.GetFullPath(assetPath)}", this);
Debug.Log($"Couldn't load model file(s) for {behaviorName} in {m_BehaviorNameOverrideDirectory} (full path: {Path.GetFullPath(m_BehaviorNameOverrideDirectory)}");
NNModel asset;
var isOnnx = m_OverrideExtension.Equals("onnx");
if (isOnnx)
{
var converter = new ONNXModelConverter(true);
var onnxModel = converter.Convert(rawModel);
var asset = isOnnx ? LoadOnnxModel(rawModel) : LoadBarracudaModel(rawModel);
asset.name = assetName;
m_CachedModels[behaviorName] = asset;
return asset;
}
NNModelData assetData = ScriptableObject.CreateInstance<NNModelData>();
using (var memoryStream = new MemoryStream())
using (var writer = new BinaryWriter(memoryStream))
{
ModelWriter.Save(writer, onnxModel);
assetData.Value = memoryStream.ToArray();
}
assetData.name = "Data";
assetData.hideFlags = HideFlags.HideInHierarchy;
NNModel LoadBarracudaModel(byte[] rawModel)
{
var asset = ScriptableObject.CreateInstance<NNModel>();
asset.modelData = ScriptableObject.CreateInstance<NNModelData>();
asset.modelData.Value = rawModel;
return asset;
}
asset = ScriptableObject.CreateInstance<NNModel>();
asset.modelData = assetData;
}
else
NNModel LoadOnnxModel(byte[] rawModel)
{
var converter = new ONNXModelConverter(true);
var onnxModel = converter.Convert(rawModel);
NNModelData assetData = ScriptableObject.CreateInstance<NNModelData>();
using (var memoryStream = new MemoryStream())
using (var writer = new BinaryWriter(memoryStream))
// Note - this approach doesn't work for onnx files. Need to replace with
// the equivalent of ONNXModelImporter.OnImportAsset()
asset = ScriptableObject.CreateInstance<NNModel>();
asset.modelData = ScriptableObject.CreateInstance<NNModelData>();
asset.modelData.Value = rawModel;
ModelWriter.Save(writer, onnxModel);
assetData.Value = memoryStream.ToArray();
assetData.name = "Data";
assetData.hideFlags = HideFlags.HideInHierarchy;
asset.name = "Override - " + Path.GetFileName(assetPath);
m_CachedModels[behaviorName] = asset;
var asset = ScriptableObject.CreateInstance<NNModel>();
asset.modelData = assetData;
/// <summary>
/// Load the NNModel file from the specified path, and give it to the attached agent.

10
README.md


# Unity ML-Agents Toolkit
[![docs badge](https://img.shields.io/badge/docs-reference-blue.svg)](https://github.com/Unity-Technologies/ml-agents/tree/release_7_docs/docs/)
[![docs badge](https://img.shields.io/badge/docs-reference-blue.svg)](https://github.com/Unity-Technologies/ml-agents/tree/release_8_docs/docs/)
[![license badge](https://img.shields.io/badge/license-Apache--2.0-green.svg)](LICENSE)

## Releases & Documentation
**Our latest, stable release is `Release 7`. Click
[here](https://github.com/Unity-Technologies/ml-agents/tree/release_7_docs/docs/Readme.md)
**Our latest, stable release is `Release 8`. Click
[here](https://github.com/Unity-Technologies/ml-agents/tree/release_8_docs/docs/Readme.md)
to get started with the latest release of ML-Agents.**
The table below lists all our releases, including our `master` branch which is

| **Version** | **Release Date** | **Source** | **Documentation** | **Download** |
|:-------:|:------:|:-------------:|:-------:|:------------:|
| **master (unstable)** | -- | [source](https://github.com/Unity-Technologies/ml-agents/tree/master) | [docs](https://github.com/Unity-Technologies/ml-agents/tree/master/docs/Readme.md) | [download](https://github.com/Unity-Technologies/ml-agents/archive/master.zip) |
| **Release 7** | **September 16, 2020** | **[source](https://github.com/Unity-Technologies/ml-agents/tree/release_7)** | **[docs](https://github.com/Unity-Technologies/ml-agents/tree/release_7_docs/docs/Readme.md)** | **[download](https://github.com/Unity-Technologies/ml-agents/archive/release_7.zip)** |
| **Release 8** | **October 14, 2020** | **[source](https://github.com/Unity-Technologies/ml-agents/tree/release_8)** | **[docs](https://github.com/Unity-Technologies/ml-agents/tree/release_8_docs/docs/Readme.md)** | **[download](https://github.com/Unity-Technologies/ml-agents/archive/release_8.zip)** |
| **Release 7** | September 16, 2020 | [source](https://github.com/Unity-Technologies/ml-agents/tree/release_7) | [docs](https://github.com/Unity-Technologies/ml-agents/tree/release_7_docs/docs/Readme.md) | [download](https://github.com/Unity-Technologies/ml-agents/archive/release_7.zip) |
| **Release 1** | April 30, 2020 | [source](https://github.com/Unity-Technologies/ml-agents/tree/release_1) | [docs](https://github.com/Unity-Technologies/ml-agents/tree/release_1_docs/docs/Readme.md) | [download](https://github.com/Unity-Technologies/ml-agents/archive/release_1.zip) |
## Citation

1
com.unity.ml-agents.extensions/Documentation~/Grid-Sensor.md


The Grid Sensor combines the generality of data extraction from Raycasts with the image processing power of Convolutional Neural Networks. The Grid Sensor can be used to collect data in the general form of a "Width x Height x Channel" matrix which can be used for training Reinforcement Learning agents or for data analysis.
<img src="images/gridsensor-debug.png" align="middle" width="3000"/>
# Motivation

31
com.unity.ml-agents.extensions/Documentation~/com.unity.ml-agents.extensions.md


# About ML-Agents Extensions package (`com.unity.ml-agents.extensions`)
The Unity ML-Agents Extensions package optional add-ons to the C# SDK for the
The Unity ML-Agents Extensions package contains optional add-ons to the C# SDK for the
[Unity ML-Agents Toolkit](https://github.com/Unity-Technologies/ml-agents).
These extensions are all considered experimental, and their API or behavior

| _Runtime_ | Contains core C# APIs for integrating ML-Agents into your Unity scene. |
| _Tests_ | Contains the unit tests for the package. |
<a name="Installation"></a>
## Installation
The ML-Agents Extensions package is not currently available in the Package Manager. There are two
recommended ways to install the package:
## Installation
### Local Installation
[Clone the repository](../../docs/Installation.md#clone-the-ml-agents-toolkit-repository-optional) and follow the
[Local Installation for Development](../../docs/Installation.md#advanced-local-installation-for-development-1)
directions (substituting `com.unity.ml-agents.extensions` for the package name).
### Github via Package Manager
In Unity 2019.4 or later, open the Package Manager, hit the "+" button, and select "Add package from git URL".
![Package Manager git URL](../../docs/images/unity_package_manager_git_url.png)
In the dialog that appears, enter
```
git+https://github.com/Unity-Technologies/ml-agents.git?path=com.unity.ml-agents.extensions
```
To install this _ML-Agents_ package, follow the instructions in the [Package
Manager documentation](https://docs.unity3d.com/Manual/upm-ui-install.html).
You can also edit your project's `manifest.json` directly and add the following line to the `dependencies`
section:
```
"com.unity.ml-agents.extensions": "git+https://github.com/Unity-Technologies/ml-agents.git?path=com.unity.ml-agents.extensions",
```
See [Git dependencies](https://docs.unity3d.com/Manual/upm-git.html#subfolder) for more information.
## Requirements

- 2018.4 and later
## Known Limitations
none
## Need Help?
The main [README](../../README.md) contains links for contacting the team or getting support.

4
com.unity.ml-agents.extensions/README.md


# ML-Agents Extensions
This is a source-only package for new features based on ML-Agents.
More details coming soon.
See the [package documentation](Documentation~/com.unity.ml-agents.extensions.md) for more information

4
com.unity.ml-agents.extensions/Runtime/Sensors/GridSensor.cs


[Tooltip("Whether to show gizmos or not")]
public bool ShowGizmos = false;
public SensorCompressionType CompressionType = SensorCompressionType.PNG;
/// <summary>
/// Array of colors displaying the DebugColors for each cell in OnDrawGizmos. Only updated if ShowGizmos.
/// </summary>

/// <inheritdoc/>
public virtual SensorCompressionType GetCompressionType()
{
return SensorCompressionType.PNG;
return CompressionType;
}
/// <summary>

2
com.unity.ml-agents.extensions/package.json


"unity": "2018.4",
"description": "A source-only package for new features based on ML-Agents",
"dependencies": {
"com.unity.ml-agents": "1.4.0-preview"
"com.unity.ml-agents": "1.5.0-preview"
}
}

38
com.unity.ml-agents/CHANGELOG.md


and this project adheres to
[Semantic Versioning](http://semver.org/spec/v2.0.0.html).
### Major Changes
#### com.unity.ml-agents (C#)
#### ml-agents / ml-agents-envs / gym-unity (Python)

### Bug Fixes
#### com.unity.ml-agents (C#)
#### ml-agents / ml-agents-envs / gym-unity (Python)
## [1.5.0-preview] - 2020-10-14
### Major Changes
#### com.unity.ml-agents (C#)
#### ml-agents / ml-agents-envs / gym-unity (Python)
- Added the Random Network Distillation (RND) intrinsic reward signal to the Pytorch
trainers. To use RND, add a `rnd` section to the `reward_signals` section of your
yaml configuration file. [More information here](https://github.com/Unity-Technologies/ml-agents/blob/master/docs/Training-Configuration-File.md#rnd-intrinsic-reward) (#4473)
### Minor Changes
#### com.unity.ml-agents (C#)
- Stacking for compressed observations is now supported. An additional setting
option `Observation Stacks` is added in editor to sensor components that support
compressed observations. A new class `ISparseChannelSensor` with an
additional method `GetCompressedChannelMapping()`is added to generate a mapping
of the channels in compressed data to the actual channel after decompression,
for the python side to decompress correctly. (#4476)
- Added a new visual 3DBall environment. (#4513)
#### ml-agents / ml-agents-envs / gym-unity (Python)
- The Communication API was changed to 1.2.0 to indicate support for stacked
compressed observation. A new entry `compressed_channel_mapping` is added to the
proto to handle decompression correctly. Newer versions of the package that wish to
make use of this will also need a compatible version of the Python trainers. (#4476)
- In the `VisualFoodCollector` scene, a vector flag representing the frozen state of
the agent is added to the input observations in addition to the original first-person
camera frame. The scene is able to train with the provided default config file. (#4511)
- Added conversion to string for sampler classes to increase the verbosity of
the curriculum lesson changes. The lesson updates would now output the sampler
stats in addition to the lesson and parameter name to the console. (#4484)
- Localized documentation in Russian is added. Thanks to @SergeyMatrosov for
the contribution. (#4529)
### Bug Fixes
#### com.unity.ml-agents (C#)
- Fixed a bug where accessing the Academy outside of play mode would cause the
Academy to get stepped multiple times when in play mode. (#4532)
#### ml-agents / ml-agents-envs / gym-unity (Python)

2
com.unity.ml-agents/Documentation~/com.unity.ml-agents.md


[unity ML-Agents Toolkit]: https://github.com/Unity-Technologies/ml-agents
[unity inference engine]: https://docs.unity3d.com/Packages/com.unity.barracuda@latest/index.html
[package manager documentation]: https://docs.unity3d.com/Manual/upm-ui-install.html
[installation instructions]: https://github.com/Unity-Technologies/ml-agents/blob/release_7_docs/docs/Installation.md
[installation instructions]: https://github.com/Unity-Technologies/ml-agents/blob/release_8_docs/docs/Installation.md
[github repository]: https://github.com/Unity-Technologies/ml-agents
[python package]: https://github.com/Unity-Technologies/ml-agents
[execution order of event functions]: https://docs.unity3d.com/Manual/ExecutionOrder.html

1
com.unity.ml-agents/Editor/CameraSensorComponentEditor.cs


EditorGUILayout.PropertyField(so.FindProperty("m_Width"), true);
EditorGUILayout.PropertyField(so.FindProperty("m_Height"), true);
EditorGUILayout.PropertyField(so.FindProperty("m_Grayscale"), true);
EditorGUILayout.PropertyField(so.FindProperty("m_ObservationStacks"), true);
}
EditorGUI.EndDisabledGroup();
EditorGUILayout.PropertyField(so.FindProperty("m_Compression"), true);

1
com.unity.ml-agents/Editor/RenderTextureSensorComponentEditor.cs


EditorGUILayout.PropertyField(so.FindProperty("m_RenderTexture"), true);
EditorGUILayout.PropertyField(so.FindProperty("m_SensorName"), true);
EditorGUILayout.PropertyField(so.FindProperty("m_Grayscale"), true);
EditorGUILayout.PropertyField(so.FindProperty("m_ObservationStacks"), true);
}
EditorGUI.EndDisabledGroup();

49
com.unity.ml-agents/Runtime/Academy.cs


* API. For more information on each of these entities, in addition to how to
* set-up a learning environment and train the behavior of characters in a
* Unity scene, please browse our documentation pages on GitHub:
* https://github.com/Unity-Technologies/ml-agents/tree/release_7_docs/docs/
* https://github.com/Unity-Technologies/ml-agents/tree/release_8_docs/docs/
*/
namespace Unity.MLAgents

{
void FixedUpdate()
{
Academy.Instance.EnvironmentStep();
// Check if the stepper belongs to the current Academy and destroy it if it's not.
// This is to prevent from having leaked stepper from previous runs.
if (!Academy.IsInitialized || !Academy.Instance.IsStepperOwner(this))
{
Destroy(this.gameObject);
}
else
{
Academy.Instance.EnvironmentStep();
}
}
}

/// fall back to inference or heuristic decisions. (You can also set agents to always use
/// inference or heuristics.)
/// </remarks>
[HelpURL("https://github.com/Unity-Technologies/ml-agents/tree/release_7_docs/" +
[HelpURL("https://github.com/Unity-Technologies/ml-agents/tree/release_8_docs/" +
"docs/Learning-Environment-Design.md")]
public class Academy : IDisposable
{

/// <term>1.1.0</term>
/// <description>Support concatenated PNGs for compressed observations.</description>
/// </item>
/// <item>
/// <term>1.2.0</term>
/// <description>Support compression mapping for stacked compressed observations.</description>
/// </item>
const string k_ApiVersion = "1.1.0";
const string k_ApiVersion = "1.2.0";
internal const string k_PackageVersion = "1.4.0-preview";
internal const string k_PackageVersion = "1.5.0-preview";
const int k_EditorTrainingPort = 5004;

Application.quitting += Dispose;
LazyInitialize();
#if UNITY_EDITOR
EditorApplication.playModeStateChanged += HandleOnPlayModeChanged;
#endif
#if UNITY_EDITOR
/// <summary>
/// Clean up the Academy when switching from edit mode to play mode
/// </summary>
/// <param name="state">State.</param>
void HandleOnPlayModeChanged(PlayModeStateChange state)
{
if (state == PlayModeStateChange.ExitingEditMode)
{
Dispose();
}
}
#endif
/// <summary>
/// Initialize the Academy if it hasn't already been initialized.