brax icon indicating copy to clipboard operation
brax copied to clipboard

Rendering after every few epochs at train time

Open aggritvik opened this issue 2 years ago • 3 comments
trafficstars

Hi! Thanks for opensourcing this amazing piece of software! Currently, I'm trying to learn RL for Robotics and I want to be able to see the physical rendering of an episode after every few epochs at training time to visualise the gradual progression of the agent, from doing nothing to performing the task well. Feel free to skip my efforts below if there is a straightforward way to do this.

Brax version - 0.9.1

I've followed the example colab notebooks in the Readme section:

def HTML(html_obj):
    with open('render.htm', 'wb') as f:
        f.write(html_obj.encode("UTF-8"))
        webbrowser.open(r'render.htm', new=0)
HTML(html.render(env.sys.replace(dt=env.dt), rollout))

I get the error

AttributeError: 'GymWrapper' object has no attribute 'sys'

I'd really appreciate any guidance I can get on how to proceed.

aggritvik avatar Jun 04 '23 18:06 aggritvik

Hi @aggritvik, thanks for using brax! For the error you mentioned, GymWrapper has an attribute _env.sys

For rendering intermediate policies, you may want to use brax.io.image to create the rendered frames, and then render them using the progress_fn. Let us know if that works!

btaba avatar Jun 09 '23 20:06 btaba

Thanks @btaba! I'll work on your inputs. Is there a brax tutorial, which can be followed by a beginner?

aggritvik avatar Jun 10 '23 14:06 aggritvik

Hi @aggritvik, sorry for the late reply. There isn't an example of doing intermediate rendering right now, but the colab you mentioned in the original post has a call to def progress(num_steps, metrics):. To render intermediate episodes, it should likely be done during eval, somewhere around here https://github.com/google/brax/blob/main/brax/training/agents/ppo/train.py#L338-L344

btaba avatar Aug 17 '23 03:08 btaba