liveBook · Manning

TensorBoard

As explained in Deep Learning with PyTorch, Second Edition

A visualization tool for inspecting machine-learning training runs, metrics, and related summaries in a browser.

A training loop can print a metric after each epoch, but a single number does not tell you whether performance is improving or whether the latest value is an outlier. TensorBoard turns logged training metrics into browser-based graphs so you can follow their trends. Although it originated with TensorFlow, it also works with PyTorch. section 13.9

To inspect an existing run:

  • Install TensorBoard with `pip install tensorboard`, then start it with `tensorboard --logdir runs/`. Point `--logdir` at the directory containing your logged data. section 13.9.1
  • Open `http://localhost:6006` in a browser. If training ran on another computer, use that computer’s hostname or IP address instead of `localhost`. section 13.9.1
  • Select the Scalars tab to view metric graphs. Select the runs you want to compare; hiding other runs can make crowded graphs easier to read. section 13.9.1

Smoothing can make a noisy trend easier to see, but too much can hide important changes. The unsmoothed values remain visible as a faded line. TensorBoard also offers Histograms and precision–recall curves; the Distributions tab is not needed for this workflow. section 13.9.1

In PyTorch, `torch.utils.tensorboard.SummaryWriter` writes data for TensorBoard. Create separate writers for training and validation, reuse them across epochs, and give each a `log_dir` under `runs/`. Waiting until there is data to write avoids creating empty runs when an experiment crashes early. section 13.9.2

Log each computed metric

Once a writer exists, a metrics-logging loop can call `writer.add_scalar(key, value, self.totalTrainingSamples_count)` for each entry in `metrics_dict`. The metric name becomes its tag, while the training-sample count supplies the step. Early training values may be noisy; keep that in mind when reading the graph. section 13.9.2

Graphs are most useful when the metric measures what matters. A classifier trained on mostly negative samples can appear accurate while classifying every sample as negative. Graphing quality metrics such as precision and recall helps reveal performance that overall accuracy obscures. TensorBoard can also display generated 2D images over a training run to track changes in model output. section 14.0 section 15.11

How Deep Learning with PyTorch, Second Edition covers it

How deep it goes
Walks through installation, dashboard controls, and PyTorch scalar logging, but does not discuss the Distributions tab.
Examples
Uses a `runs/` launch command, paired training and validation writers, a scalar-logging loop, and a misleadingly accurate classifier.
What it assumes
Assumes a training script that produces metrics, while providing the commands to install and launch TensorBoard.
What you can do after
Operate/configure it to compare training runs and log PyTorch metrics for browser-based inspection.
How it connects
Connects PyTorch SummaryWriter and training runs to scalar metrics, validation metrics, precision–recall curves, and class imbalance.

Also explained in

Compare how 2 books explain TensorBoard →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with PyTorch, Second Edition. The section links point to the parts of the book it draws on.