Video#

class genesis_forge.wrappers.VideoWrapper(env: GenesisEnv, camera_attr: str = 'camera', video_length_sec: int = 8, episode_trigger: Callable[[int], bool] | None = None, step_trigger: Callable[[int], bool] | None = None, out_dir: str = './videos', fps: int = 60, env_idx: int = 0, filename: str = None, record_final_episode: bool = True, logging: bool = True)[source]#

Bases: Wrapper

Automatically record videos during training at a regular step or episode intervals.

Based on the RecordVideo wrapper from Gymnasium: https://gymnasium.farama.org/main/api/wrappers/misc_wrappers/#gymnasium.wrappers.RecordVideo

Recordings will be made from a dedicated camera, which you need to add to your environment (see the example below).

To control how frequently recordings are made specify either episode_trigger or step_trigger (not both). They should be functions returning a boolean that indicates whether a recording should be started at the current episode or step, respectively. If neither episode_trigger nor step_trigger is passed, a default episode_trigger will be used, which records at the episode indices 0, 1, 8, 27, …, \(k^3\), …, 729, 1000, 2000, 3000,.

Parameters:
  • env – GenesisEnv

  • camera_attr – The attribute of the base environment that contains the camera to use for recording.

  • episode_trigger – Function that accepts an episode count integer and returns True if a recording should be started at this episode

  • step_trigger – Function that accepts a step count integer and returns True if a recording should be started at this step

  • video_length_sec – Length of each video, in seconds.

  • out_dir – Directory to save the videos to.

  • fps – Frames per second for the video.

  • env_idx – If triggering on episode, this is the index of the environment to be counting episodes for.

  • filename – The filename for the video. If None, the video will automatically be named for the current step. If defined, each video will overwrite the previous video with this name.

Example:

class MyEnv(GenesisEnv):
    __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        # Construct the scene
        self.scene = gs.Scene()

        # Assign a camera to the `camera` env attribute
        self.camera = scene.add_camera(pos=(-2.5, -1.5, 1.0))


def train():
    env = MyEnv()
    env = VideoWrapper(
        env,
        camera_attr="camera",
        out_dir="./videos"
    )
    env.build()
    ...training code...

Record every 1500 steps:

env = MyEnv()
env = VideoWrapper(
    env,
    camera_attr="camera",
    out_dir="./videos",
    step_trigger=lambda step: step % 1500 == 0
)

Initialize the logging wrapper with the function to use for data logging.

build() None[source]#

Load the camera from the environment.

close()[source]#

Finish recording on close

finish_recording()[source]#

Stop recording and save the video, if the recording type is ‘active’.

get_observations() torch.Tensor#

Uses the get_observations() of the env that can be overwritten to change the returned data.

reset(env_ids: Sequence[int] = None) tuple[torch.Tensor, dict[str, Any]]#

Uses the reset() of the env that can be overwritten to change the returned data.

start_recording(type: Literal['active', 'background'] = 'active')[source]#

Start recording a video.

step(actions: torch.Tensor) Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, dict[str, Any]][source]#

Record a video image at each step.

property action_space: gymnasium.spaces#

The action space of the environment.

can_be_wrapped: bool = True#
property dt: float#

The time step of the environment.

env: GenesisEnv = None#
property extras: dict#

The extras/infos dictionary that should be returned by the step and reset functions. This dictionary will be cleared at the start of every step.

property num_actions: int#

The number of actions for each environment.

property num_envs: int#

The number of parallel environments.

property num_observations: int#

The number of observations for each environment.

property observation_space: gymnasium.spaces#

The observation space of the environment.

property robot: Any#

Get the environment robot.

property scene: genesis.Scene#

Get the environment scene.

property unwrapped: GenesisEnv#

Returns the base environment of the wrapper.

This will be the bare GenesisEnv environment, underneath all layers of wrappers.

property video_length_steps: int#

The number of steps that will be recorded for each video.