VisualDL
VisualDL is a deep learning visualization tool from PaddlePaddle that helps design and debug deep learning jobs. It offers features for visualizing scalars, parameter distributions, model structures, images, audio, text, high-dimensional data, and more. It is actively developed, with new features continuously added.
Common errors
-
TypeError: __init__() got an unexpected keyword argument 'file'
cause The installed `protobuf` library version is outdated (older than 3.5), leading to an API incompatibility with VisualDL.fix`pip install --upgrade protobuf` -
ModuleNotFoundError: No module named 'visualdl' OR Abort trap: 6 (when running visualdl command)
cause This typically indicates a mismatch between the Python interpreter used to run the `visualdl` command/module and the Python environment where VisualDL was originally installed. This often happens outside of an activated virtual environment.fixEnsure your virtual environment (e.g., conda or venv) where VisualDL was installed is activated. Alternatively, use `python -m visualdl.server --logdir ...` to explicitly invoke VisualDL with the correct Python interpreter. If the issue persists, consider reinstalling VisualDL within a fresh virtual environment.
Warnings
- gotcha Running VisualDL might result in `TypeError: __init__() got an unexpected keyword argument 'file'` if your `protobuf` library version is too old (not 3.5+).
- breaking In VisualDL v2.1.0 and later, the `LogReader` class changed a parameter name from `file_name` to `file_path`. Older code using `file_name` will break.
- deprecated VisualDL officially dropped support for Python 2 on January 1, 2020. While older versions might technically work, Python 3 is now required for full functionality, new features, and continued updates.
Install
-
pip install --upgrade visualdl
Imports
- LogWriter
from visualdl import LogWriter
Quickstart
import random
from visualdl import LogWriter
import os
# Create a log directory
logdir = os.path.join(os.environ.get('VISUALDL_LOGDIR', './visualdl_logs'))
os.makedirs(logdir, exist_ok=True)
# Initialize LogWriter
# The sync_cycle parameter specifies how often data should be written to disk.
logger = LogWriter(logdir=logdir, sync_cycle=1000)
# Log scalar data
with logger.mode("train"):
scalar_writer = logger.scalar("scalars/loss")
for step in range(100):
scalar_writer.add_record(step, random.random() * 10)
with logger.mode("eval"):
scalar_writer = logger.scalar("scalars/accuracy")
for step in range(100):
scalar_writer.add_record(step, random.random())
print(f"VisualDL logs saved to: {logdir}")
print(f"To view, run in your terminal: visualdl --logdir {logdir}")