CleanDiffuserTeam / CleanDiffuser

CleanDiffuser: An Easy-to-use Modularized Library for Diffusion Models in Decision Making
Apache License 2.0
184 stars 16 forks source link

How to save a video of the trained agent in tutorials #12

Closed RongXueZoe closed 1 week ago

RongXueZoe commented 1 week ago

Hi,

I've trained several agents following the tutorials and now I want to render videos like dp_pusht.py does. Since the env used in tutorial 1 is kitchen-complete-v0, I modified dbc_kitchen.py as follows:

  1. change the env_name from kitchen-all-v0 to kitchen-complete-v0 and import d4rl in advance.
  2. modify the config file according to the settings in 1_a_minimal_DBC_implementation.py.
  3. delete the use_abs_action arg in gym.make(args.env_name, use_abs_action=args.abs_action).

However, it seems that when initializing the env, simply changing the env_name is not enough. The error goes:

File "/home/xxxxx/CleanDiffuser/pipelines/dbc_kitchen_own.py", line 29, in thunk
    env = KitchenLowdimWrapper(env=env, init_qpos=None, init_qvel=None, render_hw=(240, 360))
File "/home/xxxxx/CleanDiffuser/cleandiffuser/env/kitchen/kitchen_lowdim_wrapper.py", line 15, in __init__
    self.all_tasks = env.ALL_TASKS
File "/home/xxxxx/mambaforge/envs/cleandiffuser/lib/python3.9/site-packages/gym/core.py", line 238, in __getattr__
    return getattr(self.env, name)
AttributeError: 'KitchenMicrowaveKettleLightSliderV0' object has no attribute 'ALL_TASKS'

I'll appreciate it if you could tell me how to render a video like the push T task does, using my own trained model.

ZibinDong commented 1 week ago

Hi,

thank you for being so detailed. The environment used in 1_a_minimal_DBC_implementation.py is d4rl Kitchen, which differs from the RelayKitchen used in dbc_kitchen.py. Therefore, we cannot mix their rendering methods. We will implement a unified logger for saving and rendering as soon as possible. In the meantime, we recommend using an alternative approach: you can obtain an RGB image by using env.sim.render() for d4rl Kitchen environment. You can then use libraries like imageio to compose a video from the saved images of an episode.

Thank you once again for your inquiry. We will work on addressing this issue.

pickxiguapi commented 1 week ago

This involves these things:

  1. I have to say this is a bit of a confusing issue in our code. We followed the common practice of papers to use the kitchen dataset from D4RL for the RL algorithm and the Relay-kitchen dataset for the IL algorithm, and even though both datasets have the same underlying physics engine, they still have parts of the API that are not exactly the same, such as rendering.
  2. As a result, IL and RL environments cannot use the same set of APIs, and we are doing our best to build a common set of loggers that include more common VideoRecorder.
  3. We will be announcing the CleanDiffuser roadmap for the month in the next two days including the important update of logger and render.
pickxiguapi commented 1 week ago

Hi,

thank you for being so detailed. The environment used in 1_a_minimal_DBC_implementation.py is d4rl Kitchen, which differs from the RelayKitchen used in dbc_kitchen.py. Therefore, we cannot mix their rendering methods. We will implement a unified logger for saving and rendering as soon as possible. In the meantime, we recommend using an alternative approach: you can obtain an RGB image by using env.sim.render() for d4rl Kitchen environment. You can then use libraries like imageio to compose a video from the saved images of an episode.

Thank you once again for your inquiry. We will work on addressing this issue.

We recommend using direct calls to the original environment API as an alternate solution, and we will continue to optimize the CleanDiffuser.

ZibinDong commented 1 week ago

I have added some code for visualization in tutorial 1. You can pull the latest version to try it out. I will close this issue for now. If you have any further questions, please feel free to reopen it.

RongXueZoe commented 1 week ago

Thank you for your detailed reply! The latest version works fine. Thanks again for your great work:)