SummaryWriter
Explore how to use PyTorch's SummaryWriter to create meaningful logs for TensorBoard. Learn to set up organized log directories, add model graphs, and track training and validation losses over epochs. Understand best practices for managing multiple runs to avoid corrupted visualizations and enhance model training insights.
We'll cover the following...
Overview of SummaryWriter
It all starts with the creation of a SummaryWriter:
If we try printing this, we get the following output:
Since we told TensorBoard to look for logs inside the runs folder, it only makes sense to actually log to that folder. Moreover, to be able to distinguish between different experiments or models, we should also specify a sub-folder: test.
If we do not specify any folder, TensorBoard will default to
runs/CURRENT_DATETIME_HOSTNAME, which is not such a great name if you are looking for your experiment results in the future.
So, it is recommended to try to name it in a more meaningful way likeruns/testorruns/simple_linear_regression. It will then create a subfolder insideruns(the folder we specified when we started TensorBoard).
Even better, you should name it in a meaningful way, and add DateTime or a sequential number as a suffix likeruns/test_001orruns/test_20200502172130to avoid writing data of multiple runs into the same folder (we will see why this is bad in the add_scalars section below).
SummaryWriter methods
The SummaryWriter class implements several methods to allow us to send information to TensorBoard: