Problem in using SubprocVecEnv for training custom gym envs
I am trying to run this peice of code
import gym;
from baselines import logger
from baselines.acktr.acktr_disc import learn
from baselines.common.vec_env.vec_frame_stack import VecFrameStack
from baselines.ppo2.policies import CnnPolicy
from baselines.bench import Monitor
from baselines.common import set_global_seeds
from baselines.common.vec_env.subproc_vec_env import SubprocVecEnv
import os
import numpy as np
from baselines.common.cmd_util import make_atari_env, atari_arg_parser
def make_custom_env(env_id, num_env, seed, wrapper_kwargs=None, start_index=0):
"""
Create a wrapped, monitored SubprocVecEnv for Atari.
"""
if wrapper_kwargs is None: wrapper_kwargs = {}
def make_env(rank): # pylint: disable=C0111
def _thunk():
env = gym.make(env_id)
env.seed(seed + rank)
env = Monitor(env, logger.get_dir() and os.path.join(logger.get_dir(), str(rank)))
return env
return _thunk
set_global_seeds(seed)
return SubprocVecEnv([make_env(i + start_index) for i in range(num_env)])
def train(num_timesteps, seed, num_cpu):
env = VecFrameStack(make_custom_env('Breakout-v0',1,3), 1)
policy_fn = CnnPolicy
learn(policy_fn, env, seed, total_timesteps=int(num_timesteps * 1.1), nprocs=num_cpu)
env.close()
if __name__ == "__main__":
logger.configure()
train(num_timesteps=100, seed=10, num_cpu=1)
ON running this I get this error. raise ValueError("Cannot take the length of Shape with unknown rank.")
ValueError: Cannot take the length of Shape with unknown rank. I tried the same across multiple OS platform, tried on several other games, but stuck with the same error. Can someone help me understand if I am doing something wrong with SubprocVecEnv
I have a similar issue when trying to run the example code for acktr
python -m baselines.acktr.run_atari
`(gym10-py35) teves@teves:~/gym$ python -m baselines.acktr.run_atari Logging to /tmp/openai-2018-03-06-11-16-08-184079 2018-03-06 11:16:10.514767: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA WARNING:tensorflow:From /home/teves/baselines/baselines/common/distributions.py:134: softmax_cross_entropy_with_logits (from tensorflow.python.ops.nn_ops) is deprecated and will be removed in a future version. Instructions for updating:
Future major versions of TensorFlow will allow gradients to flow into the labels input on backprop by default.
See tf.nn.softmax_cross_entropy_with_logits_v2.
WARNING:tensorflow:From /home/teves/baselines/baselines/a2c/utils.py:13: calling reduce_max (from tensorflow.python.ops.math_ops) with keep_dims is deprecated and will be removed in a future version.
Instructions for updating:
keep_dims is deprecated, use keepdims instead
WARNING:tensorflow:From /home/teves/baselines/baselines/a2c/utils.py:15: calling reduce_sum (from tensorflow.python.ops.math_ops) with keep_dims is deprecated and will be removed in a future version.
Instructions for updating:
keep_dims is deprecated, use keepdims instead
Traceback (most recent call last):
File "/home/teves/anaconda3/envs/gym10-py35/lib/python3.5/runpy.py", line 184, in _run_module_as_main
"main", mod_spec)
File "/home/teves/anaconda3/envs/gym10-py35/lib/python3.5/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/teves/baselines/baselines/acktr/run_atari.py", line 21, in
I am also presuming version mismatch issue. Need to debug further.
The same error.
The same error when running ‘run_atari.py’.
For acktr I am seeing the above 'rank' error for run_atari.py as mentioned by @zimoqingfeng
In the case of the a2c code, I was able to get a custom environment working with baselines using the run_atari and relating helper code as an example.