Skip to content

Commit 7202ece

Browse files
araffinqgallouedec
andauthored
Update tensorboard callback doc (#1221)
Co-authored-by: Quentin Gallouédec <[email protected]>
1 parent 96b1a7c commit 7202ece

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

docs/guide/tensorboard.rst

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Here is a simple example on how to log both additional tensor or arbitrary scala
8686
"""
8787
8888
def __init__(self, verbose=0):
89-
super(TensorboardCallback, self).__init__(verbose)
89+
super().__init__(verbose)
9090
9191
def _on_step(self) -> bool:
9292
# Log scalar value (here a random variable)
@@ -125,7 +125,7 @@ Here is an example of how to render an image to TensorBoard at regular intervals
125125
126126
class ImageRecorderCallback(BaseCallback):
127127
def __init__(self, verbose=0):
128-
super(ImageRecorderCallback, self).__init__(verbose)
128+
super().__init__(verbose)
129129
130130
def _on_step(self):
131131
image = self.training_env.render(mode="rgb_array")
@@ -162,7 +162,7 @@ Here is an example of how to store a plot in TensorBoard at regular intervals:
162162
163163
class FigureRecorderCallback(BaseCallback):
164164
def __init__(self, verbose=0):
165-
super(FigureRecorderCallback, self).__init__(verbose)
165+
super().__init__(verbose)
166166
167167
def _on_step(self):
168168
# Plot values (here a random variable)
@@ -308,6 +308,13 @@ can get direct access to the underlying SummaryWriter in a callback:
308308
.. warning::
309309
This is method is not recommended and should only be used by advanced users.
310310

311+
.. note::
312+
313+
If you want a concrete example, you can watch `how to log lap time with donkeycar env <https://www.youtube.com/watch?v=v8j2bpcE4Rg&t=4619s>`_,
314+
or read the code in the `RL Zoo <https://github.com/DLR-RM/rl-baselines3-zoo/blob/feat/gym-donkeycar/rl_zoo3/callbacks.py#L251-L270>`_.
315+
You might also want to take a look at `issue #1160 <https://github.com/DLR-RM/stable-baselines3/issues/1160>`_ and `issue #1219 <https://github.com/DLR-RM/stable-baselines3/issues/1219>`_.
316+
317+
311318
.. code-block:: python
312319
313320
from stable_baselines3 import SAC
@@ -331,6 +338,11 @@ can get direct access to the underlying SummaryWriter in a callback:
331338
332339
def _on_step(self) -> bool:
333340
if self.n_calls % self._log_freq == 0:
341+
# You can have access to info from the env using self.locals.
342+
# for instance, when using one env (index 0 of locals["infos"]):
343+
# lap_count = self.locals["infos"][0]["lap_count"]
344+
# self.tb_formatter.writer.add_scalar("train/lap_count", lap_count, self.num_timesteps)
345+
334346
self.tb_formatter.writer.add_text("direct_access", "this is a value", self.num_timesteps)
335347
self.tb_formatter.writer.flush()
336348

docs/misc/changelog.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,11 @@ Documentation:
6666
- Updated Hugging Face Integration page (@simoninithomas)
6767
- Changed ``env`` to ``vec_env`` when environment is vectorized
6868
- Updated custom policy docs to better explain the ``mlp_extractor``'s dimensions (@AlexPasqua)
69-
- Update custom policy documentation (@athatheo)
69+
- Updated custom policy documentation (@athatheo)
70+
- Improved tensorboard callback doc
7071
- Clarify doc when using image-like input
7172

73+
7274
Release 1.6.2 (2022-10-10)
7375
--------------------------
7476

0 commit comments

Comments
 (0)