浏览代码

Change docs and ipynb to reflect new import path for UnityEnvironment (#2690)

/develop-gpu-test
GitHub 5 年前
当前提交
68266eed
共有 6 个文件被更改,包括 34 次插入33 次删除
  1. 6
      docs/Learning-Environment-Executable.md
  2. 1
      docs/Migrating.md
  3. 20
      docs/Python-API.md
  4. 32
      docs/Training-on-Amazon-Web-Service.md
  5. 6
      docs/Training-on-Microsoft-Azure.md
  6. 2
      notebooks/getting-started.ipynb

6
docs/Learning-Environment-Executable.md


to be able to control your agents from Python, you will need to put the Brain
controlling the Agents to be a **Learning Brain** and drag it into the
Academy's `Broadcast Hub`. In the 3DBall
scene, this can be done in the Platform GameObject within the Game prefab in
`Assets/ML-Agents/Examples/3DBall/Prefabs/`, or in each instance of the
scene, this can be done in the Platform GameObject within the Game prefab in
`Assets/ML-Agents/Examples/3DBall/Prefabs/`, or in each instance of the
Platform in the Scene.
Next, we want the set up scene to play correctly when the training process

'file_name' of the `UnityEnvironment`. For instance:
```python
from mlagents.envs import UnityEnvironment
from mlagents.envs.environment import UnityEnvironment
env = UnityEnvironment(file_name=<env_name>)
```

1
docs/Migrating.md


* `UnitySDK/Assets/ML-Agents/Scripts/Communicator.cs` and its class `Communicator` have been renamed to `UnitySDK/Assets/ML-Agents/Scripts/ICommunicator.cs` and `ICommunicator` respectively.
* The `SpaceType` Enums `discrete`, and `continuous` have been renamed to `Discrete` and `Continuous`.
* We have removed the `Done` call as well as the capacity to set `Max Steps` on the Academy. Therefore an AcademyReset will never be triggered from C# (only from Python). If you want to reset the simulation after a fixed number of steps, or when an event in the simulation occurs, we recommend looking at our multi-agent example environments (such as BananaCollector). In our examples, groups of Agents can be reset through an "Area" that can reset groups of Agents.
* The import for `mlagents.envs.UnityEnvironment` was removed. If you are using the Python API, change `from mlagents.envs import UnityEnvironment` to `from mlagents.envs.environment import UnityEnvironment`.
## Migrating from ML-Agents toolkit v0.8 to v0.9

20
docs/Python-API.md


The ML-Agents Toolkit provides a Python API for controlling the Agent simulation
loop of an environment or game built with Unity. This API is used by the
training algorithms inside the ML-Agent Toolkit, but you can also write your own
Python programs using this API. Go [here](../notebooks/getting-started.ipynb)
Python programs using this API. Go [here](../notebooks/getting-started.ipynb)
for a Jupyter Notebook walking through the functionality of the API.
The key objects in the Python API include:

of your Unity environment is 3DBall.app, in python, run:
```python
from mlagents.envs import UnityEnvironment
from mlagents.envs.environment import UnityEnvironment
env = UnityEnvironment(file_name="3DBall", worker_id=0, seed=1)
```

`(batch size, number of branches)` if the vector action space is discrete.
Once loaded, you can use your UnityEnvironment object, which referenced by a
variable named `env` in this example, can be used in the following way:
variable named `env` in this example, can be used in the following way:
- **Print : `print(str(env))`**
Prints all parameters relevant to the loaded environment and the
Brains.
- **Reset : `env.reset(train_mode=True, config=None)`**
- **Print : `print(str(env))`**
Prints all parameters relevant to the loaded environment and the
Brains.
- **Reset : `env.reset(train_mode=True, config=None)`**
Brain names to BrainInfo objects.
Brain names to BrainInfo objects.
- `train_mode` indicates whether to run the environment in train (`True`) or
test (`False`) mode.
- `config` is an optional dictionary of configuration flags specific to the

Define the reset parameters on the Academy Inspector window in the Unity
Editor.
- **Step : `env.step(action, memory=None, text_action=None)`**
- **Step : `env.step(action, memory=None, text_action=None)`**
Sends a step signal to the environment using the actions. For each Brain :
- `action` can be one dimensional arrays or two dimensional arrays if you have
multiple Agents per Brain.

action = {'brain1':[1.0, 2.0], 'brain2':[3.0,4.0]}
```
Returns a dictionary mapping Brain names to BrainInfo objects.
Returns a dictionary mapping Brain names to BrainInfo objects.
- **Close : `env.close()`**
Sends a shutdown signal to the environment and closes the communication
socket.

32
docs/Training-on-Amazon-Web-Service.md


We've prepared a pre-configured AMI for you with the ID: `ami-016ff5559334f8619` in the
`us-east-1` region. It was created as a modification of [Deep Learning AMI
(Ubuntu)](https://aws.amazon.com/marketplace/pp/B077GCH38C). The AMI has been
tested with p2.xlarge instance. Furthermore, if you want to train without
headless mode, you need to enable X Server.
(Ubuntu)](https://aws.amazon.com/marketplace/pp/B077GCH38C). The AMI has been
tested with p2.xlarge instance. Furthermore, if you want to train without
headless mode, you need to enable X Server.
After launching your EC2 instance using the ami and ssh into it, run the
After launching your EC2 instance using the ami and ssh into it, run the
following commands to enable it:
```sh

# Remove the Section "Files" from the /etc/X11/xorg.conf file
# And remove two lines that contain Section "Files" and EndSection
$ sudo vim /etc/X11/xorg.conf
$ sudo vim /etc/X11/xorg.conf
```
#### Update and setup Nvidia driver:

# Please refer to http://download.nvidia.com/XFree86/Linux-#x86_64/latest.txt
# Please refer to http://download.nvidia.com/XFree86/Linux-#x86_64/latest.txt
$ wget http://download.nvidia.com/XFree86/Linux-x86_64/390.87/NVIDIA-Linux-x86_64-390.87.run
$ sudo /bin/bash ./NVIDIA-Linux-x86_64-390.67.run --accept-license --no-questions --ui=none

# You will have a list of processes running on the GPU, Xorg should not be in
# the list, as shown below.
$ nvidia-smi
# Thu Jun 14 20:21:11 2018
# +-----------------------------------------------------------------------------+
# | NVIDIA-SMI 390.67 Driver Version: 390.67 |

# |=============================================================================|
# | No running processes found |
# +-----------------------------------------------------------------------------+
```
#### Start X Server and make the ubuntu use X Server for display:

# For more information on glxgears, see ftp://www.x.org/pub/X11R6.8.1/doc/glxgears.1.html.
$ glxgears
# If Xorg is configured correctly, you should see the following message
```
## Training on EC2 instance

2. Open the Build Settings window (menu: File > Build Settings).
3. Select Linux as the Target Platform, and x86_64 as the target architecture
3. Select Linux as the Target Platform, and x86_64 as the target architecture
(the default x86 currently does not work).
4. Check Headless Mode if you have not setup the X Server. (If you do not use
Headless Mode, you have to setup the X Server to enable training.)

9. Test the instance setup from Python using:
```python
from mlagents.envs import UnityEnvironment
from mlagents.envs.environment import UnityEnvironment
env = UnityEnvironment(<your_env>)
```

```console
mlagents-learn <trainer-config-file> --env=<your_env> --train
```
If you've built your Linux executable, but forget to copy over the corresponding <Executable_Name>_Data folder, you will see error message like the following:
If you've built your Linux executable, but forget to copy over the corresponding <Executable_Name>_Data folder, you will see error message like the following:
```sh
Set current directory to /home/ubuntu/ml-agents/ml-agents

The environment and the Python interface have compatible versions.
```
It would be also really helpful to check your /home/ubuntu/.config/unity3d/<Some_Path>/Player.log to see what happens with your Unity environment.
It would be also really helpful to check your /home/ubuntu/.config/unity3d/<Some_Path>/Player.log to see what happens with your Unity environment.
### Could not launch X Server

```sh
NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.
```
This means the NVIDIA's driver needs to be updated. Refer to [this section](Training-on-Amazon-Web-Service.md#update-and-setup-nvidia-driver) for more information.
This means the NVIDIA's driver needs to be updated. Refer to [this section](Training-on-Amazon-Web-Service.md#update-and-setup-nvidia-driver) for more information.

6
docs/Training-on-Microsoft-Azure.md


7. Test the instance setup from Python using:
```python
from mlagents.envs import UnityEnvironment
from mlagents.envs.environment import UnityEnvironment
env = UnityEnvironment(<your_env>)
```

## Monitoring your Training Run with TensorBoard
Once you have started training, you can [use TensorBoard to observe the
training](Using-Tensorboard.md).
training](Using-Tensorboard.md).
1. Start by [opening the appropriate port for web traffic to connect to your VM](https://docs.microsoft.com/en-us/azure/virtual-machines/windows/nsg-quickstart-portal).
1. Start by [opening the appropriate port for web traffic to connect to your VM](https://docs.microsoft.com/en-us/azure/virtual-machines/windows/nsg-quickstart-portal).
* Note that you don't need to generate a new `Network Security Group` but
instead, go to the **Networking** tab under **Settings** for your VM.

2
notebooks/getting-started.ipynb


"import numpy as np\n",
"import sys\n",
"\n",
"from mlagents.envs import UnityEnvironment\n",
"from mlagents.envs.environment import UnityEnvironment\n",
"\n",
"%matplotlib inline\n",
"\n",

正在加载...
取消
保存