A compatibility layer for TensorBoard's SummaryWriter to log to Weights & Biases
Project description
wandb_tsbw
A compatibility layer for TensorBoard's SummaryWriter to log to Weights & Biases.
Description
wandb_tsbw provides a drop-in replacement for TensorBoard's SummaryWriter that logs to Weights & Biases (W&B) instead. This allows users to easily migrate from TensorBoard to W&B without changing their existing code.
Installation
pip install wandb_tsbw
Requirements
- Python >= 3.6
- wandb >= 0.12.0
- numpy >= 1.19.0
Usage
Simply replace your TensorBoard import with the wandb_tsbw import:
# Original TensorBoard code:
# from torch.utils.tensorboard import SummaryWriter
# New W&B-based code:
from wandb_tsbw import SummaryWriter
# Rest of your code remains the same
writer = SummaryWriter(log_dir='./runs/experiment_1')
writer.add_scalar('loss', 0.5, global_step=1)
# Pass W&B specific parameters through wandb_kwargs
writer = SummaryWriter(
log_dir='./runs/experiment_1',
wandb_kwargs={
'project': 'my_project',
'entity': 'my_team',
'tags': ['experiment', 'classification'],
'group': 'model_v1'
}
)
Features
The SummaryWriter class implements the same interface as TensorBoard's SummaryWriter but sends all data to W&B. It supports:
- Scalar logging
- Multiple scalars logging
- Histogram logging
- Image logging
- Text logging
- Figure logging (Matplotlib)
- Hyperparameter logging
- PR curve logging
- Embedding visualization
- Audio logging
- Video logging
Differences from TensorBoard
While wandb_tsbw attempts to provide a drop-in replacement for TensorBoard's SummaryWriter, there are some subtle differences:
- W&B requires authentication. Make sure you've run
wandb loginbefore using this package. - W&B has different visualization capabilities, so some visualizations may look different.
- W&B automatically syncs data to their cloud servers, while TensorBoard keeps data locally.
- Some advanced TensorBoard features (like debugging) may not be fully supported.
Example
import torch
import torch.nn.functional as F
from wandb_tsbw import SummaryWriter
import numpy as np
# Initialize the SummaryWriter
writer = SummaryWriter(log_dir='runs/experiment_1')
# Log scalars
for i in range(10):
writer.add_scalar('Loss/train', np.random.random(), i)
writer.add_scalar('Loss/test', np.random.random(), i)
writer.add_scalar('Accuracy/train', np.random.random(), i)
writer.add_scalar('Accuracy/test', np.random.random(), i)
# Log histogram
writer.add_histogram('Conv1.bias', torch.randn(100), 0)
# Log image
img = torch.zeros(3, 100, 100) # C, H, W
img[0] = torch.arange(0, 10000).reshape(100, 100) / 10000
writer.add_image('Example Image', img, 0)
# Log text
writer.add_text('Text Example', 'Hello World!', 0)
# Log hyperparameters
writer.add_hparams(
{'lr': 0.1, 'batch_size': 64},
{'accuracy': 0.9, 'loss': 0.2}
)
# Close the writer
writer.close()
Debugging:
Option 1: Use pytest's command line option
Run pytest with the --trace option to drop into the debugger at the start of each test:
pytest-3 tests/test_writer.py::TestSummaryWriter::test_add_hparams --trace
Option 4: Debug on test failure
You can configure pytest to automatically start the debugger when a test fails:
pytest-3 tests/test_writer.py -v --pdb
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wandb_tsbw-0.1.0.tar.gz.
File metadata
- Download URL: wandb_tsbw-0.1.0.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc3430cd4047b1dbd3d41f056aafafc5e171bea8eb57cca0d2a914574f2e1ec9
|
|
| MD5 |
9f2ca68fa7845b6dced87e39ffa2181a
|
|
| BLAKE2b-256 |
205243cde1544b9f0c179d6c8ea231907a1ef5f0e153cbaf4248697f6891fe8f
|
File details
Details for the file wandb_tsbw-0.1.0-py3-none-any.whl.
File metadata
- Download URL: wandb_tsbw-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4dd1e80efb5663fdb70e85d8f8478c496f948f96df0211f6b02ba5dda5d3ef4a
|
|
| MD5 |
b0f3fe3bcbade852dad634631972a0ae
|
|
| BLAKE2b-256 |
cbece3385254005cd3b2358c8c8cd0372518fbcf1205c2df34d14ec6bba6789d
|