Monitor Your Experiments with TensorBoard¶
TensorBoard is a powerful tool that allows you to monitor and visualize an experiment. This section introduces how to set up TensorBoard logging in garage, and how to view/share your TensorBoard logs.
Prerequisite¶
The TensorBoard package should be installed upon garage’s installation. It can be also manually installed via:
pip install tensorboard
Log to TensorBoard¶
This section introduces how to log TensorBoard output with logger
, and how to
log different types of TensorBoard output.
Find more about how to use logger
here.
Log Scalar Values to TensorBoard¶
You would need dowel.TabularInput
.
To prepare your TensorBoard output, import dowel’s TabularInput
instance
tabular
by:
from dowel import tabular
Add scalar values:
tabular.record('Epoch', epoch)
tabular.record('# Sample', i_sample)
tabular.record('AverageDiscountedReturn', return)
Finally, log your scalar values with logger
:
logger.log(tabular)
Log Histograms to TensorBoard¶
To log histograms to TensorBoard, you would need to pass
dowel.Histogram
to tabular
.
dowel.Histogram
is implemented as a typed view of a numpy array.
It will accept input that numpy.asarray
will.
For example:
from dowel import Histogram, logger, tabular
samples = norm.rvs(100) # ndarray of 100 samples of a normal distribution
hist = Histogram(samples)
tabular.record('Sample', hist)
logger.log(tabular)
You can use Histogram()
to log distribution types from
scipy.stats
.
View Your TensorBoard Logs¶
You can view your TensorBoard results via the TensorBoard command line tool:
$ tensorboard --logdir logs
Once you run the command, you will see
$ tensorboard --logdir logs
Serving TensorBoard on localhost; to expose to the network, use a proxy or pass --bind_all
TensorBoard 2.2.2 at http://localhost:6006/ (Press CTRL+C to quit)
Open your browser and navigate to the link to see a dashboard of your TensorBoard results.
Note that if your --logdir
directory contains multiple TensorBoard logs,
the dashboard will show all of them. This is useful when comparing results from
multiple runs.
You can find more TensorBoard dashboard details here.
Advanced Features¶
Change the output directory or x-axis¶
By default, @wrap_experiment
sets up TensorBoard output via:
logger.add_output(dowel.TensorBoardOutput(log_dir, x_axis='TotalEnvSteps'))
The default log_dir
is $(pwd)/data/local
, and the x_axis
is
'TotalEnvSteps'
.
To manually output to a different directory, you can
set up logger
in your experiment by:
logger.add_output(dowel.TensorBoardOutput(MyLogDir))
Add additional x-axes¶
If you’d like to view your logs on more than one x-axis, you can configure dowel
to log to additional x-axes by passing a list of tabular keys to the
additional_x_axes
parameter of TensorBoardOutput
.
logger.add_output(dowel.TensorBoardOutput(
log_dir,
x_axis='TotalEnvSteps',
additional_x_axes=['Itr'], # Logs keys by optimization iteration as well
))
Using this configuration, the key Loss
will appear in TensorBoard under both
the tag Loss
using TotalEnvSteps
as its x-axis, and under the tag Loss/Itr
using Itr
as its x-axis.
This page was authored by Eric Yihan Chen (@AiRuiChen).