-
Notifications
You must be signed in to change notification settings - Fork 334
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
[Feature] A PixelRenderTransform #2099
Changes from 6 commits
8e09bfa
7cdf26f
8c5db0b
ff45e53
614d4de
675f5c9
f068784
199085a
7a7e1db
70315fb
e7986ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -759,6 +759,46 @@ to always know what the latest available actions are. You can do this like so: | |
Recorders | ||
--------- | ||
|
||
Recording data during environment rollout execution is crucial to keep an eye on the algorithm performance as well as | ||
reporting results after training. | ||
|
||
TorchRL offers several tools to interact with the environment output: first and foremost, a ``callback`` callable | ||
can be passed to the :meth:`~torchrl.envs.EnvBase.rollout` method. This function will be called upon the collected | ||
tensordict at each iteration of the rollout (if some iterations have to be skipped, an internal variable should be added | ||
to keep track of the call count within ``callback``). | ||
|
||
To save collected tensordicts on disk, the :class:`~torchrl.record.TensorDictRecorder` can be used. | ||
|
||
Recording videos | ||
~~~~~~~~~~~~~~~~ | ||
|
||
Several backends offer the possibility of recording rendered images from the environment. | ||
If the pixels are already part of the environment output (e.g. Atari or other game simulators), a | ||
:class:`~torchrl.record.VideoRecorder` can be appended to the environment. This environment transform takes as input | ||
a logger capable of recording videos (e.g. :class:`~torchrl.record.loggers.CSVLogger`, :class:`~torchrl.record.loggers.WandbLogger` | ||
or :class:`~torchrl.record.loggers.TensorBoardLogger`) as well as a tag indicating where the video should be saved. | ||
For instance, to save mp4 videos on disk, one can use :class:`~torchrl.record.loggers.CSVLogger` with a `video_format="mp4"` | ||
argument. | ||
|
||
The :class:`~torchrl.record.VideoRecorder` transform can handle batched images and automatically detects numpy or PyTorch | ||
formatted images (WHC or CWH). | ||
|
||
>>> logger = CSVLogger("dummy-exp", video_format="mp4") | ||
>>> env = GymEnv("ALE/Pong-v5") | ||
>>> env = env.append_transform(VideoRecorder(logger, tag="rendered", in_keys=["pixels"])) | ||
>>> env.rollout(10) | ||
>>> env.transform.dump() # Save the video and clear cache | ||
|
||
Note that the cache of the transform will keep on growing until dump is called. It is the user responsibility to | ||
take care of calling dumpy when needed to avoid OOM issues. | ||
|
||
In some cases, creating a testing environment where images can be collected is tedious or expensive, or simply impossible | ||
(some libraries only allow one environment instance per workspace). | ||
In these cases, assuming that a `render` method is available in the environment, the :class:`~torchrl.record.PixelRenderTransform` | ||
can be used to call `render` on the parent environment and save the images in the rollout data stream. | ||
This class should only be used within the same process as the environment that is being rendered (remote calls to `render` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This part is bit unclear. Is it saying that, for example, using ParallelEnv with |
||
are not allowed). | ||
|
||
.. currentmodule:: torchrl.record | ||
|
||
Recorders are transforms that register data as they come in, for logging purposes. | ||
|
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.
BIt of a sidenote, but at least in current public doc version the signature of the callback is not very clear. Maybe clarify here (or ideally in
rollout
's doc) that the callback is called withcallback(self, tensordict)
?