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:
WrapperAutomatically 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_triggerorstep_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 neitherepisode_triggernorstep_triggeris passed, a defaultepisode_triggerwill 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
Trueif a recording should be started at this episodestep_trigger – Function that accepts a step count integer and returns
Trueif a recording should be started at this stepvideo_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.
- get_observations() torch.Tensor#
Uses the
get_observations()of theenvthat can be overwritten to change the returned data.
- reset(env_ids: Sequence[int] = None) tuple[torch.Tensor, dict[str, Any]]#
Uses the
reset()of theenvthat can be overwritten to change the returned data.
- 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.
- 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 observation_space: gymnasium.spaces#
The observation space of the environment.
- property scene: genesis.Scene#
Get the environment scene.
- property unwrapped: GenesisEnv#
Returns the base environment of the wrapper.
This will be the bare
GenesisEnvenvironment, underneath all layers of wrappers.