Skip to content

Commit 20569f9

Browse files
authored
Merge pull request #884 from Unity-Technologies/release-v0.4
Release v0.4
2 parents 4749aee + 562d49d commit 20569f9

File tree

453 files changed

+85274
-10872
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

453 files changed

+85274
-10872
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
*.unity binary
33
*.prefab binary
44
*.meta binary
5+
*/CommunicatorObjects/* binary
6+
*/communicator_objects/* binary
57
*.md text

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
/unity-environment/[Pp]ackages/
77
/unity-environment/[Uu]nity[Pp]ackage[Mm]anager/
88
/unity-environment/Assets/AssetStoreTools*
9+
/unity-environment/Assets/Plugins*
10+
/unity-environment/Assets/Gizmos*
911

1012
# Tensorflow Model Info
1113
/models

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,7 @@ RUN pip install --trusted-host pypi.python.org -r requirements.txt
129129
WORKDIR /execute
130130
COPY python /execute/python
131131

132+
# port 5005 is the port used in in Editor training.
133+
EXPOSE 5005
134+
132135
ENTRYPOINT ["python", "python/learn.py"]

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,17 @@ to the wider research and game developer communities.
2929
* Visualizing network outputs within the environment
3030
* Simplified set-up with Docker
3131

32-
## Documentation and References
32+
## Documentation
3333

34-
**For more information, in addition to installation and usage
35-
instructions, see our [documentation home](docs/Readme.md).** If you have
36-
used a version of ML-Agents prior to v0.3, we strongly recommend
37-
our [guide on migrating to v0.3](docs/Migrating-v0.3.md).
34+
* For more information, in addition to installation and usage
35+
instructions, see our [documentation home](docs/Readme.md).
36+
* If you have
37+
used a version of ML-Agents prior to v0.4, we strongly recommend
38+
our [guide on migrating from earlier versions](docs/Migrating.md).
3839

39-
We have also published a series of blog posts that are relevant for ML-Agents:
40+
## References
41+
42+
We have published a series of blog posts that are relevant for ML-Agents:
4043
- Overviewing reinforcement learning concepts
4144
([multi-armed bandit](https://blogs.unity3d.com/2017/06/26/unity-ai-themed-blog-entries/)
4245
and [Q-learning](https://blogs.unity3d.com/2017/08/22/unity-ai-reinforcement-learning-with-q-learning/))

docs/Basic-Guide.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Basic Guide
2+
3+
This guide will show you how to use a pretrained model in an example Unity environment, and show you how to train the model yourself.
4+
5+
If you are not familiar with the [Unity Engine](https://unity3d.com/unity),
6+
we highly recommend the [Roll-a-ball tutorial](https://unity3d.com/learn/tutorials/s/roll-ball-tutorial) to learn all the basic concepts of Unity.
7+
8+
## Setting up ML-Agents within Unity
9+
10+
In order to use ML-Agents within Unity, you need to change some Unity settings first. Also [TensorFlowSharp plugin](https://s3.amazonaws.com/unity-ml-agents/0.4/TFSharpPlugin.unitypackage) is needed for you to use pretrained model within Unity, which is based on the [TensorFlowSharp repo](https://github.com/migueldeicaza/TensorFlowSharp).
11+
12+
1. Launch Unity
13+
2. On the Projects dialog, choose the **Open** option at the top of the window.
14+
3. Using the file dialog that opens, locate the `unity-environment` folder within the ML-Agents project and click **Open**.
15+
4. Go to **Edit** > **Project Settings** > **Player**
16+
5. For **each** of the platforms you target
17+
(**PC, Mac and Linux Standalone**, **iOS** or **Android**):
18+
1. Option the **Other Settings** section.
19+
2. Select **Scripting Runtime Version** to
20+
**Experimental (.NET 4.6 Equivalent)**
21+
3. In **Scripting Defined Symbols**, add the flag `ENABLE_TENSORFLOW`.
22+
After typing in the flag name, press Enter.
23+
6. Go to **File** > **Save Project**
24+
25+
![Project Settings](images/project-settings.png)
26+
27+
[Download](https://s3.amazonaws.com/unity-ml-agents/0.4/TFSharpPlugin.unitypackage) the TensorFlowSharp plugin. Then import it into Unity by double clicking the downloaded file. You can check if it was successfully imported by checking the TensorFlow files in the Project window under **Assets** > **ML-Agents** > **Plugins** > **Computer**.
28+
29+
**Note**: If you don't see anything under **Assets**, drag the `ml-agents/unity-environment/Assets/ML-Agents` folder under **Assets** within Project window.
30+
31+
![Imported TensorFlowsharp](images/imported-tensorflowsharp.png)
32+
33+
## Running a Pre-trained Model
34+
35+
1. In the **Project** window, go to `Assets/ML-Agents/Examples/3DBall` folder and open the `3DBall` scene file.
36+
2. In the **Hierarchy** window, select the **Ball3DBrain** child under the **Ball3DAcademy** GameObject to view its properties in the Inspector window.
37+
3. On the **Ball3DBrain** object's **Brain** component, change the **Brain Type** to **Internal**.
38+
4. In the **Project** window, locate the `Assets/ML-Agents/Examples/3DBall/TFModels` folder.
39+
5. Drag the `3DBall` model file from the `TFModels` folder to the **Graph Model** field of the **Ball3DBrain** object's **Brain** component.
40+
5. Click the **Play** button and you will see the platforms balance the balls using the pretrained model.
41+
42+
![Running a pretrained model](images/running-a-pretrained-model.gif)
43+
44+
## Using the Basics Jupyter Notebook
45+
46+
The `python/Basics` [Jupyter notebook](Background-Jupyter.md) contains a
47+
simple walkthrough of the functionality of the Python
48+
API. It can also serve as a simple test that your environment is configured
49+
correctly. Within `Basics`, be sure to set `env_name` to the name of the
50+
Unity executable if you want to [use an executable](Learning-Environment-Executable.md) or to `None` if you want to interact with the current scene in the Unity Editor.
51+
52+
More information and documentation is provided in the
53+
[Python API](Python-API.md) page.
54+
55+
## Training the Brain with Reinforcement Learning
56+
### Setting the Brain to External
57+
Since we are going to build this environment to conduct training, we need to
58+
set the brain used by the agents to **External**. This allows the agents to
59+
communicate with the external training process when making their decisions.
60+
61+
1. In the **Scene** window, click the triangle icon next to the Ball3DAcademy
62+
object.
63+
2. Select its child object **Ball3DBrain**.
64+
3. In the Inspector window, set **Brain Type** to **External**.
65+
66+
![Set Brain to External](images/mlagents-SetExternalBrain.png)
67+
68+
### Training the environment
69+
1. Open a command or terminal window.
70+
2. Nagivate to the folder where you installed ML-Agents.
71+
3. Change to the `python` directory.
72+
4. Run `python3 learn.py --run-id=<run-identifier> --train`
73+
Where:
74+
- `<run-identifier>` is a string used to separate the results of different training runs
75+
- And the `--train` tells learn.py to run a training session (rather than inference)
76+
5. When the message _"Start training by pressing the Play button in the Unity Editor"_ is displayed on the screen, you can press the :arrow_forward: button in Unity to start training in the Editor.
77+
78+
**Note**: Alternatively, you can use an executable rather than the Editor to perform training. Please refer to [this page](Learning-Environment-Executable.md) for instructions on how to build and use an executable.
79+
80+
![Training command example](images/training-command-example.png)
81+
82+
**Note**: If you're using Anaconda, don't forget to activate the ml-agents environment first.
83+
84+
If the learn.py runs correctly and starts training, you should see something like this:
85+
86+
![Training running](images/training-running.png)
87+
88+
### After training
89+
You can press Ctrl+C to stop the training, and your trained model will be at `ml-agents/python/models/<run-identifier>/editor_<academy_name>_<run-identifier>.bytes` where `<academy_name>` is the name of the Academy GameObject in the current scene. This file corresponds to your model's latest checkpoint. You can now embed this trained model into your internal brain by following the steps below, which is similar to the steps described [above](#play-an-example-environment-using-pretrained-model).
90+
91+
1. Move your model file into
92+
`unity-environment/Assets/ML-Agents/Examples/3DBall/TFModels/`.
93+
2. Open the Unity Editor, and select the **3DBall** scene as described above.
94+
3. Select the **Ball3DBrain** object from the Scene hierarchy.
95+
4. Change the **Type of Brain** to **Internal**.
96+
5. Drag the `<env_name>_<run-identifier>.bytes` file from the Project window of the Editor
97+
to the **Graph Model** placeholder in the **Ball3DBrain** inspector window.
98+
6. Press the :arrow_forward: button at the top of the Editor.
99+
100+
## Next Steps
101+
102+
* For more information on ML-Agents, in addition to helpful background, check out the [ML-Agents Overview](ML-Agents-Overview.md) page.
103+
* For a more detailed walk-through of our 3D Balance Ball environment, check out the [Getting Started](Getting-Started-with-Balance-Ball.md) page.
104+
* For a "Hello World" introduction to creating your own learning environment, check out the [Making a New Learning Environment](Learning-Environment-Create-New.md) page.
105+
* For a series of Youtube video tutorials, checkout the [Machine Learning Agents PlayList](https://www.youtube.com/playlist?list=PLX2vGYjWbI0R08eWQkO7nQkGiicHAX7IX) page.

docs/FAQ.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Frequently Asked Questions
2+
3+
4+
### Scripting Runtime Environment not setup correctly
5+
6+
If you haven't switched your scripting runtime version from .NET 3.5 to .NET 4.6, you will see such error message:
7+
8+
```
9+
error CS1061: Type `System.Text.StringBuilder' does not contain a definition for `Clear' and no extension method `Clear' of type `System.Text.StringBuilder' could be found. Are you missing an assembly reference?
10+
```
11+
12+
This is because .NET 3.5 doesn't support method Clear() for StringBuilder, refer to [Setting Up ML-Agents Within Unity](Installation.md#setting-up-ml-agent-within-unity) for solution.
13+
14+
### TensorFlowSharp flag not turned on.
15+
16+
If you have already imported the TensorFlowSharp plugin, but havn't set ENABLE_TENSORFLOW flag for your scripting define symbols, you will see the following error message:
17+
18+
```
19+
You need to install and enable the TensorFlowSharp plugin in order to use the internal brain.
20+
```
21+
22+
This error message occurs because the TensorFlowSharp plugin won't be usage without the ENABLE_TENSORFLOW flag, refer to [Setting Up ML-Agents Within Unity](Installation.md#setting-up-ml-agent-within-unity) for solution.
23+
24+
### Tensorflow epsilon placeholder error
25+
26+
If you have a graph placeholder set in the internal Brain inspector that is not present in the TensorFlow graph, you will see some error like this:
27+
28+
```
29+
UnityAgentsException: One of the Tensorflow placeholder could not be found. In brain <some_brain_name>, there are no FloatingPoint placeholder named <some_placeholder_name>.
30+
```
31+
32+
Solution: Go to all of your Brain object, find `Graph placeholders` and change its `size` to 0 to remove the `epsilon` placeholder.
33+
34+
Similarly, if you have a graph scope set in the internal Brain inspector that is not correctly set, you will see some error like this:
35+
36+
```
37+
UnityAgentsException: The node <Wrong_Graph_Scope>/action could not be found. Please make sure the graphScope <Wrong_Graph_Scope>/ is correct
38+
```
39+
40+
Solution: Make sure your Graph Scope field matches the corresponding brain object name in your Hierachy Inspector when there is multiple brain.
41+
42+
### Environment Permission Error
43+
44+
If you directly import your Unity environment without building it in the
45+
editor, you might need to give it additional permissions to execute it.
46+
47+
If you receive such a permission error on macOS, run:
48+
49+
`chmod -R 755 *.app`
50+
51+
or on Linux:
52+
53+
`chmod -R 755 *.x86_64`
54+
55+
On Windows, you can find
56+
[instructions](https://technet.microsoft.com/en-us/library/cc754344(v=ws.11).aspx).
57+
58+
### Environment Connection Timeout
59+
60+
If you are able to launch the environment from `UnityEnvironment` but
61+
then receive a timeout error, there may be a number of possible causes.
62+
* _Cause_: There may be no Brains in your environment which are set
63+
to `External`. In this case, the environment will not attempt to
64+
communicate with python. _Solution_: Set the Brains(s) you wish to
65+
externally control through the Python API to `External` from the
66+
Unity Editor, and rebuild the environment.
67+
* _Cause_: On OSX, the firewall may be preventing communication with
68+
the environment. _Solution_: Add the built environment binary to the
69+
list of exceptions on the firewall by following
70+
[instructions](https://support.apple.com/en-us/HT201642).
71+
* _Cause_: An error happened in the Unity Environment preventing
72+
communication. _Solution_: Look into the
73+
[log files](https://docs.unity3d.com/Manual/LogFiles.html)
74+
generated by the Unity Environment to figure what error happened.
75+
76+
### Communication port {} still in use
77+
78+
If you receive an exception `"Couldn't launch new environment because
79+
communication port {} is still in use. "`, you can change the worker
80+
number in the Python script when calling
81+
82+
`UnityEnvironment(file_name=filename, worker_id=X)`
83+
84+
### Mean reward : nan
85+
86+
If you receive a message `Mean reward : nan` when attempting to train a
87+
model using PPO, this is due to the episodes of the learning environment
88+
not terminating. In order to address this, set `Max Steps` for either
89+
the Academy or Agents within the Scene Inspector to a value greater
90+
than 0. Alternatively, it is possible to manually set `done` conditions
91+
for episodes from within scripts for custom episode-terminating events.

docs/Feature-Monitor.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
The monitor allows visualizing information related to the agents or training process within a Unity scene.
66

77
You can track many different things both related and unrelated to the agents themselves. To use the Monitor, call the Log function anywhere in your code :
8+
89
```csharp
9-
Monitor.Log(key, value, displayType , target)
10+
Monitor.Log(key, value, target)
1011
```
12+
1113
* *`key`* is the name of the information you want to display.
12-
* *`value`* is the information you want to display.
13-
* *`displayType`* is a MonitorType that can be either `text`, `slider`, `bar` or `hist`.
14-
* `text` will convert `value` into a string and display it. It can be useful for displaying error messages!
15-
* `slider` is used to display a single float between -1 and 1. Note that value must be a float if you want to use a slider. If the value is positive, the slider will be green, if the value is negative, the slider will be red.
16-
* `hist` is used to display multiple floats. Note that value must be a list or array of floats. The Histogram will be a sequence of vertical sliders.
17-
* `bar` is used to see the proportions. Note that value must be a list or array of positive floats. For each float in values, a rectangle of width of value divided by the sum of all values will be show. It is best for visualizing values that sum to 1.
14+
* *`value`* is the information you want to display. *`value`* can have different types :
15+
* *`string`* - The Monitor will display the string next to the key. It can be useful for displaying error messages.
16+
* *`float`* - The Monitor will display a slider. Note that the values must be between -1 and 1. If the value is positive, the slider will be green, if the value is negative, the slider will be red.
17+
* *`float[]`* - The Monitor Log call can take an additional argument called `displayType` that can be either `INDEPENDENT` (default) or `PROPORTIONAL` :
18+
* *`INDEPENDENT`* is used to display multiple independent floats as a histogram. The histogram will be a sequence of vertical sliders.
19+
* *`PROPORTION`* is used to see the proportions between numbers. For each float in values, a rectangle of width of value divided by the sum of all values will be show. It is best for visualizing values that sum to 1.
1820
* *`target`* is the transform to which you want to attach information. If the transform is `null` the information will be attached to the global monitor.

0 commit comments

Comments
 (0)