-
Notifications
You must be signed in to change notification settings - Fork 8.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add save_video util and deprecate RecordVideo in favor of it #3016
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks good, I added two comments for minor code changes
Thanks @younik for preparing the PR. What is the motivation for this change and why is using the Deprecating |
Args: | ||
frames (List[RenderFrame]): A list of frames to compose the video. | ||
video_folder (str): The folder where the recordings will be stored | ||
episode_trigger: Function that accepts an integer and returns ``True`` iff a recording should be started at this episode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am very confused - why would episode_trigger
still be here? It seems strange when users execute save_video
the videos might not be saved…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the beginning, the expected type of frames was a List of episodes, where an episode is a List of frames.
Talking with @pseudo-rnd-thoughts, we agree it is simpler as it is now, with frames as a List of frames of the same episode.
For how it is right now, yes, we can drop episode_trigger
and the user can just do it with an if statement.
Notice that it still can happen that save_video
doesn't save anything depending on step_trigger
... _, _, done, _ = env.step(action) | ||
... if done: | ||
... save_video( | ||
... env.render(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like here only calls env.render()
when the env is done. Does this mean when calling env = gym.make("FrozenLake-v1", render_mode="rgb_array")
each frame is rendered and cached? If this is the case this could be an undesirable bottleneck — we might only keep the rendered frames of a few episodes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, with the current Render API env.render()
returns the list of frames of the whole episode when the mode is rgb_array
; old-like behavior can be obtained with single_rgb_array
.
When you call render()
or reset()
, the frame list is cleaned
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I am struggling to understand this. If I don’t want to render every frame, how can I achieve it with the current API? What is the old-like behavior with single_rgb_array
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to render a single frame representing the current state, you can achieve it with single_rgb_array
, thus similar to before:
env = gym.make("MyEnv", render_mode="single_rgb_array")
env.reset()
for _ in range(n_steps):
env.step(...)
env.render() # single frame
env.close()
Otherwise, with rgb_array
:
env = gym.make("MyEnv", render_mode="rgb_array")
env.reset()
for _ in range(n_steps):
_, _, done, _ = env.step(...)
if done:
break
env.render() # List of all frames
env.close()
Hello, yes, this adds more boilerplate to user code, on the other side, |
Could we do both? I think having the |
Sure, I updated |
Personally, I think we should have both. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This PR adds a deprecation warning to RecordVideo, in favor of a cleaner util function https://github.com/younik/gym/blob/record-video/gym/utils/save_video.py
See also #2905
Sample usage: