mirror of
https://github.com/Farama-Foundation/Gymnasium.git
synced 2025-08-30 09:55:39 +00:00
Add RecordVideo
docs (#2332)
* add `RecordVideo` docs * add deprecation notice
This commit is contained in:
@@ -69,8 +69,39 @@ Gym includes numerous wrappers for environments that include preprocessing and v
|
|||||||
`RecordEpisodeStatistic(env)` [text]
|
`RecordEpisodeStatistic(env)` [text]
|
||||||
* Needs review (including for good assertion messages and test coverage)
|
* Needs review (including for good assertion messages and test coverage)
|
||||||
|
|
||||||
`RecordVideo(env, ...)` [text]
|
`RecordVideo(env, video_folder, record_video_trigger, video_length=0, name_prefix="rl-video")` [text]
|
||||||
* https://github.com/openai/gym/pull/2300
|
|
||||||
|
The `RecordVideo` is a lightweight `gym.Wrapper` that helps recording videos. See the following
|
||||||
|
code as an example.
|
||||||
|
|
||||||
|
```python
|
||||||
|
import gym
|
||||||
|
env = gym.make("CartPole-v1")
|
||||||
|
env = gym.wrappers.RecordVideo(env, "videos", record_video_trigger=lambda x: x % 100 == 0)
|
||||||
|
observation = env.reset()
|
||||||
|
for _ in range(1000):
|
||||||
|
env.render()
|
||||||
|
action = env.action_space.sample() # your agent here (this takes random actions)
|
||||||
|
observation, reward, done, info = env.step(action)
|
||||||
|
|
||||||
|
if done:
|
||||||
|
observation = env.reset()
|
||||||
|
env.close()
|
||||||
|
```
|
||||||
|
|
||||||
|
To use it, you need to specify the `video_folder` as the storing location and
|
||||||
|
`record_video_trigger` as a frequency at which you want to record.
|
||||||
|
|
||||||
|
There are two modes of video the recording:
|
||||||
|
1. Episodic mode.
|
||||||
|
* By default `video_length=0` means the wrapper will record *episodic* videos: it will keep
|
||||||
|
record the frames until the env returns `done=True`.
|
||||||
|
2. Fixed-interval mode.
|
||||||
|
* By tuning `video_length` such as `video_length=100`, the wrapper will record exactly 100 frames
|
||||||
|
for every videos the wrapper creates.
|
||||||
|
|
||||||
|
Lastly the `name_prefix` allows you to customize the name of the videos.
|
||||||
|
|
||||||
|
|
||||||
`TimeLimit(env, max_episode_steps)` [text]
|
`TimeLimit(env, max_episode_steps)` [text]
|
||||||
* Needs review (including for good assertion messages and test coverage)
|
* Needs review (including for good assertion messages and test coverage)
|
||||||
|
@@ -4,6 +4,7 @@ import os
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
import gym
|
import gym
|
||||||
|
import warnings
|
||||||
from gym import Wrapper
|
from gym import Wrapper
|
||||||
from gym import error, version, logger
|
from gym import error, version, logger
|
||||||
from gym.wrappers.monitoring import stats_recorder, video_recorder
|
from gym.wrappers.monitoring import stats_recorder, video_recorder
|
||||||
@@ -27,6 +28,9 @@ class Monitor(Wrapper):
|
|||||||
mode=None,
|
mode=None,
|
||||||
):
|
):
|
||||||
super(Monitor, self).__init__(env)
|
super(Monitor, self).__init__(env)
|
||||||
|
warnings.warn(
|
||||||
|
"The Monitor wrapper is being deprecated in favor of gym.wrappers.RecordVideo and gym.wrappers.RecordEpisodeStatistics (see https://github.com/openai/gym/issues/2297)"
|
||||||
|
)
|
||||||
|
|
||||||
self.videos = []
|
self.videos = []
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user