lcswillems / rl-starter-files

RL starter files in order to immediately train, visualize and evaluate an agent without writing any line of code
MIT License
651 stars 184 forks source link

Problem with 'agent.py' for gym.spaces.Box based gym environments #38

Closed GusHebblewhite closed 4 years ago

GusHebblewhite commented 4 years ago

Hi there :)

When I run the evaluate script with some gym environments (e.g. procgen coinrun) I get the following error:

AttributeError: 'function' object has no attribute 'vocab'

This appears to be because when the Agent class (in agent.py) is initialized the vocab attribute only gets created by get_obss_preprocessor (in format.py) for environments that have dictionaries as their observation space.

This bug can be temporarily fixed by putting the line that throws the error in an if statement: [agent.py]

if isinstance(obs_space, gym.spaces.Dict) and list(obs_space.spaces.keys()) == ["image"]:
    self.preprocess_obss.vocab.load_vocab(utils.get_vocab(model_dir))

I'm not confident I understand the code well enough to submit a PR, but the above might solve it.

Thanks! Gus

lcswillems commented 4 years ago

Hi Gus,

Thanks for reporting this issue!

I have pushed a fix to this repo. Could you pull it and say me if it fixes your issue?

GusHebblewhite commented 4 years ago

Hi Lucas

Sorry for taking so long to get back to you. This does indeed fix this issue, so I think we can close it.

There still seems to be some kind of problem with using vectorised envs with the environment I'm using (procgen coinrun) - the code seems to stall unless args.procs is set to '1'. I'll have a dig and open a separate issue if it makes sense to.

Best, Gus