Documentation
Search…
wandb.log
Logs a dictonary of data to the current run's history.
1
log(
2
data: Dict[str, Any],
3
step: int = None,
4
commit: bool = None,
5
sync: bool = None
6
) -> None
Copied!
Use wandb.log to log data from runs, such as scalars, images, video, histograms, plots, and tables.
See our guides to logging for live examples, code snippets, best practices, and more.
The most basic usage is wandb.log({"train-loss": 0.5, "accuracy": 0.9}). This will save the loss and accuracy to the run's history and update the summary values for these metrics.
Visualize logged data in the workspace at wandb.ai, or locally on a self-hosted instance of the W&B app, or export data to visualize and explore locally, e.g. in Jupyter notebooks, with our API.
In the UI, summary values show up in the run table to compare single values across runs. Summary values can also be set directly with wandb.run.summary["key"] = value.
Logged values don't have to be scalars. Logging any wandb object is supported. For example wandb.log({"example": wandb.Image("myimage.jpg")}) will log an example image which will be displayed nicely in the W&B UI. See the reference documentation for all of the different supported types or check out our guides to logging for examples, from 3D molecular structures and segmentation masks to PR curves and histograms. wandb.Tables can be used to logged structured data. See our guide to logging tables for details.
Logging nested metrics is encouraged and is supported in the W&B UI. If you log with a nested dictionary like wandb.log({"train": {"acc": 0.9}, "val": {"acc": 0.8}}), the metrics will be organized into train and val sections in the W&B UI.
wandb keeps track of a global step, which by default increments with each call to wandb.log, so logging related metrics together is encouraged. If it's inconvenient to log related metrics together calling wandb.log({"train-loss": 0.5, commit=False}) and then wandb.log({"accuracy": 0.9}) is equivalent to calling wandb.log({"train-loss": 0.5, "accuracy": 0.9}).
wandb.log is not intended to be called more than a few times per second. If you want to log more frequently than that it's better to aggregate the data on the client side or you may get degraded performance.
Arguments
Text
row
(dict, optional) A dict of serializable python objects i.e str, ints, floats, Tensors, dicts, or any of the wandb.data_types.
commit
(boolean, optional) Save the metrics dict to the wandb server and increment the step. If false wandb.log just updates the current metrics dict with the row argument and metrics won't be saved until wandb.log is called with commit=True.
step
(integer, optional) The global step in processing. This persists any non-committed earlier steps but defaults to not committing the specified step.
sync
(boolean, True) This argument is deprecated and currently doesn't change the behaviour of wandb.log.

Examples:

For more and more detailed examples, see our guides to logging.
Basic usage
1
wandb.log({'accuracy': 0.9, 'epoch': 5})
Copied!
Incremental logging
1
wandb.log({'loss': 0.2}, commit=False)
2
# Somewhere else when I'm ready to report this step:
3
wandb.log({'accuracy': 0.8})
Copied!
Histogram
1
wandb.log({"gradients": wandb.Histogram(numpy_array_or_sequence)})
Copied!
Image
1
wandb.log({"examples": [wandb.Image(numpy_array_or_pil, caption="Label")]})
Copied!
Video
1
wandb.log({"video": wandb.Video(numpy_array_or_video_path, fps=4,
2
format="gif")})
Copied!
Matplotlib Plot
1
wandb.log({"chart": plt})
Copied!
PR Curve
1
wandb.log({'pr': wandb.plots.precision_recall(y_test, y_probas, labels)})
Copied!
3D Object
1
wandb.log({"generated_samples":
2
[wandb.Object3D(open("sample.obj")),
3
wandb.Object3D(open("sample.gltf")),
4
wandb.Object3D(open("sample.glb"))]})
Copied!
Raises
Text
wandb.Error
if called before wandb.init
ValueError
if invalid data is passed
Last modified 3h ago
Copy link