Fix RuntimeError (#910) (#1015)

* Update the commands to install Tensorflow

The current 'tensorflow' package is for Tensorflow 2, which is not supported by the master branch of baselines.

* Update command to install Tensorflow 1.14

* Fix RuntimeError (#910)

 - Removed interfering calls to env.reset() in play mode.
   (Note that the worker in the subprocess is calling env.reset() already)

 - Fixed the printed reward when running multiple envs in play mode.
This commit is contained in:
johannespitz
2019-10-26 00:24:41 +02:00
committed by pzhokhov
parent adba88b218
commit c6144bdb6a
2 changed files with 11 additions and 11 deletions

View File

@@ -48,15 +48,15 @@ The master branch supports Tensorflow from version 1.4 to 1.14. For Tensorflow 2
git clone https://github.com/openai/baselines.git git clone https://github.com/openai/baselines.git
cd baselines cd baselines
``` ```
- If you don't have TensorFlow installed already, install your favourite flavor of TensorFlow. In most cases, - If you don't have TensorFlow installed already, install your favourite flavor of TensorFlow. In most cases, you may use
```bash ```bash
pip install tensorflow-gpu # if you have a CUDA-compatible gpu and proper drivers pip install tensorflow-gpu==1.14 # if you have a CUDA-compatible gpu and proper drivers
``` ```
or or
```bash ```bash
pip install tensorflow pip install tensorflow==1.14
``` ```
should be sufficient. Refer to [TensorFlow installation guide](https://www.tensorflow.org/install/) to install Tensorflow 1.14, which is the latest version of Tensorflow supported by the master branch. Refer to [TensorFlow installation guide](https://www.tensorflow.org/install/)
for more details. for more details.
- Install baselines package - Install baselines package

View File

@@ -226,7 +226,7 @@ def main(args):
state = model.initial_state if hasattr(model, 'initial_state') else None state = model.initial_state if hasattr(model, 'initial_state') else None
dones = np.zeros((1,)) dones = np.zeros((1,))
episode_rew = 0 episode_rew = np.zeros(env.num_envs) if isinstance(env, VecEnv) else np.zeros(1)
while True: while True:
if state is not None: if state is not None:
actions, _, state, _ = model.step(obs,S=state, M=dones) actions, _, state, _ = model.step(obs,S=state, M=dones)
@@ -234,13 +234,13 @@ def main(args):
actions, _, _, _ = model.step(obs) actions, _, _, _ = model.step(obs)
obs, rew, done, _ = env.step(actions) obs, rew, done, _ = env.step(actions)
episode_rew += rew[0] if isinstance(env, VecEnv) else rew episode_rew += rew
env.render() env.render()
done = done.any() if isinstance(done, np.ndarray) else done done_any = done.any() if isinstance(done, np.ndarray) else done
if done: if done_any:
print('episode_rew={}'.format(episode_rew)) for i in np.nonzero(done)[0]:
episode_rew = 0 print('episode_rew={}'.format(episode_rew[i]))
obs = env.reset() episode_rew[i] = 0
env.close() env.close()